1 # 2 # Copyright (c) 1995, 2012, 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 # 27 # Generic makefile for building executables. 28 # 29 30 # WARNING: This file is shared with other workspaces. 31 # So when it includes other files, it must use JDK_TOPDIR. 32 # 33 34 # 35 # If building programs, use a normal compile approach 36 # 37 ifeq ($(COMPILE_APPROACH),batch) 38 override COMPILE_APPROACH = normal 39 endif 40 41 # set the platform specific directory for macosx, also this platform shares 42 # substantial family ties with its siblings (solaris and linux), thus we add 43 # solaris src path to its compilation dependencies. 44 ifeq ($(PLATFORM), macosx) 45 LAUNCHER_PLATFORM_SRC = $(BUILDDIR)/../src/macosx 46 LAUNCHER_SOLARIS_PLATFORM_SRC = $(BUILDDIR)/../src/solaris 47 else 48 LAUNCHER_PLATFORM_SRC = $(PLATFORM_SRC) 49 endif 50 51 ifndef LAUNCHER_SHARE_SRC 52 LAUNCHER_SHARE_SRC = $(SHARE_SRC) 53 endif 54 55 ACTUAL_PROGRAM_NAME = $(PROGRAM)$(EXE_SUFFIX) 56 ACTUAL_PROGRAM_DIR = $(BINDIR) 57 ACTUAL_PROGRAM = $(ACTUAL_PROGRAM_DIR)/$(ACTUAL_PROGRAM_NAME) 58 59 # Make sure the default rule is all 60 program_default_rule: all 61 62 program: $(ACTUAL_PROGRAM) 63 64 # Work-around for missing processor specific mapfiles 65 ifndef CROSS_COMPILE_ARCH 66 # reuse the mapfiles in the launcher's directory, the same should 67 # be applicable to the tool launchers as well. 68 FILES_m = $(BUILDDIR)/java/main/java/mapfile-$(ARCH) 69 include $(BUILDDIR)/common/Mapfile-vers.gmk 70 endif 71 72 include $(JDK_TOPDIR)/make/common/Rules.gmk 73 74 ifdef NEVER_ACT_AS_SERVER_CLASS_MACHINE 75 OTHER_CPPFLAGS += -DNEVER_ACT_AS_SERVER_CLASS_MACHINE 76 endif 77 78 # 79 # Create a dependency on libjli (Java Launcher Infrastructure) 80 # 81 # On UNIX, this is a relative dependency using $ORIGIN. Unfortunately, to 82 # do this reliably on Linux takes a different syntax than Solaris. 83 # 84 # On Windows, this is done by using the same directory as the executable 85 # itself, as with all the Windows libraries. 86 # 87 ifeq ($(PLATFORM), macosx) 88 ifneq ($(ARCH), universal) 89 LDFLAGS += -Wl,-all_load 90 endif 91 LDFLAGS += $(OUTPUTDIR)/tmp/java/jli/$(OBJDIRNAME)/static/libjli.a 92 93 ifeq ($(SYSTEM_ZLIB),true) 94 OTHER_LDLIBS += -lz 95 endif 96 endif 97 98 ifneq (,$(findstring $(PLATFORM), linux solaris)) # UNIX systems 99 LDFLAGS += -L $(LIBDIR)/$(LIBARCH)/jli 100 OTHER_LDLIBS += -ljli 101 ifeq ($(PLATFORM), solaris) 102 ## Temporarily remove for Modules Solaris 64bit only build 103 #ifeq ($(ARCH_DATA_MODEL), 32) 104 LDFLAGS += -R \$$ORIGIN/../lib/$(LIBARCH)/jli 105 LDFLAGS += -R \$$ORIGIN/../jre/lib/$(LIBARCH)/jli 106 #else 107 # LDFLAGS += -R \$$ORIGIN/../../lib/$(LIBARCH)/jli 108 # LDFLAGS += -R \$$ORIGIN/../../lib/$(LIBARCH)/jli 109 #endif 110 endif 111 ifeq ($(PLATFORM), linux) 112 LDFLAGS += $(LDFLAG_Z_ORIGIN) 113 LDFLAGS += -Wl,--allow-shlib-undefined 114 LDFLAGS += -Wl,-rpath -Wl,\$$ORIGIN/../lib/$(LIBARCH)/jli 115 LDFLAGS += -Wl,-rpath -Wl,\$$ORIGIN/../jre/lib/$(LIBARCH)/jli 116 endif 117 endif 118 119 ifeq ($(PLATFORM), windows) 120 JLI_LCF = $(OUTPUTDIR)/tmp/java/jli/$(OBJDIRNAME)/jli.lcf 121 ifdef STATIC_JLI 122 LDFLAGS += -libpath:$(OUTPUTDIR)/tmp/java/jli/$(OBJDIRNAME)/static 123 else 124 LDFLAGS += -libpath:$(OUTPUTDIR)/tmp/java/jli/$(OBJDIRNAME) 125 endif 126 OTHER_LDLIBS += jli.lib 127 endif 128 129 # 130 # Launcher specific files. 131 # 132 FILES_o = $(OBJDIR)/main.$(OBJECT_SUFFIX) 133 134 $(ACTUAL_PROGRAM):: classes $(INIT) 135 136 # 137 # Windows only 138 # 139 ifeq ($(PLATFORM), windows) 140 # JDK name required here 141 RC_FLAGS += /D "JDK_FNAME=$(PROGRAM)$(EXE_SUFFIX)" \ 142 /D "JDK_INTERNAL_NAME=$(PROGRAM)" \ 143 /D "JDK_FTYPE=0x1L" 144 145 $(OBJDIR)/$(PROGRAM).res: $(VERSIONINFO_RESOURCE) 146 @$(prep-target) 147 ifndef LOCAL_RESOURCE_FILE 148 $(RC) $(RC_FLAGS) $(CC_OBJECT_OUTPUT_FLAG)$(@) $(VERSIONINFO_RESOURCE) 149 endif 150 151 $(OBJDIR)/$(PROGRAM).lcf: $(OBJDIR)/$(PROGRAM).res $(FILES_o) 152 @$(prep-target) 153 @$(ECHO) $(FILES_o) > $@ 154 ifndef LOCAL_RESOURCE_FILE 155 @$(ECHO) $(OBJDIR)/$(PROGRAM).res >> $@ 156 endif 157 @$(ECHO) setargv.obj >> $@ 158 @$(ECHO) Created $@ 159 160 $(ACTUAL_PROGRAM):: $(OBJDIR)/$(PROGRAM)$(EXE_SUFFIX) 161 @$(install-cmd-file) 162 163 ifeq ($(ARCH_DATA_MODEL), 32) 164 STACK_SIZE=327680 165 else 166 # We need more Stack for Windows 64bit 167 STACK_SIZE=1048576 168 endif 169 170 IMVERSION=$(JDK_MINOR_VERSION).$(JDK_MICRO_VERSION).$(JDK_UPDATE_VER).$(COOKED_BUILD_NUMBER) 171 $(OBJDIR)/$(PROGRAM).exe.manifest: $(JDK_TOPDIR)/src/windows/resource/java.manifest 172 @$(prep-target) 173 $(SED) 's%IMVERSION%$(IMVERSION)%g;s%PROGRAM%$(PROGRAM)%g' $< > $@ 174 175 ifeq ($(ENABLE_FULL_DEBUG_SYMBOLS),1) 176 MAP_OPTION="-map:$(OBJDIR)/$(PROGRAM).map" 177 endif 178 179 # We used a hand-crafted manifest file for all executables. 180 # It is tweaked to embed the build number and executable name. 181 # Use ";#2" for .dll and ";#1" for .exe in the MT command below: 182 $(OBJDIR)/$(PROGRAM)$(EXE_SUFFIX):: $(OBJDIR)/$(PROGRAM).lcf $(FILES_o) $(JLI_LCF) $(OBJDIR)/$(PROGRAM).exe.manifest 183 @$(prep-target) 184 @set -- $?; \ 185 $(ECHO) Rebuilding $@ because of $$1 $$2 $$3 $$4 $$5 $$6 $${7:+...}; 186 $(LINK) -out:$@ /STACK:$(STACK_SIZE) \ 187 $(MAP_OPTION) $(LFLAGS) $(LDFLAGS) \ 188 @$(OBJDIR)/$(PROGRAM).lcf $(LDLIBS) 189 ifdef MT 190 $(MT) /manifest $(OBJDIR)/$(PROGRAM).exe.manifest /outputresource:$@;#1 191 endif 192 @$(call binary_file_verification,$@) 193 ifeq ($(ENABLE_FULL_DEBUG_SYMBOLS),1) 194 ifeq ($(ZIP_DEBUGINFO_FILES),1) 195 (set -e ; \ 196 $(CD) $(OBJDIR) ; \ 197 $(ZIPEXE) -q $(PROGRAM).diz $(PROGRAM).map $(PROGRAM).pdb ; \ 198 $(RM) $(PROGRAM).map $(PROGRAM).pdb ; \ 199 ) 200 endif 201 endif 202 else 203 # 204 # Note that we have to link -lthread even when USE_PTHREADS is true. 205 # This is becuase checkForCorrectLibthread() croaks otherwise. 206 # 207 LIBTHREAD = -lthread 208 ifeq ($(USE_PTHREADS),true) 209 THREADLIBS = -lpthread $(LIBTHREAD) 210 else 211 THREADLIBS = $(LIBTHREAD) 212 endif 213 214 ifeq ($(PLATFORM), macosx) 215 THREADLIBS = -pthread 216 # Needed for linking the various launchers 217 LDFLAGS += -framework Cocoa -framework Security \ 218 -framework ApplicationServices 219 OTHER_CPPFLAGS += -DPACKAGE_PATH='"$(PACKAGE_PATH)"' 220 221 # Default Info.plist file for the command line tools. This gets overridden by 222 # some of the jvmstat tools so that they have task_for_pid() privileges 223 ifndef INFO_PLIST_FILE 224 INFO_PLIST_FILE = Info-cmdline.plist 225 endif 226 LDFLAGS += -sectcreate __TEXT __info_plist $(LAUNCHER_PLATFORM_SRC)/lib/$(INFO_PLIST_FILE) 227 else 228 INFO_PLIST_FILE= 229 endif 230 231 # 232 # This rule only applies on unix. It supports quantify and its ilk. 233 # 234 $(ACTUAL_PROGRAM):: $(FILES_o) 235 @$(prep-target) 236 @set -- $?; \ 237 $(ECHO) Rebuilding $@ because of $$1 $$2 $$3 $$4 $$5 $$6 $${7:+...}; 238 @$(MKDIR) -p $(TEMPDIR) 239 $(LINK_PRE_CMD) $(CC) $(CC_OBJECT_OUTPUT_FLAG)$@ $(LDFLAGS) \ 240 $(FILES_o) $(THREADLIBS) $(LDLIBS) 241 ifeq ($(findstring privileged, $(INFO_PLIST_FILE)), privileged) 242 -codesign -s openjdk_codesign $@ 243 endif 244 @$(call binary_file_verification,$@) 245 ifneq ($(PLATFORM), macosx) 246 ifeq ($(ENABLE_FULL_DEBUG_SYMBOLS),1) 247 ifeq ($(PROGRAM_SUPPORTS_FULL_DEBUG_SYMBOLS),1) 248 (set -e ; \ 249 $(CD) $(@D) ; \ 250 $(OBJCOPY) --only-keep-debug $(@F) $(@F).debuginfo ; \ 251 $(OBJCOPY) --add-gnu-debuglink=$(@F).debuginfo $(@F) ; \ 252 ) 253 ifeq ($(STRIP_POLICY),all_strip) 254 $(STRIP) $@ 255 else 256 ifeq ($(STRIP_POLICY),min_strip) 257 ifeq ($(PLATFORM), solaris) 258 $(STRIP) -x $@ 259 else 260 # assume Linux 261 $(STRIP) -g $@ 262 endif 263 # implied else here is no stripping at all 264 endif 265 endif 266 ifeq ($(ZIP_DEBUGINFO_FILES),1) 267 (set -e ; \ 268 $(CD) $(@D) ; \ 269 $(ZIPEXE) -q $(@F).diz $(@F).debuginfo ; \ 270 $(RM) $(@F).debuginfo ; \ 271 ) 272 # save ZIP'ed debug info with rest of the program's build artifacts 273 $(MV) $@.diz $(OBJDIR) 274 else 275 # save debug info with rest of the program's build artifacts 276 $(MV) $@.debuginfo $(OBJDIR) 277 endif 278 endif # PROGRAM_SUPPORTS_FULL_DEBUG_SYMBOLS 279 endif # ENABLE_FULL_DEBUG_SYMBOLS 280 endif # PLATFORM-!macosx 281 $(install-module-file) 282 283 endif # PLATFORM 284 285 clean:: 286 ifeq ($(PLATFORM), windows) 287 $(RM) $(OBJDIR)/$(PROGRAM).rc 288 $(RM) $(OBJDIR)/$(PROGRAM).ico 289 $(RM) $(OBJDIR)/$(PROGRAM).lcf 290 $(RM) $(OBJDIR)/$(PROGRAM).map 291 $(RM) $(OBJDIR)/$(PROGRAM).pdb 292 $(RM) $(OBJDIR)/$(PROGRAM).exp 293 $(RM) $(OBJDIR)/$(PROGRAM).lib 294 $(RM) $(OBJDIR)/$(PROGRAM)$(EXE_SUFFIX) 295 $(RM) $(OBJDIR)/$(PROGRAM).ilk 296 $(RM) *.pdb 297 else 298 $(RM) $(OBJDIR)/$(PROGRAM).debuginfo 299 endif 300 $(RM) $(OBJDIR)/$(PROGRAM).diz 301 302 303 clobber:: 304 $(RM) $(ACTUAL_PROGRAM) 305 306 # 307 # Now include make dependencies (created during compilation, see Rules.gmk) 308 # 309 ifeq ($(INCREMENTAL_BUILD),true) 310 # Workaround: gnumake sometimes says files is empty when it shouldn't 311 # was: files := $(foreach file, $(wildcard */$(ARCH)/*.$(DEPEND_SUFFIX)), $(file)) 312 files := $(shell $(LS) $(OBJDIR)/*.$(DEPEND_SUFFIX) 2>/dev/null) 313 ifneq ($(strip $(files)),) 314 include $(files) 315 endif 316 endif 317 318 ifdef JAVA_ARGS 319 OTHER_CPPFLAGS += -DJAVA_ARGS='$(JAVA_ARGS)' 320 OTHER_CPPFLAGS += -DLAUNCHER_NAME='"$(LAUNCHER_NAME)"' 321 endif 322 323 ifdef PROGRAM_MODULE 324 OTHER_CPPFLAGS += -DMODULE_NAME='"$(PROGRAM_MODULE)"' 325 OTHER_CPPFLAGS += -DMODULE_VERSION='"$(MODULE_VERSION)"' 326 endif 327 328 ifeq ($(PLATFORM), windows) 329 ifdef RELEASE 330 OTHER_CPPFLAGS += -DVERSION='"$(RELEASE)"' 331 endif 332 endif 333 334 335 ifneq ($(PLATFORM), windows) 336 HAVE_GETHRTIME=true 337 endif 338 339 ifeq ($(HAVE_GETHRTIME),true) 340 OTHER_CPPFLAGS += -DHAVE_GETHRTIME 341 endif 342 343 OTHER_INCLUDES += -I$(LAUNCHER_SHARE_SRC)/bin -I$(LAUNCHER_PLATFORM_SRC)/bin 344 ifeq ($(PLATFORM), macosx) 345 OTHER_INCLUDES += -I$(LAUNCHER_SOLARIS_PLATFORM_SRC)/bin 346 ifneq ($(SYSTEM_ZLIB), true) 347 OTHER_INCLUDES += -I$(SHARE_SRC)/native/java/util/zip/zlib-1.1.3 348 endif 349 else 350 OTHER_INCLUDES += -I$(SHARE_SRC)/native/java/util/zip/zlib-1.1.3 351 endif 352 353 OTHER_CPPFLAGS += -DPROGNAME='"$(PROGRAM)"' 354 VERSION_DEFINES += -DFULL_VERSION='"$(FULL_VERSION)"' 355 356 VERSION_DEFINES += -DJDK_MAJOR_VERSION='"$(JDK_MAJOR_VERSION)"' \ 357 -DJDK_MINOR_VERSION='"$(JDK_MINOR_VERSION)"' 358 359 360 361 $(OBJDIR)/main.$(OBJECT_SUFFIX): $(LAUNCHER_SHARE_SRC)/bin/main.c 362 @$(prep-target) 363 $(COMPILE.c) $(CC_OBJECT_OUTPUT_FLAG)$(OBJDIR)/main.$(OBJECT_SUFFIX) \ 364 $(VERSION_DEFINES) $< 365 366 # 367 # Default dependencies 368 # 369 370 all: build 371 372 build: program 373 374 debug: 375 $(MAKE) VARIANT=DBG build 376 377 fastdebug: 378 $(MAKE) VARIANT=DBG FASTDEBUG=true build 379 380 .PHONY: all build program clean clobber debug fastdebug