【发布时间】:2010-03-06 22:44:32
【问题描述】:
我想在我的项目目录中建立一个 Makefile 系统,以便在其中定义的规则将在其他目录中定义。例如,假设我有一个名为“test”的目录,里面是“test.c”,但我想使用根目录中 Makefile 中定义的规则构建 test.c
这是一个例子
#Makefile (inside base dir)
%.o: %.c
gcc -Wall -c $^
all:
make -C test out.a
#test/Makefile
out.a: test.o
ar rcs $@ $^
#test/test.c
int main() {
return 0;
}
#inside root dir
$make
make -C test
make[1]: Entering directory `test'
cc -c -o test.o test.c
/usr/ucb/cc: language optional software package not installed
make[1]: *** [test.o] Error 1
make[1]: Leaving directory `test'
make: *** [all] Error 2
注意它是如何使用根 makefile 中定义的 gcc 调用 cc 而不是我的规则的。
总而言之,我不想在每个 Makefile 中定义相同的规则
【问题讨论】:
标签: inheritance makefile