1 # 2 # Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. 3 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 # 5 # This code is free software; you can redistribute it and/or modify it 6 # under the terms of the GNU General Public License version 2 only, as 7 # published by the Free Software Foundation. Oracle designates this 8 # particular file as subject to the "Classpath" exception as provided 9 # by Oracle in the LICENSE file that accompanied this code. 10 # 11 # This code is distributed in the hope that it will be useful, but WITHOUT 12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 # version 2 for more details (a copy is included in the LICENSE file that 15 # accompanied this code). 16 # 17 # You should have received a copy of the GNU General Public License version 18 # 2 along with this work; if not, write to the Free Software Foundation, 19 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 # 21 # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 # or visit www.oracle.com if you need additional information or have any 23 # questions. 24 # 25 26 # When you read this source. Remember that $(sort ...) has the side effect 27 # of removing duplicates. It is actually this side effect that is 28 # desired whenever sort is used below! 29 30 ifeq (,$(_MAKEBASE_GMK)) 31 $(error You must include MakeBase.gmk prior to including NativeCompilation.gmk) 32 endif 33 34 ifeq ($(COMPILER_TYPE),CC) 35 COMPILING_MSG=echo $(LOG_INFO) "Compiling $(notdir $1) (for $(notdir $2))" 36 LINKING_MSG=echo $(LOG_INFO) "Linking $1" 37 LINKING_EXE_MSG=echo $(LOG_INFO) "Linking executable $1" 38 ARCHIVING_MSG=echo $(LOG_INFO) "Archiving $1" 39 else 40 COMPILING_MSG= 41 LINKING_MSG= 42 LINKING_EXE_MSG= 43 ARCHIVING_MSG= 44 endif 45 46 define add_native_source 47 # param 1 = BUILD_MYPACKAGE 48 # parma 2 = the source file name (..../alfa.c or .../beta.cpp) 49 # param 3 = the bin dir that stores all .o (.obj) and .d files. 50 # param 4 = the c flags to the compiler 51 # param 5 = the c compiler 52 # param 6 = the c++ flags to the compiler 53 # param 7 = the c++ compiler 54 # param 8 = the flags to the assembler 69 $1_$2_COMP=$(AS) 70 $1_$2_DEP_FLAG:= 71 else 72 # Compile as a C++ file 73 $1_$2_FLAGS=$6 $$($1_$(notdir $2)_CXXFLAGS) -DTHIS_FILE='"$$(<F)"' -c 74 $1_$2_COMP=$7 75 $1_$2_DEP_FLAG:=$(CXX_FLAG_DEPS) 76 endif 77 # Generate the .o (.obj) file name and place it in the bin dir. 78 $1_$2_OBJ:=$3/$$(patsubst %.cpp,%$(OBJ_SUFFIX),$$(patsubst %.c,%$(OBJ_SUFFIX),$$(patsubst %.m,%$(OBJ_SUFFIX),$$(patsubst %.s,%$(OBJ_SUFFIX),$$(notdir $2))))) 79 # Only continue if this object file hasn't been processed already. This lets the first found 80 # source file override any other with the same name. 81 ifeq (,$$(findstring $$($1_$2_OBJ),$$($1_OBJS_SO_FAR))) 82 $1_OBJS_SO_FAR+=$$($1_$2_OBJ) 83 ifeq (,$$(filter %.s,$2)) 84 # And this is the dependency file for this obj file. 85 $1_$2_DEP:=$$(patsubst %$(OBJ_SUFFIX),%.d,$$($1_$2_OBJ)) 86 # Include previously generated dependency information. (if it exists) 87 -include $$($1_$2_DEP) 88 89 ifeq ($(COMPILER_TYPE),CL) 90 $1_$2_DEBUG_OUT_FLAGS:=-Fd$$(patsubst %$(OBJ_SUFFIX),%.pdb,$$($1_$2_OBJ)) \ 91 -Fm$$(patsubst %$(OBJ_SUFFIX),%.map,$$($1_$2_OBJ)) 92 endif 93 endif 94 95 $$($1_$2_OBJ) : $2 96 ifeq ($(COMPILER_TYPE),CC) 97 $$(call COMPILING_MSG,$2,$$($1_TARGET)) 98 # The Sun studio compiler doesn't output the full path to the object file in the 99 # generated deps files. Fixing it with sed. If compiling assembly, don't try this. 100 ifeq ($(COMPILER_NAME)$$(filter %.s,$2),ossc) 101 $$($1_$2_COMP) $$($1_$2_FLAGS) $$($1_$2_DEP_FLAG) $$($1_$2_DEP).tmp $(CC_OUT_OPTION)$$($1_$2_OBJ) $2 102 $(SED) 's|^$$(@F):|$$@:|' $$($1_$2_DEP).tmp > $$($1_$2_DEP) 103 else 104 $$($1_$2_COMP) $$($1_$2_FLAGS) $$($1_$2_DEP_FLAG) $$($1_$2_DEP) $(CC_OUT_OPTION)$$($1_$2_OBJ) $2 105 endif 106 endif 107 # The Visual Studio compiler lacks a feature for generating make dependencies, but by 108 # setting -showIncludes, all included files are printed. These are filtered out and 109 # parsed into make dependences. 110 ifeq ($(COMPILER_TYPE),CL) 111 ($$($1_$2_COMP) $$($1_$2_FLAGS) -showIncludes $$($1_$2_DEBUG_OUT_FLAGS) \ 112 $(CC_OUT_OPTION)$$($1_$2_OBJ) $2 ; echo $$$$? > $$($1_$2_DEP).exitvalue) \ 113 | $(TEE) $$($1_$2_DEP).raw | $(GREP) -v "^Note: including file:" \ 114 && exit `cat $$($1_$2_DEP).exitvalue` 115 $(RM) $$($1_$2_DEP).exitvalue 116 ($(ECHO) $$@: \\ \ 117 && $(SED) -e '/^Note: including file:/!d' \ 118 -e 's|Note: including file: *||' \ 119 -e 's|\\|/|g' \ 120 -e 's|^\([a-zA-Z]\):|/cygdrive/\1|g' \ 121 -e '/$(subst /,\/,$(TOPDIR))/!d' \ 122 -e 's|$$$$| \\|g' \ 123 $$($1_$2_DEP).raw) > $$($1_$2_DEP) 124 endif 125 endif 126 endef 127 128 define SetupNativeCompilation 129 # param 1 is for example BUILD_MYPACKAGE 130 # param 2,3,4,5,6,7,8 are named args. | 1 # 2 # Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved. 3 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 # 5 # This code is free software; you can redistribute it and/or modify it 6 # under the terms of the GNU General Public License version 2 only, as 7 # published by the Free Software Foundation. Oracle designates this 8 # particular file as subject to the "Classpath" exception as provided 9 # by Oracle in the LICENSE file that accompanied this code. 10 # 11 # This code is distributed in the hope that it will be useful, but WITHOUT 12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 # version 2 for more details (a copy is included in the LICENSE file that 15 # accompanied this code). 16 # 17 # You should have received a copy of the GNU General Public License version 18 # 2 along with this work; if not, write to the Free Software Foundation, 19 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 # 21 # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 # or visit www.oracle.com if you need additional information or have any 23 # questions. 24 # 25 26 # When you read this source. Remember that $(sort ...) has the side effect 27 # of removing duplicates. It is actually this side effect that is 28 # desired whenever sort is used below! 29 30 ifeq (,$(_MAKEBASE_GMK)) 31 $(error You must include MakeBase.gmk prior to including NativeCompilation.gmk) 32 endif 33 34 ifneq ($(TOOLCHAIN_TYPE), microsoft) 35 COMPILING_MSG=echo $(LOG_INFO) "Compiling $(notdir $1) (for $(notdir $2))" 36 LINKING_MSG=echo $(LOG_INFO) "Linking $1" 37 LINKING_EXE_MSG=echo $(LOG_INFO) "Linking executable $1" 38 ARCHIVING_MSG=echo $(LOG_INFO) "Archiving $1" 39 else 40 COMPILING_MSG= 41 LINKING_MSG= 42 LINKING_EXE_MSG= 43 ARCHIVING_MSG= 44 endif 45 46 define add_native_source 47 # param 1 = BUILD_MYPACKAGE 48 # parma 2 = the source file name (..../alfa.c or .../beta.cpp) 49 # param 3 = the bin dir that stores all .o (.obj) and .d files. 50 # param 4 = the c flags to the compiler 51 # param 5 = the c compiler 52 # param 6 = the c++ flags to the compiler 53 # param 7 = the c++ compiler 54 # param 8 = the flags to the assembler 69 $1_$2_COMP=$(AS) 70 $1_$2_DEP_FLAG:= 71 else 72 # Compile as a C++ file 73 $1_$2_FLAGS=$6 $$($1_$(notdir $2)_CXXFLAGS) -DTHIS_FILE='"$$(<F)"' -c 74 $1_$2_COMP=$7 75 $1_$2_DEP_FLAG:=$(CXX_FLAG_DEPS) 76 endif 77 # Generate the .o (.obj) file name and place it in the bin dir. 78 $1_$2_OBJ:=$3/$$(patsubst %.cpp,%$(OBJ_SUFFIX),$$(patsubst %.c,%$(OBJ_SUFFIX),$$(patsubst %.m,%$(OBJ_SUFFIX),$$(patsubst %.s,%$(OBJ_SUFFIX),$$(notdir $2))))) 79 # Only continue if this object file hasn't been processed already. This lets the first found 80 # source file override any other with the same name. 81 ifeq (,$$(findstring $$($1_$2_OBJ),$$($1_OBJS_SO_FAR))) 82 $1_OBJS_SO_FAR+=$$($1_$2_OBJ) 83 ifeq (,$$(filter %.s,$2)) 84 # And this is the dependency file for this obj file. 85 $1_$2_DEP:=$$(patsubst %$(OBJ_SUFFIX),%.d,$$($1_$2_OBJ)) 86 # Include previously generated dependency information. (if it exists) 87 -include $$($1_$2_DEP) 88 89 ifeq ($(TOOLCHAIN_TYPE), microsoft) 90 $1_$2_DEBUG_OUT_FLAGS:=-Fd$$(patsubst %$(OBJ_SUFFIX),%.pdb,$$($1_$2_OBJ)) \ 91 -Fm$$(patsubst %$(OBJ_SUFFIX),%.map,$$($1_$2_OBJ)) 92 endif 93 endif 94 95 $$($1_$2_OBJ) : $2 96 ifneq ($(TOOLCHAIN_TYPE), microsoft) 97 $$(call COMPILING_MSG,$2,$$($1_TARGET)) 98 # The Solaris studio compiler doesn't output the full path to the object file in the 99 # generated deps files. Fixing it with sed. If compiling assembly, don't try this. 100 ifeq ($(TOOLCHAIN_TYPE)$$(filter %.s,$2), solstudio) 101 $$($1_$2_COMP) $$($1_$2_FLAGS) $$($1_$2_DEP_FLAG) $$($1_$2_DEP).tmp $(CC_OUT_OPTION)$$($1_$2_OBJ) $2 102 $(SED) 's|^$$(@F):|$$@:|' $$($1_$2_DEP).tmp > $$($1_$2_DEP) 103 else 104 $$($1_$2_COMP) $$($1_$2_FLAGS) $$($1_$2_DEP_FLAG) $$($1_$2_DEP) $(CC_OUT_OPTION)$$($1_$2_OBJ) $2 105 endif 106 endif 107 # The Visual Studio compiler lacks a feature for generating make dependencies, but by 108 # setting -showIncludes, all included files are printed. These are filtered out and 109 # parsed into make dependences. 110 ifeq ($(TOOLCHAIN_TYPE), microsoft) 111 ($$($1_$2_COMP) $$($1_$2_FLAGS) -showIncludes $$($1_$2_DEBUG_OUT_FLAGS) \ 112 $(CC_OUT_OPTION)$$($1_$2_OBJ) $2 ; echo $$$$? > $$($1_$2_DEP).exitvalue) \ 113 | $(TEE) $$($1_$2_DEP).raw | $(GREP) -v "^Note: including file:" \ 114 && exit `cat $$($1_$2_DEP).exitvalue` 115 $(RM) $$($1_$2_DEP).exitvalue 116 ($(ECHO) $$@: \\ \ 117 && $(SED) -e '/^Note: including file:/!d' \ 118 -e 's|Note: including file: *||' \ 119 -e 's|\\|/|g' \ 120 -e 's|^\([a-zA-Z]\):|/cygdrive/\1|g' \ 121 -e '/$(subst /,\/,$(TOPDIR))/!d' \ 122 -e 's|$$$$| \\|g' \ 123 $$($1_$2_DEP).raw) > $$($1_$2_DEP) 124 endif 125 endif 126 endef 127 128 define SetupNativeCompilation 129 # param 1 is for example BUILD_MYPACKAGE 130 # param 2,3,4,5,6,7,8 are named args. |