0

メイクファイルに次のコード ブロックがあります。

param_test_dir:

    @if test -d $(BUILD_DIR); then \
        echo Build exists...; \
    else \
    echo Build directory does not exist, making build dir...; \
mkdir $(BUILD_DIR); \
fi
@if test -d $(TEST_DIR); then \
    echo Tests exists...; \
else \
    echo Tests directory does not exist, making tests dir...; \
mkdir $(TEST_DIR); \
fi
@if test -d $(TEST_DIR)/param_unit_test; then \
    echo Param unit test directory exists...; \
else \
    echo Param unit test directory does \
    not exist, making build dir...; \
    mkdir $(TEST_DIR)/param_unit_test; \
fi
@if test -d $(TEST_DIR)/param_unit_test/source; then \
    echo Param unit test source directory exists...; \
else \
    echo Param unit test source directory does \
    not exist, making build dir...; \
    mkdir $(TEST_DIR)/param_unit_test/source; \
fi
@if test -d $(TEST_DIR)/param_unit_test/obj; then \
    echo Param unit test object directory exists...; \
else \
    echo Param unit test object directory does \
    not exist, making object dir...; \
    mkdir $(TEST_DIR)/param_unit_test/obj; \
fi
@if test -d $(TEST_DIR)/param_unit_test/bin; then \
    echo Param unit test executable directory exists...; \
else \
    echo Param unit test executable directory does \
    not exist, making executable dir...; \
    mkdir $(TEST_DIR)/param_unit_test/bin; \
fi

基本的に、ビルドディレクトリが存在しない場合にメイクファイルがクラッシュして死ぬことはないので、これは必要です。ディレクトリツリーの欠落部分を再作成したいのです。入れ子になっているのは、ビルド ディレクトリ、ビルド内のテスト ディレクトリ (モジュール テストと完全なプログラムの場合)、およびそのテスト ディレクトリ内にテスト用の個々のディレクトリがあり、それぞれにソース、obj、およびが必要なためです。ビンディレクトリ。そのため、作成するものがたくさんあります。

これが私の質問です。メイクファイルの「魔法」を利用して、次のような単一の変数を供給する方法はありますか?

PATH=./build/tests/param_test/bin

その巨大な if ステートメントではなく、1 つまたは 2 つのライナーのように、必要なすべてのディレクトリを作成しますか?

前もって感謝します!!

4

2 に答える 2

3
mkdir -p build/tests/param_test/bin

mkdir manual : -p、--parents、存在する場合はエラーなし、必要に応じて親ディレクトリを作成

于 2010-07-08T19:15:08.100 に答える
0

移植可能なメイクファイル (Windows でも動作するものなど) を作成する必要がある場合は、すべてのプラットフォームで同じコマンドを使用できるソリューションを検討してください。@Sjoerd によるソリューションは unixish マシンでは問題なく動作しますが、Windows ではわずかな違いがあります(XP、Vista、および Windows 7 で試しました)。

# Unix solution
mkdir -p build/tests/param_test/bin
# Windows solution
mkdir build\tests\param_test\bin

オプションはありません-p。バックスラッシュが必要です。

ディレクトリを再帰的に作成しますが、ディレクトリが既に存在する場合は文句を言います。苦情を抑制する「サイレント」オプションはありません。

私が使用しているのは、Perl ワンライナーを使用したソリューションです。システムの他のビルドステップでは Perl が必要なため、これは移植可能です。YMMV。

perl "-MFile::Path" -e "mkpath 'build/tests/param_test/bin'"

Perl では、Windows でもスラッシュを使用できることに注意してください。

于 2010-12-21T11:20:00.017 に答える