一个 Makefile 实例,用于编译各多个子目录测试代码

时间:2021-08-23 12:46:03
是一个统一编译各子目录下测试代码的Makefile, 写的时候在语法上花了不少时间,放在这里,留作纪念:P

SUBDIRS := `find -maxdepth 1 -type d | sed "/.svn/d" | sed "1d"| sed "s/.////g"`

OUTPUT  := ../bin

SUFFIX  := _test

 

.PHONY: all clean distclean install $(SUBDIRS)

all:

    echo $(SUBDIRS)

    for subdir in $(SUBDIRS); do /

        $(MAKE) -C $$subdir; /

    done

clean:

    for subdir in $(SUBDIRS); do /

        $(MAKE) -C $$subdir clean; /

    done

install: all

    for subdir in $(SUBDIRS); do /

        SUFFIX=$(SUFFIX);/

        cp $$subdir/$$subdir$$SUFFIX $(OUTPUT)/ ; /

    done

distclean: clean

    rm -f $(OUTPUT)/*