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