- 论坛徽章:
- 0
|
foo.h
--------------------------------------------------------------------------------------------------------------
#ifndef FOO_H
#define FOO_H
void foo();
#endif
foo.c
--------------------------------------------------------------------------------------------------------------
#include <stdio.h>
#include "foo.h"
void foo()
{
printf("Makefile\n" ;
}
main.c
--------------------------------------------------------------------------------------------------------------
extern void foo();
int main()
{
foo();
return 0;
}
makefile
######################################################################
CC=gcc
RM=rm
RMFLAGS=-rf
######################################################################
.PHONY:clean all
######################################################################
DIR_BIN=bin
DIR_OBJ=obj
DIR_DEP=dep
DIRS=${DIR_BIN} ${DIR_OBJ} ${DIR_DEP}
BIN=simple
BIN:=${addprefix ${DIR_BIN}/,${BIN}}
SRC=${wildcard *.c}
OBJ=${SRC:.c=.o}
OBJ:=${addprefix ${DIR_OBJ}/,${OBJ}}
DEP=${SRC:.c=.dep}
DEP:=${addprefix ${DIR_DEP}/,${DEP}}
######################################################################
all {BIN}
-include ${DEP}
${DIRS}:
mkdir $@
${BIN} {DIR_BIN} ${OBJ}
${CC} -o $@ ${filter %.o,$^}
${DIR_OBJ}/%.o {DIR_OBJ} %.c
${CC} -o $@ -c ${filter %.c,$^}
${DIR_DEP}/%.dep {DIR_DEP} %.c
${CC} -E -MM ${CPPFLAGS} $< > $@.$$$$;\
sed 's,\(.*\)\.o[:]*,\1.o $@:,g' < $@.$$$$ > $@;\
${RM} ${RMFLAGS} $@.$$$$
clean:
rm ${RMFLAGS} ${DIRS}
程序及makefile文件均来自《驾驭makefile》,但是在我的{virtualbox Fedora17, gcc4.7, make3.82}里结果却是这样的:
mkdir dep
gcc -E -MM dep > dep/main.dep.$$;\
sed 's,\(.*\)\.o[:]*,\1.o dep/main.dep:,g' < dep/main.dep.$$ > dep/main.dep;\
rm -rf dep/main.dep.$$
gcc -E -MM dep > dep/foo.dep.$$;\
sed 's,\(.*\)\.o[:]*,\1.o dep/foo.dep:,g' < dep/foo.dep.$$ > dep/foo.dep;\
rm -rf dep/foo.dep.$$
gcc -E -MM dep > dep/main.dep.$$;\
sed 's,\(.*\)\.o[:]*,\1.o dep/main.dep:,g' < dep/main.dep.$$ > dep/main.dep;\
rm -rf dep/main.dep.$$
gcc -E -MM dep > dep/foo.dep.$$;\
sed 's,\(.*\)\.o[:]*,\1.o dep/foo.dep:,g' < dep/foo.dep.$$ > dep/foo.dep;\
rm -rf dep/foo.dep.$$
。。。
这样一直循环下去,求救各位,是什么原因呢? |
|