octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

question about defining some handy makefile targets


From: John W. Eaton
Subject: question about defining some handy makefile targets
Date: Wed, 29 Jul 2015 16:58:17 -0400
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Icedove/31.7.0

I often find myself wanting to know what the value of a variable is in Octave's Makefile. Similarly, I sometimes want to clean up or build a set of targets that are listed in some variable. I don't know of an easy way to do these things other than temporarily defining a custom target in a Makefile. If there is some easy way, then let me know and we can probably forget what follows... Otherwise, I'm thinking of defining some makefile targets so that you can (for example) clean or build or show variables like BUILT_DOC_IMAGES or DIRSTAMP_FILES. One way to do that would be to add a series of explicit targets like

  show-BUILT_DOC_IMAGES:
    @echo $(BUILT_DOC_IMAGES)

  clean-BUILT_DOC_IMAGES:
    rm -f $(BUILT_DOC_IMAGES)

  build-BUILT_DOC_IMAGES: $(BUILT_DOC_IMAGES)

Or, perhaps the last two aren't strictly needed because it would be possible to do things like

  rm -f $(make show-BUILT_DOC_IMAGES)
  make $(make show-BUILT_DOC_IMAGES)

Though I also don't see the harm in defining the extra rules if it makes things slightly easier...

With the magic of GNU Make, however, we could define all of these from a list of variable names by doing something like

  TARGET_VARIABLES := BUILT_DOC_IMAGES DIRSTAMP_FILES

  define VARIABLE_RULES
  show-$(1):
    @echo $($(1))
  .phony: show-$(1)
  clean-$(1):
    rm -f $($(1))
  .phony: clean-$(1)
  build-$(1): $($(1))
  .phony: $(1)
  endef

  $(foreach VAR,$(TARGET_VARIABLES),$(eval $(call VARIABLE_RULES,$(VAR))))

and shell completion (at least in bash) still works for these targets, so typing

  make show-<TAB>

will display a list of all the show-VAR targets that are available.

One disadvantage that I see is that the TARGET_VARIABLES list must be maintained manually. Another option would be to define rules like

  show-target-var:
    @echo $($(VAR))

  clean-target-var:
    rm -f $($(VAR))

  build-target-var: $($(VAR))

and then use commands like

  make show-target-var VAR=DIRSTAMP_FILES

then it would be possible to show, clean, or build any set of targets that are listed in a variable.

I suppose both forms could be defined and we could just maintain the TARGET_VARIABLES list for the most interesting sets of files and then the other rules would provide the same actions for more obscure variables like libinterp_octave_value_liboctave_value_la_DEPENDENCIES or whatever.

Would anyone else benefit from having rules like these defined?

jwe



reply via email to

[Prev in Thread] Current Thread [Next in Thread]