在链接之前是否可以让make
检查文件?
我有一个makefile
系统,其顶级Makefile
会调用其他子目录并在其中发出make
。
我的系统的目标是:
所以现在我让我的孩子Makefile
做了“如果构建失败,那么父母失败,如果链接失败,那么父母继续”有点事情:
#build the source code
$(CC) -o $@ -c $<
#link the executable
-$(CC) $^ -o $@ $(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/
的Makefile是:
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 $@ -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 $@ $(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
答案 0 :(得分:0)
您可以使用:
LIB = $(wildcard idontexist.a)
如果存在,将扩展为文件名,如果不存在,则为空。