Sources from subdirectories in Makefile

This should do it: SOURCES = $(wildcard *.cpp) $(wildcard */*.cpp) If you change you mind and want a recursive solution (i.e. to any depth), it can be done but it involves some of the more powerful Make functions. You know, the ones that allow you to do things you really shouldn’t. EDIT: Jack Kelly points … Read more

Change a make variable, and call another rule, from a recipe in same Makefile?

Use a target-specific variable There is one more special feature of target-specific variables: when you define a target-specific variable that variable value is also in effect for all prerequisites of this target, and all their prerequisites, etc. (unless those prerequisites override that variable with their own target-specific variable value). TEXENGINE=pdflatex pdflatex: echo the engine is … Read more

Append compile flags to CFLAGS and CXXFLAGS while configuration/make

You almost have it right; why did you add the semicolon? To do it on the configure line: ./configure CFLAGS=’-g -O2 -w’ CXXFLAGS=’-g -O2 -w’ To do it on the make line: make CFLAGS=’-g -O2 -w’ CXXFLAGS=’-g -O2 -w’ However, that doesn’t really remove consider all warnings as errors; that removes all warnings. So specifying … Read more

What does $$@ and the pipe symbol in Makefile stand for?

Suppose you were writing an ordinary rule: $(DEST_DIR)/foo : $(SOURCE_DIR)/foo cp $(SOURCE_DIR)/foo $(DEST_DIR)/foo That works, but the redundancy is troublesome. Sooner or later you’ll change $(DEST_DIR)/foo in the preq but forget to change it in the rule. And the rule is hard to read. So we put in an automatic variable: $(DEST_DIR)/foo : $(SOURCE_DIR)/foo cp … Read more

When to use space or tab in Makefile?

You have to understand that a makefile is really written in two completely different “languages”, in one file. Recipes (the commands that run compilers, echo, etc.) are written in shell script syntax. The rest of the makefile that is not in a recipe is written in makefile syntax. In order for make to tell the … Read more