From 73b31ae00b772f6dcbc077533aff75d358916407 Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen Date: Mon, 22 May 2017 21:15:58 +0200 Subject: [PATCH] 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. --- make/compile.make | 9 ++++++--- make/mescc-guile.make | 37 ++++++++++++++++++++++++++++++++++++- make/mescc-mes.make | 42 ++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 82 insertions(+), 6 deletions(-) diff --git a/make/compile.make b/make/compile.make index cfb95fc2..828a0ebd 100644 --- a/make/compile.make +++ b/make/compile.make @@ -1,9 +1,12 @@ 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): CPPFLAGS:=$$(CPPFLAGS) $$(CPP_FLAGS) $(2:%=-D%) $(3:%=-I%) -$(OUT)/$(1:.c=.$(CROSS)o): CFLAGS:=$$(CFLAGS) $$(C_FLAGS) +$(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): COMPILE.c:=$$(CC) $$(CFLAGS) $$(CPPFLAGS) $(TARGET_ARCH) -c +$(OUT)/$(1:.c=.$(CROSS)o): $(MAKEFILE_LIST) $(OUT)/$(1:.c=.$(CROSS)o): $(1) @echo " $$(cc) $$(notdir $$<) -> $$(notdir $$@)" @mkdir -p $$(dir $$@) diff --git a/make/mescc-guile.make b/make/mescc-guile.make index 6639fac4..fb46365c 100644 --- a/make/mescc-guile.make +++ b/make/mescc-guile.make @@ -28,11 +28,12 @@ $(OUT)/$(TARGET): $(O_FILES) $(QUIET)$(LINK.c) $(O_FILES) $(LOADLIBES) $(LDLIBS) -o $@ 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): CPPFLAGS:=$(2:%=-D %) $(3:%=-I %) $(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): $(1) @echo " $$(cc) $$(notdir $(1)) -> $$(notdir $$@)" @@ -40,12 +41,46 @@ $(OUT)/$(1:.c=.$(CROSS)o): $(1) $$(QUIET)$$(COMPILE.c) $$(CPPFLAGS) $$(OUTPUT_OPTION) $(1) 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),) MLIBC.scm:=DONE else C_FILES:=$(filter-out libc/libc-mes.c,$(C_FILES)) C_FILES:=$(filter-out libc/mini-libc-mes.c,$(C_FILES)) endif + +ifneq ($(MESC_DIRECT),) $(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 diff --git a/make/mescc-mes.make b/make/mescc-mes.make index 990901dd..5213f409 100644 --- a/make/mescc-mes.make +++ b/make/mescc-mes.make @@ -21,19 +21,22 @@ $(OUT)/$(TARGET): LD:=$(MESLD.mes) $(OUT)/$(TARGET): CC:=$(MESCC.mes) $(OUT)/$(TARGET): CFLAGS:= $(OUT)/$(TARGET): LDFLAGS:= +$(OUT)/$(TARGET): $(MAKEFILE_LIST) +$(OUT)/$(TARGET): scripts/mes $(OUT)/$(TARGET): O_FILES:=$(O_FILES) $(OUT)/$(TARGET): $(O_FILES) @echo " $(ld) $(notdir $(O_FILES)) -> $(notdir $@)" $(QUIET)$(LINK.c) $(O_FILES) $(LOADLIBES) $(LDLIBS) -o $@ 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): COMPILE.c:=$(MESCC.mes) -c $(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): 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): $(1) @echo " $$(cc) $$(notdir $(1)) -> $$(notdir $$@)" @@ -41,12 +44,47 @@ $(OUT)/$(1:.c=.$(CROSS)o): $(1) $$(QUIET)$$(COMPILE.c) $$(OUTPUT_OPTION) $(1) 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),) MLIBC.mes:=DONE else C_FILES:=$(filter-out libc/libc-mes.c,$(C_FILES)) endif +ifneq ($(MESC_DIRECT),) $(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