common/makefiles/NativeCompilation.gmk

changeset 494
e64f2cb57d05
parent 478
2ba6f4da4bf3
child 533
e175ecff1391
equal deleted inserted replaced
488:8a3fe0ae06a8 494:e64f2cb57d05
30 ifeq (,$(_MAKEBASE_GMK)) 30 ifeq (,$(_MAKEBASE_GMK))
31 $(error You must include MakeBase.gmk prior to including NativeCompilation.gmk) 31 $(error You must include MakeBase.gmk prior to including NativeCompilation.gmk)
32 endif 32 endif
33 33
34 ifeq ($(COMPILER_TYPE),CC) 34 ifeq ($(COMPILER_TYPE),CC)
35 COMPILING_MSG=echo Compiling $1 35 COMPILING_MSG=echo $(LOG_INFO) "Compiling $(notdir $1) (for $(notdir $2))"
36 LINKING_MSG=echo Linking $1 36 LINKING_MSG=echo $(LOG_INFO) "Linking $1"
37 LINKING_EXE_MSG=echo Linking executable $1 37 LINKING_EXE_MSG=echo $(LOG_INFO) "Linking executable $1"
38 ARCHIVING_MSG=echo Archiving $1 38 ARCHIVING_MSG=echo $(LOG_INFO) "Archiving $1"
39 else 39 else
40 COMPILING_MSG= 40 COMPILING_MSG=
41 LINKING_MSG= 41 LINKING_MSG=
42 LINKING_EXE_MSG= 42 LINKING_EXE_MSG=
43 ARCHIVING_MSG= 43 ARCHIVING_MSG=
92 endif 92 endif
93 endif 93 endif
94 94
95 $$($1_$2_OBJ) : $2 95 $$($1_$2_OBJ) : $2
96 ifeq ($(COMPILER_TYPE),CC) 96 ifeq ($(COMPILER_TYPE),CC)
97 $$(call COMPILING_MSG,$$(notdir $2)) 97 $$(call COMPILING_MSG,$2,$$($1_TARGET))
98 $$($1_$2_COMP) $$($1_$2_FLAGS) $$($1_$2_DEP_FLAG) $$($1_$2_DEP) $(CC_OUT_OPTION)$$($1_$2_OBJ) $2 98 $$($1_$2_COMP) $$($1_$2_FLAGS) $$($1_$2_DEP_FLAG) $$($1_$2_DEP) $(CC_OUT_OPTION)$$($1_$2_OBJ) $2
99 endif 99 endif
100 ifeq ($(COMPILER_TYPE),CL) 100 ifeq ($(COMPILER_TYPE),CL)
101 $$($1_$2_COMP) $$($1_$2_FLAGS) $$($1_$2_DEBUG_OUT_FLAGS) $(CC_OUT_OPTION)$$($1_$2_OBJ) $2 101 $$($1_$2_COMP) $$($1_$2_FLAGS) $$($1_$2_DEBUG_OUT_FLAGS) $(CC_OUT_OPTION)$$($1_$2_OBJ) $2
102 endif 102 endif
127 # REORDER reorder file 127 # REORDER reorder file
128 # DEBUG_SYMBOLS add debug symbols (if configured on) 128 # DEBUG_SYMBOLS add debug symbols (if configured on)
129 # CC the compiler to use, default is $(CC) 129 # CC the compiler to use, default is $(CC)
130 # LDEXE the linker to use for linking executables, default is $(LDEXE) 130 # LDEXE the linker to use for linking executables, default is $(LDEXE)
131 # OPTIMIZATION sets optimization level to NONE, LOW, HIGH, HIGHEST 131 # OPTIMIZATION sets optimization level to NONE, LOW, HIGH, HIGHEST
132 $(if $2,$1_$(strip $2)) 132 $(foreach i,2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25, $(if $($i),$1_$(strip $($i)))$(NEWLINE))
133 $(if $3,$1_$(strip $3)) 133 $(call LogSetupMacroEntry,SetupNativeCompilation($1),$2,$3,$4,$5,$6,$7,$8,$9,$(10),$(11),$(12),$(13),$(14),$(15),$(16),$(17),$(18),$(19),$(20),$(21),$(22),$(23),$(24),$(25))
134 $(if $4,$1_$(strip $4))
135 $(if $5,$1_$(strip $5))
136 $(if $6,$1_$(strip $6))
137 $(if $7,$1_$(strip $7))
138 $(if $8,$1_$(strip $8))
139 $(if $9,$1_$(strip $9))
140 $(if $(10),$1_$(strip $(10)))
141 $(if $(11),$1_$(strip $(11)))
142 $(if $(12),$1_$(strip $(12)))
143 $(if $(13),$1_$(strip $(13)))
144 $(if $(14),$1_$(strip $(14)))
145 $(if $(15),$1_$(strip $(15)))
146 $(if $(16),$1_$(strip $(16)))
147 $(if $(17),$1_$(strip $(17)))
148 $(if $(18),$1_$(strip $(18)))
149 $(if $(19),$1_$(strip $(19)))
150 $(if $(20),$1_$(strip $(20)))
151 $(if $(21),$1_$(strip $(21)))
152 $(if $(22),$1_$(strip $(22)))
153 $(if $(23),$1_$(strip $(23)))
154 $(if $(24),$1_$(strip $(24)))
155 $(if $(25),$1_$(strip $(25)))
156 $(if $(26),$(error Internal makefile error: Too many arguments to SetupNativeCompilation, please update NativeCompilation.gmk)) 134 $(if $(26),$(error Internal makefile error: Too many arguments to SetupNativeCompilation, please update NativeCompilation.gmk))
157 135
158 ifneq (,$$($1_BIN)) 136 ifneq (,$$($1_BIN))
159 $$(error BIN has been replaced with OBJECT_DIR) 137 $$(error BIN has been replaced with OBJECT_DIR)
160 endif 138 endif
234 212
235 ifeq (,$$($1_LANG)) 213 ifeq (,$$($1_LANG))
236 $$(error You have to specify LANG for native compilation $1) 214 $$(error You have to specify LANG for native compilation $1)
237 endif 215 endif
238 ifeq (C,$$($1_LANG)) 216 ifeq (C,$$($1_LANG))
239 ifeq ($$($1_LDEXE),) 217 ifeq ($$($1_LDEXE),)
240 $1_LDEXE:=$(LDEXE) 218 $1_LDEXE:=$(LDEXE)
241 endif 219 endif
242 $1_LD:=$(LD) 220 $1_LD:=$(LD)
243 else 221 else
244 ifeq (C++,$$($1_LANG)) 222 ifeq (C++,$$($1_LANG))
245 $1_LD:=$(LDCXX) 223 $1_LD:=$(LDCXX)
246 $1_LDEXE:=$(LDEXECXX) 224 $1_LDEXE:=$(LDEXECXX)
252 ifeq ($$($1_CC),) 230 ifeq ($$($1_CC),)
253 $1_CC:=$(CC) 231 $1_CC:=$(CC)
254 endif 232 endif
255 233
256 # Make sure the dirs exist. 234 # Make sure the dirs exist.
257 $$(shell $(MKDIR) -p $$($1_SRC) $$($1_OBJECT_DIR) $$($1_OUTPUT_DIR)) 235 $$(eval $$(call MakeDir,$$($1_OBJECT_DIR) $$($1_OUTPUT_DIR)))
236 $$(foreach d,$$($1_SRC), $$(if $$(wildcard $$d),,$$(error SRC specified to SetupNativeCompilation $1 contains missing directory $$d)))
237
258 # Find all files in the source trees. Sort to remove duplicates. 238 # Find all files in the source trees. Sort to remove duplicates.
259 $1_ALL_SRCS := $$(sort $$(foreach i,$$($1_SRC), $$(shell $(FIND) $$i -type f))) 239 $1_ALL_SRCS := $$(sort $$(shell $(FIND) $$($1_SRC) -type f))
260 # Extract the C/C++ files. 240 # Extract the C/C++ files.
261 $1_EXCLUDE_FILES:=$$(foreach i,$$($1_SRC),$$(addprefix $$i/,$$($1_EXCLUDE_FILES))) 241 $1_EXCLUDE_FILES:=$$(foreach i,$$($1_SRC),$$(addprefix $$i/,$$($1_EXCLUDE_FILES)))
262 $1_INCLUDE_FILES:=$$(foreach i,$$($1_SRC),$$(addprefix $$i/,$$($1_INCLUDE_FILES))) 242 $1_INCLUDE_FILES:=$$(foreach i,$$($1_SRC),$$(addprefix $$i/,$$($1_INCLUDE_FILES)))
263 ifneq ($$($1_EXCLUDE_FILES),) 243 ifneq ($$($1_EXCLUDE_FILES),)
264 $1_EXCLUDE_FILES:=$$(addprefix %,$$($1_EXCLUDE_FILES)) 244 $1_EXCLUDE_FILES:=$$(addprefix %,$$($1_EXCLUDE_FILES))
289 # a reproducable order on the input files to the linker). 269 # a reproducable order on the input files to the linker).
290 $1_EXPECTED_OBJS:=$$(sort $$(addprefix $$($1_OBJECT_DIR)/,$$(patsubst %.cpp,%$(OBJ_SUFFIX),$$(patsubst %.c,%$(OBJ_SUFFIX),$$(patsubst %.m,%$(OBJ_SUFFIX),$$(patsubst %.s,%$(OBJ_SUFFIX),$$(notdir $$($1_SRCS)))))))) 270 $1_EXPECTED_OBJS:=$$(sort $$(addprefix $$($1_OBJECT_DIR)/,$$(patsubst %.cpp,%$(OBJ_SUFFIX),$$(patsubst %.c,%$(OBJ_SUFFIX),$$(patsubst %.m,%$(OBJ_SUFFIX),$$(patsubst %.s,%$(OBJ_SUFFIX),$$(notdir $$($1_SRCS))))))))
291 # Are there too many object files on disk? Perhaps because some source file was removed? 271 # Are there too many object files on disk? Perhaps because some source file was removed?
292 $1_SUPERFLOUS_OBJS:=$$(sort $$(filter-out $$($1_EXPECTED_OBJS),$$($1_BINS))) 272 $1_SUPERFLOUS_OBJS:=$$(sort $$(filter-out $$($1_EXPECTED_OBJS),$$($1_BINS)))
293 # Clean out the superfluous object files. 273 # Clean out the superfluous object files.
294 $$(shell $(RM) -f $$($1_SUPERFLUOUS_OBJS)) 274 ifneq ($$($1_SUPERFLUOUS_OBJS),)
275 $$(shell $(RM) -f $$($1_SUPERFLUOUS_OBJS))
276 endif
295 277
296 # Pickup extra OPENJDK_TARGET_OS_API and/or OPENJDK_TARGET_OS dependent variables for CFLAGS. 278 # Pickup extra OPENJDK_TARGET_OS_API and/or OPENJDK_TARGET_OS dependent variables for CFLAGS.
297 $1_EXTRA_CFLAGS:=$$($1_CFLAGS_$(OPENJDK_TARGET_OS_API)) $$($1_CFLAGS_$(OPENJDK_TARGET_OS)) 279 $1_EXTRA_CFLAGS:=$$($1_CFLAGS_$(OPENJDK_TARGET_OS_API)) $$($1_CFLAGS_$(OPENJDK_TARGET_OS))
298 ifneq ($(DEBUG_LEVEL),release) 280 ifneq ($(DEBUG_LEVEL),release)
299 # Pickup extra debug dependent variables for CFLAGS 281 # Pickup extra debug dependent variables for CFLAGS
356 $1_EXTRA_CXXFLAGS += $(CXX_O_FLAG_HIGHEST) 338 $1_EXTRA_CXXFLAGS += $(CXX_O_FLAG_HIGHEST)
357 else ifneq (, $$($1_OPTIMIZATION)) 339 else ifneq (, $$($1_OPTIMIZATION))
358 $$(error Unknown value for OPTIMIZATION: $$($1_OPTIMIZATION)) 340 $$(error Unknown value for OPTIMIZATION: $$($1_OPTIMIZATION))
359 endif 341 endif
360 342
361 # Now create a list of the packages that are about to compile. Used when sending source
362 # in a batch to the compiler.
363 $$(shell $(RM) $$($1_OBJECT_DIR)/_the.list_of_sources)
364 $$(eval $$(call ListPathsSafelyNow,$1_SRCS,\n, >> $$($1_OBJECT_DIR)/_the.list_of_sources))
365
366 # Now call add_native_source for each source file we are going to compile. 343 # Now call add_native_source for each source file we are going to compile.
367 $$(foreach p,$$($1_SRCS),\ 344 $$(foreach p,$$($1_SRCS),\
368 $$(eval $$(call add_native_source,$1,$$p,$$($1_OBJECT_DIR),\ 345 $$(eval $$(call add_native_source,$1,$$p,$$($1_OBJECT_DIR),\
369 $$($1_CFLAGS) $$($1_EXTRA_CFLAGS),$$($1_CC),\ 346 $$($1_CFLAGS) $$($1_EXTRA_CFLAGS),$$($1_CC),\
370 $$($1_CXXFLAGS) $$($1_EXTRA_CXXFLAGS),$(CXX),$$($1_ASFLAGS)))) 347 $$($1_CXXFLAGS) $$($1_EXTRA_CXXFLAGS),$(CXX),$$($1_ASFLAGS))))
383 $(SED) 's%IMVERSION%$$(IMVERSIONVALUE)%g;s%PROGRAM%$$($1_PROGRAM)%g' $$< > $$@ 360 $(SED) 's%IMVERSION%$$(IMVERSIONVALUE)%g;s%PROGRAM%$$($1_PROGRAM)%g' $$< > $$@
384 endif 361 endif
385 endif 362 endif
386 363
387 # mapfile doesnt seem to be implemented on macosx (yet??) 364 # mapfile doesnt seem to be implemented on macosx (yet??)
388 ifneq ($(OPENJDK_TARGET_CPU),ppc)
389 ifneq ($(OPENJDK_TARGET_CPU),arm)
390 ifneq ($(OPENJDK_TARGET_OS),macosx) 365 ifneq ($(OPENJDK_TARGET_OS),macosx)
391 ifneq ($(OPENJDK_TARGET_OS),windows) 366 ifneq ($(OPENJDK_TARGET_OS),windows)
392 $1_REAL_MAPFILE:=$$($1_MAPFILE) 367 $1_REAL_MAPFILE:=$$($1_MAPFILE)
393 ifneq (,$$($1_REORDER)) 368 ifneq (,$$($1_REORDER))
394 $1_REAL_MAPFILE:=$$($1_OBJECT_DIR)/mapfile 369 $1_REAL_MAPFILE:=$$($1_OBJECT_DIR)/mapfile
397 $$(MKDIR) -p $$(@D) 372 $$(MKDIR) -p $$(@D)
398 $$(CP) $$($1_MAPFILE) $$@.tmp 373 $$(CP) $$($1_MAPFILE) $$@.tmp
399 $$(SED) -e 's=OUTPUTDIR=$$($1_OBJECT_DIR)=' $$($1_REORDER) >> $$@.tmp 374 $$(SED) -e 's=OUTPUTDIR=$$($1_OBJECT_DIR)=' $$($1_REORDER) >> $$@.tmp
400 $$(MV) $$@.tmp $$@ 375 $$(MV) $$@.tmp $$@
401 endif 376 endif
402 endif
403 endif
404 endif 377 endif
405 endif 378 endif
406 379
407 # Pickup extra OPENJDK_TARGET_OS_API and/or OPENJDK_TARGET_OS dependent variables 380 # Pickup extra OPENJDK_TARGET_OS_API and/or OPENJDK_TARGET_OS dependent variables
408 # for LDFLAGS and LDFLAGS_SUFFIX 381 # for LDFLAGS and LDFLAGS_SUFFIX
443 # $(OBJCOPY) --add-gnu-debuglink=... corrupts SUNW_* sections. 416 # $(OBJCOPY) --add-gnu-debuglink=... corrupts SUNW_* sections.
444 # Use $(ADD_GNU_DEBUGLINK) until a fixed $(OBJCOPY) is available. 417 # Use $(ADD_GNU_DEBUGLINK) until a fixed $(OBJCOPY) is available.
445 $$($1_OBJECT_DIR)/$$(LIBRARY_PREFIX)$$($1_LIBRARY).debuginfo : $$($1_TARGET) \ 418 $$($1_OBJECT_DIR)/$$(LIBRARY_PREFIX)$$($1_LIBRARY).debuginfo : $$($1_TARGET) \
446 $(FIX_EMPTY_SEC_HDR_FLAGS) $(ADD_GNU_DEBUGLINK) 419 $(FIX_EMPTY_SEC_HDR_FLAGS) $(ADD_GNU_DEBUGLINK)
447 $(RM) $$@ 420 $(RM) $$@
448 $(FIX_EMPTY_SEC_HDR_FLAGS) $$< 421 $(FIX_EMPTY_SEC_HDR_FLAGS) $(LOG_INFO) $$<
449 $(OBJCOPY) --only-keep-debug $$< $$@ 422 $(OBJCOPY) --only-keep-debug $$< $$@
450 $(CD) $$(@D) && $(ADD_GNU_DEBUGLINK) $$(@F) $$< 423 $(CD) $$(@D) && $(ADD_GNU_DEBUGLINK) $(LOG_INFO) $$(@F) $$<
451 else # not solaris 424 else # not solaris
452 $$($1_OBJECT_DIR)/$$(LIBRARY_PREFIX)$$($1_LIBRARY).debuginfo : $$($1_TARGET) 425 $$($1_OBJECT_DIR)/$$(LIBRARY_PREFIX)$$($1_LIBRARY).debuginfo : $$($1_TARGET)
453 $(RM) $$@ 426 $(RM) $$@
454 $(OBJCOPY) --only-keep-debug $$< $$@ 427 $(OBJCOPY) --only-keep-debug $$< $$@
455 $(CD) $$(@D) && $(OBJCOPY) --add-gnu-debuglink=$$(@F) $$< 428 $(CD) $$(@D) && $(OBJCOPY) --add-gnu-debuglink=$$(@F) $$<
521 # $(OBJCOPY) --add-gnu-debuglink=... corrupts SUNW_* sections. 494 # $(OBJCOPY) --add-gnu-debuglink=... corrupts SUNW_* sections.
522 # Use $(ADD_GNU_DEBUGLINK) until a fixed $(OBJCOPY) is available. 495 # Use $(ADD_GNU_DEBUGLINK) until a fixed $(OBJCOPY) is available.
523 $$($1_OBJECT_DIR)/$$($1_PROGRAM).debuginfo : $$($1_TARGET) \ 496 $$($1_OBJECT_DIR)/$$($1_PROGRAM).debuginfo : $$($1_TARGET) \
524 $(FIX_EMPTY_SEC_HDR_FLAGS) $(ADD_GNU_DEBUGLINK) 497 $(FIX_EMPTY_SEC_HDR_FLAGS) $(ADD_GNU_DEBUGLINK)
525 $(RM) $$@ 498 $(RM) $$@
526 $(FIX_EMPTY_SEC_HDR_FLAGS) $$< 499 $(FIX_EMPTY_SEC_HDR_FLAGS) $(LOG_INFO) $$<
527 $(OBJCOPY) --only-keep-debug $$< $$@ 500 $(OBJCOPY) --only-keep-debug $$< $$@
528 $(CD) $$(@D) && $(ADD_GNU_DEBUGLINK) $$(@F) $$< 501 $(CD) $$(@D) && $(ADD_GNU_DEBUGLINK) $(LOG_INFO) $$(@F) $$<
529 else # not solaris 502 else # not solaris
530 $$($1_OBJECT_DIR)/$$($1_PROGRAM).debuginfo : $$($1_TARGET) 503 $$($1_OBJECT_DIR)/$$($1_PROGRAM).debuginfo : $$($1_TARGET)
531 $(RM) $$@ 504 $(RM) $$@
532 $(OBJCOPY) --only-keep-debug $$< $$@ 505 $(OBJCOPY) --only-keep-debug $$< $$@
533 $(CD) $$(@D) && $(OBJCOPY) --add-gnu-debuglink=$$(@F) $$< 506 $(CD) $$(@D) && $(OBJCOPY) --add-gnu-debuglink=$$(@F) $$<
562 $$(call LINKING_EXE_MSG,$$($1_BASENAME)) 535 $$(call LINKING_EXE_MSG,$$($1_BASENAME))
563 $$($1_LDEXE) $$($1_LDFLAGS) $$($1_EXTRA_LDFLAGS) $(EXE_OUT_OPTION)$$($1_TARGET) \ 536 $$($1_LDEXE) $$($1_LDFLAGS) $$($1_EXTRA_LDFLAGS) $(EXE_OUT_OPTION)$$($1_TARGET) \
564 $$($1_EXPECTED_OBJS) $$($1_RES) $$($1_LDFLAGS_SUFFIX) \ 537 $$($1_EXPECTED_OBJS) $$($1_RES) $$($1_LDFLAGS_SUFFIX) \
565 $$($1_EXTRA_LDFLAGS_SUFFIX) 538 $$($1_EXTRA_LDFLAGS_SUFFIX)
566 ifneq (,$$($1_GEN_MANIFEST)) 539 ifneq (,$$($1_GEN_MANIFEST))
567 $(MT) -nologo /manifest $$($1_GEN_MANIFEST) /outputresource:$$@;#1 540 $(MT) -nologo -manifest $$($1_GEN_MANIFEST) -outputresource:$$@;#1
568 endif 541 endif
569 542
570 endif 543 endif
571 endef 544 endef

mercurial