Sources from subdirectories in Makefile

后端 未结 7 1320
无人共我
无人共我 2020-11-29 19:06

I have a C++ library built using a Makefile. Until recently, all the sources were in a single directory, and the Makefile did something like this

SOURCES = $(w

7条回答
  •  再見小時候
    2020-11-29 19:51

    You can use several rules in wildcard:

    SOURCES := $(wildcard *.cpp */*.cpp)
    

    if you need more depth:

    SOURCES := $(wildcard *.cpp */*.cpp */*/*.cpp */*/*/*.cpp)
    

    Unfortunately, and unlike what we sometimes read, glob (**) is not supported by makefile and will be interpreted as normal wildcard (*).

    For example **/*.cpp match dir/file.cpp but neither file.cpp nor dir/sub/file.cpp.

    If you need infinite depth use shell:

    SOURCES := $(shell find . -name "*.cpp")
    

提交回复
热议问题