makefile syntax
- dependencies (相依性項目)
- one target (目標項目)
- some source code files
- (target), (semicolon), (space or tab), ....., (source code files), (space or tab), .....
- e.g. all: myapp myapp.l
- rules (法則)
- the rules illustrate how to generate a target
- (tab)
- the rules muse be on the same line
- comment (註解)
- (#)
- macro (巨集)
- define the macro => MACRONAME = value
- access the macro => $(MACRONAME), ${MACRONAME}
- -
- make will ignore the error
- e.g. -mkdir
- e.g. -rm -r
- @
- make will not output the executed command on standard output
- #這是makefile的格式(註解)
[target]: [dependency] [dependency]
[TAB][rule]
[TAB][rule]
[target]: [dependency]
[TAB][rule]
make options
-k : 會讓make再遇到錯誤之時,仍然繼續執行而不會停在第一個問題點。可以利用這個選項找出發生問題的原始碼檔案。
-n : 告訴make只列出要進行的工作,而不會真正去執行它。
-f : tell the make to use the as a makefile. Otherwise, the make will use the makefile, Makefile (recommend).
-p : 要求 make 印出內建法則
-j3 : use the 3 cores
Automatic Varaiables
$@ : The name of the current target
$% : The filename element of an archive member specification
$<: first="" he="" name="" nbsp="" of="" p="" prerequisite="" the="">
$?: The names of all prerequisites that are newer than the target, separated by spaces,代表須要重建(被修改)的相依性項目
$^: The names of all prerequisites, separated by spaces. This is list has duplicated names removed.
$+: Similar to $^, except $+ includes duplicateds.. This variable was created for specific situations such as arguments to linkers where duplicated values have meaning.
$*: The stem of the target filename. A stem is typically a filename without its suffix. Current dependencies without the extension (副檔名)
- define the marcro : 1) make CC=c89 2) make "CC = c89"
- Use the all as the first target in makefile
- all (target)
- install (target)
- uninstall (target)
- clean (target)
GNU gcc
gcc -MM : generate a dependency list to make
Conventional Macros (common built in rules of makefiles)
typing "make −p" to print out the defaults
AR | Archive−maintaining program; default is `ar'. |
AS | Program for compiling assembly files; default is `as'. |
CC | Program for compiling C programs; default is `cc'. |
CO | Program for checking out files from RCS; default is `co'. |
CXX | Program for compiling C++ programs; default is `g++'. |
CPP | Program for running the C preprocessor, with results to standard output; default is `$(CC) -E'. |
ARFLAGS | Flags to give the archive-maintaining program; default is `rv'. |
ASFLAGS | Extra flags to give to the assembler when explicitly invoked on a `.s' or `.S' file. |
CFLAGS | Extra flags to give to the C compiler. |
CXXFLAGS | Extra flags to give to the C compiler. |
COFLAGS | Extra flags to give to the RCS co program. |
CPPFLAGS | Extra flags to give to the C preprocessor and programs, which use it (such as C and Fortran compilers). |
Conditional Directives
- ifeq
- ifneq
- ifdef
- ifndef
- else
- endif
e.g.
ifeq (arg1, arg2) ifeq 'arg1' 'arg2' ifeq "arg1" "arg2" ifeq "arg1" 'arg2' ifeq 'arg1' "arg2"
相關文件
- Linux 程式設計教學手冊 CH9
- 撰寫Makefile教學
- Makefile語法簡介
- 利用Autotools來建立Makefile檔案
- 實戰Makefile.am
- TutorialPoint Quick Guide
- http://www.tutorialspoint.com/makefile/makefile_quick_guide.htm
- Autotools Tutorial for Beginners