User:JoeyArmstrong/makefiles/howto

From MozillaWiki
Jump to: navigation, search

String Formatting

http://www.gnu.org/software/make/manual/html_node/Text-Functions.html

  • Comma separated list
<code>
values = a
ifdef b
  values += v
endef

null=#
SPACE=$(null) $(null)
comma=,
formatted = $(subst $(SPACE),$(comma),$(values))
</code>
  • Conditional logic for files
<code>
files = $(wildcard files/of/interest/*)
logs = $(findstring .log,$(files))

targets =$(null)
targets += $(if $(logs),digest_logs)

digest_logs:
   echo "Logfiles to process: $(logs)"
</code>


Problems

  • On windows care should be taken when shell commands are used to gather file dependencies. Windows paths that contain a drive letter will strongly resemble multiple make targets.
<code>
deps = c:\foo\bar0 c:\foo\bar1 c:\foo\bar2

$(deps):
       echo $@
</code>