0
在链接之前可以让make
检查文件吗?是否有可能让GNU检查文件的存在?
我有一个makefile
系统,顶级Makefile
调用其他子目录,并在其中发出make
。
我的系统的目标是:
- 构建源
- 停止父目录和任何当前的子目录,如果有任何编译错误的版本。
- 链接可执行
- 显示过程中,如果有一个失败的链接阶段的错误是由于缺少归档文件。注意:只有当前子目录级别的构建应显示错误并退出,但整个过程应继续并移至下一个子目录。在现有存档文件在链接阶段
- 显示一个错误,如果出现故障,由于未定义符号
所以现在我有我的孩子Makefile
做一个“如果构建失败,那么家长会失败,如果链路出现故障,那么父母继续”通过诸如此类的事情:
#build the source code
$(CC) -o [email protected] -c $<
#link the executable
-$(CC) $^ -o [email protected] $(LIB) #the - allows the parent to continue even if this fails
这作品,但是这将允许任何链接错误要通过,我只想让父母继续如果档案$(LIB)
不存在。
澄清:鉴于以下目录结构:
C
├── Makefile
└── childdir
├── a.c // This source file uses functions from idontexist.a
└── Makefile
顶层makefile是:
.PHONEY: all
all:
@echo "Start the build!" # I want to see this always
$(MAKE) --directory=childdir # then if this works, or fails because the
# .a is missing
@echo "Do more stuff!" # then I want to see this
的生成文件在childdir/
是:
LIB=idontexist.a #This doesn't exist and that's fine
EXE=target
SRC=a.c
OBJS=$(patsubst %.c,%.o,$(SRC))
%.o : %.c
$(CC) -o [email protected] -c $< #If this fails, I want the ENTIRE build to fail, that's
# good, I want that.
.PHONEY: all
all: $(EXE)
$(EXE):$(OBJS)
-$(CC) $^ -o [email protected] $(LIB) #If this fails, because $(LIB) is missing
# I don't really care, if it's because we can't find
# some symbol AND the file DOES exist, that's a problem