CC=g++
ifdef VERBOSE
AT=
else
AT=@
endif
FILES=$(foreach dir,$(DIRS),$(wildcard $(dir)/Makefile))
#export CPPSRC := $(foreach dir,$(SOURCE_DIR),$(wildcard $(dir)/*.cpp))
#SOURCES = $(foreach d,$(SRCDIRS),$(wildcard $(addprefix $(d)/*,$(SRCEXTS))))
samples=$(FILES)
.PHONY:all clean help
all:
$(AT)$(foreach sample, $(samples), $(MAKE) -C $(sample);)
clean:
$(AT)$(foreach sample, $(samples), $(MAKE) clean -C $(sample);)
help:
$(AT)echo "Sample building help menu."
$(AT)echo "Samples:"
$(AT)$(foreach sample,$(samples), echo "\t$(sample)";)
$(AT)echo "Commands:"
$(AT)echo "all - build all samples."
$(AT)echo "clean - clean all samples."
.PHONY: test
#mkdir -p ddd;
test:
for i in ./* ; do\
if [ -d $$i ]; then\
echo "$$i";\
echo `basename $$i`;\
fi ;\
done
echo "done";
.PHONY: show
SRC = $(wildcard *.c)
#这里递归遍历3级子目录
SDIRS := $(shell find . -maxdepth 5 -type d)
#这里循环遍历目录的cpp文件
SFILES = $(foreach dir,$(SDIRS),$(wildcard $(dir)/Makefile))
#SFILES = $(foreach dir,$(SDIRS),$(wildcard $(dir)/*.cpp))
#$(foreach var text commond)
#var:局部变量
#text:文件列表,空格隔开,每一次取一个值赋值为变量var
#commond:对var变量进行操作(一般会使用var变量,不然没意义),每次操作结果都会以空格隔开,最后返回空格隔开的列表。
#SRC_EXT = c
#SRC_PATH = test
#rwildcard = $(foreach d, $(wildcard $1*), $(call rwildcard,$d/,$2) \
$(filter $2, $d))
#SOURCES := $(call rwildcard, $(SRC_PATH), %.$(SRC_EXT))
#all:
# @echo "SOURCES=$(SOURCES)"
show:
@echo $(foreach nv, $(SFILES), $(nv))
$(AT)$(foreach nv, $(SFILES), $(MAKE) clean -C $(nv);)
.PHONY: cleanall
SUBDIRS = $(shell find . * -type d | grep -v "\.")
cleanall:
@for subdir in $(SUBDIRS); do $(MAKE) -C $$subdir clean; done
.PHONY:makeall
makeall:
@for subdir in $(SUBDIRS); do $(MAKE) -C $$subdir; done