Xman Blog Inside

Friday, September 08, 2006

Make Quick Reference

Inside Makefile:
TARGET: DEPENDENCY LINE OR RULES LINE
COMMAND
COMMAND
...
A command line (with TAB in front) is running in a subshell by itself.
# A comment.
name = text in nameMacro definition.
$ASingle character macro reference.
$(name) or ${name}Macro references.
make -pPrint internally defined macros.
make target "DIR=/dir /dir2"Use DIR defined in command even if you defined DIR in your Makefile!
DIR=/bin make targetUse DIR in Makefile if any, otherwise use DIR=/bin.
make -eShell variables have higher priority than file macro definitions.
FILE=a.c b.c
@echo ${FILE:.c=.o}
a.o b.o
Replace suffix .c by .o. The @ suppress the printing of commands executed.
$@Current target. Use in command line only.
$?List of pre-requisites newer than current target. Use in command line only.
$$@Current target. Use in dependency line only.
$*File name without suffix part. Use in commands in suffix rule only.
$%Name of the .o when target is a library module.
$<The pre-requisite file. Use in commands in suffix rule only.
.SUFFIXES: .o .cSuffixes that make will consider.
.c.o:
${CC} -c $<
Suffix rule. To produce .o from a .c.
t: libm.a(sin.o)Target t depends on sin.o in libm.a. Hence, if sin.o is newer than libm.a, implicit rule replace newer sin.o into libm.a, then create target t.
libm.a :: sin.c
libm.a :: cos.c
Rebuild libm.a using different commands depends on the pre-requisites.
- rm -f *.oIgnore errors in the command rm, hence, errors will not stop the make process.
t: a.c \
b.c
Use '\' to continue with the next line.
.SUFFIXES:
.SUFFIXES: .a .b
.SUFFIXES: .c
1. Clear implicit suffixes. 2. Define .a .b suffixes. 3. Add .c into the suffix list.
.c.a:
true
Override default suffix rule with null command
t:
echo $$HOME
Use $$ in commands for environment variable.
.IGNOREForce make to ignore errors and keep going.
${<D}, ${<F}Pre-requisite file directory, pre-requisite file name.
VPATHView path.
include inc.mkInclude the file inc.mk.
.PRECIOUS: a.x b.xDo not let make deletes files a.x and b.x.
.SILENTDo not echo commands while executing.
.DEFAULT:
echo "hello"
Define a default action.

Reference: C Programming Utility: Managing Projects with make by Andrew Oram and Steve Talbott

Labels: ,

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home