Saturday, December 31, 2016

Useful Makefile Tricks

An experienced c/c++ programmer should be able to write a concise and elegant makefile. Here are my personal study notes.


String Pattern Substitution

Sometimes I want to substitute part of a file name, or I want to filter out some file names entirely. "patsubst" is very handy.  Here is an excellent document.

Example: to filter out all "unit test" object files from obj files, we find pattern match of "_test.o" and replace the matched filename with "", effectively removing the file name.

OBJS := $(patsubst %_test.o, , $(OBJS_ALL))




No comments:

Post a Comment