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