写了一个文件夹比较多的程序,在写主Makefile的时候,需要进入子文件夹执行make,在这里记录下,自己运行成功的Makefile。
SUBDIRS=directory1 directory2 directory3
RECURSIVE_MAKE= @for subdir in $(SUBDIRS); \
do \
echo "making in $subdir"; \
( cd $subdir && $(MAKE) all -f Makefile -e CC='${CC}' CFLAG='${CFLAG}') || exit 1; \
done
RECURSIVE_CLEAN= @for subdir in $(SUBDIRS); \
do \
echo "cleaning in $subdir"; \
( cd $subdir && $(MAKE) clean -f Makefile) || exit 1; \
done
subdirs:
$(RECURSIVE_MAKE)
all: subdirs
dclean:
$(RECURSIVE_CLEAN)
make是可以带参数的,我这里写的是子文件夹里的Makefile的变量CC和CFLAG都用我这个主Makefile里的设置。