diff --git a/Build/Makefile.Linux.mk b/Build/Makefile.Linux.mk index 09f2c2ca..6818a77e 100644 --- a/Build/Makefile.Linux.mk +++ b/Build/Makefile.Linux.mk @@ -1,194 +1,33 @@ - - include $(EWOL_FOLDER)/Build/Makefile.common.mk -#include $(EWOL_FOLDER)/Build/ewol.mk - -############################################################################### -### Compilateur base system ### -############################################################################### -CXX=g++ -CC=gcc -AR=ar -X11FLAGS= -lGL -lGLU -# some X11 mode availlable : -# install package : libxxf86vm-dev -X11FLAGS+= -lX11 -DEWOL_X11_MODE__XF86V -lXxf86vm -# install package : libxrender-dev -#X11FLAGS+= -lX11 -DEWOL_X11_MODE__XRENDER -lXrandr - - -ifeq ($(shell if `pkg-config --exists freetype2` ; then echo "yes"; else echo "no"; fi), yes) - FREETYPE_CFLAGS= `pkg-config --cflags freetype2` -DEWOL_USE_FREE_TYPE - FREETYPE_LDFLAGS= `pkg-config --libs freetype2` -DEWOL_USE_FREE_TYPE -else - FREETYPE_CFLAGS= - FREETYPE_LDFLAGS= - $(Info libFreeType-dev is not installed) -endif - - - -OBJECT_DIR=Object_$(PLATFORM) - -ifeq ("$(DEBUG)", "0") - OBJECT_DIRECTORY=$(OBJECT_DIR)/release - OUTPUT_NAME = $(OUTPUT_NAME_RELEASE) -else - OBJECT_DIRECTORY=$(OBJECT_DIR)/debug - OUTPUT_NAME = $(OUTPUT_NAME_DEBUG) -endif - - - -############################################################################### -### Basic C flags ### -############################################################################### - -# basic X11 librairy ==> show if we can une under lib ... -CXXFLAGS= $(X11FLAGS) $(FREETYPE_CFLAGS) -D__PLATFORM__$(PLATFORM) $(PROJECT_CXXFLAGS) - -ifeq ("$(DEBUG)", "0") - CXXFLAGS+= -O2 -else - # Enable debug (cgdb ***) - CXXFLAGS+= -g -O0 -endif -# display all flags -CXXFLAGS+= -Wall -# ... -CXXFLAGS+= -D_REENTRANT -# internal defines -CXXFLAGS+= $(DEFINE) -# remove warning from the convertion char* -CXXFLAGS+= -Wno-write-strings - -CXXFLAGS+= -DPROJECT_NAME="$(PROJECT_NAME)" - -CFLAGS= $(CXXFLAGS) -std=c99 - -# basic extern librairy -LDFLAGS= $(X11FLAGS) $(FREETYPE_LDFLAGS) $(PROJECT_LDFLAGS) - -# Dynamic connection of the CALLBACK of the GUI -LDFLAGS+= -Wl,--export-dynamic - -# TODO : add the prefix ... -CXXFILES = $(PROJECT_SOURCES) -# create the list of module : -LISTE_MODULES = $(sort $(dir $(CXXFILES))) - -############################################################################### -### Build Object Files List ### -############################################################################### -OBJ = $(addprefix $(OBJECT_DIRECTORY)/, $(CXXFILES:.cpp=.o)) - - -############################################################################### -### Main Part of Makefile ### -############################################################################### -all: $(PROJECT_NAME) - --include $(OBJ:.o=.d) - -.ewol: - @cd $(EWOL_FOLDER) ; make -s PLATFORM=$(PLATFORM) DEBUG=$(DEBUG) - -.ewol-clean: - @cd $(EWOL_FOLDER) ; make -s PLATFORM=$(PLATFORM) clean - -.encadrer: +all: @echo $(CADRE_HAUT_BAS) @echo $(CADRE_COTERS) @echo ' DEBUT DE COMPILATION DU PROGRAMME :'$(CADRE_COTERS) - @echo ' Repertoire Sources : $(PROJECT_FILE_DIRECTORY)/'$(CADRE_COTERS) - @echo ' Repertoire object : $(OBJECT_DIRECTORY)/'$(CADRE_COTERS) - @echo ' Binaire de sortie : $(F_VIOLET)$(PROJECT_NAME) $(F_NORMALE)'$(CADRE_COTERS) + @echo ' Project name : $(F_BLUE)$(PROJECT_NAME)$(F_NORMALE)'$(CADRE_COTERS) + @echo ' Project Vendor : $(F_CYAN)$(PROJECT_VENDOR)$(F_NORMALE)'$(CADRE_COTERS) + @echo ' Build date : $(F_ROUGE)$(BUILD_TIME) $(F_NORMALE)'$(CADRE_COTERS) + @echo ' Tag : $(F_VIOLET)$(PROJECT_VERSION_TAG) $(F_NORMALE)'$(CADRE_COTERS) @echo $(CADRE_COTERS) @echo $(CADRE_HAUT_BAS) - @mkdir -p $(addprefix $(OBJECT_DIRECTORY)/, $(LISTE_MODULES)) + + @echo $(F_ROUGE)" (ndk-build) build native code"$(F_NORMALE) + cd $(PROJECT_NDK) ; NDK_PROJECT_PATH=$(PROJECT_PATH) NDK_MODULE_PATH=$(PROJECT_MODULE) ./ndk-build + #cd $(PROJECT_NDK) ; NDK_PROJECT_PATH=$(PROJECT_PATH) NDK_MODULE_PATH=$(PROJECT_MODULE) NDK_LOG=~/.ndklog.txt make -f $(EWOL_FOLDER)/Build/coreLinux/build-local.mk -$(info PROJECT_FILE_DIRECTORY=$(PROJECT_FILE_DIRECTORY) ; OBJECT_DIRECTORY=$(OBJECT_DIRECTORY)) - -# build C++ -$(OBJECT_DIRECTORY)/%.o: $(PROJECT_FILE_DIRECTORY)/%.cpp $(MAKE_DEPENDENCE) - @echo $(F_VERT)" (.o) $<"$(F_NORMALE) - @$(CXX) $< -c -o $@ $(INCLUDE_DIRECTORY) $(CXXFLAGS) -MMD - -# build binary Release Mode -$(PROJECT_NAME): .ewol .encadrer $(PROJECT_LIB_DEPENDENCY) $(OBJ) $(MAKE_DEPENDENCE) - @echo $(F_ROUGE)" (bin) $(PROJECT_NAME) "$(F_NORMALE) - @$(CXX) $(OBJ) $(EWOL_FOLDER)/libewol.a $(LDFLAGS) -o $@ - - - -clean: .ewol-clean +install: all @echo $(CADRE_HAUT_BAS) - @echo ' CLEANING : $(F_VIOLET)$(OUTPUT_NAME)$(F_NORMALE)'$(CADRE_COTERS) + @echo ' INSTALL : $(F_VIOLET)./bin/$(PROJECT_NAME)-debug.apk$(F_NORMALE)'$(CADRE_COTERS) @echo $(CADRE_HAUT_BAS) - @echo $(F_VERT)" (rm) $(OBJECT_DIR)"$(F_NORMALE) - @rm -rf $(OBJECT_DIR) - @echo $(F_VERT)" (rm) $(PROJECT_NAME) $(OUTPUT_NAME_DEBUG) $(OUTPUT_NAME_RELEASE)"$(F_NORMALE) - @rm -f $(PROJECT_NAME) $(OUTPUT_NAME_DEBUG) $(OUTPUT_NAME_RELEASE) - @echo $(F_VERT)" (rm) doxygen/*"$(F_NORMALE) - @rm -rf doxygen - @rm -f doxygen.log - @echo $(F_VERT)" (rm) *.bck"$(F_NORMALE) - @rm -f `find . -name "*.bck"` - - -count: - wc -l Makefile `find $(FILE_DIRECTORY)/ -name "*.cpp"` `find $(PROJECT_FILE_DIRECTORY)/ -name "*.h"` - - -install: .encadrer .versionFile $(PROJECT_NAME) - @echo ' INSTALL : $(OUTPUT_NAME_RELEASE)=>$(PROJECT_NAME)' - @echo " (stripped) $(OUTPUT_NAME_RELEASE) => $(PROJECT_NAME) " - @cp $(OUTPUT_NAME_RELEASE) $(PROJECT_NAME) - @strip -s $(PROJECT_NAME) - @echo " (copy) $(PROJECT_NAME) /usr/bin/ " - @cp -vf $(PROJECT_NAME) /usr/bin/ - @echo " (data) data/* ==> /usr/share/$(PROJECT_NAME)/ " - @mkdir -p /usr/share/$(PROJECT_NAME)/ - @rm -rf /usr/share/$(PROJECT_NAME)/* - @cp -vf assets/* /usr/share/$(PROJECT_NAME)/ - - -# http://alp.developpez.com/tutoriels/debian/creer-paquet/ -package: .encadrer - @echo 'Create Folders ...' - @mkdir -p package/$(PROJECT_NAME)/DEBIAN/ - @mkdir -p package/$(PROJECT_NAME)/usr/bin/ - @mkdir -p package/$(PROJECT_NAME)/usr/share/doc/ - @mkdir -p package/$(PROJECT_NAME)/usr/share/edn/ - # Create the control file - @echo "Package: "$(PROJECT_NAME) > package/$(PROJECT_NAME)/DEBIAN/control - @echo "Version: "$(VERSION_TAG_SHORT) >> package/$(PROJECT_NAME)/DEBIAN/control - @echo "Section: Development,Editors" >> package/$(PROJECT_NAME)/DEBIAN/control - @echo "Priority: optional" >>package/$(PROJECT_NAME)/DEBIAN/control - @echo "Architecture: all" >> package/$(PROJECT_NAME)/DEBIAN/control - @echo "Depends: bash" >> package/$(PROJECT_NAME)/DEBIAN/control - @echo "Maintainer: Mr DUPIN Edouard " >> package/$(PROJECT_NAME)/DEBIAN/control - @echo "Description: Text editor for sources code with ctags management" >> package/$(PROJECT_NAME)/DEBIAN/control - @echo "" >> package/$(PROJECT_NAME)/DEBIAN/control - # Create the PostRm - @echo "#!/bin/bash" > package/$(PROJECT_NAME)/DEBIAN/postrm - @echo "rm ~/."$(PROJECT_NAME) >> package/$(PROJECT_NAME)/DEBIAN/postrm - @echo "" >> package/$(PROJECT_NAME)/DEBIAN/postrm - # Enable Execution in script - @chmod 755 package/$(PROJECT_NAME)/DEBIAN/post* - @#chmod 755 package/$(PROJECT_NAME)/DEBIAN/pre* - # copy licence and information : - @cp README package/$(PROJECT_NAME)/usr/share/doc/README - @cp licence.txt package/$(PROJECT_NAME)/usr/share/doc/copyright - @echo "First generation in progress" >> package/$(PROJECT_NAME)/usr/share/doc/changelog - @cp -vf $(PROJECT_NAME) package/$(PROJECT_NAME)/usr/bin/ - @cp -vf data/*.xml package/$(PROJECT_NAME)/usr/share/edn/ - @cd package; dpkg-deb --build $(PROJECT_NAME) - + # TODO : Later .... +clean: + @echo $(CADRE_HAUT_BAS) + @echo ' CLEANING : bin libs gen obj'$(CADRE_COTERS) + @echo $(CADRE_HAUT_BAS) + # TODO : Later .... diff --git a/Build/Makefile.Linux_old.mk b/Build/Makefile.Linux_old.mk new file mode 100644 index 00000000..09f2c2ca --- /dev/null +++ b/Build/Makefile.Linux_old.mk @@ -0,0 +1,194 @@ + + + + +include $(EWOL_FOLDER)/Build/Makefile.common.mk + +#include $(EWOL_FOLDER)/Build/ewol.mk + +############################################################################### +### Compilateur base system ### +############################################################################### +CXX=g++ +CC=gcc +AR=ar + + + +X11FLAGS= -lGL -lGLU +# some X11 mode availlable : +# install package : libxxf86vm-dev +X11FLAGS+= -lX11 -DEWOL_X11_MODE__XF86V -lXxf86vm +# install package : libxrender-dev +#X11FLAGS+= -lX11 -DEWOL_X11_MODE__XRENDER -lXrandr + + +ifeq ($(shell if `pkg-config --exists freetype2` ; then echo "yes"; else echo "no"; fi), yes) + FREETYPE_CFLAGS= `pkg-config --cflags freetype2` -DEWOL_USE_FREE_TYPE + FREETYPE_LDFLAGS= `pkg-config --libs freetype2` -DEWOL_USE_FREE_TYPE +else + FREETYPE_CFLAGS= + FREETYPE_LDFLAGS= + $(Info libFreeType-dev is not installed) +endif + + + +OBJECT_DIR=Object_$(PLATFORM) + +ifeq ("$(DEBUG)", "0") + OBJECT_DIRECTORY=$(OBJECT_DIR)/release + OUTPUT_NAME = $(OUTPUT_NAME_RELEASE) +else + OBJECT_DIRECTORY=$(OBJECT_DIR)/debug + OUTPUT_NAME = $(OUTPUT_NAME_DEBUG) +endif + + + +############################################################################### +### Basic C flags ### +############################################################################### + +# basic X11 librairy ==> show if we can une under lib ... +CXXFLAGS= $(X11FLAGS) $(FREETYPE_CFLAGS) -D__PLATFORM__$(PLATFORM) $(PROJECT_CXXFLAGS) + +ifeq ("$(DEBUG)", "0") + CXXFLAGS+= -O2 +else + # Enable debug (cgdb ***) + CXXFLAGS+= -g -O0 +endif +# display all flags +CXXFLAGS+= -Wall +# ... +CXXFLAGS+= -D_REENTRANT +# internal defines +CXXFLAGS+= $(DEFINE) +# remove warning from the convertion char* +CXXFLAGS+= -Wno-write-strings + +CXXFLAGS+= -DPROJECT_NAME="$(PROJECT_NAME)" + +CFLAGS= $(CXXFLAGS) -std=c99 + +# basic extern librairy +LDFLAGS= $(X11FLAGS) $(FREETYPE_LDFLAGS) $(PROJECT_LDFLAGS) + +# Dynamic connection of the CALLBACK of the GUI +LDFLAGS+= -Wl,--export-dynamic + +# TODO : add the prefix ... +CXXFILES = $(PROJECT_SOURCES) +# create the list of module : +LISTE_MODULES = $(sort $(dir $(CXXFILES))) + +############################################################################### +### Build Object Files List ### +############################################################################### +OBJ = $(addprefix $(OBJECT_DIRECTORY)/, $(CXXFILES:.cpp=.o)) + + +############################################################################### +### Main Part of Makefile ### +############################################################################### +all: $(PROJECT_NAME) + +-include $(OBJ:.o=.d) + +.ewol: + @cd $(EWOL_FOLDER) ; make -s PLATFORM=$(PLATFORM) DEBUG=$(DEBUG) + +.ewol-clean: + @cd $(EWOL_FOLDER) ; make -s PLATFORM=$(PLATFORM) clean + +.encadrer: + @echo $(CADRE_HAUT_BAS) + @echo $(CADRE_COTERS) + @echo ' DEBUT DE COMPILATION DU PROGRAMME :'$(CADRE_COTERS) + @echo ' Repertoire Sources : $(PROJECT_FILE_DIRECTORY)/'$(CADRE_COTERS) + @echo ' Repertoire object : $(OBJECT_DIRECTORY)/'$(CADRE_COTERS) + @echo ' Binaire de sortie : $(F_VIOLET)$(PROJECT_NAME) $(F_NORMALE)'$(CADRE_COTERS) + @echo $(CADRE_COTERS) + @echo $(CADRE_HAUT_BAS) + @mkdir -p $(addprefix $(OBJECT_DIRECTORY)/, $(LISTE_MODULES)) + +$(info PROJECT_FILE_DIRECTORY=$(PROJECT_FILE_DIRECTORY) ; OBJECT_DIRECTORY=$(OBJECT_DIRECTORY)) + +# build C++ +$(OBJECT_DIRECTORY)/%.o: $(PROJECT_FILE_DIRECTORY)/%.cpp $(MAKE_DEPENDENCE) + @echo $(F_VERT)" (.o) $<"$(F_NORMALE) + @$(CXX) $< -c -o $@ $(INCLUDE_DIRECTORY) $(CXXFLAGS) -MMD + +# build binary Release Mode +$(PROJECT_NAME): .ewol .encadrer $(PROJECT_LIB_DEPENDENCY) $(OBJ) $(MAKE_DEPENDENCE) + @echo $(F_ROUGE)" (bin) $(PROJECT_NAME) "$(F_NORMALE) + @$(CXX) $(OBJ) $(EWOL_FOLDER)/libewol.a $(LDFLAGS) -o $@ + + + +clean: .ewol-clean + @echo $(CADRE_HAUT_BAS) + @echo ' CLEANING : $(F_VIOLET)$(OUTPUT_NAME)$(F_NORMALE)'$(CADRE_COTERS) + @echo $(CADRE_HAUT_BAS) + @echo $(F_VERT)" (rm) $(OBJECT_DIR)"$(F_NORMALE) + @rm -rf $(OBJECT_DIR) + @echo $(F_VERT)" (rm) $(PROJECT_NAME) $(OUTPUT_NAME_DEBUG) $(OUTPUT_NAME_RELEASE)"$(F_NORMALE) + @rm -f $(PROJECT_NAME) $(OUTPUT_NAME_DEBUG) $(OUTPUT_NAME_RELEASE) + @echo $(F_VERT)" (rm) doxygen/*"$(F_NORMALE) + @rm -rf doxygen + @rm -f doxygen.log + @echo $(F_VERT)" (rm) *.bck"$(F_NORMALE) + @rm -f `find . -name "*.bck"` + + +count: + wc -l Makefile `find $(FILE_DIRECTORY)/ -name "*.cpp"` `find $(PROJECT_FILE_DIRECTORY)/ -name "*.h"` + + +install: .encadrer .versionFile $(PROJECT_NAME) + @echo ' INSTALL : $(OUTPUT_NAME_RELEASE)=>$(PROJECT_NAME)' + @echo " (stripped) $(OUTPUT_NAME_RELEASE) => $(PROJECT_NAME) " + @cp $(OUTPUT_NAME_RELEASE) $(PROJECT_NAME) + @strip -s $(PROJECT_NAME) + @echo " (copy) $(PROJECT_NAME) /usr/bin/ " + @cp -vf $(PROJECT_NAME) /usr/bin/ + @echo " (data) data/* ==> /usr/share/$(PROJECT_NAME)/ " + @mkdir -p /usr/share/$(PROJECT_NAME)/ + @rm -rf /usr/share/$(PROJECT_NAME)/* + @cp -vf assets/* /usr/share/$(PROJECT_NAME)/ + + +# http://alp.developpez.com/tutoriels/debian/creer-paquet/ +package: .encadrer + @echo 'Create Folders ...' + @mkdir -p package/$(PROJECT_NAME)/DEBIAN/ + @mkdir -p package/$(PROJECT_NAME)/usr/bin/ + @mkdir -p package/$(PROJECT_NAME)/usr/share/doc/ + @mkdir -p package/$(PROJECT_NAME)/usr/share/edn/ + # Create the control file + @echo "Package: "$(PROJECT_NAME) > package/$(PROJECT_NAME)/DEBIAN/control + @echo "Version: "$(VERSION_TAG_SHORT) >> package/$(PROJECT_NAME)/DEBIAN/control + @echo "Section: Development,Editors" >> package/$(PROJECT_NAME)/DEBIAN/control + @echo "Priority: optional" >>package/$(PROJECT_NAME)/DEBIAN/control + @echo "Architecture: all" >> package/$(PROJECT_NAME)/DEBIAN/control + @echo "Depends: bash" >> package/$(PROJECT_NAME)/DEBIAN/control + @echo "Maintainer: Mr DUPIN Edouard " >> package/$(PROJECT_NAME)/DEBIAN/control + @echo "Description: Text editor for sources code with ctags management" >> package/$(PROJECT_NAME)/DEBIAN/control + @echo "" >> package/$(PROJECT_NAME)/DEBIAN/control + # Create the PostRm + @echo "#!/bin/bash" > package/$(PROJECT_NAME)/DEBIAN/postrm + @echo "rm ~/."$(PROJECT_NAME) >> package/$(PROJECT_NAME)/DEBIAN/postrm + @echo "" >> package/$(PROJECT_NAME)/DEBIAN/postrm + # Enable Execution in script + @chmod 755 package/$(PROJECT_NAME)/DEBIAN/post* + @#chmod 755 package/$(PROJECT_NAME)/DEBIAN/pre* + # copy licence and information : + @cp README package/$(PROJECT_NAME)/usr/share/doc/README + @cp licence.txt package/$(PROJECT_NAME)/usr/share/doc/copyright + @echo "First generation in progress" >> package/$(PROJECT_NAME)/usr/share/doc/changelog + @cp -vf $(PROJECT_NAME) package/$(PROJECT_NAME)/usr/bin/ + @cp -vf data/*.xml package/$(PROJECT_NAME)/usr/share/edn/ + @cd package; dpkg-deb --build $(PROJECT_NAME) + + diff --git a/Build/coreLinux/add-application.mk b/Build/coreLinux/add-application.mk new file mode 100644 index 00000000..ff56c5e8 --- /dev/null +++ b/Build/coreLinux/add-application.mk @@ -0,0 +1,239 @@ +# Copyright (C) 2009 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +# this script is used to record an application definition in the +# NDK build system, before performing any build whatsoever. +# +# It is included repeatedly from build/core/main.mk and expects a +# variable named '_application_mk' which points to a given Application.mk +# file that will be included here. The latter must define a few variables +# to describe the application to the build system, and the rest of the +# code here will perform book-keeping and basic checks +# + +$(call assert-defined, _application_mk _app) +$(call ndk_log,Parsing $(_application_mk)) + +$(call clear-vars, $(NDK_APP_VARS)) + +# Check that NDK_DEBUG is properly defined. If it is +# the only valid states are: undefined, 0, 1, false and true +# +# We set APP_DEBUG to , 'true' or 'false'. +# +APP_DEBUG := $(strip $(NDK_DEBUG)) +ifeq ($(APP_DEBUG),0) + APP_DEBUG:= false +endif +ifeq ($(APP_DEBUG),1) + APP_DEBUG := true +endif +ifdef APP_DEBUG + ifneq (,$(filter-out true false,$(APP_DEBUG))) + $(call __ndk_warning,NDK_DEBUG is defined to the unsupported value '$(NDK_DEBUG)', will be ignored!) + endif +endif + +include $(_application_mk) + +$(call check-required-vars,$(NDK_APP_VARS_REQUIRED),$(_application_mk)) + +_map := NDK_APP.$(_app) + +# strip the 'lib' prefix in front of APP_MODULES modules +APP_MODULES := $(call strip-lib-prefix,$(APP_MODULES)) + +APP_PROJECT_PATH := $(strip $(APP_PROJECT_PATH)) +ifndef APP_PROJECT_PATH + APP_PROJECT_PATH := $(NDK_PROJECT_PATH) +endif + +# check whether APP_PLATFORM is defined. If not, look for project.properties in +# the $(APP_PROJECT_PATH) and extract the value with awk's help. If nothing is here, +# revert to the default value (i.e. "android-3"). +# +APP_PLATFORM := $(strip $(APP_PLATFORM)) +ifndef APP_PLATFORM + _local_props := $(strip $(wildcard $(APP_PROJECT_PATH)/project.properties)) + ifndef _local_props + # NOTE: project.properties was called default.properties before + _local_props := $(strip $(wildcard $(APP_PROJECT_PATH)/default.properties)) + endif + ifdef _local_props + APP_PLATFORM := $(strip $(shell $(HOST_AWK) -f $(BUILD_AWK)/extract-platform.awk $(_local_props))) + $(call ndk_log, Found APP_PLATFORM=$(APP_PLATFORM) in $(_local_props)) + else + APP_PLATFORM := android-3 + $(call ndk_log, Defaulted to APP_PLATFORM=$(APP_PLATFORM)) + endif +endif + +# SPECIAL CASE: android-6 and android-7 are the same thing than android-5 +# with regards to the NDK. Adjust accordingly! +ifneq (,$(filter android-6 android-7,$(APP_PLATFORM))) + APP_PLATFORM := android-5 + $(call ndk_log, Adjusting APP_PLATFORM to $(APP_PLATFORM)) +endif + +# Check that the value of APP_PLATFORM corresponds to a known platform +# If not, we're going to use the max supported platform value. +# +_bad_platform := $(strip $(filter-out $(NDK_ALL_PLATFORMS),$(APP_PLATFORM))) +ifdef _bad_platform + $(call ndk_log,Application $(_app) targets unknown platform '$(_bad_platform)') + APP_PLATFORM := android-$(NDK_MAX_PLATFORM_LEVEL) + $(call ndk_log,Switching to $(APP_PLATFORM)) +endif + +# Check that the value of APP_ABI corresponds to known ABIs +# 'all' is a special case that means 'all supported ABIs' +# +# It will be handled in setup-app.mk. We can't hope to change +# the value of APP_ABI is the user enforces it on the command-line +# with a call like: ndk-build APP_ABI=all +# +# Because GNU Make makes the APP_ABI variable read-only (any assignments +# to it will be ignored) +# +APP_ABI := $(strip $(APP_ABI)) +ifndef APP_ABI + # Default ABI is 'armeabi' + APP_ABI := armeabi +endif +ifneq ($(APP_ABI),all) + _bad_abis := $(strip $(filter-out $(NDK_ALL_ABIS),$(APP_ABIS))) + ifdef _bad_abis + $(call __ndk_info,Application $(_app) targets unknown ABI '$(_bad_abis)') + $(call __ndk_info,Please fix the APP_ABI definition in $(_application_mk)) + $(call __ndk_info,to use a set of the following values: $(NDK_ALL_ABIS)) + $(call __ndk_error,Aborting) + endif +endif + +# If APP_BUILD_SCRIPT is defined, check that the file exists. +# If undefined, look in $(APP_PROJECT_PATH)/jni/Android.mk +# +APP_BUILD_SCRIPT := $(strip $(APP_BUILD_SCRIPT)) +ifdef APP_BUILD_SCRIPT + _build_script := $(strip $(wildcard $(APP_BUILD_SCRIPT))) + ifndef _build_script + $(call __ndk_info,Your APP_BUILD_SCRIPT points to an unknown file: $(APP_BUILD_SCRIPT)) + $(call __ndk_error,Aborting...) + endif + APP_BUILD_SCRIPT := $(_build_script) + $(call ndk_log, Using build script $(APP_BUILD_SCRIPT)) +else + _build_script := $(strip $(wildcard $(APP_PROJECT_PATH)/jni/Android.mk)) + ifndef _build_script + $(call __ndk_info,There is no Android.mk under $(APP_PROJECT_PATH)/jni) + $(call __ndk_info,If this is intentional, please define APP_BUILD_SCRIPT to point) + $(call __ndk_info,to a valid NDK build script.) + $(call __ndk_error,Aborting...) + endif + APP_BUILD_SCRIPT := $(_build_script) + $(call ndk_log, Defaulted to APP_BUILD_SCRIPT=$(APP_BUILD_SCRIPT)) +endif + +# Determine whether the application should be debuggable. +# - If APP_DEBUG is set to 'true', then it always should. +# - If APP_DEBUG is set to 'false', then it never should +# - Otherwise, extract the android:debuggable attribute from the manifest. +# +ifdef APP_DEBUG + APP_DEBUGGABLE := $(APP_DEBUG) + ifdef NDK_LOG + ifeq ($(APP_DEBUG),true) + $(call ndk_log,Application '$(_app)' forced debuggable through NDK_DEBUG) + else + $(call ndk_log,Application '$(_app)' forced *not* debuggable through NDK_DEBUG) + endif + endif +else + # NOTE: To make unit-testing simpler, handle the case where there is no manifest. + APP_DEBUGGABLE := false + APP_MANIFEST := $(strip $(wildcard $(APP_PROJECT_PATH)/AndroidManifest.xml)) + ifdef APP_MANIFEST + APP_DEBUGGABLE := $(shell $(HOST_AWK) -f $(BUILD_AWK)/extract-debuggable.awk $(APP_MANIFEST)) + endif + ifdef NDK_LOG + ifeq ($(APP_DEBUGGABLE),true) + $(call ndk_log,Application '$(_app)' *is* debuggable) + else + $(call ndk_log,Application '$(_app)' is not debuggable) + endif + endif +endif + +# LOCAL_BUILD_MODE will be either release or debug +# +# If APP_OPTIM is defined in the Application.mk, just use this. +# +# Otherwise, set to 'debug' if android:debuggable is set to TRUE, +# and to 'release' if not. +# +ifneq ($(APP_OPTIM),) + # check that APP_OPTIM, if defined, is either 'release' or 'debug' + $(if $(filter-out release debug,$(APP_OPTIM)),\ + $(call __ndk_info, The APP_OPTIM defined in $(_application_mk) must only be 'release' or 'debug')\ + $(call __ndk_error,Aborting)\ + ) + $(call ndk_log,Selecting optimization mode through Application.mk: $(APP_OPTIM)) +else + ifeq ($(APP_DEBUGGABLE),true) + $(call ndk_log,Selecting debug optimization mode (app is debuggable)) + APP_OPTIM := debug + else + $(call ndk_log,Selecting release optimization mode (app is not debuggable)) + APP_OPTIM := release + endif +endif + +# set release/debug build flags. We always use the -g flag because +# we generate symbol versions of the binaries that are later stripped +# when they are copied to the final project's libs/ directory. +# +ifeq ($(APP_OPTIM),debug) + APP_CFLAGS := -O0 -g $(APP_CFLAGS) +else + APP_CFLAGS := -O2 -DNDEBUG -g $(APP_CFLAGS) +endif + +# Check that APP_STL is defined. If not, use the default value (system) +# otherwise, check that the name is correct. +APP_STL := $(strip $(APP_STL)) +ifndef APP_STL + APP_STL := system +else + $(call ndk-stl-check,$(APP_STL)) +endif + + + +$(if $(call get,$(_map),defined),\ + $(call __ndk_info,Weird, the application $(_app) is already defined by $(call get,$(_map),defined))\ + $(call __ndk_error,Aborting)\ +) + +$(call set,$(_map),defined,$(_application_mk)) + +# Record all app-specific variable definitions +$(foreach __name,$(NDK_APP_VARS),\ + $(call set,$(_map),$(__name),$($(__name)))\ +) + +# Record the Application.mk for debugging +$(call set,$(_map),Application.mk,$(_application_mk)) + +NDK_ALL_APPS += $(_app) diff --git a/Build/coreLinux/add-platform.mk b/Build/coreLinux/add-platform.mk new file mode 100644 index 00000000..da83717b --- /dev/null +++ b/Build/coreLinux/add-platform.mk @@ -0,0 +1,33 @@ +# Copyright (C) 2009 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +$(call assert-defined,_platform NDK_PLATFORMS_ROOT) + +# For each platform, determine the corresponding supported ABIs +# And record them in NDK_PLATFORM_$(platform)_ABIS +# +_abis := $(strip $(notdir $(wildcard $(NDK_PLATFORMS_ROOT)/$(_platform)/arch-*))) +_abis := $(_abis:arch-%=%) + +$(call ndk_log,PLATFORM $(_platform) supports: $(_abis)) + +NDK_PLATFORM_$(_platform)_ABIS := $(_abis) + +# Record the sysroots for each supported ABI +# +$(foreach _abi,$(_abis),\ + $(eval NDK_PLATFORM_$(_platform)_$(_abi)_SYSROOT := $(NDK_PLATFORMS_ROOT)/$(_platform)/arch-$(_abi))\ + $(call ndk_log, ABI $(_abi) sysroot is: $(NDK_PLATFORM_$(_platform)_$(_abi)_SYSROOT))\ +) diff --git a/Build/coreLinux/add-toolchain.mk b/Build/coreLinux/add-toolchain.mk new file mode 100644 index 00000000..26d19525 --- /dev/null +++ b/Build/coreLinux/add-toolchain.mk @@ -0,0 +1,72 @@ +# Copyright (C) 2009 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +# this script is included repeatedly by main.mk to add a new toolchain +# definition to the NDK build system. +# +# '_config_mk' must be defined as the path of a toolchain +# configuration file (config.mk) that will be included here. +# +$(call assert-defined, _config_mk) + +# The list of variables that must or may be defined +# by the toolchain configuration file +# +NDK_TOOLCHAIN_VARS_REQUIRED := TOOLCHAIN_ABIS +NDK_TOOLCHAIN_VARS_OPTIONAL := + +# Clear variables that are supposed to be defined by the config file +$(call clear-vars,$(NDK_TOOLCHAIN_VARS_REQUIRED)) +$(call clear-vars,$(NDK_TOOLCHAIN_VARS_OPTIONAL)) + +# Include the config file +include $(_config_mk) + +# Check that the proper variables were defined +$(call check-required-vars,$(NDK_TOOLCHAIN_VARS_REQUIRED),$(_config_mk)) + +# Check that the file didn't do something stupid +$(call assert-defined, _config_mk) + +# Now record the toolchain-specific information +_dir := $(patsubst %/,%,$(dir $(_config_mk))) +_name := $(notdir $(_dir)) +_abis := $(TOOLCHAIN_ABIS) + +_toolchain := NDK_TOOLCHAIN.$(_name) + +# check that the toolchain name is unique +$(if $(strip $($(_toolchain).defined)),\ + $(call __ndk_error,Toolchain $(_name) defined in $(_parent) is\ + already defined in $(NDK_TOOLCHAIN.$(_name).defined))) + +$(_toolchain).defined := $(_toolchain_config) +$(_toolchain).abis := $(_abis) +$(_toolchain).setup := $(wildcard $(_dir)/setup.mk) + +$(if $(strip $($(_toolchain).setup)),,\ + $(call __ndk_error, Toolchain $(_name) lacks a setup.mk in $(_dir))) + +NDK_ALL_TOOLCHAINS += $(_name) +NDK_ALL_ABIS += $(_abis) + +# NKD_ABI..toolchains records the list of toolchains that support +# a given ABI +# +$(foreach _abi,$(_abis),\ + $(eval NDK_ABI.$(_abi).toolchains += $(_name)) \ +) + +# done diff --git a/Build/coreLinux/build-all.mk b/Build/coreLinux/build-all.mk new file mode 100644 index 00000000..5ac64bf7 --- /dev/null +++ b/Build/coreLinux/build-all.mk @@ -0,0 +1,114 @@ +# Copyright (C) 2009-2010 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +# +# This script is used to build all wanted NDK binaries. It is included +# by several scripts. +# + +# ensure that the following variables are properly defined +$(call assert-defined,NDK_APPS NDK_APP_OUT) + +# ==================================================================== +# +# Prepare the build for parsing Android.mk files +# +# ==================================================================== + +# These phony targets are used to control various stages of the build +.PHONY: all \ + host_libraries host_executables \ + installed_modules \ + executables libraries static_libraries shared_libraries \ + clean clean-objs-dir \ + clean-executables clean-libraries \ + clean-installed-modules \ + clean-installed-binaries + +# These macros are used in Android.mk to include the corresponding +# build script that will parse the LOCAL_XXX variable definitions. +# +CLEAR_VARS := $(BUILD_SYSTEM)/clear-vars.mk +BUILD_HOST_EXECUTABLE := $(BUILD_SYSTEM)/build-host-executable.mk +BUILD_HOST_STATIC_LIBRARY := $(BUILD_SYSTEM)/build-host-static-library.mk +BUILD_STATIC_LIBRARY := $(BUILD_SYSTEM)/build-static-library.mk +BUILD_SHARED_LIBRARY := $(BUILD_SYSTEM)/build-shared-library.mk +BUILD_EXECUTABLE := $(BUILD_SYSTEM)/build-executable.mk +PREBUILT_SHARED_LIBRARY := $(BUILD_SYSTEM)/prebuilt-shared-library.mk +PREBUILT_STATIC_LIBRARY := $(BUILD_SYSTEM)/prebuilt-static-library.mk + +ANDROID_MK_INCLUDED := \ + $(CLEAR_VARS) \ + $(BUILD_HOST_EXECUTABLE) \ + $(BUILD_HOST_STATIC_LIBRARY) \ + $(BUILD_STATIC_LIBRARY) \ + $(BUILD_SHARED_LIBRARY) \ + $(BUILD_EXECUTABLE) \ + $(PREBUILT_SHARED_LIBRARY) \ + + +# this is the list of directories containing dependency information +# generated during the build. It will be updated by build scripts +# when module definitions are parsed. +# +ALL_DEPENDENCY_DIRS := + +# this is the list of all generated files that we would need to clean +ALL_HOST_EXECUTABLES := +ALL_HOST_STATIC_LIBRARIES := +ALL_STATIC_LIBRARIES := +ALL_SHARED_LIBRARIES := +ALL_EXECUTABLES := + +WANTED_INSTALLED_MODULES := + +# the first rule +all: installed_modules host_libraries host_executables + + +$(foreach _app,$(NDK_APPS),\ + $(eval include $(BUILD_SYSTEM)/setup-app.mk)\ +) + +# ==================================================================== +# +# Now finish the build preparation with a few rules that depend on +# what has been effectively parsed and recorded previously +# +# ==================================================================== + +clean: clean-intermediates clean-installed-binaries + +distclean: clean + +installed_modules: clean-installed-binaries libraries $(WANTED_INSTALLED_MODULES) +host_libraries: $(HOST_STATIC_LIBRARIES) +host_executables: $(HOST_EXECUTABLES) + +static_libraries: $(STATIC_LIBRARIES) +shared_libraries: $(SHARED_LIBRARIES) +executables: $(EXECUTABLES) + +libraries: static_libraries shared_libraries + +clean-host-intermediates: + $(hide) $(call host-rm,$(HOST_EXECUTABLES) $(HOST_STATIC_LIBRARIES)) + +clean-intermediates: clean-host-intermediates + $(hide) $(call host-rm,$(EXECUTABLES) $(STATIC_LIBRARIES) $(SHARED_LIBRARIES)) + +# include dependency information +ALL_DEPENDENCY_DIRS := $(sort $(ALL_DEPENDENCY_DIRS)) +-include $(wildcard $(ALL_DEPENDENCY_DIRS:%=%/*.d)) diff --git a/Build/coreLinux/build-binary.mk b/Build/coreLinux/build-binary.mk new file mode 100644 index 00000000..cb8c8161 --- /dev/null +++ b/Build/coreLinux/build-binary.mk @@ -0,0 +1,356 @@ +# Copyright (C) 2008 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +# Check that LOCAL_MODULE is defined, then restore its LOCAL_XXXX values +$(call assert-defined,LOCAL_MODULE) +$(call module-restore-locals,$(LOCAL_MODULE)) + +# For now, only support target (device-specific modules). +# We may want to introduce support for host modules in the future +# but that is too experimental for now. +# +my := TARGET_ + +# LOCAL_MAKEFILE must also exist and name the Android.mk that +# included the module build script. +# +$(call assert-defined,LOCAL_MAKEFILE LOCAL_BUILD_SCRIPT LOCAL_BUILT_MODULE) + +include $(BUILD_SYSTEM)/import-locals.mk + +# +# Ensure that 'make ' and 'make clean-' work +# +.PHONY: $(LOCAL_MODULE) +$(LOCAL_MODULE): $(LOCAL_BUILT_MODULE) + +cleantarget := clean-$(LOCAL_MODULE)-$(TARGET_ARCH_ABI) +.PHONY: $(cleantarget) +clean: $(cleantarget) + +$(cleantarget): PRIVATE_MODULE := $(LOCAL_MODULE) +$(cleantarget): PRIVATE_TEXT := [$(TARGET_ARCH_ABI)] +$(cleantarget): PRIVATE_CLEAN_FILES := $(LOCAL_BUILT_MODULE) \ + $($(my)OBJS) + +$(cleantarget):: + @$(HOST_ECHO) "Clean: $(PRIVATE_MODULE) $(PRIVATE_TEXT)" + $(hide) $(call host-rmdir,$(PRIVATE_CLEAN_FILES)) + +ifeq ($(NDK_APP_DEBUGGABLE),true) +$(NDK_APP_GDBSETUP): PRIVATE_SRC_DIRS += $(LOCAL_C_INCLUDES) $(LOCAL_PATH) +endif + +# list of generated object files +LOCAL_OBJECTS := + +# always define ANDROID when building binaries +# +LOCAL_CFLAGS := -DANDROID $(LOCAL_CFLAGS) + +# +# Add the default system shared libraries to the build +# +ifeq ($(LOCAL_SYSTEM_SHARED_LIBRARIES),none) + LOCAL_SHARED_LIBRARIES += $(TARGET_DEFAULT_SYSTEM_SHARED_LIBRARIES) +else + LOCAL_SHARED_LIBRARIES += $(LOCAL_SYSTEM_SHARED_LIBRARIES) +endif + + +# +# Check LOCAL_CPP_EXTENSION, use '.cpp' by default +# +bad_cpp_extensions := $(strip $(filter-out .%,$(LOCAL_CPP_EXTENSION))) +ifdef bad_cpp_extensions + $(call __ndk_info,WARNING: Invalid LOCAL_CPP_EXTENSION values: $(bad_cpp_extensions)) + LOCAL_CPP_EXTENSION := $(filter $(bad_cpp_extensions),$(LOCAL_CPP_EXTENSIONS)) +endif +LOCAL_CPP_EXTENSION := $(strip $(LOCAL_CPP_EXTENSION)) +ifeq ($(LOCAL_CPP_EXTENSION),) + LOCAL_CPP_EXTENSION := .cpp +else +endif + +# +# If LOCAL_ALLOW_UNDEFINED_SYMBOLS is not true, the linker will allow the generation +# of a binary that uses undefined symbols. +# +ifneq ($(LOCAL_ALLOW_UNDEFINED_SYMBOLS),true) + LOCAL_LDFLAGS += $($(my)NO_UNDEFINED_LDFLAGS) +endif + +# If LOCAL_DISABLE_NO_EXECUTE is not true, we disable generated code from running from +# the heap and stack by default. +# +ifndef ($(LOCAL_DISABLE_NO_EXECUTE),true) + LOCAL_CFLAGS += $($(my)NO_EXECUTE_CFLAGS) + LOCAL_LDFLAGS += $($(my)NO_EXECUTE_LDFLAGS) +endif + +# +# The original Android build system allows you to use the .arm prefix +# to a source file name to indicate that it should be defined in either +# 'thumb' or 'arm' mode, depending on the value of LOCAL_ARM_MODE +# +# First, check LOCAL_ARM_MODE, it should be empty, 'thumb' or 'arm' +# We make the default 'thumb' +# +LOCAL_ARM_MODE := $(strip $(LOCAL_ARM_MODE)) +ifdef LOCAL_ARM_MODE + ifneq ($(words $(LOCAL_ARM_MODE)),1) + $(call __ndk_info, LOCAL_ARM_MODE in $(LOCAL_MAKEFILE) must be one word, not '$(LOCAL_ARM_MODE)') + $(call __ndk_error, Aborting) + endif + # check that LOCAL_ARM_MODE is defined to either 'arm' or 'thumb' + $(if $(filter-out thumb arm, $(LOCAL_ARM_MODE)),\ + $(call __ndk_info, LOCAL_ARM_MODE must be defined to either 'arm' or 'thumb' in $(LOCAL_MAKEFILE) not '$(LOCAL_ARM_MODE)')\ + $(call __ndk_error, Aborting)\ + ) +endif + +# As a special case, the original Android build system +# allows one to specify that certain source files can be +# forced to build in ARM mode by using a '.arm' suffix +# after the extension, e.g. +# +# LOCAL_SRC_FILES := foo.c.arm +# +# to build source file $(LOCAL_PATH)/foo.c as ARM +# + +# As a special extension, the NDK also supports the .neon extension suffix +# to indicate that a single file can be compiled with ARM NEON support +# We must support both foo.c.neon and foo.c.arm.neon here +# +# Also, if LOCAL_ARM_NEON is set to 'true', force Neon mode for all source +# files +# + +neon_sources := $(filter %.neon,$(LOCAL_SRC_FILES)) +neon_sources := $(neon_sources:%.neon=%) + +LOCAL_ARM_NEON := $(strip $(LOCAL_ARM_NEON)) +ifdef LOCAL_ARM_NEON + $(if $(filter-out true false,$(LOCAL_ARM_NEON)),\ + $(call __ndk_info,LOCAL_ARM_NEON must be defined either to 'true' or 'false' in $(LOCAL_MAKEFILE), not '$(LOCAL_ARM_NEON)')\ + $(call __ndk_error,Aborting) \ + ) +endif +ifeq ($(LOCAL_ARM_NEON),true) + neon_sources += $(LOCAL_SRC_FILES:%.neon=%) +endif + +neon_sources := $(strip $(neon_sources)) +ifdef neon_sources + ifneq ($(TARGET_ARCH_ABI),armeabi-v7a) + $(call __ndk_info,NEON support is only possible for armeabi-v7a ABI) + $(call __ndk_info,Please add checks against TARGET_ARCH_ABI in $(LOCAL_MAKEFILE)) + $(call __ndk_error,Aborting) + endif + $(call tag-src-files,$(neon_sources:%.arm=%),neon) +endif + +LOCAL_SRC_FILES := $(LOCAL_SRC_FILES:%.neon=%) + +# strip the .arm suffix from LOCAL_SRC_FILES +# and tag the relevant sources with the 'arm' tag +# +arm_sources := $(filter %.arm,$(LOCAL_SRC_FILES)) +arm_sources := $(arm_sources:%.arm=%) +thumb_sources := $(filter-out %.arm,$(LOCAL_SRC_FILES)) +LOCAL_SRC_FILES := $(LOCAL_SRC_FILES:%.arm=%) + +ifeq ($(LOCAL_ARM_MODE),arm) + arm_sources := $(LOCAL_SRC_FILES) +endif +ifeq ($(LOCAL_ARM_MODE),thumb) + arm_sources := $(empty) +endif +$(call tag-src-files,$(arm_sources),arm) + +# Process all source file tags to determine toolchain-specific +# target compiler flags, and text. +# +$(call TARGET-process-src-files-tags) + +# only call dump-src-file-tags during debugging +#$(dump-src-file-tags) + +LOCAL_DEPENDENCY_DIRS := + +# all_source_patterns contains the list of filename patterns that correspond +# to source files recognized by our build system +all_source_extensions := .c .s .S $(LOCAL_CPP_EXTENSION) +all_source_patterns := $(foreach _ext,$(all_source_extensions),%$(_ext)) +all_cpp_patterns := $(foreach _ext,$(LOCAL_CPP_EXTENSION),%$(_ext)) + +unknown_sources := $(strip $(filter-out $(all_source_patterns),$(LOCAL_SRC_FILES))) +ifdef unknown_sources + $(call __ndk_info,WARNING: Unsupported source file extensions in $(LOCAL_MAKEFILE) for module $(LOCAL_MODULE)) + $(call __ndk_info, $(unknown_sources)) +endif + +# LOCAL_OBJECTS will list all object files corresponding to the sources +# listed in LOCAL_SRC_FILES, in the *same* order. +# +LOCAL_OBJECTS := $(LOCAL_SRC_FILES) +$(foreach _ext,$(all_source_extensions),\ + $(eval LOCAL_OBJECTS := $$(LOCAL_OBJECTS:%$(_ext)=%.o))\ +) +LOCAL_OBJECTS := $(filter %.o,$(LOCAL_OBJECTS)) +LOCAL_OBJECTS := $(subst ../,__/,$(LOCAL_OBJECTS)) +LOCAL_OBJECTS := $(foreach _obj,$(LOCAL_OBJECTS),$(LOCAL_OBJS_DIR)/$(_obj)) + +# If the module has any kind of C++ features, enable them in LOCAL_CPPFLAGS +# +ifneq (,$(call module-has-c++-features,$(LOCAL_MODULE),rtti)) + LOCAL_CPPFLAGS += -frtti +endif +ifneq (,$(call module-has-c++-features,$(LOCAL_MODULE),exceptions)) + LOCAL_CPPFLAGS += -fexceptions +endif + +# If we're using the 'system' STL and use rtti or exceptions, then +# automatically link against the GNU libsupc++ for now. +# +ifneq (,$(call module-has-c++-features,$(LOCAL_MODULE),rtti exceptions)) + ifeq (system,$(NDK_APP_STL)) + LOCAL_LDLIBS := $(LOCAL_LDLIBS) $(NDK_ROOT)/sources/cxx-stl/gnu-libstdc++/libs/$(TARGET_ARCH_ABI)/libsupc++.a + endif +endif + +# Build the sources to object files +# + +$(foreach src,$(filter %.c,$(LOCAL_SRC_FILES)), $(call compile-c-source,$(src),$(call get-object-name,$(src)))) +$(foreach src,$(filter %.S %.s,$(LOCAL_SRC_FILES)), $(call compile-s-source,$(src),$(call get-object-name,$(src)))) + +$(foreach src,$(filter $(all_cpp_patterns),$(LOCAL_SRC_FILES)),\ + $(call compile-cpp-source,$(src),$(call get-object-name,$(src)))\ +) + +# +# The compile-xxx-source calls updated LOCAL_OBJECTS and LOCAL_DEPENDENCY_DIRS +# +ALL_DEPENDENCY_DIRS += $(sort $(LOCAL_DEPENDENCY_DIRS)) +CLEAN_OBJS_DIRS += $(LOCAL_OBJS_DIR) + +# +# Handle the static and shared libraries this module depends on +# +LOCAL_STATIC_LIBRARIES := $(call strip-lib-prefix,$(LOCAL_STATIC_LIBRARIES)) +LOCAL_WHOLE_STATIC_LIBRARIES := $(call strip-lib-prefix,$(LOCAL_WHOLE_STATIC_LIBRARIES)) +LOCAL_SHARED_LIBRARIES := $(call strip-lib-prefix,$(LOCAL_SHARED_LIBRARIES)) + +# Transitive closure of static libraries +LOCAL_STATIC_LIBRARIES := $(call module-get-depends,$(LOCAL_STATIC_LIBRARIES),STATIC_LIBRARIES) +LOCAL_WHOLE_STATIC_LIBRARIES := $(call module-get-depends,$(LOCAL_WHOLE_STATIC_LIBRARIES),WHOLE_STATIC_LIBRARIES) + +static_libraries := $(call map,module-get-built,$(LOCAL_STATIC_LIBRARIES)) +whole_static_libraries := $(call map,module-get-built,$(LOCAL_WHOLE_STATIC_LIBRARIES)) + +shared_libraries := $(call map,module-get-built,$(LOCAL_SHARED_LIBRARIES))\ + $(TARGET_PREBUILT_SHARED_LIBRARIES) + +$(LOCAL_BUILT_MODULE): $(static_libraries) $(whole_static_libraries) $(shared_libraries) + +# If LOCAL_LDLIBS contains anything like -l then +# prepend a -L$(SYSROOT)/usr/lib to it to ensure that the linker +# looks in the right location +# +ifneq ($(filter -l%,$(LOCAL_LDLIBS)),) + LOCAL_LDLIBS := -L$(call host-path,$(SYSROOT)/usr/lib) $(LOCAL_LDLIBS) +endif + +$(LOCAL_BUILT_MODULE): PRIVATE_STATIC_LIBRARIES := $(static_libraries) +$(LOCAL_BUILT_MODULE): PRIVATE_WHOLE_STATIC_LIBRARIES := $(whole_static_libraries) +$(LOCAL_BUILT_MODULE): PRIVATE_SHARED_LIBRARIES := $(shared_libraries) +$(LOCAL_BUILT_MODULE): PRIVATE_OBJECTS := $(LOCAL_OBJECTS) +$(LOCAL_BUILT_MODULE): PRIVATE_LIBGCC := $(TARGET_LIBGCC) + +$(LOCAL_BUILT_MODULE): PRIVATE_LD := $(TARGET_LD) +$(LOCAL_BUILT_MODULE): PRIVATE_LDFLAGS := $(TARGET_LDFLAGS) $(LOCAL_LDFLAGS) +$(LOCAL_BUILT_MODULE): PRIVATE_LDLIBS := $(LOCAL_LDLIBS) $(TARGET_LDLIBS) + +$(LOCAL_BUILT_MODULE): PRIVATE_NAME := $(notdir $(LOCAL_BUILT_MODULE)) +$(LOCAL_BUILT_MODULE): PRIVATE_CXX := $(TARGET_CXX) +$(LOCAL_BUILT_MODULE): PRIVATE_CC := $(TARGET_CC) +$(LOCAL_BUILT_MODULE): PRIVATE_AR := $(TARGET_AR) $(TARGET_ARFLAGS) +$(LOCAL_BUILT_MODULE): PRIVATE_SYSROOT := $(SYSROOT) + +# +# If this is a static library module +# +ifeq ($(call module-get-class,$(LOCAL_MODULE)),STATIC_LIBRARY) +$(LOCAL_BUILT_MODULE): $(LOCAL_OBJECTS) + @ $(call host-mkdir,$(dir $@)) + @ $(HOST_ECHO) "StaticLibrary : $(PRIVATE_NAME)" + $(hide) $(call host-rm,$@) + $(hide) $(cmd-build-static-library) + +ALL_STATIC_LIBRARIES += $(LOCAL_BUILT_MODULE) +endif + +# +# If this is a shared library module +# +ifeq ($(call module-get-class,$(LOCAL_MODULE)),SHARED_LIBRARY) +$(LOCAL_BUILT_MODULE): $(LOCAL_OBJECTS) + @ $(call host-mkdir,$(dir $@)) + @ $(HOST_ECHO) "SharedLibrary : $(PRIVATE_NAME)" + $(hide) $(cmd-build-shared-library) + +ALL_SHARED_LIBRARIES += $(LOCAL_BUILT_MODULE) +endif + +# +# If this is an executable module +# +ifeq ($(call module-get-class,$(LOCAL_MODULE)),EXECUTABLE) +$(LOCAL_BUILT_MODULE): $(LOCAL_OBJECTS) + @ $(call host-mkdir,$(dir $@)) + @ $(HOST_ECHO) "Executable : $(PRIVATE_NAME)" + $(hide) $(cmd-build-executable) + +ALL_EXECUTABLES += $(LOCAL_BUILT_MODULE) +endif + +# +# If this is a prebuilt module +# +ifeq ($(call module-is-prebuilt,$(LOCAL_MODULE)),$(true)) +$(LOCAL_BUILT_MODULE): $(LOCAL_OBJECTS) + @ $(call host-mkdir,$(dir $@)) + @ $(HOST_ECHO) "Prebuilt : $(PRIVATE_NAME) <= $(call pretty-dir,$(dir $<))" + $(hide) $(call host-cp,$<,$@) +endif + +# +# If this is an installable module +# +ifeq ($(call module-is-installable,$(LOCAL_MODULE)),$(true)) +$(LOCAL_INSTALLED): PRIVATE_NAME := $(notdir $(LOCAL_BUILT_MODULE)) +$(LOCAL_INSTALLED): PRIVATE_SRC := $(LOCAL_BUILT_MODULE) +$(LOCAL_INSTALLED): PRIVATE_DST_DIR := $(NDK_APP_DST_DIR) +$(LOCAL_INSTALLED): PRIVATE_DST := $(LOCAL_INSTALLED) +$(LOCAL_INSTALLED): PRIVATE_STRIP := $(TARGET_STRIP) + +$(LOCAL_INSTALLED): $(LOCAL_BUILT_MODULE) clean-installed-binaries + @$(HOST_ECHO) "Install : $(PRIVATE_NAME) => $(call pretty-dir,$(PRIVATE_DST))" + $(hide) $(call host-mkdir,$(PRIVATE_DST_DIR)) + $(hide) $(call host-install,$(PRIVATE_SRC),$(PRIVATE_DST)) + $(hide) $(call cmd-strip, $(PRIVATE_DST)) +endif diff --git a/Build/coreLinux/build-executable.mk b/Build/coreLinux/build-executable.mk new file mode 100644 index 00000000..dda5592b --- /dev/null +++ b/Build/coreLinux/build-executable.mk @@ -0,0 +1,34 @@ +# Copyright (C) 2009 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +# this file is included from Android.mk files to build a target-specific +# executable program +# + +LOCAL_BUILD_SCRIPT := BUILD_EXECUTABLE +LOCAL_MAKEFILE := $(local-makefile) + +$(call check-defined-LOCAL_MODULE,$(LOCAL_BUILD_SCRIPT)) +$(call check-LOCAL_MODULE,$(LOCAL_MAKEFILE)) +$(call check-LOCAL_MODULE_FILENAME) + +# we are building target objects +my := TARGET_ + +$(call handle-module-filename,,) +$(call handle-module-built) + +LOCAL_MODULE_CLASS := EXECUTABLE +include $(BUILD_SYSTEM)/build-module.mk diff --git a/Build/coreLinux/build-local.mk b/Build/coreLinux/build-local.mk new file mode 100644 index 00000000..b8e826a2 --- /dev/null +++ b/Build/coreLinux/build-local.mk @@ -0,0 +1,154 @@ +# Copyright (C) 2010 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +# This file is designed to be called from the 'ndk-build' script +# or similar wrapper tool. +# + +# Detect the NDK installation path by processing this Makefile's location. +# This assumes we are located under $NDK_ROOT/main.mk +# +NDK_ROOT := $(dir $(lastword $(MAKEFILE_LIST))) +#NDK_ROOT := $(strip $(NDK_ROOT:%build/core/=%)) +NDK_ROOT := $(subst \,/,$(NDK_ROOT)) +NDK_ROOT := $(NDK_ROOT:%/=%) +ifeq ($(NDK_ROOT),) + # for the case when we're invoked from the NDK install path + NDK_ROOT := . +endif +ifdef NDK_LOG + $(info Android NDK: NDK installation path auto-detected: '$(NDK_ROOT)') +endif +ifneq ($(words $(NDK_ROOT)),1) + $(info Android NDK: You NDK installation path contains spaces.) + $(info Android NDK: Please re-install to a different location to fix the issue !) + $(error Aborting.) +endif + +$(info NDK ROOT : $(NDK_ROOT)) +include $(NDK_ROOT)/init.mk + +# ==================================================================== +# +# If NDK_PROJECT_PATH is not defined, find the application's project +# path by looking at the manifest file in the current directory or +# any of its parents. If none is found, try again with 'jni/Android.mk' +# +# Note that we first look at the current directory to avoid using +# absolute NDK_PROJECT_PATH values. This reduces the length of all +# source, object and binary paths that are passed to build commands. +# +# It turns out that some people use ndk-build to generate static +# libraries without a full Android project tree. +# +# ==================================================================== + +find-project-dir = $(strip $(call find-project-dir-inner,$(abspath $1),$2)) + +find-project-dir-inner = \ + $(eval __found_project_path := )\ + $(eval __find_project_path := $1)\ + $(eval __find_project_file := $2)\ + $(call find-project-dir-inner-2)\ + $(__found_project_path) + +find-project-dir-inner-2 = \ + $(call ndk_log,Looking for $(__find_project_file) in $(__find_project_path))\ + $(eval __find_project_manifest := $(strip $(wildcard $(__find_project_path)/$(__find_project_file))))\ + $(if $(__find_project_manifest),\ + $(call ndk_log, Found it !)\ + $(eval __found_project_path := $(__find_project_path))\ + ,\ + $(eval __find_project_parent := $(patsubst %/,%,$(dir $(__find_project_path))))\ + $(if $(__find_project_parent),\ + $(eval __find_project_path := $(__find_project_parent))\ + $(call find-project-dir-inner-2)\ + )\ + ) + +NDK_PROJECT_PATH := $(strip $(NDK_PROJECT_PATH)) +ifndef NDK_PROJECT_PATH + ifneq (,$(strip $(wildcard AndroidManifest.xml))) + NDK_PROJECT_PATH := . + else + ifneq (,$(strip $(wildcard jni/Android.mk))) + NDK_PROJECT_PATH := . + endif + endif +endif +ifndef NDK_PROJECT_PATH + NDK_PROJECT_PATH := $(call find-project-dir,.,jni/Android.mk) +endif +ifndef NDK_PROJECT_PATH + NDK_PROJECT_PATH := $(call find-project-dir,$(strip $(shell pwd)),AndroidManifest.xml) +endif +ifndef NDK_PROJECT_PATH + NDK_PROJECT_PATH := $(call find-project-dir,$(strip $(shell pwd)),jni/Android.mk) +endif +ifndef NDK_PROJECT_PATH + $(call __ndk_info,Could not find application project directory !) + $(call __ndk_info,Please define the NDK_PROJECT_PATH variable to point to it.) + $(call __ndk_error,Aborting) +endif + +# Check that there are no spaces in the project path, or bad things will happen +ifneq ($(words $(NDK_PROJECT_PATH)),1) + $(call __ndk_info,Your Android application project path contains spaces: '$(NDK_PROJECT_PATH)') + $(call __ndk_info,The Android NDK build cannot work here. Please move your project to a different location.) + $(call __ndk_error,Aborting.) +endif + +NDK_APPLICATION_MK := $(strip $(wildcard $(NDK_PROJECT_PATH)/jni/Application.mk)) +ifndef NDK_APPLICATION_MK + NDK_APPLICATION_MK := $(NDK_ROOT)/default-application.mk +endif + +$(call ndk_log,Found project path: $(NDK_PROJECT_PATH)) + +# Place all generated files here +NDK_APP_OUT := $(NDK_PROJECT_PATH)/obj + +# Fake an application named 'local' +_app := local +_application_mk := $(NDK_APPLICATION_MK) +NDK_APPS := $(_app) + +include $(BUILD_SYSTEM)/add-application.mk + +# If a goal is DUMP_xxx then we dump a variable xxx instead +# of building anything +# +DUMP_VAR := $(patsubst DUMP_%,%,$(filter DUMP_%,$(MAKECMDGOALS))) +MAKECMDGOALS := $(filter-out DUMP_$(DUMP_VAR),$(MAKECMDGOALS)) + +include $(BUILD_SYSTEM)/setup-imports.mk + +ifneq (,$(DUMP_VAR)) + +# We only support a single DUMP_XXX goal at a time for now. +ifneq ($(words $(DUMP_VAR)),1) + $(call __ndk_error,!!TOO-MANY-DUMP-VARIABLES!!) +endif + +$(foreach _app,$(NDK_APPS),\ + $(eval include $(BUILD_SYSTEM)/setup-app.mk)\ +) + +DUMP_$(DUMP_VAR): + @echo $($(DUMP_VAR)) +else + # Build it + include $(BUILD_SYSTEM)/build-all.mk +endif diff --git a/Build/coreLinux/build-module.mk b/Build/coreLinux/build-module.mk new file mode 100644 index 00000000..d0ab95d9 --- /dev/null +++ b/Build/coreLinux/build-module.mk @@ -0,0 +1,34 @@ +# Copyright (C) 2010 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +$(call check-defined-LOCAL_MODULE,$(LOCAL_BUILD_SCRIPT)) +$(call check-LOCAL_MODULE,$(LOCAL_MAKEFILE)) + +# This file is used to record the LOCAL_XXX definitions of a given +# module. It is included by BUILD_STATIC_LIBRARY, BUILD_SHARED_LIBRARY +# and others. +# +LOCAL_MODULE_CLASS := $(strip $(LOCAL_MODULE_CLASS)) +ifndef LOCAL_MODULE_CLASS +$(call __ndk_info,$(LOCAL_MAKEFILE):$(LOCAL_MODULE): LOCAL_MODULE_CLASS definition is missing !) +$(call __ndk_error,Aborting) +endif + +$(if $(call module-class-check,$(LOCAL_MODULE_CLASS)),,\ +$(call __ndk_info,$(LOCAL_MAKEFILE):$(LOCAL_MODULE): Unknown LOCAL_MODULE_CLASS value: $(LOCAL_MODULE_CLASS))\ +$(call __ndk_error,Aborting)\ +) + +$(call module-add,$(LOCAL_MODULE)) diff --git a/Build/coreLinux/build-shared-library.mk b/Build/coreLinux/build-shared-library.mk new file mode 100644 index 00000000..159aebb5 --- /dev/null +++ b/Build/coreLinux/build-shared-library.mk @@ -0,0 +1,34 @@ +# Copyright (C) 2009 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +# this file is included from Android.mk files to build a target-specific +# shared library +# + +LOCAL_BUILD_SCRIPT := BUILD_SHARED_LIBRARY +LOCAL_MAKEFILE := $(local-makefile) + +$(call check-defined-LOCAL_MODULE,$(LOCAL_BUILD_SCRIPT)) +$(call check-LOCAL_MODULE,$(LOCAL_MAKEFILE)) +$(call check-LOCAL_MODULE_FILENAME) + +# we are building target objects +my := TARGET_ + +$(call handle-module-filename,lib,.so) +$(call handle-module-built) + +LOCAL_MODULE_CLASS := SHARED_LIBRARY +include $(BUILD_SYSTEM)/build-module.mk diff --git a/Build/coreLinux/build-static-library.mk b/Build/coreLinux/build-static-library.mk new file mode 100644 index 00000000..cab37583 --- /dev/null +++ b/Build/coreLinux/build-static-library.mk @@ -0,0 +1,34 @@ +# Copyright (C) 2009 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +# this file is included from Android.mk files to build a target-specific +# static library +# + +LOCAL_BUILD_SCRIPT := BUILD_STATIC_LIBRARY +LOCAL_MAKEFILE := $(local-makefile) + +$(call check-defined-LOCAL_MODULE,$(LOCAL_BUILD_SCRIPT)) +$(call check-LOCAL_MODULE,$(LOCAL_MAKEFILE)) + +# we are building target objects +my := TARGET_ + +$(call handle-module-filename,lib,.a) +$(call handle-module-built) + +LOCAL_MODULE_CLASS := STATIC_LIBRARY +include $(BUILD_SYSTEM)/build-module.mk + diff --git a/Build/coreLinux/check-cygwin-make.mk b/Build/coreLinux/check-cygwin-make.mk new file mode 100644 index 00000000..27bc2279 --- /dev/null +++ b/Build/coreLinux/check-cygwin-make.mk @@ -0,0 +1,43 @@ +# Copyright (C) 2010 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +# Check that we have a Cygwin-compatible make. +# +# For some reason, a lot of application developers on Windows +# have another GNU Make installed in their path, that fails +# miserably with our build scripts. If we can detect this use +# case, early, we will be able to dump a human-readable error +# message with some help to fix the issue. +# + +.PHONY: all +all: + +# Get the cygwin-specific path to the make executable +# (e.g. /cygdrive/c/cygwin/usr/bin/make), then strip the +# .exe suffix, if any. +# +CYGWIN_MAKE := $(shell cygpath --unix --absolute $(firstword $(MAKE))) +CYGWIN_MAKE := $(CYGWIN_MAKE:%.exe=%) + +# Now try to find it on the file system, a non-cygwin compatible +# GNU Make, even if launched from a Cygwin shell, will not +# +SELF_MAKE := $(strip $(wildcard $(CYGWIN_MAKE).exe)) +ifeq ($(SELF_MAKE),) + $(error Android NDK: $(firstword $(MAKE)) is not cygwin-compatible) +endif + +# that's all diff --git a/Build/coreLinux/clear-vars.mk b/Build/coreLinux/clear-vars.mk new file mode 100644 index 00000000..e9ad319a --- /dev/null +++ b/Build/coreLinux/clear-vars.mk @@ -0,0 +1,22 @@ +# Copyright (C) 2009 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +# this file is included repeatedly from Android.mk files in order to clean +# the module-specific variables from the environment, + +$(call clear-src-tags) + +# Note: As a special exception, we don't want to clear LOCAL_PATH +$(call clear-vars, $(filter-out LOCAL_PATH,$(modules-LOCALS:%=LOCAL_%))) diff --git a/Build/coreLinux/default-application.mk b/Build/coreLinux/default-application.mk new file mode 100644 index 00000000..8135c555 --- /dev/null +++ b/Build/coreLinux/default-application.mk @@ -0,0 +1,23 @@ +# Copyright (C) 2010 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +# This is the default Application.mk that is being used for applications +# that don't provide $PROJECT_PATH/jni/Application.mk +# +APP_PROJECT_PATH := $(NDK_PROJECT_PATH) + +# We expect the build script to be located here +APP_BUILD_SCRIPT := $(APP_PROJECT_PATH)/jni/Android.mk + diff --git a/Build/coreLinux/default-build-commands.mk b/Build/coreLinux/default-build-commands.mk new file mode 100644 index 00000000..8beec0ff --- /dev/null +++ b/Build/coreLinux/default-build-commands.mk @@ -0,0 +1,97 @@ +# The following definitions are the defaults used by all toolchains. +# This is included in setup-toolchain.mk just before the inclusion +# of the toolchain's specific setup.mk file which can then override +# these definitions. +# + +# These flags are used to ensure that a binary doesn't reference undefined +# flags. +TARGET_NO_UNDEFINED_LDFLAGS := -Wl,--no-undefined + +# These flags are used to enfore the NX (no execute) security feature in the +# generated machine code. This adds a special section to the generated shared +# libraries that instruct the Linux kernel to disable code execution from +# the stack and the heap. +TARGET_NO_EXECUTE_CFLAGS := -Wa,--noexecstack +TARGET_NO_EXECUTE_LDFLAGS := -Wl,-z,noexecstack + +# NOTE: Ensure that TARGET_LIBGCC is placed after all private objects +# and static libraries, but before any other library in the link +# command line when generating shared libraries and executables. +# +# This ensures that all libgcc.a functions required by the target +# will be included into it, instead of relying on what's available +# on other libraries like libc.so, which may change between system +# releases due to toolchain or library changes. +# +define cmd-build-shared-library +$(PRIVATE_CXX) \ + -nostdlib -Wl,-soname,$(notdir $@) \ + -Wl,-shared,-Bsymbolic \ + $(call host-path,\ + $(TARGET_CRTBEGIN_SO_O) \ + $(PRIVATE_OBJECTS)) \ + $(call link-whole-archives,$(PRIVATE_WHOLE_STATIC_LIBRARIES))\ + $(call host-path,\ + $(PRIVATE_STATIC_LIBRARIES) \ + $(PRIVATE_LIBGCC) \ + $(PRIVATE_SHARED_LIBRARIES)) \ + $(PRIVATE_LDFLAGS) \ + $(PRIVATE_LDLIBS) \ + $(call host-path,\ + $(TARGET_CRTEND_SO_O)) \ + -o $(call host-path,$@) +endef + +define cmd-build-executable +$(PRIVATE_CXX) \ + -nostdlib -Bdynamic \ + -Wl,-dynamic-linker,/system/bin/linker \ + -Wl,--gc-sections \ + -Wl,-z,nocopyreloc \ + $(call host-path,\ + $(TARGET_CRTBEGIN_DYNAMIC_O) \ + $(PRIVATE_OBJECTS)) \ + $(call link-whole-archives,$(PRIVATE_WHOLE_STATIC_LIBRARIES))\ + $(call host-path,\ + $(PRIVATE_STATIC_LIBRARIES) \ + $(PRIVATE_LIBGCC) \ + $(PRIVATE_SHARED_LIBRARIES)) \ + $(PRIVATE_LDFLAGS) \ + $(PRIVATE_LDLIBS) \ + $(call host-path,\ + $(TARGET_CRTEND_O)) \ + -o $(call host-path,$@) +endef + +define cmd-build-static-library +$(PRIVATE_AR) $(call host-path,$@) $(call host-path,$(PRIVATE_OBJECTS)) +endef + +# The strip command is only used for shared libraries and executables. +# It is thus safe to use --strip-unneeded, which is only dangerous +# when applied to static libraries or object files. +cmd-strip = $(PRIVATE_STRIP) --strip-unneeded $(call host-path,$1) + +TARGET_LIBGCC = $(shell $(TARGET_CC) -print-libgcc-file-name) +TARGET_LDLIBS := -lc -lm + +# +# IMPORTANT: The following definitions must use lazy assignment because +# the value of TOOLCHAIN_PREFIX or TARGET_CFLAGS can be changed later by +# the toolchain's setup.mk script. +# + +TARGET_CC = $(TOOLCHAIN_PREFIX)gcc +TARGET_CFLAGS = + +TARGET_CXX = $(TOOLCHAIN_PREFIX)g++ +TARGET_CXXFLAGS = $(TARGET_CFLAGS) -fno-exceptions -fno-rtti + +TARGET_LD = $(TOOLCHAIN_PREFIX)ld +TARGET_LDFLAGS := + +TARGET_AR = $(TOOLCHAIN_PREFIX)ar +TARGET_ARFLAGS := crs + +TARGET_STRIP = $(TOOLCHAIN_PREFIX)strip diff --git a/Build/coreLinux/definitions.mk b/Build/coreLinux/definitions.mk new file mode 100644 index 00000000..cd38ddaa --- /dev/null +++ b/Build/coreLinux/definitions.mk @@ -0,0 +1,1612 @@ +# Copyright (C) 2009 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Common definitions for the Android NDK build system +# + +# We use the GNU Make Standard Library +include $(NDK_ROOT)/build/gmsl/gmsl + +# If NDK_TRACE is enabled then calls to the library functions are +# traced to stdout using warning messages with their arguments + +ifdef NDK_TRACE +__ndk_tr1 = $(warning $0('$1')) +__ndk_tr2 = $(warning $0('$1','$2')) +__ndk_tr3 = $(warning $0('$1','$2','$3')) +else +__ndk_tr1 := +__ndk_tr2 := +__ndk_tr3 := +endif + +# ----------------------------------------------------------------------------- +# Macro : empty +# Returns : an empty macro +# Usage : $(empty) +# ----------------------------------------------------------------------------- +empty := + +# ----------------------------------------------------------------------------- +# Macro : space +# Returns : a single space +# Usage : $(space) +# ----------------------------------------------------------------------------- +space := $(empty) $(empty) + +space4 := $(space)$(space)$(space)$(space) + +# ----------------------------------------------------------------------------- +# Function : last2 +# Arguments: a list +# Returns : the penultimate (next-to-last) element of a list +# Usage : $(call last2, ) +# ----------------------------------------------------------------------------- +last2 = $(word $(words $1), x $1) + +# ----------------------------------------------------------------------------- +# Function : last3 +# Arguments: a list +# Returns : the antepenultimate (second-next-to-last) element of a list +# Usage : $(call last3, ) +# ----------------------------------------------------------------------------- +last3 = $(word $(words $1), x x $1) + +# ----------------------------------------------------------------------------- +# Function : remove-duplicates +# Arguments: a list +# Returns : the list with duplicate items removed, order is preserved. +# Usage : $(call remove-duplicates, ) +# Note : This is equivalent to the 'uniq' function provided by GMSL, +# however this implementation is non-recursive and *much* +# faster. It will also not explode the stack with a lot of +# items like 'uniq' does. +# ----------------------------------------------------------------------------- +remove-duplicates = $(strip \ + $(eval __uniq_ret :=) \ + $(foreach __uniq_item,$1,\ + $(if $(findstring $(__uniq_item),$(__uniq_ret)),,\ + $(eval __uniq_ret += $(__uniq_item))\ + )\ + )\ + $(__uniq_ret)) + +# ----------------------------------------------------------------------------- +# Macro : this-makefile +# Returns : the name of the current Makefile in the inclusion stack +# Usage : $(this-makefile) +# ----------------------------------------------------------------------------- +this-makefile = $(lastword $(MAKEFILE_LIST)) + +# ----------------------------------------------------------------------------- +# Macro : local-makefile +# Returns : the name of the last parsed Android.mk file +# Usage : $(local-makefile) +# ----------------------------------------------------------------------------- +local-makefile = $(lastword $(filter %Android.mk,$(MAKEFILE_LIST))) + +# ----------------------------------------------------------------------------- +# Function : assert-defined +# Arguments: 1: list of variable names +# Returns : None +# Usage : $(call assert-defined, VAR1 VAR2 VAR3...) +# Rationale: Checks that all variables listed in $1 are defined, or abort the +# build +# ----------------------------------------------------------------------------- +assert-defined = $(foreach __varname,$(strip $1),\ + $(if $(strip $($(__varname))),,\ + $(call __ndk_error, Assertion failure: $(__varname) is not defined)\ + )\ +) + +# ----------------------------------------------------------------------------- +# Function : clear-vars +# Arguments: 1: list of variable names +# 2: file where the variable should be defined +# Returns : None +# Usage : $(call clear-vars, VAR1 VAR2 VAR3...) +# Rationale: Clears/undefines all variables in argument list +# ----------------------------------------------------------------------------- +clear-vars = $(foreach __varname,$1,$(eval $(__varname) := $(empty))) + +# ----------------------------------------------------------------------------- +# Function : check-required-vars +# Arguments: 1: list of variable names +# 2: file where the variable(s) should be defined +# Returns : None +# Usage : $(call check-required-vars, VAR1 VAR2 VAR3..., ) +# Rationale: Checks that all required vars listed in $1 were defined by $2 +# or abort the build with an error +# ----------------------------------------------------------------------------- +check-required-vars = $(foreach __varname,$1,\ + $(if $(strip $($(__varname))),,\ + $(call __ndk_info, Required variable $(__varname) is not defined by $2)\ + $(call __ndk_error,Aborting)\ + )\ +) + +# ----------------------------------------------------------------------------- +# Function : host-path +# Arguments: 1: file path +# Returns : file path, as understood by the host file system +# Usage : $(call host-path,) +# Rationale: This function is used to translate Cygwin paths into +# Cygwin-specific ones. On other platforms, it will just +# return its argument. +# ----------------------------------------------------------------------------- +ifeq ($(HOST_OS),cygwin) +host-path = $(if $(strip $1),$(call cygwin-to-host-path,$1)) +else +host-path = $1 +endif + +# ----------------------------------------------------------------------------- +# Function : host-rm +# Arguments: 1: list of files +# Usage : $(call host-rm,) +# Rationale: This function expands to the host-specific shell command used +# to remove some files. +# ----------------------------------------------------------------------------- +ifeq ($(HOST_OS),windows) +host-rm = $(foreach _filepattern,$1,$(if $(strip $(wildcard $(_filepattern))),del /f/q/s $(subst /,\,$(_filepattern)) >NUL)) +else +host-rm = rm -f $1 +endif + +# ----------------------------------------------------------------------------- +# Function : host-rmdir +# Arguments: 1: list of files or directories +# Usage : $(call host-rm,) +# Rationale: This function expands to the host-specific shell command used +# to remove some files _and_ directories. +# ----------------------------------------------------------------------------- +ifeq ($(HOST_OS),windows) +host-rmdir = del /f/s/e/q $(subst /,\,$1) >NUL 2>NUL +else +host-rmdir = rm -rf $1 +endif + +# ----------------------------------------------------------------------------- +# Function : host-mkdir +# Arguments: 1: directory path +# Usage : $(call host-mkdir, +# Rationale: This function expands to the host-specific shell command used +# to create a path if it doesn't exist. +# ----------------------------------------------------------------------------- +ifeq ($(HOST_OS),windows) +host-mkdir = if not exist $(subst /,\,$1) md $(subst /,\,$1) +else +host-mkdir = mkdir -p $1 +endif + +# ----------------------------------------------------------------------------- +# Function : host-cp +# Arguments: 1: source file +# 2: target file +# Usage : $(call host-cp,,) +# Rationale: This function expands to the host-specific shell command used +# to copy a single file +# ----------------------------------------------------------------------------- +ifeq ($(HOST_OS),windows) +host-cp = copy /b/y $(subst /,\,$1 $2) > NUL +else +host-cp = cp -f $1 $2 +endif + +# ----------------------------------------------------------------------------- +# Function : host-install +# Arguments: 1: source file +# 2: target file +# Usage : $(call host-install,,) +# Rationale: This function expands to the host-specific shell command used +# to install a file or directory, while preserving its timestamps +# (if possible). +# ----------------------------------------------------------------------------- +ifeq ($(HOST_OS),windows) +host-install = copy /b/y $(subst /,\,$1 $2) > NUL +else +host-install = install -p $1 $2 +endif + + +# ----------------------------------------------------------------------------- +# Function : host-c-includes +# Arguments: 1: list of file paths (e.g. "foo bar") +# Returns : list of include compiler options (e.g. "-Ifoo -Ibar") +# Usage : $(call host-c-includes,) +# Rationale: This function is used to translate Cygwin paths into +# Cygwin-specific ones. On other platforms, it will just +# return its argument. +# ----------------------------------------------------------------------------- +ifeq ($(HOST_OS),cygwin) +host-c-includes = $(patsubst %,-I%,$(call host-path,$1)) +else +host-c-includes = $(1:%=-I%) +endif + + +# ----------------------------------------------------------------------------- +# Function : link-whole-archives +# Arguments: 1: list of whole static libraries +# Returns : linker flags to use the whole static libraries +# Usage : $(call link-whole-archives,) +# Rationale: This function is used to put the list of whole static libraries +# inside a -Wl,--whole-archive ... -Wl,--no-whole-archive block. +# If the list is empty, it returns an empty string. +# This function also calls host-path to translate the library +# paths. +# ----------------------------------------------------------------------------- +link-whole-archives = $(if $(strip $1),$(call link-whole-archive-flags,$1)) +link-whole-archive-flags = -Wl,--whole-archive $(call host-path,$1) -Wl,--no-whole-archive + +# ============================================================================= +# +# Modules database +# +# The following declarations are used to manage the list of modules +# defined in application's Android.mk files. +# +# Technical note: +# We use __ndk_modules to hold the list of all modules corresponding +# to a given application. +# +# For each module 'foo', __ndk_modules.foo. is used +# to store module-specific information. +# +# type -> type of module (e.g. 'static', 'shared', ...) +# depends -> list of other modules this module depends on +# +# Also, LOCAL_XXXX values defined for a module are recorded in XXXX, e.g.: +# +# PATH -> recorded LOCAL_PATH for the module +# CFLAGS -> recorded LOCAL_CFLAGS for the module +# ... +# +# Some of these are created by build scripts like BUILD_STATIC_LIBRARY: +# +# MAKEFILE -> The Android.mk where the module is defined. +# LDFLAGS -> Final linker flags +# OBJECTS -> List of module objects +# BUILT_MODULE -> location of module built file (e.g. obj///libfoo.so) +# +# Note that some modules are never installed (e.g. static libraries). +# +# ============================================================================= + +# The list of LOCAL_XXXX variables that are recorded for each module definition +# These are documented by docs/ANDROID-MK.TXT. Exception is LOCAL_MODULE +# +modules-LOCALS := \ + MODULE \ + MODULE_FILENAME \ + PATH \ + SRC_FILES \ + CPP_EXTENSION \ + C_INCLUDES \ + CFLAGS \ + CXXFLAGS \ + CPPFLAGS \ + STATIC_LIBRARIES \ + WHOLE_STATIC_LIBRARIES \ + SHARED_LIBRARIES \ + LDLIBS \ + ALLOW_UNDEFINED_SYMBOLS \ + ARM_MODE \ + ARM_NEON \ + DISABLE_NO_EXECUTE \ + EXPORT_CFLAGS \ + EXPORT_CPPFLAGS \ + EXPORT_LDLIBS \ + EXPORT_C_INCLUDES \ + FILTER_ASM \ + CPP_FEATURES \ + +# The following are generated by the build scripts themselves + +# LOCAL_MAKEFILE will contain the path to the Android.mk defining the module +modules-LOCALS += MAKEFILE + +# LOCAL_LDFLAGS will contain the set of final linker flags for the module +modules-LOCALS += LDFLAGS + +# LOCAL_OBJECTS will contain the list of object files generated from the +# module's sources, if any. +modules-LOCALS += OBJECTS + +# LOCAL_BUILT_MODULE will contain the location of the symbolic version of +# the generated module (i.e. the one containing all symbols used during +# native debugging). It is generally under $PROJECT/obj/local/ +modules-LOCALS += BUILT_MODULE + +# LOCAL_OBJS_DIR will contain the location where the object files for +# this module will be stored. Usually $PROJECT/obj/local//obj +modules-LOCALS += OBJS_DIR + +# LOCAL_INSTALLED will contain the location of the installed version +# of the module. Usually $PROJECT/libs// +# where and depend on the module class. +modules-LOCALS += INSTALLED + +# LOCAL_MODULE_CLASS will contain the type of the module +# (e.g. STATIC_LIBRARY, SHARED_LIBRARY, etc...) +modules-LOCALS += MODULE_CLASS + +# the list of managed fields per module +modules-fields = depends \ + $(modules-LOCALS) + +# ----------------------------------------------------------------------------- +# Function : modules-clear +# Arguments: None +# Returns : None +# Usage : $(call modules-clear) +# Rationale: clears the list of defined modules known by the build system +# ----------------------------------------------------------------------------- +modules-clear = \ + $(foreach __mod,$(__ndk_modules),\ + $(foreach __field,$(modules-fields),\ + $(eval __ndk_modules.$(__mod).$(__field) := $(empty))\ + )\ + )\ + $(eval __ndk_modules := $(empty_set)) \ + $(eval __ndk_top_modules := $(empty)) \ + $(eval __ndk_import_list := $(empty)) \ + $(eval __ndk_import_depth := $(empty)) + +# ----------------------------------------------------------------------------- +# Function : modules-get-list +# Arguments: None +# Returns : The list of all recorded modules +# Usage : $(call modules-get-list) +# ----------------------------------------------------------------------------- +modules-get-list = $(__ndk_modules) + +# ----------------------------------------------------------------------------- +# Function : modules-get-top-list +# Arguments: None +# Returns : The list of all recorded non-imported modules +# Usage : $(call modules-get-top-list) +# ----------------------------------------------------------------------------- +modules-get-top-list = $(__ndk_top_modules) + +# ----------------------------------------------------------------------------- +# Function : module-add +# Arguments: 1: module name +# Returns : None +# Usage : $(call module-add,) +# Rationale: add a new module. If it is already defined, print an error message +# and abort. This will record all LOCAL_XXX variables for the module. +# ----------------------------------------------------------------------------- +module-add = \ + $(call assert-defined,LOCAL_MAKEFILE LOCAL_BUILT_MODULE LOCAL_OBJS_DIR LOCAL_MODULE_CLASS)\ + $(if $(call set_is_member,$(__ndk_modules),$1),\ + $(call __ndk_info,Trying to define local module '$1' in $(LOCAL_MAKEFILE).)\ + $(call __ndk_info,But this module was already defined by $(__ndk_modules.$1.MAKEFILE).)\ + $(call __ndk_error,Aborting.)\ + )\ + $(eval __ndk_modules := $(call set_insert,$(__ndk_modules),$1))\ + $(if $(strip $(__ndk_import_depth)),,\ + $(eval __ndk_top_modules := $(call set_insert,$(__ndk_top_modules),$1))\ + )\ + $(if $(call module-class-is-installable,$(LOCAL_MODULE_CLASS)),\ + $(eval LOCAL_INSTALLED := $(NDK_APP_DST_DIR)/$(notdir $(LOCAL_BUILT_MODULE)))\ + )\ + $(foreach __local,$(modules-LOCALS),\ + $(eval __ndk_modules.$1.$(__local) := $(LOCAL_$(__local)))\ + )\ + $(call module-handle-c++-features,$1) + + +# Retrieve the class of module $1 +module-get-class = $(__ndk_modules.$1.MODULE_CLASS) + +# Retrieve built location of module $1 +module-get-built = $(__ndk_modules.$1.BUILT_MODULE) + +# Returns $(true) is module $1 is installable +# An installable module is one that will be copied to $PROJECT/libs// +# (e.g. shared libraries). +# +module-is-installable = $(call module-class-is-installable,$(call module-get-class,$1)) + +# Returns $(true) if module $1 is prebuilt +# A prebuilt module is one declared with BUILD_PREBUILT_SHARED_LIBRARY or +# BUILD_PREBUILT_STATIC_LIBRARY +# +module-is-prebuilt = $(call module-class-is-prebuilt,$(call module-get-class,$1)) + +# ----------------------------------------------------------------------------- +# Function : module-get-export +# Arguments: 1: module name +# 2: export variable name without LOCAL_EXPORT_ prefix (e.g. 'CFLAGS') +# Returns : Exported value +# Usage : $(call module-get-export,,) +# Rationale: Return the recorded value of LOCAL_EXPORT_$2, if any, for module $1 +# ----------------------------------------------------------------------------- +module-get-export = $(__ndk_modules.$1.EXPORT_$2) + +# ----------------------------------------------------------------------------- +# Function : module-get-listed-export +# Arguments: 1: list of module names +# 2: export variable name without LOCAL_EXPORT_ prefix (e.g. 'CFLAGS') +# Returns : Exported values +# Usage : $(call module-get-listed-export,,) +# Rationale: Return the recorded value of LOCAL_EXPORT_$2, if any, for modules +# listed in $1. +# ----------------------------------------------------------------------------- +module-get-listed-export = $(strip \ + $(foreach __listed_module,$1,\ + $(call module-get-export,$(__listed_module),$2)\ + )) + +# ----------------------------------------------------------------------------- +# Function : modules-restore-locals +# Arguments: 1: module name +# Returns : None +# Usage : $(call module-restore-locals,) +# Rationale: Restore the recorded LOCAL_XXX definitions for a given module. +# ----------------------------------------------------------------------------- +module-restore-locals = \ + $(foreach __local,$(modules-LOCALS),\ + $(eval LOCAL_$(__local) := $(__ndk_modules.$1.$(__local)))\ + ) + +# Dump all module information. Only use this for debugging +modules-dump-database = \ + $(info Modules: $(__ndk_modules)) \ + $(foreach __mod,$(__ndk_modules),\ + $(info $(space4)$(__mod):)\ + $(foreach __field,$(modules-fields),\ + $(eval __fieldval := $(strip $(__ndk_modules.$(__mod).$(__field))))\ + $(if $(__fieldval),\ + $(if $(filter 1,$(words $(__fieldval))),\ + $(info $(space4)$(space4)$(__field): $(__fieldval)),\ + $(info $(space4)$(space4)$(__field): )\ + $(foreach __fielditem,$(__fieldval),\ + $(info $(space4)$(space4)$(space4)$(__fielditem))\ + )\ + )\ + )\ + )\ + )\ + $(info --- end of modules list) + + +# ----------------------------------------------------------------------------- +# Function : module-add-static-depends +# Arguments: 1: module name +# 2: list/set of static library modules this module depends on. +# Returns : None +# Usage : $(call module-add-static-depends,,) +# Rationale: Record that a module depends on a set of static libraries. +# Use module-get-static-dependencies to retrieve final list. +# ----------------------------------------------------------------------------- +module-add-static-depends = \ + $(call module-add-depends-any,$1,$2,depends) \ + +# ----------------------------------------------------------------------------- +# Function : module-add-shared-depends +# Arguments: 1: module name +# 2: list/set of shared library modules this module depends on. +# Returns : None +# Usage : $(call module-add-shared-depends,,) +# Rationale: Record that a module depends on a set of shared libraries. +# Use modulge-get-shared-dependencies to retrieve final list. +# ----------------------------------------------------------------------------- +module-add-shared-depends = \ + $(call module-add-depends-any,$1,$2,depends) \ + +# Used internally by module-add-static-depends and module-add-shared-depends +# NOTE: this function must not modify the existing dependency order when new depends are added. +# +module-add-depends-any = \ + $(eval __ndk_modules.$1.$3 += $(filter-out $(__ndk_modules.$1.$3),$(call strip-lib-prefix,$2))) + +# Used to recompute all dependencies once all module information has been recorded. +# +modules-compute-dependencies = \ + $(foreach __module,$(__ndk_modules),\ + $(call module-compute-depends,$(__module))\ + ) + +module-compute-depends = \ + $(call module-add-static-depends,$1,$(__ndk_modules.$1.STATIC_LIBRARIES))\ + $(call module-add-static-depends,$1,$(__ndk_modules.$1.WHOLE_STATIC_LIBRARIES))\ + $(call module-add-shared-depends,$1,$(__ndk_modules.$1.SHARED_LIBRARIES))\ + +module-get-installed = $(__ndk_modules.$1.INSTALLED) + +# ----------------------------------------------------------------------------- +# Function : modules-get-all-dependencies +# Arguments: 1: list of module names +# Returns : List of all the modules $1 depends on transitively. +# Usage : $(call modules-all-get-dependencies,) +# Rationale: This computes the closure of all module dependencies starting from $1 +# ----------------------------------------------------------------------------- +module-get-all-dependencies = $(strip \ + $(call modules-get-closure,$1,depends)) + +modules-get-closure = \ + $(eval __closure_deps := $(strip $(call strip-lib-prefix,$1))) \ + $(eval __closure_wq := $(__closure_deps)) \ + $(eval __closure_field := $(strip $2)) \ + $(call modules-closure)\ + $(__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 not have any conditional looping construct +# like 'while'. +# +modules-closure = \ + $(eval __closure_mod := $(call first,$(__closure_wq))) \ + $(eval __closure_wq := $(call rest,$(__closure_wq))) \ + $(eval __closure_val := $(call strip-lib-prefix,$(__ndk_modules.$(__closure_mod).$(__closure_field)))) \ + $(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)) \ + +# ----------------------------------------------------------------------------- +# Function : module-get-depends +# Arguments: 1: list of module names +# 2: local module type (e.g. SHARED_LIBRARIES) +# Returns : List all the modules $1 depends on transitively. +# Usage : $(call module-get-depends,,) +# Rationale: This computes the closure of all local module dependencies starting from $1 +# ----------------------------------------------------------------------------- +module-get-depends = $(strip $(call modules-get-closure,$1,$2)) + + +# ----------------------------------------------------------------------------- +# Function : modules-get-all-installable +# Arguments: 1: list of module names +# Returns : List of all the installable modules $1 depends on transitively. +# Usage : $(call modules-all-get-installable,) +# Rationale: This computes the closure of all installable module dependencies starting from $1 +# ----------------------------------------------------------------------------- +# For now, only the closure of LOCAL_SHARED_LIBRARIES is enough +modules-get-all-installable = $(strip \ + $(foreach __alldep,$(call module-get-depends,$1,depends),\ + $(if $(call module-is-installable,$(__alldep)),$(__alldep))\ + )) + +# Return the C++ extension of a given module +# $1: module name +module-get-cpp-extension = $(strip \ + $(if $(__ndk_modules.$1.CPP_EXTENSION),\ + $(__ndk_modules.$1.CPP_EXTENSION),\ + .cpp\ + )) + +# Return the list of C++ sources of a given module +# +module-get-c++-sources = \ + $(filter %$(call module-get-cpp-extension,$1),$(__ndk_modules.$1.SRC_FILES)) + +# Returns true if a module has C++ sources +# +module-has-c++-sources = $(strip $(call module-get-c++-sources,$1)) + + +# Add C++ dependencies to any module that has C++ sources. +# $1: list of C++ runtime static libraries (if any) +# $2: list of C++ runtime shared libraries (if any) +# +modules-add-c++-dependencies = \ + $(foreach __module,$(__ndk_modules),\ + $(if $(call module-has-c++-sources,$(__module)),\ + $(call ndk_log,Module '$(__module)' has C++ sources)\ + $(call module-add-c++-deps,$(__module),$1,$2),\ + )\ + ) + + +# Return the compiler flags used to compile a C++ module +# Order matters and should match the one used by the build command +module-get-c++-flags = $(strip \ + $(__ndk_modules.$1.CFLAGS) \ + $(__ndk_modules.$1.CPPFLAGS) \ + $(__ndk_modules.$1.CXXFLAGS)) + +# This function is used to remove certain flags from a module compiler flags +# $1: Module name +# $2: List of flags to remove +# +module-filter-out-compiler-flags = \ + $(eval __ndk_modules.$1.CFLAGS := $(filter-out $2,$(__ndk_modules.$1.CFLAGS)))\ + $(eval __ndk_modules.$1.CPPFLAGS := $(filter-out $2,$(__ndk_modules.$1.CPPFLAGS)))\ + $(eval __ndk_modules.$1.CXXFLAGS := $(filter-out $2,$(__ndk_modules.$1.CXXFLAGS))) + +# Return true if a module's compiler flags enable rtti +# We just look at -frtti and -fno-rtti on the command-line +# and keep the last one of these flags. +module-flags-have-rtti = $(strip \ + $(filter -frtti,\ + $(lastword $(filter -frtti -fno-rtti,$(call module-get-c++-flags,$1)))\ + )\ + ) + +# Same with C++ exception support (i.e. -fexceptions and -fno-exceptions) +# +module-flags-have-exceptions = $(strip \ + $(filter -fexceptions,\ + $(lastword $(filter -fexceptions -fno-execeptions,$(call module-get-c++-flags,$1)))\ + )\ + ) + +# Handle the definition of LOCAL_CPP_FEATURES, i.e.: +# +# - If it is defined, check that it only contains valid values +# - If it is undefined, try to compute its value automatically by +# looking at the C++ compiler flags used to build the module +# +# After this, we remove all features flags from the module's command-line +# And add only the correct ones back in LOCAL_CPP_FLAGS +# +module-handle-c++-features = \ + $(if $(strip $(__ndk_modules.$1.CPP_FEATURES)),\ + $(eval __cxxbad := $(filter-out rtti exceptions,$(__ndk_modules.$1.CPP_FEATURES)))\ + $(if $(__cxxbad),\ + $(call __ndk_info,WARNING: Ignoring invalid values in LOCAL_CPP_FEATURES definition in $(__ndk_modules.$1.MAKEFILE): $(__cxxbad))\ + $(eval __ndk_modules.$1.CPP_FEATURES := $(strip $(filter-out $(__cxxbad),$(__ndk_modules.$1.CPP_FEATURES))))\ + )\ + ,\ + $(eval __ndk_modules.$1.CPP_FEATURES := $(strip \ + $(if $(call module-flags-have-rtti,$1),rtti) \ + $(if $(call module-flags-have-exceptions,$1),exceptions) \ + )) \ + )\ + $(call module-filter-out-compiler-flags,$1,-frtti -fno-rtti -fexceptions -fno-exceptions)\ + +# Returns true if a module or its dependencies have specific C++ features +# (i.e. RTTI or Exceptions) +# +# $1: module name +# $2: list of features (e.g. 'rtti' or 'exceptions') +# +module-has-c++-features = $(strip \ + $(eval __cxxdeps := $(call module-get-all-dependencies,$1))\ + $(eval __cxxflags := $(foreach __cxxdep,$(__cxxdeps),$(__ndk_modules.$(__cxxdep).CPP_FEATURES)))\ + $(if $(filter $2,$(__cxxflags)),true,)\ + ) + +# Add standard C++ dependencies to a given module +# +# $1: module name +# $2: list of C++ runtime static libraries (if any) +# $3: list of C++ runtime shared libraries (if any) +# +module-add-c++-deps = \ + $(eval __ndk_modules.$1.STATIC_LIBRARIES += $(2))\ + $(eval __ndk_modules.$1.SHARED_LIBRARIES += $(3)) + + +# ============================================================================= +# +# Utility functions +# +# ============================================================================= + +# ----------------------------------------------------------------------------- +# Function : parent-dir +# Arguments: 1: path +# Returns : Parent dir or path of $1, with final separator removed. +# ----------------------------------------------------------------------------- +parent-dir = $(patsubst %/,%,$(dir $1)) + + +# ----------------------------------------------------------------------------- +# Function : pretty-dir +# Arguments: 1: path +# Returns : Remove NDK_PROJECT_PATH prefix from a given path. This can be +# used to perform pretty-printing for logs. +# ----------------------------------------------------------------------------- +pretty-dir = $(patsubst $(NDK_ROOT)/%,/%,\ + $(patsubst $(NDK_PROJECT_PATH)/%,%,$1)) + +# ----------------------------------------------------------------------------- +# Function : check-user-define +# Arguments: 1: name of variable that must be defined by the user +# 2: name of Makefile where the variable should be defined +# 3: name/description of the Makefile where the check is done, which +# must be included by $2 +# Returns : None +# ----------------------------------------------------------------------------- +check-user-define = $(if $(strip $($1)),,\ + $(call __ndk_error,Missing $1 before including $3 in $2)) + +# ----------------------------------------------------------------------------- +# This is used to check that LOCAL_MODULE is properly defined by an Android.mk +# file before including one of the $(BUILD_SHARED_LIBRARY), etc... files. +# +# Function : check-user-LOCAL_MODULE +# Arguments: 1: name/description of the included build Makefile where the +# check is done +# Returns : None +# Usage : $(call check-user-LOCAL_MODULE, BUILD_SHARED_LIBRARY) +# ----------------------------------------------------------------------------- +check-defined-LOCAL_MODULE = \ + $(call check-user-define,LOCAL_MODULE,$(local-makefile),$(1)) \ + $(if $(call seq,$(words $(LOCAL_MODULE)),1),,\ + $(call __ndk_info,LOCAL_MODULE definition in $(local-makefile) must not contain space)\ + $(call __ndk_error,Please correct error. Aborting)\ + ) + +# ----------------------------------------------------------------------------- +# This is used to check that LOCAL_MODULE_FILENAME, if defined, is correct. +# +# Function : check-user-LOCAL_MODULE_FILENAME +# Returns : None +# Usage : $(call check-user-LOCAL_MODULE_FILENAME) +# ----------------------------------------------------------------------------- +check-LOCAL_MODULE_FILENAME = \ + $(if $(strip $(LOCAL_MODULE_FILENAME)),\ + $(if $(call seq,$(words $(LOCAL_MODULE_FILENAME)),1),,\ + $(call __ndk_info,$(LOCAL_MAKEFILE):$(LOCAL_MODULE): LOCAL_MODULE_FILENAME must not contain spaces)\ + $(call __ndk_error,Plase correct error. Aborting)\ + )\ + $(if $(filter %.a %.so,$(LOCAL_MODULE_FILENAME)),\ + $(call __ndk_info,$(LOCAL_MAKEFILE):$(LOCAL_MODULE): LOCAL_MODULE_FILENAME should not include file extensions)\ + )\ + ) + +# ----------------------------------------------------------------------------- +# Function : handle-module-filename +# Arguments : 1: default file prefix +# 2: file suffix +# Returns : None +# Usage : $(call handle-module-filename,,) +# Rationale : To be used to check and or set the module's filename through +# the LOCAL_MODULE_FILENAME variable. +# ----------------------------------------------------------------------------- +handle-module-filename = $(eval $(call ev-handle-module-filename,$1,$2)) + +# +# Check that LOCAL_MODULE_FILENAME is properly defined +# - with one single item +# - without a library file extension +# - with no directory separators +# +define ev-check-module-filename +ifneq (1,$$(words $$(LOCAL_MODULE_FILENAME))) + $$(call __ndk_info,$$(LOCAL_MAKEFILE):$$(LOCAL_MODULE): LOCAL_MODULE_FILENAME must not contain any space) + $$(call __ndk_error,Aborting) +endif +ifneq (,$$(filter %.a %.so,$$(LOCAL_MODULE_FILENAME))) + $$(call __ndk_info,$$(LOCAL_MAKEFILE):$$(LOCAL_MODULE): LOCAL_MODULE_FILENAME must not contain a file extension) + $$(call __ndk_error,Aborting) +endif +ifneq (1,$$(words $$(subst /, ,$$(LOCAL_MODULE_FILENAME)))) + $$(call __ndk_info,$$(LOCAL_MAKEFILE):$$(LOCAL_MODULE): LOCAL_MODULE_FILENAME must not contain directory separators) + $$(call __ndk_error,Aborting) +endif +endef + +# +# Check the definition of LOCAL_MODULE_FILENAME. If none exists, +# infer it from the LOCAL_MODULE name. +# +# $1: default file prefix +# $2: default file suffix +# +define ev-handle-module-filename +LOCAL_MODULE_FILENAME := $$(strip $$(LOCAL_MODULE_FILENAME)) +ifndef LOCAL_MODULE_FILENAME + LOCAL_MODULE_FILENAME := $1$$(LOCAL_MODULE) +endif +$$(eval $$(call ev-check-module-filename)) +LOCAL_MODULE_FILENAME := $$(LOCAL_MODULE_FILENAME)$2 +endef + +handle-prebuilt-module-filename = $(eval $(call ev-handle-prebuilt-module-filename,$1)) + +# +# Check the definition of LOCAL_MODULE_FILENAME for a _prebuilt_ module. +# If none exists, infer it from $(LOCAL_SRC_FILES) +# +# $1: default file suffix +# +define ev-handle-prebuilt-module-filename +LOCAL_MODULE_FILENAME := $$(strip $$(LOCAL_MODULE_FILENAME)) +ifndef LOCAL_MODULE_FILENAME + LOCAL_MODULE_FILENAME := $$(notdir $(LOCAL_SRC_FILES)) + LOCAL_MODULE_FILENAME := $$(LOCAL_MODULE_FILENAME:%.a=%) + LOCAL_MODULE_FILENAME := $$(LOCAL_MODULE_FILENAME:%.so=%) +endif +LOCAL_MODULE_FILENAME := $$(LOCAL_MODULE_FILENAME)$1 +$$(eval $$(call ev-check-module-filename)) +endef + + +# ----------------------------------------------------------------------------- +# Function : handle-module-built +# Returns : None +# Usage : $(call handle-module-built) +# Rationale : To be used to automatically compute the location of the generated +# binary file, and the directory where to place its object files. +# ----------------------------------------------------------------------------- +handle-module-built = \ + $(eval LOCAL_BUILT_MODULE := $(TARGET_OUT)/$(LOCAL_MODULE_FILENAME))\ + $(eval LOCAL_OBJS_DIR := $(TARGET_OBJS)/$(LOCAL_MODULE)) + +# ----------------------------------------------------------------------------- +# Strip any 'lib' prefix in front of a given string. +# +# Function : strip-lib-prefix +# Arguments: 1: module name +# Returns : module name, without any 'lib' prefix if any +# Usage : $(call strip-lib-prefix,$(LOCAL_MODULE)) +# ----------------------------------------------------------------------------- +strip-lib-prefix = $(1:lib%=%) + +# ----------------------------------------------------------------------------- +# This is used to strip any lib prefix from LOCAL_MODULE, then check that +# the corresponding module name is not already defined. +# +# Function : check-user-LOCAL_MODULE +# Arguments: 1: path of Android.mk where this LOCAL_MODULE is defined +# Returns : None +# Usage : $(call check-LOCAL_MODULE,$(LOCAL_MAKEFILE)) +# ----------------------------------------------------------------------------- +check-LOCAL_MODULE = \ + $(eval LOCAL_MODULE := $$(call strip-lib-prefix,$$(LOCAL_MODULE))) + +# ----------------------------------------------------------------------------- +# Macro : my-dir +# Returns : the directory of the current Makefile +# Usage : $(my-dir) +# ----------------------------------------------------------------------------- +my-dir = $(call parent-dir,$(lastword $(MAKEFILE_LIST))) + +# ----------------------------------------------------------------------------- +# Function : all-makefiles-under +# Arguments: 1: directory path +# Returns : a list of all makefiles immediately below some directory +# Usage : $(call all-makefiles-under, ) +# ----------------------------------------------------------------------------- +all-makefiles-under = $(wildcard $1/*/Android.mk) + +# ----------------------------------------------------------------------------- +# Macro : all-subdir-makefiles +# Returns : list of all makefiles in subdirectories of the current Makefile's +# location +# Usage : $(all-subdir-makefiles) +# ----------------------------------------------------------------------------- +all-subdir-makefiles = $(call all-makefiles-under,$(call my-dir)) + +# ============================================================================= +# +# Source file tagging support. +# +# Each source file listed in LOCAL_SRC_FILES can have any number of +# 'tags' associated to it. A tag name must not contain space, and its +# usage can vary. +# +# For example, the 'debug' tag is used to sources that must be built +# in debug mode, the 'arm' tag is used for sources that must be built +# using the 32-bit instruction set on ARM platforms, and 'neon' is used +# for sources that must be built with ARM Advanced SIMD (a.k.a. NEON) +# support. +# +# More tags might be introduced in the future. +# +# LOCAL_SRC_TAGS contains the list of all tags used (initially empty) +# LOCAL_SRC_FILES contains the list of all source files. +# LOCAL_SRC_TAG. contains the set of source file names tagged +# with +# LOCAL_SRC_FILES_TAGS. contains the set of tags for a given +# source file name +# +# Tags are processed by a toolchain-specific function (e.g. TARGET-compute-cflags) +# which will call various functions to compute source-file specific settings. +# These are currently stored as: +# +# LOCAL_SRC_FILES_TARGET_CFLAGS. contains the list of +# target-specific C compiler flags used to compile a given +# source file. This is set by the function TARGET-set-cflags +# defined in the toolchain's setup.mk script. +# +# LOCAL_SRC_FILES_TEXT. contains the 'text' that will be +# displayed along the label of the build output line. For example +# 'thumb' or 'arm ' with ARM-based toolchains. +# +# ============================================================================= + +# ----------------------------------------------------------------------------- +# Macro : clear-all-src-tags +# Returns : remove all source file tags and associated data. +# Usage : $(clear-all-src-tags) +# ----------------------------------------------------------------------------- +clear-all-src-tags = \ +$(foreach __tag,$(LOCAL_SRC_TAGS), \ + $(eval LOCAL_SRC_TAG.$(__tag) := $(empty)) \ +) \ +$(foreach __src,$(LOCAL_SRC_FILES), \ + $(eval LOCAL_SRC_FILES_TAGS.$(__src) := $(empty)) \ + $(eval LOCAL_SRC_FILES_TARGET_CFLAGS.$(__src) := $(empty)) \ + $(eval LOCAL_SRC_FILES_TEXT.$(__src) := $(empty)) \ +) \ +$(eval LOCAL_SRC_TAGS := $(empty_set)) + +# ----------------------------------------------------------------------------- +# Macro : tag-src-files +# Arguments: 1: list of source files to tag +# 2: tag name (must not contain space) +# Usage : $(call tag-src-files,,) +# Rationale: Add a tag to a list of source files +# ----------------------------------------------------------------------------- +tag-src-files = \ +$(eval LOCAL_SRC_TAGS := $(call set_insert,$2,$(LOCAL_SRC_TAGS))) \ +$(eval LOCAL_SRC_TAG.$2 := $(call set_union,$1,$(LOCAL_SRC_TAG.$2))) \ +$(foreach __src,$1, \ + $(eval LOCAL_SRC_FILES_TAGS.$(__src) += $2) \ +) + +# ----------------------------------------------------------------------------- +# Macro : get-src-files-with-tag +# Arguments: 1: tag name +# Usage : $(call get-src-files-with-tag,) +# Return : The list of source file names that have been tagged with +# ----------------------------------------------------------------------------- +get-src-files-with-tag = $(LOCAL_SRC_TAG.$1) + +# ----------------------------------------------------------------------------- +# Macro : get-src-files-without-tag +# Arguments: 1: tag name +# Usage : $(call get-src-files-without-tag,) +# Return : The list of source file names that have NOT been tagged with +# ----------------------------------------------------------------------------- +get-src-files-without-tag = $(filter-out $(LOCAL_SRC_TAG.$1),$(LOCAL_SRC_FILES)) + +# ----------------------------------------------------------------------------- +# Macro : set-src-files-target-cflags +# Arguments: 1: list of source files +# 2: list of compiler flags +# Usage : $(call set-src-files-target-cflags,,) +# Rationale: Set or replace the set of compiler flags that will be applied +# when building a given set of source files. This function should +# normally be called from the toolchain-specific function that +# computes all compiler flags for all source files. +# ----------------------------------------------------------------------------- +set-src-files-target-cflags = $(foreach __src,$1,$(eval LOCAL_SRC_FILES_TARGET_CFLAGS.$(__src) := $2)) + +# ----------------------------------------------------------------------------- +# Macro : add-src-files-target-cflags +# Arguments: 1: list of source files +# 2: list of compiler flags +# Usage : $(call add-src-files-target-cflags,,) +# Rationale: A variant of set-src-files-target-cflags that can be used +# to append, instead of replace, compiler flags for specific +# source files. +# ----------------------------------------------------------------------------- +add-src-files-target-cflags = $(foreach __src,$1,$(eval LOCAL_SRC_FILES_TARGET_CFLAGS.$(__src) += $2)) + +# ----------------------------------------------------------------------------- +# Macro : get-src-file-target-cflags +# Arguments: 1: single source file name +# Usage : $(call get-src-file-target-cflags,) +# Rationale: Return the set of target-specific compiler flags that must be +# applied to a given source file. These must be set prior to this +# call using set-src-files-target-cflags or add-src-files-target-cflags +# ----------------------------------------------------------------------------- +get-src-file-target-cflags = $(LOCAL_SRC_FILES_TARGET_CFLAGS.$1) + +# ----------------------------------------------------------------------------- +# Macro : set-src-files-text +# Arguments: 1: list of source files +# 2: text +# Usage : $(call set-src-files-text,,) +# Rationale: Set or replace the 'text' associated to a set of source files. +# The text is a very short string that complements the build +# label. For example, it will be either 'thumb' or 'arm ' for +# ARM-based toolchains. This function must be called by the +# toolchain-specific functions that processes all source files. +# ----------------------------------------------------------------------------- +set-src-files-text = $(foreach __src,$1,$(eval LOCAL_SRC_FILES_TEXT.$(__src) := $2)) + +# ----------------------------------------------------------------------------- +# Macro : get-src-file-text +# Arguments: 1: single source file +# Usage : $(call get-src-file-text,) +# Rationale: Return the 'text' associated to a given source file when +# set-src-files-text was called. +# ----------------------------------------------------------------------------- +get-src-file-text = $(LOCAL_SRC_FILES_TEXT.$1) + +# This should only be called for debugging the source files tagging system +dump-src-file-tags = \ +$(info LOCAL_SRC_TAGS := $(LOCAL_SRC_TAGS)) \ +$(info LOCAL_SRC_FILES = $(LOCAL_SRC_FILES)) \ +$(foreach __tag,$(LOCAL_SRC_TAGS),$(info LOCAL_SRC_TAG.$(__tag) = $(LOCAL_SRC_TAG.$(__tag)))) \ +$(foreach __src,$(LOCAL_SRC_FILES),$(info LOCAL_SRC_FILES_TAGS.$(__src) = $(LOCAL_SRC_FILES_TAGS.$(__src)))) \ +$(info WITH arm = $(call get-src-files-with-tag,arm)) \ +$(info WITHOUT arm = $(call get-src-files-without-tag,arm)) \ +$(foreach __src,$(LOCAL_SRC_FILES),$(info LOCAL_SRC_FILES_TARGET_CFLAGS.$(__src) = $(LOCAL_SRC_FILES_TARGET_CFLAGS.$(__src)))) \ +$(foreach __src,$(LOCAL_SRC_FILES),$(info LOCAL_SRC_FILES_TEXT.$(__src) = $(LOCAL_SRC_FILES_TEXT.$(__src)))) \ + + +# ============================================================================= +# +# Application.mk support +# +# ============================================================================= + +# the list of variables that *must* be defined in Application.mk files +NDK_APP_VARS_REQUIRED := + +# the list of variables that *may* be defined in Application.mk files +NDK_APP_VARS_OPTIONAL := APP_OPTIM APP_CPPFLAGS APP_CFLAGS APP_CXXFLAGS \ + APP_PLATFORM APP_BUILD_SCRIPT APP_ABI APP_MODULES \ + APP_PROJECT_PATH APP_STL + +# the list of all variables that may appear in an Application.mk file +# or defined by the build scripts. +NDK_APP_VARS := $(NDK_APP_VARS_REQUIRED) \ + $(NDK_APP_VARS_OPTIONAL) \ + APP_DEBUG \ + APP_DEBUGGABLE \ + APP_MANIFEST + +# ============================================================================= +# +# Android.mk support +# +# ============================================================================= + +# ============================================================================= +# +# Build commands support +# +# ============================================================================= + +get-object-name = $(strip \ + $(subst ../,__/,\ + $(eval __obj := $1)\ + $(foreach __ext,.c .s .S $(LOCAL_CPP_EXTENSION),\ + $(eval __obj := $(__obj:%$(__ext)=%.o))\ + )\ + $(__obj)\ + )) + +# ----------------------------------------------------------------------------- +# Macro : hide +# Returns : nothing +# Usage : $(hide) +# Rationale: To be used as a prefix for Make build commands to hide them +# by default during the build. To show them, set V=1 in your +# environment or command-line. +# +# For example: +# +# foo.o: foo.c +# -->|$(hide) +# +# Where '-->|' stands for a single tab character. +# +# ----------------------------------------------------------------------------- +ifeq ($(V),1) +hide = $(empty) +else +hide = @ +endif + +# cmd-convert-deps +# +# On Cygwin, we need to convert the .d dependency file generated by +# the gcc toolchain by transforming any WIndows paths inside it into +# Cygwin paths that GNU Make can understand (i.e. C:/Foo => /cygdrive/c/Foo) +# +# To do that, we will force the compiler to write the dependency file to +# .d.org, which will will later convert through a clever Awk script. +# +# The result will be written to .d and .d.org erased. +# Note that it is important to use different file names here. +# +# +# On other systems, we simply tell the compiler to write to the .d file directly. +# +# NOTE: In certain cases, no dependency file will be generated by the +# compiler (e.g. when compiling an assembly file as foo.s) +# +# convert-deps is used to compute the name of the compiler-generated dependency file +# cmd-convert-deps is a command used to convert it to a Cygwin-specific path +# +ifeq ($(HOST_OS),cygwin) +convert-deps = $1.org +cmd-convert-deps = \ + && ( if [ -f "$1.org" ]; then \ + $(HOST_AWK) -f $(BUILD_AWK)/convert-deps-to-cygwin.awk $1.org > $1 && \ + $(call host-rm,$1.org); \ + fi ) +else +convert-deps = $1 +cmd-convert-deps = +endif + +# This assumes that many variables have been pre-defined: +# _SRC: source file +# _OBJ: destination file +# _CC: 'compiler' command +# _FLAGS: 'compiler' flags +# _TEXT: Display text (e.g. "Compile++ thumb", must be EXACTLY 15 chars long) +# +define ev-build-file +$$(_OBJ): PRIVATE_SRC := $$(_SRC) +$$(_OBJ): PRIVATE_OBJ := $$(_OBJ) +$$(_OBJ): PRIVATE_DEPS := $$(call host-path,$$(_OBJ).d) +$$(_OBJ): PRIVATE_MODULE := $$(LOCAL_MODULE) +$$(_OBJ): PRIVATE_TEXT := "$$(_TEXT)" +$$(_OBJ): PRIVATE_CC := $$(_CC) +$$(_OBJ): PRIVATE_CFLAGS := $$(_FLAGS) +$$(_OBJ): $$(_SRC) $$(LOCAL_MAKEFILE) $$(NDK_APP_APPLICATION_MK) + @$$(call host-mkdir,$$(dir $$(PRIVATE_OBJ))) + @$$(HOST_ECHO) "$$(PRIVATE_TEXT) : $$(PRIVATE_MODULE) <= $$(notdir $$(PRIVATE_SRC))" + $$(hide) $$(PRIVATE_CC) -MMD -MP -MF $$(call convert-deps,$$(PRIVATE_DEPS)) $$(PRIVATE_CFLAGS) $$(call host-path,$$(PRIVATE_SRC)) -o $$(call host-path,$$(PRIVATE_OBJ)) \ + $$(call cmd-convert-deps,$$(PRIVATE_DEPS)) +endef + +# This assumes the same things than ev-build-file, but will handle +# the definition of LOCAL_FILTER_ASM as well. +define ev-build-source-file +LOCAL_DEPENDENCY_DIRS += $$(dir $$(_OBJ)) +ifndef LOCAL_FILTER_ASM + # Trivial case: Directly generate an object file + $$(eval $$(call ev-build-file)) +else + # This is where things get hairy, we first transform + # the source into an assembler file, send it to the + # filter, then generate a final object file from it. + # + + # First, remember the original settings and compute + # the location of our temporary files. + # + _ORG_SRC := $$(_SRC) + _ORG_OBJ := $$(_OBJ) + _ORG_FLAGS := $$(_FLAGS) + _ORG_TEXT := $$(_TEXT) + + _OBJ_ASM_ORIGINAL := $$(patsubst %.o,%.s,$$(_ORG_OBJ)) + _OBJ_ASM_FILTERED := $$(patsubst %.o,%.filtered.s,$$(_ORG_OBJ)) + + # If the source file is a plain assembler file, we're going to + # use it directly in our filter. + ifneq (,$$(filter %.s,$$(_SRC))) + _OBJ_ASM_ORIGINAL := $$(_SRC) + endif + + #$$(info SRC=$$(_SRC) OBJ=$$(_OBJ) OBJ_ORIGINAL=$$(_OBJ_ASM_ORIGINAL) OBJ_FILTERED=$$(_OBJ_ASM_FILTERED)) + + # We need to transform the source into an assembly file, instead of + # an object. The proper way to do that depends on the file extension. + # + # For C and C++ source files, simply replace the -c by an -S in the + # compilation command (this forces the compiler to generate an + # assembly file). + # + # For assembler templates (which end in .S), replace the -c with -E + # to send it to the preprocessor instead. + # + # Don't do anything for plain assembly files (which end in .s) + # + ifeq (,$$(filter %.s,$$(_SRC))) + _OBJ := $$(_OBJ_ASM_ORIGINAL) + ifneq (,$$(filter %.S,$$(_SRC))) + _FLAGS := $$(patsubst -c,-E,$$(_ORG_FLAGS)) + else + _FLAGS := $$(patsubst -c,-S,$$(_ORG_FLAGS)) + endif + $$(eval $$(call ev-build-file)) + endif + + # Next, process the assembly file with the filter + $$(_OBJ_ASM_FILTERED): PRIVATE_SRC := $$(_OBJ_ASM_ORIGINAL) + $$(_OBJ_ASM_FILTERED): PRIVATE_DST := $$(_OBJ_ASM_FILTERED) + $$(_OBJ_ASM_FILTERED): PRIVATE_FILTER := $$(LOCAL_FILTER_ASM) + $$(_OBJ_ASM_FILTERED): PRIVATE_MODULE := $$(LOCAL_MODULE) + $$(_OBJ_ASM_FILTERED): $$(_OBJ_ASM_ORIGINAL) + @$$(HOST_ECHO) "AsmFilter : $$(PRIVATE_MODULE) <= $$(notdir $$(PRIVATE_SRC))" + $$(hide) $$(PRIVATE_FILTER) $$(PRIVATE_SRC) $$(PRIVATE_DST) + + # Then, generate the final object, we need to keep assembler-specific + # flags which look like -Wa,