c++ - Make a simple makefile generic -
i have simple makefile me compile examples:
ex104: ex104.cpp $(cpp) ex104.cpp $(incs) $(linkflags) $(compileflags) -o ex104 clean: rm -f *.o $(executable)
now, works fine. problem is: need explicitly write rule each of examples, copying following line many, many times:
ex104: ex104.cpp $(cpp) ex104.cpp $(incs) $(linkflags) $(compileflags) -o ex104
is there way generic-ize bit? end command line below build ex252
ex252.cpp
built automatically:
make ex252
fortunately, it's template-only library, have build 1 cpp file, , not need keep track of object files.
make has bunch of default rules , want should works if instead of variables using default 1 flags given.
if version of make not have such default, should add 1 (it correspond gnu make default rule intermediary variables inlined , obsolete 1 removed) :
.cpp: $(cxx) $(cxxflags) $(cppflags) $(ldflags) $(target_arch) $^ $(ldlibs) -o $@
cxx c++ compiler
cxxflags flags c++ compiler
cppflags flags preprocessor (they common between c , c++ in gnu make)
ldflags flags linking
target_arch allows specify target architecture
ldlibs libraries link
Comments
Post a Comment