#
# 实现要点: (1) cmd_cc_c_o 使能使用 '=' 定义
# (2) 所有的.PHONY 目标需要使用 PHONY 变量同步定义
CC := gcc
Q = @
# quiet := quiet_
# quiet := silent_
comma := ,
quote := "
squote := '
empty :=
space := $(empty) $(empty)
pound := \#
escsq = $(subst $(squote),'\$(squote)',$1)
echo-cmd = $(if $($(quiet)cmd_$(1)),echo ' $(call escsq,$($(quiet)cmd_$(1)))$(echo-why)';)
cmd = $(Q)$(echo-cmd) $(cmd_$(1))
any-prereq = $(filter-out $(PHONY),$?) $(filter-out $(PHONY) $(wildcard $^),$^)
echo-why = $(call escsq,$(why))
# (1) PHONY
# (2) target is missing
# (3) something is newer than target
ifneq "$(quiet)" ""
why = $(if $(filter $@,$(PHONY)), - due to phony target, \
$(if $(wildcard $@), \
$(if $(strip $(any-prereq)), - due to $(any-prereq), \
- due to unknown), \
- due to target is missing) \
)
endif
cmd_cc_c_o = $(CC) $(c_flags) -c $< -o $@
quiet_cmd_cc_c_o = CC $<
cmd_ld_o_elf = $(CC) $(ld_flags) -o $@ $^
quiet_cmd_ld_o_elf = LD $@
%.o: %.c
$(call cmd,cc_c_o)
srctree = /path/to/strtree
addtree = $(if $(patsubst -I%,%,$(1)), \
$(if $(filter-out -I/%,$(1)),$(patsubst -I%,-I$(srctree)/%,$(1))) $(1))
CFLAGS = $(call addtree,-Idebug)
CFLAGS = $(call addtree,-Idebug)
.PHONY: all
PHONY += all
%.o: c_flags = $(CFLAGS)
all: ld_flags = $(CFLAGS)
all: all.o
$(call cmd,ld_o_elf)
@# rm -f *.o
clean:
@rm -f all *.o
.PHONY: clean
PHONY += clean
阅读(3363) | 评论(0) | 转发(0) |