From b9e52903c1c0d036ceb1abfdcebd4b019e8dc1e9 Mon Sep 17 00:00:00 2001 From: mikee47 Date: Mon, 10 Jun 2019 15:30:04 +0100 Subject: [PATCH] Tidy up Rename `ResolveSourcePath` -> `AbsoluteSourcePath` Rename `ResolveObjPath` -> `AbsoluteObjPath` Add root source parameter Don't mess about with `EXTRA_INCDIR`, that's for application code, use `INCDIR` directly Add `EXTRA_SRCFILES` (as per #985) --- .../Components/esp-open-lwip/component.mk | 4 +- Sming/Makefile-app.mk | 25 +++++------ Sming/build.mk | 45 ++++++++++--------- Sming/components.mk | 6 +-- 4 files changed, 38 insertions(+), 42 deletions(-) diff --git a/Sming/Arch/Esp8266/Components/esp-open-lwip/component.mk b/Sming/Arch/Esp8266/Components/esp-open-lwip/component.mk index a56b19a911..be8bc496ab 100644 --- a/Sming/Arch/Esp8266/Components/esp-open-lwip/component.mk +++ b/Sming/Arch/Esp8266/Components/esp-open-lwip/component.mk @@ -15,8 +15,6 @@ ifeq ($(ENABLE_LWIPDEBUG), 1) COMPONENT_CFLAGS += -DLWIP_DEBUG endif -#EXTRA_INCDIR := $(filter-out Arch/Esp8266/System/include,$(EXTRA_INCDIR)) - COMPONENT_SUBMODULES := esp-open-lwip COMPONENT_SRCDIRS := COMPONENT_SRCFILES := \ @@ -65,7 +63,7 @@ else endif # Very fussy about include paths so override default -EXTRA_INCDIR := $(COMPONENT_PATH)/esp-open-lwip/include $(SDK_BASE)/include \ +INCDIR := $(COMPONENT_PATH)/esp-open-lwip/include $(SDK_BASE)/include \ $(SMING_HOME)/System/include $(ARCH_SYS)/include \ $(ARCH_COMPONENTS)/esp8266/include $(SMING_HOME)/Wiring diff --git a/Sming/Makefile-app.mk b/Sming/Makefile-app.mk index 97751a0076..fb830a4729 100644 --- a/Sming/Makefile-app.mk +++ b/Sming/Makefile-app.mk @@ -62,12 +62,13 @@ FW_MEMINFO_SAVED := out/fwMeminfo APPCODE := # which modules (subdirectories) of the project to include in compiling +MODULES ?= app # default to app if not set by user + # define your custom directories in the project's own Makefile before including this one -MODULES ?= app # default to app if not set by user -EXTRA_INCDIR ?= include # default to include if not set by user +EXTRA_INCDIR ?= include # default to include if not set by user -# Save for later -APP_EXTRA_INCDIR := EXTRA_INCDIR +# Individual source code files to be added +EXTRA_SRCFILES ?= COMPONENT_DIRS := $(SMING_HOME) @@ -146,7 +147,7 @@ CMP_$1_VARS := $$(COMPONENT_VARS) CONFIG_VARS += $$(COMPONENT_VARS) endif CMP_$1_BUILD_DIR := $$(COMPONENT_BUILD_DIR) -CMP_$1_INCDIR := $$(COMPONENT_INCDIRS) +CMP_$1_INCDIR := $$(call AbsoluteSourcePath,$2,$$(COMPONENT_INCDIRS)) CMP_$1_TARGETS := $$(COMPONENT_TARGETS) # If there aren't any targets, nothing needs building for the Component ifneq (,$$(COMPONENT_TARGETS)) @@ -160,13 +161,8 @@ $(COMPONENT_DIRS): $(error Component path not found: "$@") $(foreach cdir,$(COMPONENT_DIRS),$(eval $(call ParseComponent,$(notdir $(cdir)),$(cdir)))) -# Build the actual include paths - have to do this separately because of how variable expansion works -# $1 -> Component name -# $2 -> Component path -define ParseIncDir -$(addprefix $2/,$(filter-out /%,$(CMP_$1_INCDIR))) $(filter /%,$(CMP_$1_INCDIR)) -endef -COMPONENTS_EXTRA_INCDIR := $(foreach cdir,$(COMPONENT_DIRS),$(call ParseIncDir,$(notdir $(cdir)),$(cdir))) +# Combine all Component include paths +COMPONENTS_EXTRA_INCDIR := $(foreach d,$(COMPONENT_DIRS),$(CMP_$(notdir $d)_INCDIR)) export COMPONENTS_EXTRA_INCDIR # Add Component libraries to list for linking @@ -193,10 +189,9 @@ submodules: ##Fetch all third-party submodules (but do not build) ##@Building # Generate the application compile target patterns and object references -COMPONENT_PATH := . -EXTRA_INCDIR := $(APP_EXTRA_INCDIR) $(COMPONENTS_EXTRA_INCDIR) +INCDIR := $(EXTRA_INCDIR) $(COMPONENTS_EXTRA_INCDIR) BUILD_DIR := $(BUILD_BASE)/ -$(eval $(call ScanModules,$(MODULES) $(APPCODE))) +$(eval $(call ScanModules,.,$(MODULES) $(APPCODE),$(EXTRA_SRCFILES))) # recreate it from 0, since you get into problems with same filenames $(APP_AR): $(OBJ) diff --git a/Sming/build.mk b/Sming/build.mk index 8dcd3a0672..4ad7ea84bf 100644 --- a/Sming/build.mk +++ b/Sming/build.mk @@ -244,42 +244,42 @@ BUILD_DIRS := # List of object files OBJ := -INCDIR = $(addprefix -I,$(EXTRA_INCDIR)) - # $1 -> source directory # $2 -> output build directory define GenerateCompileTargets BUILD_DIRS += $2 $2/%.o: $1/%.s $(vecho) "AS $$<" - $(Q) $(AS) $(INCDIR) $(CFLAGS) -c $$< -o $$@ + $(Q) $(AS) $(addprefix -I,$(INCDIR)) $(CFLAGS) -c $$< -o $$@ $2/%.o: $1/%.S $(vecho) "AS $$<" - $(Q) $(AS) $(INCDIR) $(CFLAGS) -c $$< -o $$@ + $(Q) $(AS) $(addprefix -I,$(INCDIR)) $(CFLAGS) -c $$< -o $$@ $2/%.o: $1/%.c $2/%.c.d $(vecho) "CC $$<" - $(Q) $(CC) $(INCDIR) $(CFLAGS) -std=c11 -c $$< -o $$@ + $(Q) $(CC) $(addprefix -I,$(INCDIR)) $(CFLAGS) -std=c11 -c $$< -o $$@ $2/%.o: $1/%.cpp $2/%.cpp.d $(vecho) "C+ $$<" - $(Q) $(CXX) $(INCDIR) $(CXXFLAGS) -c $$< -o $$@ + $(Q) $(CXX) $(addprefix -I,$(INCDIR)) $(CXXFLAGS) -c $$< -o $$@ $2/%.c.d: $1/%.c - $(Q) $(CC) $(INCDIR) $(CFLAGS) -std=c11 -MM -MT $2/$$*.o $$< -o $$@ + $(Q) $(CC) $(addprefix -I,$(INCDIR)) $(CFLAGS) -std=c11 -MM -MT $2/$$*.o $$< -o $$@ $2/%.cpp.d: $1/%.cpp - $(Q) $(CXX) $(INCDIR) $(CXXFLAGS) -MM -MT $2/$$*.o $$< -o $$@ + $(Q) $(CXX) $(addprefix -I,$(INCDIR)) $(CXXFLAGS) -MM -MT $2/$$*.o $$< -o $$@ .PRECIOUS: $2/%.c.d $2/%.cpp.d endef -# Resolve a source path -# $1 -> file path(s) -define ResolveSourcePath -$(if $(filter /%,$1),$1,$(COMPONENT_PATH)/$1) +# Give relative or absolute source paths, convert them all to absolute +# $1 -> source root directory +# $2 -> file path(s) +define AbsoluteSourcePath +$(foreach f,$2,$(if $(filter /%,$f),$f,$1/$f)) endef # Resolve a source path to the corresponding build output object file -# $1 -> file path(s) -define ResolveObjPath -$(BUILD_DIR)$(patsubst $(SMING_HOME)/%,%,$(patsubst $(COMPONENT_PATH)/%,%,$1)) +# $1 -> source root directory +# $2 -> file path(s) +define AbsoluteObjPath +$(foreach f,$2,$(addprefix $(BUILD_DIR),$(patsubst $(SMING_HOME)/%,%,$(patsubst $1/%,%,$f)))) endef # Scan for all known source files and append to COMPONENT_SRCFILES @@ -291,18 +291,21 @@ SOURCE_FILES += $(wildcard $1/*.s $1/*.S $1/*.c $1/*.cpp) endef # Generate compiler targets for source code, specified as directories and/or individual files -# $1 -> directories containing source files, absolute or relative -# $2 -> individual source files +# Invoked using $(eval) hence $$ escaping required +# INCDIR and BUILD_DIR must be set correctly +# $1 -> source root directory +# $2 -> directories containing source files, absolute or relative +# $3 -> individual source files define ScanModules -SOURCE_FILES += $(foreach f,$2,$(call ResolveSourcePath,$f)) +SOURCE_FILES += $(foreach f,$3,$(call AbsoluteSourcePath,$1,$f)) SOURCE_DIRS += $$(dir $$(SOURCE_FILES)) -$(foreach d,$1,$(call ScanModule,$(call ResolveSourcePath,$d))) +$(foreach d,$2,$(call ScanModule,$(call AbsoluteSourcePath,$1,$d))) SOURCE_DIRS := $(sort $$(SOURCE_DIRS:/=)) -OBJ := $$(foreach f,$$(SOURCE_FILES),$$(call ResolveObjPath,$$f)) +OBJ := $$(call AbsoluteObjPath,$1,$$(SOURCE_FILES)) OBJ := $$(OBJ:.s=.o) OBJ := $$(OBJ:.S=.o) OBJ := $$(OBJ:.c=.o) OBJ := $$(OBJ:.cpp=.o) -$$(foreach d,$$(SOURCE_DIRS),$$(eval $$(call GenerateCompileTargets,$$d,$$(call ResolveObjPath,$$d)))) +$$(foreach d,$$(SOURCE_DIRS),$$(eval $$(call GenerateCompileTargets,$$d,$$(call AbsoluteObjPath,$1,$$d)))) BUILD_DIRS := $$(sort $$(BUILD_DIRS)) endef diff --git a/Sming/components.mk b/Sming/components.mk index 6ad4821f2f..8066c0bfe7 100644 --- a/Sming/components.mk +++ b/Sming/components.mk @@ -42,7 +42,7 @@ BUILD_DIR := CFLAGS += $(GLOBAL_CFLAGS) -EXTRA_INCDIR := $(COMPONENTS_EXTRA_INCDIR) +INCDIR := $(COMPONENTS_EXTRA_INCDIR) CUSTOM_BUILD := @@ -72,7 +72,7 @@ endef CFLAGS += $(COMPONENT_CFLAGS) # Generate all the compile target patterns and object references -$(eval $(call ScanModules,$(COMPONENT_SRCDIRS),$(COMPONENT_SRCFILES))) +$(eval $(call ScanModules,$(COMPONENT_PATH),$(COMPONENT_SRCDIRS),$(COMPONENT_SRCFILES))) #$(info CURDIR = $(CURDIR)) #$(info SMING_HOME = $(SMING_HOME)) @@ -84,7 +84,7 @@ $(eval $(call ScanModules,$(COMPONENT_SRCDIRS),$(COMPONENT_SRCFILES))) #$(eval $(call PrintVariable,BUILD_DIRS)) #$(info OBJ = $(OBJ)) #$(eval $(call PrintVariable,OBJ)) -#$(eval $(call PrintVariable,EXTRA_INCDIR)) +#$(eval $(call PrintVariable,INCDIR)) $(info Building '$(COMPONENT_TARGETS)')