Makefile:编译src和测试目录时出错

时间:2023-02-06 12:42:51
LIB_DIRS = abcd xyz pqr mnq ghj

SER_DIRS = klm

.PHONY: default build lib service clean distclean

TEST_DIRS = abcd xyz pqr

test_lib :
        for dir in $(TEST_DIRS); do \
                $(MAKE) -C $$dir; \
        done

TESTS := $(addprefix TEST_, $(TEST_DIRS))

run : $(TESTS)

TEST_%:
        ./$*/test/$*_test --log_level=message

test :  test_lib run

default: all

all: build lib service

lib: 
        for dir in $(LIB_DIRS); do \
                $(MAKE) -C $$dir; \
        done

Each LIB_DIR has a src and test directory. With the make all command only src directories files should get compiled. But in my case the test directories files also get compiled along with src directories. While with make test command only test directories files get compiled. Since test files are dependent on src files, errors occur with make all for test files. Can some one help me resolve this?

每个LIB_DIR都有一个src和test目录。使用make all命令只能编译src目录文件。但在我的情况下,测试目录文件也与src目录一起编译。使用make test命令时,只有测试目录文件被编译。由于测试文件依赖于src文件,因此make all for test files会出错。有人可以帮我解决这个问题吗?

1 个解决方案

#1


Well, here is a starter:

好吧,这是一个启动者:

You should provide Makefiles in each directory that know how to build lib and test. Obviously test depends on lib.

您应该在每个知道如何构建lib和test的目录中提供Makefile。显然测试取决于lib。

You could then change your lines to

然后你可以改变你的线路

lib: 
    for dir in $(LIB_DIRS); do \
            $(MAKE) -C $$dir; \
    done

to

lib: 
    for dir in $(LIB_DIRS); do \
            $(MAKE) -C $$dir lib; \ #<- notice the target
    done

and similar for test_lib. Otherwise, it is not possible with the current set of variables since the sub-make does not know what to do.

和test_lib类似。否则,使用当前变量集是不可能的,因为sub-make不知道该怎么做。

#1


Well, here is a starter:

好吧,这是一个启动者:

You should provide Makefiles in each directory that know how to build lib and test. Obviously test depends on lib.

您应该在每个知道如何构建lib和test的目录中提供Makefile。显然测试取决于lib。

You could then change your lines to

然后你可以改变你的线路

lib: 
    for dir in $(LIB_DIRS); do \
            $(MAKE) -C $$dir; \
    done

to

lib: 
    for dir in $(LIB_DIRS); do \
            $(MAKE) -C $$dir lib; \ #<- notice the target
    done

and similar for test_lib. Otherwise, it is not possible with the current set of variables since the sub-make does not know what to do.

和test_lib类似。否则,使用当前变量集是不可能的,因为sub-make不知道该怎么做。