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
Makefilechilddir/
は次のとおりです。
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