|-- Makefile
|-- test1
| |-- Makefile
| |-- bin
| | `-- test
| |-- hello.o
| |-- include
| | `-- hello.h
| `-- src
| `-- hello.c
`-- test2
|-- Makefile
|-- bin
| `-- test
|-- hello.o
|-- include
| `-- hello.h
|-- obj
`-- src
`-- hello.c
根目录下的Makefile文件调用test2中的Makefile文件:根目录下的Makefile文件
SUBDIR = ./test2
MAKE = make
subsystem:
cd $(SUBDIR) && $(MAKE)
all: ./bin/test
CC = gcc
INCLUDE = ./include
vpath %.c ./src
vpath %.h ./include
./bin/test: hello.o
$(CC) -o $@ $^
hello.o: hello.c hello.h
$(CC) -c $< -I$(INCLUDE)
.PHONY: clean
clean:
-rm *.o
本文介绍了一个使用Makefile组织和构建子目录项目的实例。通过根目录下的Makefile调用子目录(test2)中的Makefile来完成项目的编译流程。文章详细展示了Makefile配置和依赖项管理的具体做法。
1984

被折叠的 条评论
为什么被折叠?



