diff --git a/Makefile.Android.mk b/Makefile.Android.mk index 5686726..dab9cc1 100644 --- a/Makefile.Android.mk +++ b/Makefile.Android.mk @@ -5,7 +5,7 @@ PROJECT_PACKAGE=$(PROJECT_NAME)package USER_PACKAGES += $(EWOL_FOLDER)/Sources/ TARGET_OS = Android TARGET_ARCH = ARM -CROSS = $(PROJECT_NDK)/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi- +TARGET_CROSS = $(PROJECT_NDK)/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi- #Add the basic element abstraction of ewol lib diff --git a/Makefile.Windows.mk b/Makefile.Windows.mk index 4f4e7ac..ef8306e 100644 --- a/Makefile.Windows.mk +++ b/Makefile.Windows.mk @@ -4,6 +4,6 @@ USER_PACKAGES += $(EWOL_FOLDER)/Sources/ # defien the target OS of this system TARGET_OS=Windows # define the cross compilateur -CROSS=i586-mingw32msvc- +TARGET_CROSS=i586-mingw32msvc- include $(EWOL_FOLDER)/Build/core/main.mk diff --git a/core/config.mk b/core/config.mk index fc7aa79..d521c5d 100644 --- a/core/config.mk +++ b/core/config.mk @@ -11,10 +11,11 @@ CONF := KCONFIG_NOTIMESTAMP=1 $(call fullpath,$(BUILD_SYSTEM)/conf) QCONF := KCONFIG_NOTIMESTAMP=1 $(call fullpath,$(BUILD_SYSTEM)/qconf) # Directory where original configurations are stored -CONFIG_ORIG_DIR := $(TOP_DIR)/config-ymm +CONFIG_ORIG_DIR := $(TARGET_CONFIG_DIR) # File where global configuration is stored CONFIG_GLOBAL_FILE := $(CONFIG_ORIG_DIR)/global.config +-include $(CONFIG_GLOBAL_FILE) ############################################################################### ## Begin conf/qconf by copying configuration file to a temp .config file. diff --git a/core/defs.mk b/core/defs.mk index 7e0b49f..fd1a0d9 100644 --- a/core/defs.mk +++ b/core/defs.mk @@ -12,6 +12,12 @@ empty := space := $(empty) $(empty) space4 := $(space)$(space)$(space)$(space) +true := T +false := + +# Return negation of argument. +# $1 : input boolean argument. +not = $(if $1,$(false),$(true)) # Return the first element of a list. # $ 1 : input list. @@ -52,6 +58,16 @@ check-pwd-is-top-dir = \ $(if $(patsubst $(TOP_DIR)%,%,$(shell pwd)), \ $(error Not at the top directory)) +# Compare 2 strings for equality. +# $1 : first string. +# $2 : second string. +streq = $(if $(filter-out xx,x$(subst $1,,$2)$(subst $2,,$1)x),$(false),$(true)) + +# Compare 2 strings for inequality. +# $1 : first string. +# $2 : second string. +strneq = $(call not,$(call streq,$1,$2)) + ############################################################################### ## Modules database. ## For each module 'mod', __modules.mod. is used to store @@ -99,8 +115,11 @@ modules-LOCALS += SHARED_LIBRARIES # Used as dependencies to trigger indirect build. modules-LOCALS += EXTERNAL_LIBRARIES +# General libraries to add in dependency based on their actual class (STATIC/SHARED/EXTERNAL). +modules-LOCALS += LIBRARIES + # Additional include directories to pass into the C/C++ compilers -# Format : +# Format : (-I will be prepended automatically) modules-LOCALS += C_INCLUDES # Additional flags to pass into the C or C++ compiler @@ -143,6 +162,12 @@ modules-LOCALS += EXPORT_PREREQUISITES # Module class : STATIC_LIBRARY SHARED_LIBRARY EXECUTABLE modules-LOCALS += MODULE_CLASS +# List of files to copy +# Format : +# src : source (relative to module path) +# dst : destination (relative to staging dir) +modules-LOCALS += COPY_FILES + # Other variables used internally modules-LOCALS += BUILD_MODULE modules-LOCALS += STAGING_MODULE @@ -176,17 +201,48 @@ modules-dump-database = \ ) \ $(info --- end of modules list) +# This will only dump dependencies +modules-dump-database-depends = \ + $(foreach __mod,$(__modules), \ + $(info $(__mod):) \ + $(info $(space4)$(strip $(__modules.$(__mod).depends))) \ + ) + ############################################################################### ## Add a module in the build system and save its LOCAL_xxx variables. -## $1 : name of module to add. All LOCAL_xxx variables will be saved in -## module database. +## All LOCAL_xxx variables will be saved in module database. ############################################################################### module-add = \ - $(eval __modules += $1) \ + $(eval LOCAL_MODULE := $(strip $(LOCAL_MODULE))) \ + $(if $(LOCAL_MODULE),$(empty), \ + $(error $(LOCAL_PATH): LOCAL_MODULE is not defined)) \ + $(eval __mod := $(LOCAL_MODULE)) \ + $(if $(call is-module-registered,$(__mod)), \ + $(eval __path := $(__modules.$(__mod).PATH)) \ + $(error $(LOCAL_PATH): module '$(__mod)' already registered at $(__path)) \ + ) \ + $(eval __modules += $(__mod)) \ $(foreach __local,$(modules-LOCALS), \ - $(eval __modules.$1.$(__local) := $(LOCAL_$(__local))) \ + $(eval __modules.$(__mod).$(__local) := $(LOCAL_$(__local))) \ ) +############################################################################### +## Check that a module is registered. +## $1 : module to check. +############################################################################### +is-module-registered = \ + $(strip $(foreach __mod,$(__modules), \ + $(if $(call streq,$(__mod),$1),$(true)) \ + )) + +############################################################################### +## Check that a module wil be built. +## $1 : module to check. +############################################################################### +is-module-in-build-config = \ + $(if $(CONFIG_BUILD_$(call get-define,$1)),$(true)) + + ############################################################################### ## Restore the recorded LOCAL_XXX definitions for a given module. Called ## for each module once they have all been registered and their dependencies @@ -199,15 +255,115 @@ module-restore-locals = \ ) ############################################################################### -## Used to recompute all dependencies once all module information has been +## Used to check all dependencies once all module information has been +## recorded. +############################################################################### + +# Check dependencies of all modules +modules-check-depends = \ + $(foreach __mod,$(__modules), \ + $(call __module-check-depends,$(__mod)) \ + ) + +# Check dependency of a module +# $1 : module name. +__module-check-depends = \ + $(foreach __lib,$(__modules.$1.depends), \ + $(if $(call is-module-registered,$(__lib)),$(empty), \ + $(eval __path := $(__modules.$1.PATH)) \ + $(if $(call is-module-in-build-config,$1), \ + $(error $(__path): module '$1' depends on unknown module '$(__lib)'), \ + $(warning $(__path): module '$1' depends on unknown module '$(__lib)') \ + ) \ + ) \ + ) \ + $(call __module-check-libs-class,$1,WHOLE_STATIC_LIBRARIES,STATIC_LIBRARY) \ + $(call __module-check-libs-class,$1,STATIC_LIBRARIES,STATIC_LIBRARY) \ + $(call __module-check-libs-class,$1,SHARED_LIBRARIES,SHARED_LIBRARY) \ + +# $1 : module name of owner. +# $2 : dependency to check (WHOLE_STATIC_LIBRARIES,STATIC_LIBRARIES,SHARED_LIBRARIES). +# $3 : class to check (STATIC_LIBRARY,SHARED_LIBRARY) +__module-check-libs-class = \ + $(foreach __lib,$(__modules.$1.$2), \ + $(call __module-check-lib-class,$1,$(__lib),$3) \ + ) + +# Check that a dependency is of the correct class +# $1 : module name of owner. +# $2 : library to check. +# $3 : class to check (STATIC_LIBRARY,SHARED_LIBRARY) +__module-check-lib-class = \ + $(if $(call strneq,$(__modules.$2.MODULE_CLASS),$3), \ + $(eval __path := $(__modules.$1.PATH)) \ + $(if $(call is-module-in-build-config,$1), \ + $(error $(__path): module '$1' depends on module '$2' which is not of class '$3'), \ + $(warning $(__path): module '$1' depends on module '$2' which is not of class '$3') \ + ) \ + ) + +############################################################################### +## Used to make some internal checks. +############################################################################### + +# Check variables of all modules +modules-check-variables = \ + $(foreach __mod,$(__modules), \ + $(call __module-check-variables,$(__mod)) \ + ) + +# Check variables of a module +# $1 : module name. +__module-check-variables = \ + $(call __module-check-src-files,$1) \ + $(call __module-check-c-includes,$1) + +# Check that all files listed in LOCAL_SRC_FILES exist +# $1 : module name. +__module-check-src-files = \ + $(eval __path := $(__modules.$1.PATH)) \ + $(foreach __file,$(__modules.$1.SRC_FILES), \ + $(if $(wildcard $(__path)/$(__file)),$(empty), \ + $(warning $(__path): module '$1' uses missing source file '$(__file)') \ + ) \ + ) + +# Check that all directory listed in LOCAL_C_INCLUDES exist +__module-check-c-includes = \ + $(eval __path := $(__modules.$1.PATH)) \ + $(foreach __inc,$(__modules.$1.C_INCLUDES), \ + $(eval __inc2 := $(patsubst -I%,%,$(__inc))) \ + $(if $(wildcard $(__inc2)),$(empty), \ + $(warning $(__path): module '$1' uses missing include '$(__inc2)') \ + ) \ + ) + +############################################################################### +## Used to compute all dependencies once all module information has been ## recorded. ############################################################################### # Compute dependencies of all modules -modules-compute-dependencies = \ +modules-compute-depends = \ $(foreach __mod,$(__modules), \ - $(eval __modules.$(__mod).depends := ) \ + $(eval __modules.$(__mod).depends := $(empty)) \ + $(call __module-update-depends,$(__mod)) \ $(call __module-compute-depends,$(__mod)) \ + ) + +# Update dependecies of a single module. +# It updates XXX_LIBRARIES based on LIBRARIES and actual dependency class. +# $1 : module name. +__module-update-depends = \ + $(foreach __lib,$(__modules.$1.LIBRARIES), \ + $(eval __class := $(__modules.$(__lib).MODULE_CLASS)) \ + $(if $(call streq,$(__class),STATIC_LIBRARY), \ + $(eval __modules.$1.STATIC_LIBRARIES += $(__lib)), \ + $(if $(call streq,$(__class),SHARED_LIBRARY), \ + $(eval __modules.$1.SHARED_LIBRARIES += $(__lib)), \ + $(eval __modules.$1.EXTERNAL_LIBRARIES += $(__lib)) \ + ) \ + ) \ ) # Compute dependencies of a single module @@ -254,7 +410,7 @@ module-get-listed-autoconf = \ )) ############################################################################### -## Dependecy management +## Dependency management ############################################################################### # Return list all the modules $1 depends on transitively. @@ -269,12 +425,11 @@ module-get-all-dependencies = \ # Recursively get dependency of a modules __modules-get-closure = \ - $(eval __closure_deps := $(strip $1)) \ - $(if $(__closure_deps), \ - $(eval __closure_wq := $(__closure_deps)) \ - $(eval __closure_field := $(strip $2)) \ - $(call __modules-closure)) \ - $(__closure_deps) \ + $(eval __closure_deps := $(empty)) \ + $(eval __closure_wq := $(strip $1)) \ + $(eval __closure_field := $(strip $2)) \ + $(if $(__closure_wq), $(call __modules-closure)) \ + $(strip $(__closure_deps)) # Used internally by modules-get-all-dependencies. Note the tricky use of # conditional recursion to work around the fact that the GNU Make language does @@ -286,7 +441,7 @@ __modules-closure = \ $(eval __closure_new := $(filter-out $(__closure_deps),$(__closure_val))) \ $(eval __closure_deps += $(__closure_new)) \ $(eval __closure_wq := $(strip $(__closure_wq) $(__closure_new))) \ - $(if $(__closure_wq),$(call __modules-closure)) \ + $(if $(__closure_wq),$(call __modules-closure)) ############################################################################### ## Get path of module main target file (in build or staging directory). @@ -329,6 +484,15 @@ define generate-autoconf-file $1 > $2; endef +############################################################################### +## Normalize a list of includes. It adds -I if needed. +## $1 : list of includes +############################################################################### +normalize-c-includes = \ + $(strip $(foreach __inc,$1, \ + $(addprefix -I,$(patsubst -I%,%,$(__inc))) \ + )) + ############################################################################### ## Commands for running gcc to generate a precompiled file. ############################################################################### @@ -337,8 +501,9 @@ define transform-h-to-gch @mkdir -p $(dir $@) @echo "Precompile: $(PRIVATE_MODULE) <== $(call path-from-top,$<)" $(call check-pwd-is-top-dir) -$(Q)$(CCACHE) $(CXX) \ - $(TARGET_GLOBAL_C_INCLUDES) $(PRIVATE_C_INCLUDES) \ +$(Q)$(CCACHE) $(TARGET_CXX) \ + $(TARGET_GLOBAL_C_INCLUDES) \ + $(PRIVATE_C_INCLUDES) \ $(TARGET_GLOBAL_CFLAGS) $(TARGET_GLOBAL_CPPFLAGS) $(CXX_FLAGS_WARNINGS) \ $(PRIVATE_CFLAGS) $(PRIVATE_CPPFLAGS) \ $(TARGET_PCH_FLAGS) -MMD -MP -o $@ \ @@ -353,8 +518,9 @@ define transform-cpp-to-o @mkdir -p $(dir $@) @echo "$(DISPLAY_ARM_MODE)C++: $(PRIVATE_MODULE) <== $(call path-from-top,$<)" $(call check-pwd-is-top-dir) -$(Q)$(CCACHE) $(CXX) \ - $(TARGET_GLOBAL_C_INCLUDES) $(PRIVATE_C_INCLUDES) \ +$(Q)$(CCACHE) $(TARGET_CXX) \ + $(TARGET_GLOBAL_C_INCLUDES) \ + $(PRIVATE_C_INCLUDES) \ $(TARGET_GLOBAL_CFLAGS_$(PRIVATE_ARM_MODE)) \ $(TARGET_GLOBAL_CFLAGS) $(TARGET_GLOBAL_CPPFLAGS) $(CXX_FLAGS_WARNINGS) \ $(PRIVATE_CFLAGS) $(PRIVATE_CPPFLAGS) \ @@ -370,8 +536,9 @@ define transform-c-to-o @echo "$(DISPLAY_ARM_MODE)C: $(PRIVATE_MODULE) <== $(call path-from-top,$<)" $(call check-pwd-is-top-dir) @mkdir -p $(dir $@) -$(Q)$(CCACHE) $(CC) \ - $(TARGET_GLOBAL_C_INCLUDES) $(PRIVATE_C_INCLUDES) \ +$(Q)$(CCACHE) $(TARGET_CC) \ + $(TARGET_GLOBAL_C_INCLUDES) \ + $(PRIVATE_C_INCLUDES) \ $(TARGET_GLOBAL_CFLAGS_$(PRIVATE_ARM_MODE)) \ $(TARGET_GLOBAL_CFLAGS) $(CC_FLAGS_WARNINGS) \ $(PRIVATE_CFLAGS) \ @@ -387,8 +554,9 @@ define transform-s-to-o @ echo "ASM: $(PRIVATE_MODULE) <== $(call path-from-top,$<)" $(call check-pwd-is-top-dir) @mkdir -p $(dir $@) -$(Q)$(CCACHE) $(CC) \ - $(TARGET_GLOBAL_C_INCLUDES) $(PRIVATE_C_INCLUDES) \ +$(Q)$(CCACHE) $(TARGET_CC) \ + $(TARGET_GLOBAL_C_INCLUDES) \ + $(PRIVATE_C_INCLUDES) \ $(TARGET_GLOBAL_CFLAGS_$(PRIVATE_ARM_MODE)) \ $(TARGET_GLOBAL_CFLAGS) $(CC_FLAGS_WARNINGS) \ $(PRIVATE_CFLAGS) \ @@ -407,8 +575,8 @@ define transform-o-to-static-lib @echo "StaticLib: $(PRIVATE_MODULE) ==> $(call path-from-top,$@)" $(call check-pwd-is-top-dir) @rm -f $@ -$(Q)$(AR) $(TARGET_GLOBAL_ARFLAGS) $(PRIVATE_ARFLAGS) $@ $(PRIVATE_ALL_OBJECTS) -$(Q)$(RANLIB) $@ +$(Q)$(TARGET_AR) $(TARGET_GLOBAL_ARFLAGS) $(PRIVATE_ARFLAGS) $@ $(PRIVATE_ALL_OBJECTS) +$(Q)$(TARGET_RANLIB) $@ endef ############################################################################### @@ -419,7 +587,7 @@ define transform-o-to-shared-lib @mkdir -p $(dir $@) @echo "SharedLib: $(PRIVATE_MODULE) ==> $(call path-from-top,$@)" $(call check-pwd-is-top-dir) -$(Q)$(CXX) \ +$(Q)$(TARGET_CXX) \ $(TARGET_GLOBAL_LDFLAGS_SHARED) \ -Wl,-Map -Wl,$(basename $@).map \ -shared \ @@ -446,7 +614,8 @@ define transform-o-to-executable @mkdir -p $(dir $@) @echo "Executable: $(PRIVATE_MODULE) ==> $(call path-from-top,$@)" $(call check-pwd-is-top-dir) -$(Q)$(CXX) \ +@# TODO : Set LD ... +$(Q)$(TARGET_CXX) \ $(TARGET_GLOBAL_LDFLAGS) \ -Wl,-Map -Wl,$(basename $@).map \ -Wl,-rpath-link=$(TARGET_OUT_STAGING)/lib \ @@ -464,13 +633,19 @@ $(Q)$(CXX) \ $(TARGET_GLOBAL_LDLIBS) endef +# --start-group \ +# $(PRIVATE_ALL_STATIC_LIBRARIES) \ +# $(PRIVATE_ALL_SHARED_LIBRARIES) \ +# --end-group \ +# -o $@ \ + ############################################################################### ## Commands for copying files. ############################################################################### # Copy a single file from one place to another, preserving permissions and # overwriting any existing file. -define copy-file-to-target +define do-copy-file @mkdir -p $(dir $@) $(Q)cp -fp $< $@ endef @@ -480,25 +655,8 @@ endef # $(2) : destination file define copy-one-file $(2): $(1) - @echo "Copy: $$(call path-from-top,$$@)" - $$(copy-file-to-target) -endef - -############################################################################### -## Default rules for a module. -## $1 : module name. -############################################################################### - -define def-rules - -.PHONY: $1 -$1: $(call module-get-build-filename,$1) - -.PHONY: clean-$1 -clean-$1: - @rm -f $(call module-get-build-filename,$1) - @rm -rf $(call module-get-build-dir,$1) - + @echo "Copy: $$(call path-from-top,$$<) => $$(call path-from-top,$$@)" + $$(do-copy-file) endef ############################################################################### @@ -512,7 +670,5 @@ local-get-path = $(call my-dir) local-get-build-dir = $(call module-get-build-dir,$(LOCAL_MODULE)) # Register module -local-add-module = \ - $(call module-add,$(LOCAL_MODULE)) \ - $(eval $(call def-rules,$(LOCAL_MODULE))) +local-add-module = $(module-add) diff --git a/core/executable.mk b/core/executable.mk index 9430c5e..f69bf10 100644 --- a/core/executable.mk +++ b/core/executable.mk @@ -7,10 +7,13 @@ ############################################################################### LOCAL_MODULE_CLASS := EXECUTABLE + +ifeq ("$(LOCAL_DESTDIR)","") LOCAL_DESTDIR := usr/bin +endif ifeq ("$(LOCAL_MODULE_FILENAME)","") LOCAL_MODULE_FILENAME := $(LOCAL_MODULE)$(TARGET_EXE_SUFFIX) endif -$(call module-add,$(LOCAL_MODULE)) +$(local-add-module) diff --git a/core/main.mk b/core/main.mk index 1e38300..8d47a67 100644 --- a/core/main.mk +++ b/core/main.mk @@ -30,44 +30,6 @@ ifeq ("$(V)","0") Q := @ endif -# Tools for host -HOST_CC ?= gcc -HOST_CXX ?= g++ -HOST_AR ?= ar -HOST_LD ?= ld -HOST_STRIP ?= strip - -# Tools for target -ifneq ("$(CLANG)","1") - CC := $(CROSS)gcc - CXX := $(CROSS)g++ -else - CC := $(CROSS)clang - CXX := $(CROSS)clang++ -endif -AR := $(CROSS)ar -LD := $(CROSS)ld -AS := $(CROSS)as -NM := $(CROSS)nm -STRIP := $(CROSS)strip -RANLIB := $(CROSS)ranlib -DLLTOOL := $(CROSS)dlltool - - -# Target global variables -TARGET_GLOBAL_C_INCLUDES ?= -TARGET_GLOBAL_CFLAGS ?= -TARGET_GLOBAL_CPPFLAGS ?= -TARGET_GLOBAL_RCFLAGS ?= -TARGET_GLOBAL_ARFLAGS ?= rcs -TARGET_GLOBAL_LDFLAGS ?= -TARGET_GLOBAL_LDFLAGS_SHARED ?= -TARGET_GLOBAL_LDLIBS ?= -TARGET_GLOBAL_LDLIBS_SHARED ?= -TARGET_PCH_FLAGS ?= -TARGET_DEFAULT_ARM_MODE ?= THUMB -TARGET_GLOBAL_CFLAGS_ARM ?= -TARGET_GLOBAL_CFLAGS_THUMB ?= ############################################################################### ## The folowing 2 macros can NOT be put in defs.mk as it will be included @@ -107,7 +69,8 @@ CLEAR_VARS := $(BUILD_SYSTEM)/clearvars.mk BUILD_STATIC_LIBRARY := $(BUILD_SYSTEM)/static.mk BUILD_SHARED_LIBRARY := $(BUILD_SYSTEM)/shared.mk BUILD_EXECUTABLE := $(BUILD_SYSTEM)/executable.mk -RULES := $(BUILD_SYSTEM)/rules.mk +BUILD_PREBUILT := $(BUILD_SYSTEM)/prebuilt.mk +BUILD_RULES := $(BUILD_SYSTEM)/rules.mk ############################################################################### ## Makefile scan and includes. @@ -144,7 +107,7 @@ $(foreach __makefile,$(_tmpDirectory), \ ) \ ) ifeq ("$(V)","1") - $(info makefiles="$(makefiles)") + $(info makefiles="$(makefiles)") endif # import all the makefiles include $(makefiles) @@ -155,9 +118,16 @@ include $(makefiles) ############################################################################### # Recompute all dependencies between modules -$(call modules-compute-dependencies) +$(call modules-compute-depends) -# Now, really build the modules, the second pass allows to deal with exported values +# Check dependencies +$(call modules-check-depends) + +# Check variables of modules +$(call modules-check-variables) + +# Now, really generate rules for modules. +# This second pass allows to deal with exported values. $(foreach __mod,$(__modules), \ $(eval LOCAL_MODULE := $(__mod)) \ $(eval include $(BUILD_SYSTEM)/module.mk) \ @@ -182,11 +152,21 @@ $(AUTOCONF_MERGE_FILE): $(__autoconf-list) # Main rules. ############################################################################### +# All modules +ALL_MODULES := \ + $(foreach __mod,$(__modules),$(__mod)) + +# All module to actually build +ALL_BUILD_MODULES := \ + $(foreach __mod,$(__modules), \ + $(if $(call is-module-in-build-config,$(__mod)),$(__mod))) + +# TODO : Set ALL_BUILD_MODULES ==> find the end point module (SHARED/BINARY) .PHONY: all -all: $(foreach __mod,$(__modules),$(__mod)) $(AUTOCONF_MERGE_FILE) +all: $(ALL_MODULES) $(AUTOCONF_MERGE_FILE) .PHONY: clean -clean: $(foreach __mod,$(__modules),clean-$(__mod)) +clean: $(foreach __mod,$(ALL_MODULES),clean-$(__mod)) @rm -f $(AUTOCONF_MERGE_FILE) # Dump the module database for debuging the build system @@ -194,6 +174,15 @@ clean: $(foreach __mod,$(__modules),clean-$(__mod)) dump: $(call modules-dump-database) +# Dump the module database for debuging the build system +.PHONY: dump-depends +dump-depends: + $(call modules-dump-database-depends) + +# Dummy target to check internal variables +.PHONY: check +check: + ############################################################################### # Display configuration. ############################################################################### @@ -204,6 +193,6 @@ $(info TARGET_ARCH: $(TARGET_ARCH)) $(info TARGET_OUT_BUILD: $(TARGET_OUT_BUILD)) $(info TARGET_OUT_STAGING: $(TARGET_OUT_STAGING)) $(info TARGET_OUT_FINAL: $(TARGET_OUT_FINAL)) -$(info CC_PATH: $(CC_PATH)) -$(info CC_VERSION: $(CC_VERSION)) +$(info TARGET_CC_PATH: $(TARGET_CC_PATH)) +$(info TARGET_CC_VERSION: $(TARGET_CC_VERSION)) $(info ----------------------------------------------------------------------) diff --git a/core/module.mk b/core/module.mk index d0d2b35..e26aa0d 100644 --- a/core/module.mk +++ b/core/module.mk @@ -9,19 +9,65 @@ # Bring back all LOCAL_XXX variables defined by LOCAL_MODULE $(call module-restore-locals,$(LOCAL_MODULE)) +# Do we need to copy build module to staging dir copy_to_staging := 0 +# Full path to build module +LOCAL_BUILD_MODULE := $(call module-get-build-filename,$(LOCAL_MODULE)) + +# Full path to staging module +LOCAL_STAGING_MODULE := $(call module-get-staging-filename,$(LOCAL_MODULE)) + +# Assemble the list of targets to create PRIVATE_ variables for. +LOCAL_TARGETS := $(LOCAL_BUILD_MODULE) clean-$(LOCAL_MODULE) + +# Add external libraries used by static libraries +LOCAL_EXTERNAL_LIBRARIES += \ + $(call module-get-depends,$(LOCAL_STATIC_LIBRARIES),EXTERNAL_LIBRARIES) +LOCAL_EXTERNAL_LIBRARIES += \ + $(call module-get-depends,$(LOCAL_WHOLE_STATIC_LIBRARIES),EXTERNAL_LIBRARIES) + +# List of external libraries that we need to depend on +all_external_libraries := \ + $(foreach lib,$(LOCAL_EXTERNAL_LIBRARIES), \ + $(call module-get-build-filename,$(lib))) + +############################################################################### +## Rule-specific variable definitions. +############################################################################### + +$(LOCAL_TARGETS): PRIVATE_PATH := $(LOCAL_PATH) +$(LOCAL_TARGETS): PRIVATE_MODULE := $(LOCAL_MODULE) +$(LOCAL_TARGETS): PRIVATE_CLEAN_FILES := $(LOCAL_BUILD_MODULE) +$(LOCAL_TARGETS): PRIVATE_CLEAN_DIRS := + +############################################################################### +## General rules. +############################################################################### + +# Short hand to build module +.PHONY: $(LOCAL_MODULE) +$(LOCAL_MODULE): $(LOCAL_BUILD_MODULE) + +# Clean module (several other rules with commands can be added using ::) +.PHONY: clean-$(LOCAL_MODULE) +clean-$(LOCAL_MODULE):: + @echo "Clean: $(PRIVATE_MODULE)" + $(Q)$(if $(PRIVATE_CLEAN_FILES),rm -f $(PRIVATE_CLEAN_FILES)) + $(Q)$(if $(PRIVATE_CLEAN_DIRS),rm -rf $(PRIVATE_CLEAN_DIRS)) + ############################################################################### ## Static library. ############################################################################### ifeq ("$(LOCAL_MODULE_CLASS)","STATIC_LIBRARY") -include $(RULES) +include $(BUILD_RULES) $(LOCAL_BUILD_MODULE): $(all_objects) $(transform-o-to-static-lib) +# TODO : the .a file does not arrive in the staging element ==> they micht stay in the obj folder copy_to_staging := 1 endif @@ -32,7 +78,7 @@ endif ifeq ("$(LOCAL_MODULE_CLASS)","SHARED_LIBRARY") -include $(RULES) +include $(BUILD_RULES) $(LOCAL_BUILD_MODULE): $(all_objects) $(all_libraries) $(transform-o-to-shared-lib) @@ -47,7 +93,7 @@ endif ifeq ("$(LOCAL_MODULE_CLASS)","EXECUTABLE") -include $(RULES) +include $(BUILD_RULES) $(LOCAL_BUILD_MODULE): $(all_objects) $(all_libraries) $(transform-o-to-executable) @@ -56,6 +102,44 @@ copy_to_staging := 1 endif +############################################################################### +## Prebuilt. +############################################################################### + +ifeq ("$(LOCAL_MODULE_CLASS)","PREBUILT") + +$(LOCAL_BUILD_MODULE): + @mkdir -p $(dir $@) + @touch $@ + +endif + +############################################################################### +## Files to copy. +############################################################################### + +ifneq ("$(LOCAL_COPY_FILES)","") + +# List of all destination files +all_copy_files := + +# Generate a rule to copy all files +$(foreach __pair,$(LOCAL_COPY_FILES), \ + $(eval __pair2 := $(subst :,$(space),$(__pair))) \ + $(eval __src := $(addprefix $(LOCAL_PATH)/,$(word 1,$(__pair2)))) \ + $(eval __dst := $(addprefix $(TARGET_OUT_STAGING)/,$(word 2,$(__pair2)))) \ + $(eval all_copy_files += $(__dst)) \ + $(eval $(call copy-one-file,$(__src),$(__dst))) \ +) + +# Add files to be copied as pre-requisites +$(LOCAL_BUILD_MODULE): $(all_copy_files) + +# Add rule to delete copied files during clean +clean-$(LOCAL_MODULE):: PRIVATE_CLEAN_FILES += $(all_copy_files) + +endif + ############################################################################### ## Copy to staging dir ############################################################################### diff --git a/core/prebuilt.mk b/core/prebuilt.mk new file mode 100644 index 0000000..56b1432 --- /dev/null +++ b/core/prebuilt.mk @@ -0,0 +1,15 @@ +############################################################################### +## @file prebuilt.mk +## @author Y.M. Morgan +## @date 2012/08/08 +## +## Register a prebuilt module. +############################################################################### + +LOCAL_MODULE_CLASS := PREBUILT + +ifeq ("$(LOCAL_MODULE_FILENAME)","") +LOCAL_MODULE_FILENAME := $(LOCAL_MODULE).done +endif + +$(local-add-module) diff --git a/core/rules.mk b/core/rules.mk index 8a205cf..19f2de5 100644 --- a/core/rules.mk +++ b/core/rules.mk @@ -1,29 +1,14 @@ ############################################################################### -## @file rules.mk +## @file binary-rules.mk ## @author Y.M. Morgan ## @date 2011/05/14 ## ## Generate rules for building an executable or library. ############################################################################### -# Make sure LOCAL_MODULE is defined and not empty -LOCAL_MODULE := $(strip $(LOCAL_MODULE)) -ifeq ("$(LOCAL_MODULE)","") - $(error $(LOCAL_PATH): LOCAL_MODULE is not defined) -endif - # Intermediate/Build directory build_dir := $(TARGET_OUT_BUILD)/$(LOCAL_MODULE) -# Full path to build module -LOCAL_BUILD_MODULE := $(call module-get-build-filename,$(LOCAL_MODULE)) - -# Full path to staging module -LOCAL_STAGING_MODULE := $(call module-get-staging-filename,$(LOCAL_MODULE)) - -# Assemble the list of targets to create PRIVATE_ variables for. -LOCAL_TARGETS += $(LOCAL_BUILD_MODULE) - # Prepend some directories in include list LOCAL_C_INCLUDES := $(build_dir) $(LOCAL_PATH) $(LOCAL_C_INCLUDES) @@ -93,12 +78,12 @@ all_objects := \ $(cxx_objects) \ $(c_objects) \ $(s_objects) \ - $(S_objects) \ + $(S_objects) # Get all static libraries this module depends on -LOCAL_STATIC_LIBRARIES := \ +LOCAL_STATIC_LIBRARIES += \ $(call module-get-depends,$(LOCAL_STATIC_LIBRARIES),STATIC_LIBRARIES) -LOCAL_WHOLE_STATIC_LIBRARIES := \ +LOCAL_WHOLE_STATIC_LIBRARIES += \ $(call module-get-depends,$(LOCAL_WHOLE_STATIC_LIBRARIES),WHOLE_STATIC_LIBRARIES) # Also get shared libraries used by static libraries @@ -117,7 +102,6 @@ all_static_libraries := \ all_whole_static_libraries := \ $(foreach lib,$(LOCAL_WHOLE_STATIC_LIBRARIES), \ $(call module-get-staging-filename,$(lib))) - all_external_libraries := \ $(foreach lib,$(LOCAL_EXTERNAL_LIBRARIES), \ $(TARGET_OUT_BUILD)/$(lib)/$(lib).done) @@ -127,7 +111,7 @@ all_libraries := \ $(all_shared_libraries) \ $(all_static_libraries) \ $(all_whole_static_libraries) \ - $(all_external_libraries) \ + $(all_external_libraries) ############################################################################### ## Import of dependencies. @@ -152,8 +136,6 @@ LOCAL_CPPFLAGS := $(strip $(imported_CPPFLAGS) $(LOCAL_EXPORT_CPPFLAGS) $(LOCA # The imported/exported include directories are appended to their LOCAL_XXX value # (this allows the module to override them) LOCAL_C_INCLUDES := $(sort $(strip $(subst -I-I,-I,$(addprefix -I,$(LOCAL_C_INCLUDES) $(LOCAL_EXPORT_C_INCLUDES) $(imported_C_INCLUDES))))) -#$(info LOCAL_C_INCLUDES=$(LOCAL_C_INCLUDES)) -#$(info -----) # Similarly, you want the imported/exported flags to appear _after_ the LOCAL_LDLIBS # due to the way Unix linkers work (depending libraries must appear before @@ -180,6 +162,9 @@ all_prerequisites += $(all_autoconf) # User makefile is also a prerequisite all_prerequisites += $(LOCAL_PATH)/$(USER_MAKEFILE_NAME) +# External libraries are also prerequisites +all_prerequisites += $(all_external_libraries) + # Notify that we build with dependencies LOCAL_CFLAGS += $(foreach __mod,$(all_depends), \ -DBUILD_$(call get-define,$(__mod))) @@ -217,33 +202,20 @@ $(s_objects): $(build_dir)/%.o: $(LOCAL_PATH)/%.s endif # S files -# There are dependency files for asm code... +# There is dependency files for asm code... ifneq ("$(strip $(S_objects))","") $(S_objects): $(build_dir)/%.o: $(LOCAL_PATH)/%.S $(transform-s-to-o) -include $(S_objects:%.o=%.d) endif -# clean- targets -cleantarget := clean-$(LOCAL_MODULE) -$(cleantarget) : PRIVATE_MODULE := $(LOCAL_MODULE) -$(cleantarget) : PRIVATE_CLEAN_FILES := \ - $(LOCAL_BUILD_MODULE) \ - $(LOCAL_STAGING_MODULE) \ - $(build_dir) -$(cleantarget):: - @echo "Clean: $(PRIVATE_MODULE)" - $(Q)rm -rf $(PRIVATE_CLEAN_FILES) +# Additionnal clean +clean-$(LOCAL_MODULE):: PRIVATE_CLEAN_FILES += $(LOCAL_STAGING_MODULE) +clean-$(LOCAL_MODULE):: PRIVATE_CLEAN_DIRS += $(build_dir) -## Provide a short-hand for building this module. -.PHONY: $(LOCAL_MODULE) +# Additional module dependencies $(LOCAL_MODULE): $(LOCAL_BUILD_MODULE) $(LOCAL_STAGING_MODULE) -# Make sure external libraries are built first -# Do NOT force rebuild at each check (order prerequisite) -# TODO : check why order prerequisite -#$(all_objects): | $(external_libraries) - # Make sure all prerequisites files are generated first ifneq ("$(all_prerequisites)","") $(all_objects): $(all_prerequisites) @@ -284,14 +256,10 @@ $(gch_file): $(LOCAL_PATH)/$(LOCAL_PRECOMPILED_FILE) $(transform-h-to-gch) -include $(gch_file:%.gch=%.d) -# Make sure external libraries are built first (order prerequisite) -# TODO : check why order prerequisite -#$(gch_file): | $(external_libraries) - endif ############################################################################### -# Rule-specific variable definitions. +## Rule-specific variable definitions. ############################################################################### $(LOCAL_TARGETS): PRIVATE_PATH := $(LOCAL_PATH) @@ -309,4 +277,3 @@ $(LOCAL_TARGETS): PRIVATE_ALL_WHOLE_STATIC_LIBRARIES := $(all_whole_static_libra $(LOCAL_TARGETS): PRIVATE_ALL_EXTERNAL_LIBRARIES := $(all_external_libraries) $(LOCAL_TARGETS): PRIVATE_ALL_OBJECTS := $(all_objects) - diff --git a/core/setup.mk b/core/setup.mk index c925384..f6f0ec6 100644 --- a/core/setup.mk +++ b/core/setup.mk @@ -13,6 +13,52 @@ ifneq ("$(words $(shell pwd))","1") $(error Top directory contains space characters) endif +############################################################################### +## Tools for target. +############################################################################### + +ifneq ("$(CLANG)","1") + TARGET_CC := $(TARGET_CROSS)gcc + TARGET_CXX := $(TARGET_CROSS)g++ +else + TARGET_CC := $(TARGET_CROSS)clang + TARGET_CXX := $(TARGET_CROSS)clang++ +endif +TARGET_AR := $(TARGET_CROSS)ar +TARGET_LD := $(TARGET_CROSS)ld +TARGET_NM := $(TARGET_CROSS)nm +TARGET_STRIP := $(TARGET_CROSS)strip +TARGET_STRIP := $(TARGET_CROSS)strip +TARGET_RANLIB := $(TARGET_CROSS)ranlib +TARGET_DLLTOOL := $(TARGET_CROSS)dlltool + +############################################################################### +## Tools for host. +############################################################################### +HOST_GCC ?= gcc +HOST_GXX ?= g++ +HOST_AR ?= ar +HOST_LD ?= ld +HOST_NM ?= nm +HOST_STRIP ?= strip + +############################################################################### +# Target global variables. +############################################################################### +TARGET_GLOBAL_C_INCLUDES ?= +TARGET_GLOBAL_CFLAGS ?= +TARGET_GLOBAL_CPPFLAGS ?= +TARGET_GLOBAL_ARFLAGS ?= rcs +TARGET_GLOBAL_LDFLAGS ?= +TARGET_GLOBAL_LDFLAGS_SHARED ?= +TARGET_GLOBAL_LDLIBS ?= +TARGET_GLOBAL_LDLIBS_SHARED ?= +TARGET_GLOBAL_CFLAGS_ARM ?= +TARGET_GLOBAL_CFLAGS_THUMB ?= + +TARGET_PCH_FLAGS ?= +TARGET_DEFAULT_ARM_MODE ?= THUMB + ############################################################################### ## Host/Target OS. ############################################################################### @@ -36,11 +82,9 @@ endif # Exe/dll suffix under mingw TARGET_STATIC_LIB_SUFFIX := .a ifeq ("$(TARGET_OS)","Windows") - DIR_SUFFIX := _mingw32 TARGET_EXE_SUFFIX := .exe TARGET_SHARED_LIB_SUFFIX := .dll else - DIR_SUFFIX := TARGET_EXE_SUFFIX := TARGET_SHARED_LIB_SUFFIX := .so endif @@ -105,7 +149,7 @@ endif # Architecture #ifndef TARGET_ARCH -# ifneq ("$(shell $(CC) -dumpmachine | grep 64)","") +# ifneq ("$(shell $(TARGET_CC) -dumpmachine | grep 64)","") # TARGET_ARCH := AMD64 # else # TARGET_ARCH := X86 @@ -120,29 +164,33 @@ endif # TARGET_GLOBAL_CFLAGS += -m32 #endif +TARGET_GLOBAL_LDFLAGS += -L$(TARGET_OUT_STAGING)/lib +TARGET_GLOBAL_LDFLAGS += -L$(TARGET_OUT_STAGING)/usr/lib +TARGET_GLOBAL_LDFLAGS_SHARED += -L$(TARGET_OUT_STAGING)/lib +TARGET_GLOBAL_LDFLAGS_SHARED += -L$(TARGET_OUT_STAGING)/usr/lib ############################################################################### ## Determine CC path and version. and check if installed ... ############################################################################### -CC_PATH := $(shell which $(CC)) +TARGET_CC_PATH := $(shell which $(CC)) -ifeq ("$(CC_PATH)","") +ifeq ("$(TARGET_CC_PATH)","") ifeq ("$(TARGET_OS)","Windows") - $(error Compilator does not exist : $(CC) ==> if not installed ... "apt-get install mingw32") + $(error Compilator does not exist : $(TARGET_CC) ==> if not installed ... "apt-get install mingw32") else ifeq ("$(TARGET_OS)","Android") - $(error Compilator does not exist : $(CC) ==> add and define the android NDK "http://developer.android.com/tools/sdk/ndk/index.html") + $(error Compilator does not exist : $(TARGET_CC) ==> add and define the android NDK "http://developer.android.com/tools/sdk/ndk/index.html") else ifneq ("$(CLANG)","1") - $(error Compilator does not exist : $(CC) ==> if not installed ... "apt-get install gcc g++") + $(error Compilator does not exist : $(TARGET_CC) ==> if not installed ... "apt-get install gcc g++") else - $(error Compilator does not exist : $(CC) ==> if not installed ... "apt-get install clang") + $(error Compilator does not exist : $(TARGET_CC) ==> if not installed ... "apt-get install clang") endif endif endif ifneq ("$(CLANG)","1") -CC_VERSION := $(shell $(CC) --version | head -1 | sed "s/.*\([0-9]\.[0-9]\.[0-9]\).*/\1/") +TARGET_CC_VERSION := $(shell $(TARGET_CC) --version | head -1 | sed "s/.*\([0-9]\.[0-9]\.[0-9]\).*/\1/") else -CC_VERSION := $(shell $(CC) --version | head -1 | sed "s/.*\([0-9]\.[0-9]-[0-9]\).*/\1/") +TARGET_CC_VERSION := $(shell $(TARGET_CC) --version | head -1 | sed "s/.*\([0-9]\.[0-9]-[0-9]\).*/\1/") endif diff --git a/core/shared.mk b/core/shared.mk index 355be9e..000b61c 100644 --- a/core/shared.mk +++ b/core/shared.mk @@ -7,10 +7,13 @@ ############################################################################### LOCAL_MODULE_CLASS := SHARED_LIBRARY + +ifeq ("$(LOCAL_DESTDIR)","") LOCAL_DESTDIR := usr/lib +endif ifeq ("$(LOCAL_MODULE_FILENAME)","") LOCAL_MODULE_FILENAME := $(LOCAL_MODULE)$(TARGET_SHARED_LIB_SUFFIX) endif -$(call module-add,$(LOCAL_MODULE)) +$(local-add-module) diff --git a/core/static.mk b/core/static.mk index 9168a8d..0065b49 100644 --- a/core/static.mk +++ b/core/static.mk @@ -7,10 +7,13 @@ ############################################################################### LOCAL_MODULE_CLASS := STATIC_LIBRARY + +ifeq ("$(LOCAL_DESTDIR)","") LOCAL_DESTDIR := usr/lib +endif ifeq ("$(LOCAL_MODULE_FILENAME)","") LOCAL_MODULE_FILENAME := $(LOCAL_MODULE)$(TARGET_STATIC_LIB_SUFFIX) endif -$(call module-add,$(LOCAL_MODULE)) +$(local-add-module) diff --git a/core/warnings.mk b/core/warnings.mk index ea05282..e4d6a3f 100644 --- a/core/warnings.mk +++ b/core/warnings.mk @@ -11,7 +11,7 @@ CC_FLAGS_WARNINGS := CXX_FLAGS_WARNINGS := # show option associated with warning (gcc >= 4.0.0) -ifneq (0,$(shell expr $(CC_VERSION) \>= 4.0.0)) +ifneq (0,$(shell expr $(TARGET_CC_VERSION) \>= 4.0.0)) COMMON_FLAGS_WARNINGS += -fdiagnostics-show-option endif @@ -41,11 +41,11 @@ endif ifneq ("$(CLANG)","1") # gcc >= 4.5.0 (too many false positives with previous versions) - ifneq (0,$(shell expr $(CC_VERSION) \>= 4.5.0)) + ifneq (0,$(shell expr $(TARGET_CC_VERSION) \>= 4.5.0)) COMMON_FLAGS_WARNINGS += -Wunreachable-code endif # gcc >= 4.5.2 - ifneq (0,$(shell expr $(CC_VERSION) \>= 4.5.2)) + ifneq (0,$(shell expr $(TARGET_CC_VERSION) \>= 4.5.2)) COMMON_FLAGS_WARNINGS += -Wlogical-op endif endif @@ -56,7 +56,7 @@ ifeq ("$(W)","1") COMMON_FLAGS_WARNINGS += -Wswitch-enum COMMON_FLAGS_WARNINGS += -Wcast-qual # gcc >= 4.4.0 - ifneq (0,$(shell expr $(CC_VERSION) \>= 4.4.0)) + ifneq (0,$(shell expr $(TARGET_CC_VERSION) \>= 4.4.0)) COMMON_FLAGS_WARNINGS += -Wframe-larger-than=1024 endif endif