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 $? [email protected]
	chmod 755 [email protected]
${TARGET_DIR}/test.py: test.py
	[ -d ${TARGET_DIR} ] || mkdir -p ${TARGET_DIR}
	cp -p $? [email protected]
	chmod 755 [email protected]
${TARGET_DIR}/test.py.sh: test.py.sh
	[ -d ${TARGET_DIR} ] || mkdir -p ${TARGET_DIR}
	cp -p $? [email protected]
	chmod 755 [email protected]
${TARGET_DIR}/test.pl: test.pl
	[ -d ${TARGET_DIR} ] || mkdir -p ${TARGET_DIR}
	cp -p $? [email protected]
	chmod 755 [email protected]
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 开发环境中都在使用,已经成为一种工程的编译方法

Makefile

01 src := $(shell ls *.c) /*把当前目录下所有c源代码赋给变量src*/

02 obj := $(patsubst %.c,%.o,$(src)) /*调用makefile 中的函数patsubst, 用.o文件代替.c文件*/

03

04 test: $(objs)

05 gcc -o [email protected] $^

06

07 %.o:%.c

08 gcc -c -o [email protected] $<

09

10 clean:

11 rm -f test *.o

上述Makefile中的“[email protected]", "$^", "$<" 称为自动变量。

Linux环境下的make和makefile详解

相关文章:

  • 2021-10-12
猜你喜欢
  • 2021-04-06
相关资源
相似解决方案