build: Use separate preprocessing stage for mescc.

* make/mescc-guile.make (mescc.scm-c-preprocess, (mescc.scm-compile-E):
  New defines.
  [!MESC_DIRECT]Compile .o via separate preprocessed .E stage.
This commit is contained in:
Jan Nieuwenhuizen 2017-05-22 21:15:58 +02:00
parent cf51f3f5bd
commit 73b31ae00b
3 changed files with 82 additions and 6 deletions

View file

@ -1,9 +1,12 @@
define c-compile define c-compile
$(OUT)/$(1:.c=.$(CROSS)o): $(MAKEFILE_LIST) $(OUT)/$(1:.c=.$(CROSS)o): CROSS:=$(CROSS)
$(OUT)/$(1:.c=.$(CROSS)o): CC:=$(CC)
$(OUT)/$(1:.c=.$(CROSS)o): cc:=$(CROSS)CC $(OUT)/$(1:.c=.$(CROSS)o): cc:=$(CROSS)CC
$(OUT)/$(1:.c=.$(CROSS)o): CC:=$(CROSS)$(CC) $(OUT)/$(1:.c=.$(CROSS)o): CC:=$(CROSS)$(CC)
$(OUT)/$(1:.c=.$(CROSS)o): CPPFLAGS:=$$(CPPFLAGS) $$(CPP_FLAGS) $(2:%=-D%) $(3:%=-I%) $(OUT)/$(1:.c=.$(CROSS)o): CPPFLAGS:=$(CPPFLAGS) $(CPP_FLAGS) $(2:%=-D%) $(3:%=-I%)
$(OUT)/$(1:.c=.$(CROSS)o): CFLAGS:=$$(CFLAGS) $$(C_FLAGS) $(OUT)/$(1:.c=.$(CROSS)o): CFLAGS:=$(CFLAGS) $(C_FLAGS)
$(OUT)/$(1:.c=.$(CROSS)o): COMPILE.c:=$$(CC) $$(CFLAGS) $$(CPPFLAGS) $(TARGET_ARCH) -c
$(OUT)/$(1:.c=.$(CROSS)o): $(MAKEFILE_LIST)
$(OUT)/$(1:.c=.$(CROSS)o): $(1) $(OUT)/$(1:.c=.$(CROSS)o): $(1)
@echo " $$(cc) $$(notdir $$<) -> $$(notdir $$@)" @echo " $$(cc) $$(notdir $$<) -> $$(notdir $$@)"
@mkdir -p $$(dir $$@) @mkdir -p $$(dir $$@)

View file

@ -28,11 +28,12 @@ $(OUT)/$(TARGET): $(O_FILES)
$(QUIET)$(LINK.c) $(O_FILES) $(LOADLIBES) $(LDLIBS) -o $@ $(QUIET)$(LINK.c) $(O_FILES) $(LOADLIBES) $(LDLIBS) -o $@
define mescc.scm-c-compile define mescc.scm-c-compile
$(OUT)/$(1:.c=.$(CROSS)o): $(MAKEFILE_LIST) $(OUT)/$(1:.c=.$(CROSS)o): CROSS:=$(CROSS)
$(OUT)/$(1:.c=.$(CROSS)o): cc:=MESCC.scm $(OUT)/$(1:.c=.$(CROSS)o): cc:=MESCC.scm
$(OUT)/$(1:.c=.$(CROSS)o): CC:=$(MESCC.scm) $(OUT)/$(1:.c=.$(CROSS)o): CC:=$(MESCC.scm)
$(OUT)/$(1:.c=.$(CROSS)o): CPPFLAGS:=$(2:%=-D %) $(3:%=-I %) $(OUT)/$(1:.c=.$(CROSS)o): CPPFLAGS:=$(2:%=-D %) $(3:%=-I %)
$(OUT)/$(1:.c=.$(CROSS)o): COMPILE.c:=$(MESCC.scm) -c $(CPPFLAGS) $(OUT)/$(1:.c=.$(CROSS)o): COMPILE.c:=$(MESCC.scm) -c $(CPPFLAGS)
$(OUT)/$(1:.c=.$(CROSS)o): $(MAKEFILE_LIST)
$(OUT)/$(1:.c=.$(CROSS)o): $(INSTALL_GO_FILES) $(OUT)/$(1:.c=.$(CROSS)o): $(INSTALL_GO_FILES)
$(OUT)/$(1:.c=.$(CROSS)o): $(1) $(OUT)/$(1:.c=.$(CROSS)o): $(1)
@echo " $$(cc) $$(notdir $(1)) -> $$(notdir $$@)" @echo " $$(cc) $$(notdir $(1)) -> $$(notdir $$@)"
@ -40,12 +41,46 @@ $(OUT)/$(1:.c=.$(CROSS)o): $(1)
$$(QUIET)$$(COMPILE.c) $$(CPPFLAGS) $$(OUTPUT_OPTION) $(1) $$(QUIET)$$(COMPILE.c) $$(CPPFLAGS) $$(OUTPUT_OPTION) $(1)
endef endef
define mescc.scm-c-preprocess
$(OUT)/$(1:.c=.$(CROSS)E): CROSS:=$(CROSS)
$(OUT)/$(1:.c=.$(CROSS)E): cc:=MESCC.scm
$(OUT)/$(1:.c=.$(CROSS)E): CC:=$(MESCC.scm)
$(OUT)/$(1:.c=.$(CROSS)E): CPPFLAGS:=$(2:%=-D %) $(3:%=-I %)
$(OUT)/$(1:.c=.$(CROSS)E): PREPROCESS.c:=$(MESCC.scm) -E $(CPPFLAGS)
$(OUT)/$(1:.c=.$(CROSS)E): $(MAKEFILE_LIST)
$(OUT)/$(1:.c=.$(CROSS)E): $(INSTALL_GO_FILES)
$(OUT)/$(1:.c=.$(CROSS)E): $(1)
@echo " $$(cc) $$(notdir $(1)) -> $$(notdir $$@)"
@mkdir -p $$(dir $$@)
$$(QUIET)$$(PREPROCESS.c) $$(CPPFLAGS) $$(OUTPUT_OPTION) $(1)
endef
define mescc.scm-c-compile-E
$(1:.$(CROSS)E=.$(CROSS)o): CROSS:=$(CROSS)
$(1:.$(CROSS)E=.$(CROSS)o): cc:=MESCC.scm
$(1:.$(CROSS)E=.$(CROSS)o): CC:=$(MESCC.scm)
$(1:.$(CROSS)E=.$(CROSS)o): CPPFLAGS:=$(2:%=-D %) $(3:%=-I %)
$(1:.$(CROSS)E=.$(CROSS)o): COMPILE.c:=$(MESCC.scm) -c $(CPPFLAGS)
$(1:.$(CROSS)E=.$(CROSS)o): $(MAKEFILE_LIST)
$(1:.$(CROSS)E=.$(CROSS)o): $(INSTALL_GO_FILES)
$(1:.$(CROSS)E=.$(CROSS)o): $(1)
@echo " $$(cc) $$(notdir $(1)) -> $$(notdir $$@)"
@mkdir -p $$(dir $$@)
$$(QUIET)$$(COMPILE.c) $$(CPPFLAGS) $$(OUTPUT_OPTION) $(1)
endef
ifeq ($(MLIBC.scm),) ifeq ($(MLIBC.scm),)
MLIBC.scm:=DONE MLIBC.scm:=DONE
else else
C_FILES:=$(filter-out libc/libc-mes.c,$(C_FILES)) C_FILES:=$(filter-out libc/libc-mes.c,$(C_FILES))
C_FILES:=$(filter-out libc/mini-libc-mes.c,$(C_FILES)) C_FILES:=$(filter-out libc/mini-libc-mes.c,$(C_FILES))
endif endif
ifneq ($(MESC_DIRECT),)
$(foreach c-file,$(strip $(filter %.c,$(C_FILES))),$(eval $(call mescc.scm-c-compile,$(c-file),$(DEFINES),$(INCLUDES)))) $(foreach c-file,$(strip $(filter %.c,$(C_FILES))),$(eval $(call mescc.scm-c-compile,$(c-file),$(DEFINES),$(INCLUDES))))
else
$(foreach c-file,$(strip $(filter %.c,$(C_FILES))),$(eval $(call mescc.scm-c-preprocess,$(c-file),$(DEFINES),$(INCLUDES))))
$(foreach c-file,$(strip $(filter %.c,$(C_FILES))),$(eval $(call mescc.scm-c-compile-E,$(c-file:%.c=$(OUT)/%.$(CROSS)E),$(DEFINES),$(INCLUDES))))
endif
include make/reset.make include make/reset.make

View file

@ -21,19 +21,22 @@ $(OUT)/$(TARGET): LD:=$(MESLD.mes)
$(OUT)/$(TARGET): CC:=$(MESCC.mes) $(OUT)/$(TARGET): CC:=$(MESCC.mes)
$(OUT)/$(TARGET): CFLAGS:= $(OUT)/$(TARGET): CFLAGS:=
$(OUT)/$(TARGET): LDFLAGS:= $(OUT)/$(TARGET): LDFLAGS:=
$(OUT)/$(TARGET): $(MAKEFILE_LIST)
$(OUT)/$(TARGET): scripts/mes
$(OUT)/$(TARGET): O_FILES:=$(O_FILES) $(OUT)/$(TARGET): O_FILES:=$(O_FILES)
$(OUT)/$(TARGET): $(O_FILES) $(OUT)/$(TARGET): $(O_FILES)
@echo " $(ld) $(notdir $(O_FILES)) -> $(notdir $@)" @echo " $(ld) $(notdir $(O_FILES)) -> $(notdir $@)"
$(QUIET)$(LINK.c) $(O_FILES) $(LOADLIBES) $(LDLIBS) -o $@ $(QUIET)$(LINK.c) $(O_FILES) $(LOADLIBES) $(LDLIBS) -o $@
define mescc.mes-c-compile define mescc.mes-c-compile
$(OUT)/$(1:.c=.$(CROSS)o): $(MAKEFILE_LIST) $(OUT)/$(1:.c=.$(CROSS)o): CROSS:=$(CROSS)
$(OUT)/$(1:.c=.$(CROSS)o): cc:=MESCC.mes $(OUT)/$(1:.c=.$(CROSS)o): cc:=MESCC.mes
$(OUT)/$(1:.c=.$(CROSS)o): CC:=$(MESCC.mes) $(OUT)/$(1:.c=.$(CROSS)o): CC:=$(MESCC.mes)
$(OUT)/$(1:.c=.$(CROSS)o): COMPILE.c:=$(MESCC.mes) -c $(OUT)/$(1:.c=.$(CROSS)o): COMPILE.c:=$(MESCC.mes) -c
$(OUT)/$(1:.c=.$(CROSS)o): CPPFLAGS:=$(2:%=-D %) $(3:%=-I %) $(OUT)/$(1:.c=.$(CROSS)o): CPPFLAGS:=$(2:%=-D %) $(3:%=-I %)
$(OUT)/$(1:.c=.$(CROSS)o): COMPILE.c:=$(MESCC.mes) -c $(CPPFLAGS) $(OUT)/$(1:.c=.$(CROSS)o): COMPILE.c:=$(MESCC.mes) -c $(CPPFLAGS)
$(OUT)/$(1:.c=.$(CROSS)o): all-mo $(OUT)/$(1:.c=.$(CROSS)o): $(MAKEFILE_LIST)
$(OUT)/$(1:.c=.$(CROSS)o): scripts/mes
$(OUT)/$(1:.c=.$(CROSS)o): $(INSTALL_MES_FILES) $(OUT)/$(1:.c=.$(CROSS)o): $(INSTALL_MES_FILES)
$(OUT)/$(1:.c=.$(CROSS)o): $(1) $(OUT)/$(1:.c=.$(CROSS)o): $(1)
@echo " $$(cc) $$(notdir $(1)) -> $$(notdir $$@)" @echo " $$(cc) $$(notdir $(1)) -> $$(notdir $$@)"
@ -41,12 +44,47 @@ $(OUT)/$(1:.c=.$(CROSS)o): $(1)
$$(QUIET)$$(COMPILE.c) $$(OUTPUT_OPTION) $(1) $$(QUIET)$$(COMPILE.c) $$(OUTPUT_OPTION) $(1)
endef endef
define mescc.mes-c-preprocess
$(OUT)/$(1:.c=.$(CROSS)E): CROSS:=$(CROSS)
$(OUT)/$(1:.c=.$(CROSS)E): cc:=MESCC.mes
$(OUT)/$(1:.c=.$(CROSS)E): CC:=$(MESCC.mes)
$(OUT)/$(1:.c=.$(CROSS)E): CPPFLAGS:=$(2:%=-D %) $(3:%=-I %)
$(OUT)/$(1:.c=.$(CROSS)E): PREPROCESS.c:=$(MESCC.mes) -E $(CPPFLAGS)
$(OUT)/$(1:.c=.$(CROSS)E): $(MAKEFILE_LIST)
$(OUT)/$(1:.c=.$(CROSS)o): scripts/mes
$(OUT)/$(1:.c=.$(CROSS)E): $(INSTALL_MES_FILES)
$(OUT)/$(1:.c=.$(CROSS)E): $(1)
@echo " $$(cc) $$(notdir $(1)) -> $$(notdir $$@)"
@mkdir -p $$(dir $$@)
$$(QUIET)$$(PREPROCESS.c) $$(CPPFLAGS) $$(OUTPUT_OPTION) $(1)
endef
define mescc.mes-c-compile-E
$(1:.$(CROSS)E=.$(CROSS)o): CROSS:=$(CROSS)
$(1:.$(CROSS)E=.$(CROSS)o): cc:=MESCC.mes
$(1:.$(CROSS)E=.$(CROSS)o): CC:=$(MESCC.mes)
$(1:.$(CROSS)E=.$(CROSS)o): CPPFLAGS:=$(2:%=-D %) $(3:%=-I %)
$(1:.$(CROSS)E=.$(CROSS)o): COMPILE.c:=$(MESCC.mes) -c $(CPPFLAGS)
$(1:.$(CROSS)E=.$(CROSS)o): $(MAKEFILE_LIST)
$(1:.$(CROSS)E=.$(CROSS)o): scripts/mes
$(1:.$(CROSS)E=.$(CROSS)o): $(INSTALL_MES_FILES)
$(1:.$(CROSS)E=.$(CROSS)o): $(1)
@echo " $$(cc) $$(notdir $(1)) -> $$(notdir $$@)"
@mkdir -p $$(dir $$@)
$$(QUIET)$$(COMPILE.c) $$(CPPFLAGS) $$(OUTPUT_OPTION) $(1)
endef
ifeq ($(MLIBC.mes),) ifeq ($(MLIBC.mes),)
MLIBC.mes:=DONE MLIBC.mes:=DONE
else else
C_FILES:=$(filter-out libc/libc-mes.c,$(C_FILES)) C_FILES:=$(filter-out libc/libc-mes.c,$(C_FILES))
endif endif
ifneq ($(MESC_DIRECT),)
$(foreach c-file,$(strip $(filter %.c,$(C_FILES))),$(eval $(call mescc.mes-c-compile,$(c-file),$(DEFINES),$(INCLUDES)))) $(foreach c-file,$(strip $(filter %.c,$(C_FILES))),$(eval $(call mescc.mes-c-compile,$(c-file),$(DEFINES),$(INCLUDES))))
else
$(foreach c-file,$(strip $(filter %.c,$(C_FILES))),$(eval $(call mescc.mes-c-preprocess,$(c-file),$(DEFINES),$(INCLUDES))))
$(foreach c-file,$(strip $(filter %.c,$(C_FILES))),$(eval $(call mescc.mes-c-compile-E,$(c-file:%.c=$(OUT)/%.$(CROSS)E),$(DEFINES),$(INCLUDES))))
endif
include make/reset.make include make/reset.make