1.
TARGET_DIR=../build_tmp/test/
all:
build: ${TARGET_DIR}/test_makefile ${TARGET_DIR}/test.py ${TARGET_DIR}/test.sh ${TARGET_DIR}/test.pl
${TARGET_DIR}/test_makefile: test_makefile
[ -d ${TARGET_DIR} ] || mkdir -p ${TARGET_DIR}
cp -p $? $@
chmod 755 $@
${TARGET_DIR}/test.py: test.py
[ -d ${TARGET_DIR} ] || mkdir -p ${TARGET_DIR}
cp -p $? $@
chmod 755 $@
${TARGET_DIR}/test.py.sh: test.py.sh
[ -d ${TARGET_DIR} ] || mkdir -p ${TARGET_DIR}
cp -p $? $@
chmod 755 $@
${TARGET_DIR}/test.pl: test.pl
[ -d ${TARGET_DIR} ] || mkdir -p ${TARGET_DIR}
cp -p $? $@
chmod 755 $@
clean:
rm -f ${TARGET_DIR}/test_makefile
rm -f ${TARGET_DIR}/test.py
rm -f ${TARGET_DIR}/test.sh
rm -f ${TARGET_DIR}/test.pl
注意:
Makefile是一种配置文件, Makefile 一个工程中的源文件不计数,其按类型、功能、模块分别放在若干个目录中,makefile定义了一系列的规则来指定,哪些文件需要先编译,哪些文件需要后编译,哪些文件需要重新编译,甚至于进行更复杂的功能操作,因为 makefile就像一个Shell脚本一样,其中也可以执行操作系统的命令。在Makefile 中可以使用系统shell所提供的任何命令来完成想要的工作。在绝大多数的IDE 开发环境中都在使用,已经成为一种工程的编译方法。
01 src := $(shell ls *.c) /*把当前目录下所有c源代码赋给变量src*/
02 obj := $(patsubst %.c,%.o,$(src)) /*调用makefile 中的函数patsubst, 用.o文件代替.c文件*/
03
04 test: $(objs)
05 gcc -o $@ $^
06
07 %.o:%.c
08 gcc -c -o $@ $<
09
10 clean:
11 rm -f test *.o
上述Makefile中的“$@", "$^", "$<" 称为自动变量。