views:

34

answers:

1

I have the following block of code in a makefile:

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

Basically, this is necessitated as I don't my makefile to crash and die if the build directory doesn't exist -- I want it to recreate the missing parts of the directory tree. The nesting is due to the fact that I have a build directory, a tests directory inside the build (for module tests vs. full programs) and then within that tests directory individual directories for tests, each of which need a source, obj, and bin directory. So a lot of stuff to create!

Here's my question. Is there a way to take advantage of makefile "magic" to feed it some single variable like:

PATH=./build/tests/param_test/bin

and have it create all the directories I need with like a one or two liner rather than that humongous if statement?

Thanks in advance!!

+2  A: 
mkdir -p build/tests/param_test/bin

mkdir manual: -p, --parents, no error if existing, make parent directories as needed

Sjoerd
ah. what an obvious answer... thanks... sorry for the silly question... reminds self to read manuals more often (especially since I tell my UG researchers all day to do that)... *'_'*
Jason R. Mick
bonus question @ Sjoerd... can you use wildcards in variable namesfor example if I had files parameter_manager.cpp, parameter_manager_simple.cpp, parameter_manager_namd.cpp, etc... could I do something like`PARAM_FILEs= parameter_manager_*.cpp`??
Jason R. Mick
Nevermind, tested that and it worked :)
Jason R. Mick