From 5d7ddfc424292ca110d60ae38d64d83fa9f16a52 Mon Sep 17 00:00:00 2001 From: ken Date: Wed, 2 Nov 2016 18:55:36 -0700 Subject: [PATCH] simplification of control --- Makefile | 110 ++++++++-------------------------------------- make/init.mk | 80 +++++++++++++++++++++++++++++++++ make/lib/rules.mk | 28 +++++++----- 3 files changed, 116 insertions(+), 102 deletions(-) create mode 100644 make/init.mk diff --git a/Makefile b/Makefile index d10e17b..ae486cd 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ ################################################################################ # Desc: Web Cross Compiler -# Author: Ken Grimes +# Author: ksg # Date: 2016 ################################################################################ # This makefile manages a build environment targeting native platforms with gcc @@ -9,8 +9,6 @@ # Each .c file is automatically compiled into an environment-dependent object # file of compiler-specific format (.o for gcc, .bc for llvm/emcc/em++). ################################################################################ -# The default rule to be built if none specified -default: all # webcc's root ROOT_DIR := . # source directory to find compilable language files in @@ -19,98 +17,29 @@ SRC_DIR := $(ROOT_DIR)/src DRIVER_DIR := $(SRC_DIR)/bin # make configuration directory CONF_DIR := $(ROOT_DIR)/make -# Source languages handled by this build system. These languages are capable of -# being compiled to an intermediary format for binary output by one of the -# provided compilersfor each language -LANGS := c cpp go -# Source-to-source languages handled by this build system -SLANGS := y rl -# Language-specific compilers and flags passed in from environment -c_C := $(strip $(notdir $(CC))) -c_FLAGS := $(strip $(CFLAGS)) -I$(SRC_DIR) -c_SRCL := y -cpp_C := $(strip $(notdir $(CXX))) -cpp_FLAGS := $(strip $(CXXFLAGS)) $(c_FLAGS) -go_C := gccgo -go_FLAGS := $(c_FLAGS) -# Source to source languages -# Bison -y_C := bison -y_FLAGS := -d -y_STEM := tab -y_TRG := c h -# Ragel -rl_C := ragel -rl_FLAGS := -C -rl_TRG := c -# Compiler-specific associations. Each compiler has a binary object suffix -# (OBJ), an archiver (AR), and an archiver object suffix (AROBJ). Each compiler -# may optionally have defined a linker (LD), and a binary output suffix (OUT). -cc_OBJ := o -cc_LD := $(LD) -cc_AR := $(AR) -cc_AROBJ := a -cc_DBG := gdb -$(cpp_C)_LD := $(cc_LD) -gcc_OBJ := $(cc_OBJ) -gcc_LD := $(cc_LD) -ngcc_AR := $(cc_AR) -gcc_AROBJ := $(cc_AROBJ) -gcc_DBG := $(cc_DBG) -emcc_OBJ := bc -emcc_AR := emar -emcc_AROBJ := $(emcc_OBJ) #emar is just a python script that reparses shit for emcc -emcc_OUT := .js -g++_OBJ := $(cc_OBJ) -em++_OBJ := $(emcc_OBJ) -em++_AR := $(emcc_AR) -em++_AROBJ := $(emcc_AROBJ) -em++_OUT := $(emcc_OUT) -gccgo_OBJ := o -gccgo_LD := $(cc_LD) -gccgo_AR := $(cc_AR) -gccgo_AROBJ := $(cc_AROBJ) -# Shell functions to determine what libraries can be linked by the compiler -cc_LDLIBS := $(shell ldconfig -p | sed -e 's@\-*[0-9\.]*\.so.*$$@@g' -e 's@\tlib@@g' -e '/[\t ]/d') -gcc_LDLIBS := $(cc_LDLIBS) -emcc_LDLIBS := -g++_LDLIBS := $(cc_LDLIBS) -em++_LDLIBS := -go_LDLIBS := $(cc_LDLIBS) -# location to build cross-compilation libraries in, not intended to be installed -# in the host system -LIB_DIR := $(ROOT_DIR)/lib$(shell uname -m)/$($(c_C)_OBJ) -LIBDL_DIR := $(LIB_DIR)/.cache -LIBINC_DIR := $(ROOT_DIR)/include -# The makefile MUST be capable of generating these directories and all of their -# contents. These directories are removed during the 'scrub' rule -MAKE_DIRS := $(LIB_DIR) $(LIBDL_DIR) -# Set up lib inclusions, and scan for built libs -c_FLAGS += -I$(LIBINC_DIR) -c_OBJ := $($(c_C)_OBJ) -# Modules are any directories other than 'DRIVER_MODULE' in 'SRC_DIR' and -# produce a single archive in 'SRC_DIR' containing all of the module's symbols -MODULES := $(patsubst $(SRC_DIR)/%/,%,$(filter-out $(DRIVER_DIR)/%,$(shell ls -d $(SRC_DIR)/*/))) - +# include initialization variables +include $(CONF_DIR)/init.mk # Include the make libraries -include make/lib/*.mk +include $(CONF_DIR)/lib/*.mk + +# The default rule to be built if none specified +default: all # If available, invoke the premake system ifdef PREMAKE_SOURCE_COMPILER $(eval $(call PREMAKE_SOURCE_COMPILER,)) else -$(info Warning: No premake system found, source-to-source languages (e.g. bison) not functional) +$(info No premake system found, source-to-source languages (e.g. ragel) not functional) endif # Backup the CVS password and CVSROOT environment vars in case we change them +# during lib downloading $(if $(wildcard ~/.cvspass),\ $(eval CVSPASS_BAK := $(file <~/.cvspass))) $(if $(CVSROOT),\ $(eval CVSROOT_BAK := $(CVSROOT))) -# The recursive library dependecy traversal constructs a tree ordered by nested -# dependency depth. when linking, this order is reversed. -# Initialize each language and look for its files +# Initialize each language, look for its source files, and generate rules ifdef LANG_INIT $(foreach lang,$(LANGS),\ $(eval $(call LANG_INIT,$(lang)))\ @@ -132,16 +61,13 @@ $(eval $(call SRC_LANG_DRVRULE,$(drvsrc),$(lang)))\ )) # Create driver rules for each driver we found, let users call make specifying -# the basename of the driver file, and just route to the correct e we -# made in the last paragraph -DRV_FNAMES := $(notdir $(DRV_SRC)) -.PHONY: all $(basename $(DRV_NAMES)) -$(foreach fname,$(DRV_FNAMES),\ -$(eval $(basename $(fname)): \ -$(filter %/$(basename $(fname))$($(lastword $(subst ., ,$(fname))_OUT)),$(DRV_TRG)))\ +# the basename of the driver file, and just route to the correct linking rule +$(foreach drvsrc,$(DRV_SRC),\ +$(eval $(call DRVSRC_DRIVERPHONY,$(drvsrc)))\ ) -all: $(basename $(DRV_FNAMES)) - @echo Build Complete + +.PHONY: all +all: $(PH_TARGS) # Rule to make any dirs that we're in charge of $(sort $(MAKE_DIRS)): @@ -161,7 +87,7 @@ scrub: clean # Purge destroys all distributables created by a distributable binary # (e.g. assets) -# Uninstall destroys all objects and directories that cannot be recreated by -# this make file +# Uninstall destroys all objects and directories that can be recreated by this +# make file uninstall: scrub rm -Rf $(MAKE_DIRS) diff --git a/make/init.mk b/make/init.mk new file mode 100644 index 0000000..4f46057 --- /dev/null +++ b/make/init.mk @@ -0,0 +1,80 @@ +################################################################################ +# Desc: Environment initialization for webcc +# Author: ksg +# Date: 2016 +################################################################################ +# This file reads default Make vars and environment vars to produce a standard +# set of variables to compile with +################################################################################ +# Source languages handled by this build system. These languages are capable of +# being compiled to an intermediary format for binary output by one of the +# provided compilers for each language +LANGS := c cpp go +# Language-specific compilers and flags passed in from environment +c_C := $(strip $(notdir $(CC))) +c_FLAGS := $(strip $(CFLAGS)) -I$(SRC_DIR) +c_SRCL := y +cpp_C := $(strip $(notdir $(CXX))) +cpp_FLAGS := $(strip $(CXXFLAGS)) $(c_FLAGS) +go_C := gccgo +go_FLAGS := $(c_FLAGS) +# Source-to-source languages handled by this build system +SLANGS := y rl +# Yacc +y_C := bison +y_FLAGS := -d +y_TRG := c h +y_STEM := tab +# Ragel +rl_C := ragel +rl_FLAGS := -C +rl_TRG := c +rl_STEM := fsm +# Compiler-specific associations. Each compiler has a binary object suffix +# (OBJ), an archiver (AR), and an archiver object suffix (AROBJ). Each compiler +# may optionally have defined a linker (LD), and a binary output suffix (OUT). +cc_OBJ := o +cc_LD := $(LD) +cc_AR := $(AR) +cc_AROBJ := a +cc_DBG := gdb +$(cpp_C)_LD := $(cc_LD) +gcc_OBJ := $(cc_OBJ) +gcc_LD := $(cc_LD) +ngcc_AR := $(cc_AR) +gcc_AROBJ := $(cc_AROBJ) +gcc_DBG := $(cc_DBG) +emcc_OBJ := bc +emcc_AR := emar +emcc_AROBJ := $(emcc_OBJ) #emar is just a python script that reparses shit for emcc +emcc_OUT := .js +g++_OBJ := $(cc_OBJ) +em++_OBJ := $(emcc_OBJ) +em++_AR := $(emcc_AR) +em++_AROBJ := $(emcc_AROBJ) +em++_OUT := $(emcc_OUT) +gccgo_OBJ := o +gccgo_LD := $(cc_LD) +gccgo_AR := $(cc_AR) +gccgo_AROBJ := $(cc_AROBJ) +# Shell functions to determine what libraries can be linked by the compiler +cc_LDLIBS := $(shell ldconfig -p | sed -e 's@\-*[0-9\.]*\.so.*$$@@g' -e 's@\tlib@@g' -e '/[\t ]/d') +gcc_LDLIBS := $(cc_LDLIBS) +emcc_LDLIBS := +g++_LDLIBS := $(cc_LDLIBS) +em++_LDLIBS := +go_LDLIBS := $(cc_LDLIBS) +# location to build cross-compilation libraries in, not intended to be installed +# in the host system +LIB_DIR := $(ROOT_DIR)/lib$(shell uname -m)/$($(c_C)_OBJ) +LIBDL_DIR := $(LIB_DIR)/.cache +LIBINC_DIR := $(ROOT_DIR)/include +# The makefile MUST be capable of generating these directories and all of their +# contents. These directories are removed during the 'scrub' rule +MAKE_DIRS := $(LIB_DIR) $(LIBDL_DIR) +# Set up lib inclusions, and scan for built libs +c_FLAGS += -I$(LIBINC_DIR) +c_OBJ := $($(c_C)_OBJ) +# Modules are any directories other than 'DRIVER_MODULE' in 'SRC_DIR' and +# produce a single archive in 'SRC_DIR' containing all of the module's symbols +MODULES := $(patsubst $(SRC_DIR)/%/,%,$(filter-out $(DRIVER_DIR)/%,$(shell ls -d $(SRC_DIR)/*/))) diff --git a/make/lib/rules.mk b/make/lib/rules.mk index 8bac388..c798491 100644 --- a/make/lib/rules.mk +++ b/make/lib/rules.mk @@ -107,6 +107,8 @@ $(eval DRIVER_LDFILE := $(DRV_LD)) $(eval $1_LD := $(file <$(DRIVER_LDFILE))) $(eval undefine DRIVER_LDINFO) $(eval undefine DRIVER_LDINFO_D) +$(eval DRIVER_LDINFO += $(1:%.$2=%.$($2_OBJ))) +$(eval DRIVER_LDINFO_D += $(1:$(dir $1)%.$2=$(dir $1).$($2_DBG)/%.$($2_OBJ))) $(foreach ldobj,$($1_LD), $(if $(filter -l%,$(ldobj)), $(eval ldlibname := $(ldobj:-l%=%)) @@ -129,10 +131,6 @@ $(eval DRIVER_LDINFO += $(LIB_DIR)/$(deplib).$($2_AROBJ)) $(eval DRIVER_LDINFO_D += $(LIB_DIR)/.$($2_DBG)/$(deplib).$($2_AROBJ))) )) ) -$(eval DRIVER_LDINFO += $(1:%.$2=%.$($2_OBJ))) -$(eval DRIVER_LDINFO_D += $(1:$(dir $1)%.$2=$(dir $1).$($2_DBG)/%.$($2_OBJ))) -$(info DRIVER_INFO: $(DRIVER_LDINFO)) -$(info DRIVER_INFO:: $(DRIVER_LDINFO_D)) # Directory setup $(eval MAKE_DIRS += $(dir $(DRIVER_TARG))) @@ -147,10 +145,6 @@ $(DRIVER_TARG): $(filter-out -l%,$(DRIVER_LDINFO)) | $(dir $(DRIVER_TARG)) $(eval MAKE_DIRS += $(DRIVER_TARG_DIR).$($2_DBG)/) $(DRIVER_TARG_D): $(filter-out -l%,$(DRIVER_LDINFO_D)) | $(dir $(DRIVER_TARG_D)) $($2_C) $($2_FLAGS) $(DRIVER_LDINFO_D) -o $$@ -# Make a rule to run this driver after building -$(DRIVER_NAME)-run: $(DRIVER_TARG) - $(DRIVER_TARG) -$(DRIVER_NAME)-d: $(DRIVER_TARG_D) #/SRC_LANG_DRVRULE############################################################### endef @@ -312,7 +306,7 @@ $(eval $2_INIT := t) #/LANG_LIB_INIT################################################################# endef -# Initialize data for supported lanaguages ###################################### +# Initialize data for supported lanaguages ##################################### define LANG_INIT = $(eval $1_OBJ := $($($1_C)_OBJ) @@ -351,5 +345,19 @@ $(module)_TRG += $($(module)_$1_TRG) $(foreach src,$(filter $(SRC_DIR)/$(module)/%,$($1_MOD_SRC)),\ $(eval $(call SRC_LANG_RULE,$(src),$1))\ )) -#/LANG_INIT###################################################################### +#/LANG_INIT##################################################################### +endef + +# Create a phony target and rule for the specified source driver +define DRVSRC_DRIVERPHONY +$(eval PH_TARG := $(basename $(notdir $1))) +$(eval PH_TARGS += $(PH_TARG)) +$(eval PH_LANG := $(lastword $(subst ., ,$1))) +$(eval RL_TARG := $(basename $(subst $(SRC_DIR),$(ROOT_DIR),$1))$($(PH_LANG)_OUT)) +.PHONY: $(PH_TARG) $(PH_TARG:%=%-d) +$(PH_TARG): $(RL_TARG) + @echo Built [$$@] at ./$$< +$(PH_TARG:%=%-d): $(RL_TARG:%=%-d) + @echo Build [$$@] with debugging information at ./$$< +#/SRC_SIMLIST_PHONYRULE ######################################################## endef -- 2.18.0