Things worth knowing about make
and Makefiles
.
'$
' has to be escaped by doubling it:bla: rm $$(echo "-rf /")
'-
') in front of a command to have make
ignore it's return value:bla: -rm $$(echo "-rf /")
$(OBJECTS) : javac $(subst .class,.java,$@)
FILES = Bla.java Blub.java Wrong.here $(filter %.java,$(FILES)) : javac $@ $(filter %.here,$(FILES)) : echo "Wrong here?!"
targets ...: target-pattern: prereq-patterns ... commands
Sample usage:
objects = foo.o bar.o all: $(objects) $(objects): %.o: %.c $(CC) -c $(CFLAGS) $< -o $@
* recursing paths:
PATH=/a/b/c/d/e/f/g/h PLIST:= define recurse ifneq ($(strip $(shell dirname ${1})),/) $$(eval $$(call recurse,$(shell dirname ${1}))) PLIST+= $(shell dirname ${1}) endif endef all: $(eval $(call recurse,${PATH})) @for i in ${PLIST}; do echo $$i; done
* a more advanced version of the above:
PATH=/a/b/c/d/e/f/g/h ifneq (${REVERSE},) REVERSE:=true endif REVERSE?=false PLIST:= define get_dirname $(strip $(shell dirname ${1})) endef define list_add ifneq (${2},${3}) PLIST += $$(call get_dirname,${1}) endif endef define recurse DNAME:=$$(call get_dirname,${1}) ifneq ($${DNAME},/) $$(eval $$(call list_add,${1},$${REVERSE},true)) $$(eval $$(call recurse,$${DNAME})) $$(eval $$(call list_add,${1},$${REVERSE},false)) endif endef all: $(eval $(call recurse, ${PATH})) @for i in ${PLIST}; do echo $$i; done