mescc: Refactor mlibc compilation.
[mes.git] / make / mescc-mes.make
1 CROSS:=mes-
2 C_FILES:=libc/libc-mes.c $(C_FILES)
3 O_FILES:=$(C_FILES:%.c=$(OUT)/%.$(CROSS)o)
4
5 ifneq ($(DEBUG),)
6 $(info TARGET=$(TARGET))
7 $(info C_FILES=$(C_FILES))
8 $(info O_FILES=$(O_FILES))
9 endif
10
11 CLEAN+=$(O_FILES) $(OUT)/$(TARGET)
12
13 CLEAN+=$(OUT)/$(TARGET)
14
15 INCLUDES+=libc/include libc $(OUT)/$(DIR)
16 MESCC.mes:=scripts/mescc.mes
17 MESLD.mes:=scripts/mescc.mes
18
19 $(OUT)/$(TARGET): ld:=MESLD.mes
20 $(OUT)/$(TARGET): LD:=$(MESLD.mes)
21 $(OUT)/$(TARGET): CC:=$(MESCC.mes)
22 $(OUT)/$(TARGET): CFLAGS:=
23 $(OUT)/$(TARGET): LDFLAGS:=
24 $(OUT)/$(TARGET): O_FILES:=$(O_FILES)
25 $(OUT)/$(TARGET): $(O_FILES)
26         @echo "  $(ld)  $(notdir $(O_FILES)) -> $(notdir $@)"
27         $(QUIET)$(LINK.c) $(O_FILES) $(LOADLIBES) $(LDLIBS) -o $@
28
29 define mescc.mes-c-compile
30 $(OUT)/$(1:.c=.$(CROSS)o): $(MAKEFILE_LIST)
31 $(OUT)/$(1:.c=.$(CROSS)o): cc:=MESCC.mes
32 $(OUT)/$(1:.c=.$(CROSS)o): CC:=$(MESCC.mes)
33 $(OUT)/$(1:.c=.$(CROSS)o): COMPILE.c:=$(MESCC.mes) -c
34 $(OUT)/$(1:.c=.$(CROSS)o): CPPFLAGS:=$(2:%=-D %) $(3:%=-I %)
35 $(OUT)/$(1:.c=.$(CROSS)o): COMPILE.c:=$(MESCC.mes) -c $(CPPFLAGS)
36 $(OUT)/$(1:.c=.$(CROSS)o): all-mo
37 $(OUT)/$(1:.c=.$(CROSS)o): $(INSTALL_MES_FILES)
38 $(OUT)/$(1:.c=.$(CROSS)o): $(1)
39         @echo "  $$(cc) $$(notdir $(1)) -> $$(notdir $$@)"
40         @mkdir -p $$(dir $$@)
41         $$(QUIET)$$(COMPILE.c) $$(OUTPUT_OPTION) $(1)
42 endef
43
44 ifeq ($(MLIBC.mes),)
45 MLIBC.mes:=DONE
46 else
47 C_FILES:=$(filter-out libc/libc-mes.c,$(C_FILES))
48 endif
49
50 $(foreach c-file,$(strip $(filter %.c,$(C_FILES))),$(eval $(call mescc.mes-c-compile,$(c-file),$(DEFINES),$(INCLUDES))))
51
52 include make/reset.make