diff --git a/make/common/NativeCompilation.gmk b/make/common/NativeCompilation.gmk index 39fce6ea5f6ed64015d1c1261a897904b0b3fe76..1f344ed2ccd9fbc730be64abe29331bce7a507d9 100644 --- a/make/common/NativeCompilation.gmk +++ b/make/common/NativeCompilation.gmk @@ -150,7 +150,7 @@ NATIVE_SOURCE_EXTENSIONS := %.s %.S %.c %.cpp %.cc %.m %.mm define replace_with_obj_extension $(strip \ $(foreach extension, $(NATIVE_SOURCE_EXTENSIONS), \ - $(patsubst $(extension),%$(OBJ_SUFFIX),$(filter $(extension),$1))) \ + $(patsubst $(extension),%$(OBJ_SUFFIX), $(filter $(extension), $1))) \ ) endef @@ -183,150 +183,167 @@ DEPENDENCY_TARGET_SED_PATTERN := \ -e 's/$$$$/ :/' \ # -define add_native_source - # param 1 = BUILD_MYPACKAGE - # parma 2 = the source file name (..../alfa.c or .../beta.cpp) - # param 3 = the bin dir that stores all .o (.obj) and .d files. - # param 4 = the c flags to the compiler - # param 5 = the c compiler - # param 6 = the c++ flags to the compiler - # param 7 = the c++ compiler - # param 8 = the flags to the assembler - # param 9 = set to disable THIS_FILE - - ifeq ($9, ) - $1_$2_THIS_FILE = -DTHIS_FILE='"$$( $$($1_$2_DEP) + $$($1_COMPILER) $$($1_FLAGS) $$($1_DEP_FLAG) $$($1_DEP).tmp \ + $(CC_OUT_OPTION)$$($1_OBJ) $$($1_SRC_FILE)) + $(SED) 's|^$$(@F):|$$@:|' $$($1_DEP).tmp > $$($1_DEP) else $$(call ExecuteWithLog, $$@, \ - $$($1_$2_COMP) $$($1_$2_FLAGS) $$($1_$2_DEP_FLAG) $$($1_$2_DEP) $(CC_OUT_OPTION)$$($1_$2_OBJ) $2) + $$($1_COMPILER) $$($1_FLAGS) $$($1_DEP_FLAG) $$($1_DEP) \ + $(CC_OUT_OPTION)$$($1_OBJ) $$($1_SRC_FILE)) endif # Create a dependency target file from the dependency file. # Solution suggested by http://make.mad-scientist.net/papers/advanced-auto-dependency-generation/ - ifneq ($$($1_$2_DEP), ) - $(SED) $(DEPENDENCY_TARGET_SED_PATTERN) $$($1_$2_DEP) > $$($1_$2_DEP_TARGETS) + ifneq ($$($1_DEP), ) + $(SED) $(DEPENDENCY_TARGET_SED_PATTERN) $$($1_DEP) > $$($1_DEP_TARGETS) endif else - # The Visual Studio compiler lacks a feature for generating make dependencies, but by - # setting -showIncludes, all included files are printed. These are filtered out and - # parsed into make dependences. - # Keep as much as possible on one execution line for best performance on Windows. - # No need to save exit code from compilation since pipefail is always active on - # Windows. + # The Visual Studio compiler lacks a feature for generating make + # dependencies, but by setting -showIncludes, all included files are + # printed. These are filtered out and parsed into make dependences. + # + # Keep as much as possible on one execution line for best performance + # on Windows. No need to save exit code from compilation since + # pipefail is always active on Windows. $$(call ExecuteWithLog, $$@, \ - $$($1_$2_COMP) $$($1_$2_FLAGS) -showIncludes $$($1_$2_DEBUG_OUT_FLAGS) \ - $(CC_OUT_OPTION)$$($1_$2_OBJ) $2) \ + $$($1_COMPILER) $$($1_FLAGS) -showIncludes $$($1_DEBUG_OUT_FLAGS) \ + $(CC_OUT_OPTION)$$($1_OBJ) $$($1_SRC_FILE)) \ | $(TR) -d '\r' | $(GREP) -v -e "^Note: including file:" \ - -e "^$(notdir $2)$$$$" || test "$$$$?" = "1" ; \ - $(ECHO) $$@: \\ > $$($1_$2_DEP) ; \ - $(SED) $(WINDOWS_SHOWINCLUDE_SED_PATTERN) $$($1_$2_OBJ).log \ - | $(SORT) -u >> $$($1_$2_DEP) ; \ - $(SED) $(DEPENDENCY_TARGET_SED_PATTERN) $$($1_$2_DEP) > $$($1_$2_DEP_TARGETS) + -e "^$$($1_FILENAME)$$$$" || test "$$$$?" = "1" ; \ + $(ECHO) $$@: \\ > $$($1_DEP) ; \ + $(SED) $(WINDOWS_SHOWINCLUDE_SED_PATTERN) $$($1_OBJ).log \ + | $(SORT) -u >> $$($1_DEP) ; \ + $(SED) $(DEPENDENCY_TARGET_SED_PATTERN) $$($1_DEP) > $$($1_DEP_TARGETS) endif endif endef @@ -641,11 +658,12 @@ define SetupNativeCompilationBody $1_GENERATED_PCH_SRC := $$($1_OBJECT_DIR)/$1_pch.cpp $1_GENERATED_PCH_OBJ := $$($1_OBJECT_DIR)/$1_pch.obj - $$(eval $$(call add_native_source,$1,$$($1_GENERATED_PCH_SRC), \ - $$($1_OBJECT_DIR),,, \ - $$($1_CXXFLAGS) $$($1_EXTRA_CXXFLAGS) $$($1_SYSROOT_CFLAGS) \ - -Fp$$($1_PCH_FILE) -Yc$$(notdir $$($1_PRECOMPILED_HEADER)), \ - $$($1_CXX),,no_this_file)) + $$(eval $$(call SetupCompileNativeFile, $1_$$(notdir $$($1_GENERATED_PCH_SRC)), \ + FILE := $$($1_GENERATED_PCH_SRC), \ + BASE := $1, \ + EXTRA_CXXFLAGS := -Fp$$($1_PCH_FILE) -Yc$$(notdir $$($1_PRECOMPILED_HEADER)), \ + DISABLE_THIS_FILE_DEFINE := true, \ + )) $1_USE_PCH_FLAGS := \ -Fp$$($1_PCH_FILE) -Yu$$(notdir $$($1_PRECOMPILED_HEADER)) @@ -688,13 +706,13 @@ define SetupNativeCompilationBody endif endif - # Now call add_native_source for each source file we are going to compile. - $$(foreach p, $$($1_SRCS), \ - $$(eval $$(call add_native_source,$1,$$p,$$($1_OBJECT_DIR), \ - $$($1_CFLAGS) $$($1_EXTRA_CFLAGS) $$($1_SYSROOT_CFLAGS), \ - $$($1_CC), \ - $$($1_CXXFLAGS) $$($1_EXTRA_CXXFLAGS) $$($1_SYSROOT_CFLAGS), \ - $$($1_CXX), $$($1_ASFLAGS)))) + # Now call SetupCompileNativeFile for each source file we are going to compile. + $$(foreach file, $$($1_SRCS), \ + $$(eval $$(call SetupCompileNativeFile, $1_$$(notdir $$(file)),\ + FILE := $$(file), \ + BASE := $1, \ + )) \ + ) # Setup rule for printing progress info when compiling source files. # This is a rough heuristic and may not always print accurate information.