Skip to content

Commit

Permalink
Tidy up
Browse files Browse the repository at this point in the history
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 SmingHub#985)
  • Loading branch information
mikee47 committed Jun 16, 2019
1 parent 316ed95 commit b90879e
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 42 deletions.
4 changes: 1 addition & 3 deletions Sming/Arch/Esp8266/Components/esp-open-lwip/component.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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 := \
Expand Down Expand Up @@ -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

Expand Down
25 changes: 10 additions & 15 deletions Sming/Makefile-app.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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))
Expand All @@ -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
Expand All @@ -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)
Expand Down
45 changes: 24 additions & 21 deletions Sming/build.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
6 changes: 3 additions & 3 deletions Sming/components.mk
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ BUILD_DIR :=

CFLAGS += $(GLOBAL_CFLAGS)

EXTRA_INCDIR := $(COMPONENTS_EXTRA_INCDIR)
INCDIR := $(COMPONENTS_EXTRA_INCDIR)

CUSTOM_BUILD :=

Expand Down Expand Up @@ -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))
Expand All @@ -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)')
Expand Down

0 comments on commit b90879e

Please sign in to comment.