嵌套Makefile问题解决一例
先看一下目录结构
总控Makefile如下:
1: CFLAGS=-Wall
2: CC=gcc
3:
4:
5: SUBDIRS=server client
6:
7: export CFLAGS CC
8:
9:
10:
11: all:$(SUBDIRS)
12:
13: $(SUBDIRS):
14: make -C $@
15:
16:
17: clean:
18: $(RM) server/*.o server/server
19: $(RM) client/*.o client/client
20: .PHONY:clean
另外两个Makefile分别如下:
1: server:server.o
2: $(CC) $(CFLAGS) $^ -o $@
3:
4: server.o:server.c
5: $(CC) $(CFLAGS) -c $^ -o $@
1: client:client.o
2: $(CC) $(CFLAGS) $^ -o $@
3:
4: client.o:client.c
5: $(CC) $(CFLAGS) -c $^ -o $@
当执行总控Makefile时,出现如下现象:
无法实现程序的编译。
解决方法:
方法一、将总控Makefile中的$(SUBDIRS)中的两个路径都声明为 伪目标。
1: CFLAGS=-Wall
2: CC=gcc
3:
4:
5: SUBDIRS=server client
6:
7: export CFLAGS CC
8:
9:
10:
11: all:$(SUBDIRS)
12:
13: $(SUBDIRS):
14: make -C $@
15:
16:
17: clean:
18: $(RM) server/*.o server/server
19: $(RM) client/*.o client/client
20: .PHONY:clean server client
再次指向make
方法二、将总控Makefile作如下修改
1: CFLAGS=-Wall
2: CC=gcc
3:
4:
5: SUBDIRS=server client
6:
7: export CFLAGS CC
8:
9:
10:
11: all:$(SUBDIRS)
12:
13: $(SUBDIRS):pp
14: make -C $@
15: pp:
16:
17: clean:
18: $(RM) server/*.o server/server
19: $(RM) client/*.o client/client
20: .PHONY:clean
本文来自博客园,作者:dolinux,未经同意,禁止转载