[skill][makefile] makefile 常用內容記錄
阿新 • • 發佈:2017-06-06
simple ams rec ould exec tom match cnblogs via
其實,makefile有點復雜。
文檔看了又看,還是要經常翻,做個記錄備忘 :)
1. 隱含命令 implicit rules
與 implicit rule 相對應的有 pattern rules 和 suffix rules
Compiling C programs n.o is made automatically from n.c with a recipe of the form ‘$(CC) $(CPPFLAGS) $(CFLAGS) -c’. Compiling C++ programs n.o is made automatically from n.cc, n.cpp, or n.C with a recipe of the form ‘$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c’.
We encourage you to use the suffix ‘.cc’ forC++ source files instead of ‘.C’.
Linking a single object file n is made automatically from n.o by running the linker (usually called ld) via the C compiler. The precise recipe
used is ‘$(CC) $(LDFLAGS) n.o $(LOADLIBES) $(LDLIBS)’. This rule does the right thing for a simple program with only one source file. It will also dothe right thing
if there are multiple object files (presumably coming from various other source files), one of which has a name
matching that of the executable file. Thus, x: y.o z.o when x.c, y.c and z.c all exist will execute: cc -c x.c -o x.o cc -c y.c -o y.o cc -c z.c -o z.o cc x.o y.o z.o -o x rm-f x.o rm -f y.o rm -f z.o In more complicated cases, such as when there is no object file whose name derives from the executable file name,
you must write an explicit recipe for linking.
CFLAGS Extra flags to give to the C compiler. CXXFLAGS Extra flags to give to the C++ compiler. CPPFLAGS Extra flags to give to the C preprocessor and programs that use it (the C and Fortran compilers). LDFLAGS Extra flags to give to compilers when they are supposed to invoke the linker, ‘ld’, such as -L.
Libraries (-lfoo) should be added to the LDLIBS variable instead. LDLIBS Library flags or names given to compilers when they are supposed to invoke the linker, ‘ld’.
LOADLIBES is a deprecated (but still supported) alternative to LDLIBS. Non-library linker flags,
such as -L, should go in the LDFLAGS variable.
Canceling Implicit Rules
定義一個空的 recipe 就可以取消隱含命令:
%.o : %.s
生成 *.o 的隱式命令,就被取消了。
[skill][makefile] makefile 常用內容記錄