Makefile 605 B

1234567891011121314151617181920212223242526272829
  1. DIR_BASE = $(shell pwd)
  2. #当前目录SRC
  3. SRC = $(wildcard *.c)
  4. #当前.o 文件目录改成$(BUILD_DIR)/*.o目录
  5. OBJ = $(patsubst %.c, $(BUILD_DIR)/%.o,$(SRC))
  6. # OBJ := $(SRC:.c=.o)
  7. # OBJ := $(OBJ:%=$(BUILD_DIR)/%)
  8. #源文件目录
  9. SUB_DIR = $(shell find $(DIR_BASE) -maxdepth 1 -mindepth 1 -type d)
  10. .PHONY: all $(SUB_DIR)
  11. all : $(OBJ) sub_mudule
  12. #.c 编译生成.o
  13. $(OBJ):$(BUILD_DIR)/%.o:%.c
  14. $(DEBUG) $(CC) $(CFLAGS) $(DEFINES) $(INCLUDES) -c $< -o $@
  15. sub_mudule:
  16. ifneq ($(SUB_DIR),)
  17. @for dir in $(SUB_DIR); do \
  18. if [ -e "$$dir/Makefile" ]; then \
  19. $(MAKE) -C $$dir; \
  20. fi \
  21. done
  22. endif