make wildcard subdirectory targets

后端 未结 3 891
南笙
南笙 2021-02-02 11:57

I have a \"lib\" directory in my applications main directory, which contains an arbitrary number of subdirectories, each having its own Makefile.

I would like to have a

3条回答
  •  隐瞒了意图╮
    2021-02-02 12:27

    The following will work with GNU make:

    LIBS=$(wildcard lib/*)
    all: $(LIBS)
    .PHONY: force
    $(LIBS): force
      cd $@ && pwd
    

    If there might be something other than directories in lib, you could alternatively use:

    LIBS=$(shell find lib -type d)
    

    To address the multiple targets issue, you can build special targets for each directory, then strip off the prefix for the sub-build:

    LIBS=$(wildcard lib/*)
    clean_LIBS=$(addprefix clean_,$(LIBS))
    all: $(LIBS)
    clean: $(clean_LIBS)
    .PHONY: force
    $(LIBS): force
      echo make -C $@
    $(clean_LIBS): force
      echo make -C $(patsubst clean_%,%,$@) clean
    

提交回复
热议问题