Flat object file directory structure output with GNU Make

前端 未结 5 2338
遥遥无期
遥遥无期 2020-12-13 17:11

I have a C++ small project using GNU Make. I\'d like to be able to turn the following source files:

src/
  a.cpp
  b/
    b.cpp
  c/
    c.cpp
5条回答
  •  一向
    一向 (楼主)
    2020-12-13 17:18

    This is for Win32 mingw32-make. it's works. The most important part is

    -mkdir $(patsubst %/,%,$(dir $@))

    for win32. We need to strip the trailling / for win32.

    GENERATED_DIRS = a b
    
    # Dependency generator function
    mkdir_deps =$(foreach dir,$(GENERATED_DIRS),$(dir)/.mkdir.done)
    
    # Target rule to create the generated dependency.
    # And create the .mkdir.done file for stop continuous recreate the dir
    %/.mkdir.done: # target rule
        -mkdir $(patsubst %/,%,$(dir $@))
        echo $(patsubst %/,%,$(dir $@)) >$@
    
    all: $(mkdir_deps)
        @echo Begin
    
    clean:
        @echo Cleaning
    

提交回复
热议问题