Makefile notes

Checking tabs:
cat -v -t -e makefile

Macro substitution:
SRCS = defs.c redraw.c calc.c
...
ls ${SRCS:.c=.o}
result: calc.o defs.o redraw.o
Second string can be nothing too to truncate

Suffix Rule: default begavior for a suffix:
.SUFFIXES : .o .c .s

.c.o :
$(CC) $(CFLAGS) -c $<
.s.o :
$(AS) $(ASFLAGS) -o $@ $<

$< is what triggered (only valid in suffixes)

Forcing rebuilds:
all :
make enter testex "CFLAGS=${CFLAGS}" "FRC=${FRC}"

enter : ${FRC}
make ${ENTER_OBJS} "CFLAGS=${CFLAGS}" "FRC=${FRC}"
${CC} -o $@ ${ENTER_OBJS} ${LIBRARIES}

testex : ${FRC}
make ${TESTEX_OBJS} "CFLAGS=${CFLAGS}" "FRC=${FRC}"
${CC} -o $@ ${TESTEX_OBJS} ${LIBRARIES}

force_rebuild:
[nothing here]

Then normal "make all" does normal. "make all FRC=force_rebuild" will do all

Debugging make files:
Try "make -d"

Misc notes:
A line starting with a hyphen ignores errors resulting from execution of that command

Macros:
$? = List of prereqs that have changed
$@ = Name of current target, except for libraries, which it is the lib name
$$@ = Name of current target if used AFER colon in dependency lines
$< = Name of current prereq only in suffix rules.
$* = The name (no suffix) of the current prereq that is newer. Only for suffixes.
$% = The name of the corresponding .o file when the current target is a library
Macro Mods: (not all makes support)
D = directory of any internal mac, ex: ${@D}
F = File portion of any internal except $?

Special Tagets:
.DEFAULT : Executed if make cannot find any descriptions or suffix rules to build.
.IGNORE : Ignore error codes, same as -i option.
.PRECIOUS : Files for this target are NOT removed if make is aborted.
.SILENT : Execute commands but do not echo, same as -s option.
.SUFFIXES : See above. 

Comments

No comments.