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     ifeq ($(ARCH_DATA_MODEL), 32)
 103       LDFLAGS += -R \$$ORIGIN/../lib/$(LIBARCH)/jli
 104       LDFLAGS += -R \$$ORIGIN/../jre/lib/$(LIBARCH)/jli
 105     else
 106       LDFLAGS += -R \$$ORIGIN/../../lib/$(LIBARCH)/jli
 107       LDFLAGS += -R \$$ORIGIN/../../jre/lib/$(LIBARCH)/jli
 108     endif
 109   endif
 110   ifeq ($(PLATFORM), linux)
 111     LDFLAGS += $(LDFLAG_Z_ORIGIN)
 112     LDFLAGS += -Wl,--allow-shlib-undefined
 113     LDFLAGS += -Wl,-rpath -Wl,\$$ORIGIN/../lib/$(LIBARCH)/jli
 114     LDFLAGS += -Wl,-rpath -Wl,\$$ORIGIN/../jre/lib/$(LIBARCH)/jli
 115   endif
 116 endif
 117 
 118 ifeq ($(PLATFORM), windows)
 119   JLI_LCF = $(OUTPUTDIR)/tmp/java/jli/$(OBJDIRNAME)/jli.lcf
 120   ifdef STATIC_JLI
 121     LDFLAGS += -libpath:$(OUTPUTDIR)/tmp/java/jli/$(OBJDIRNAME)/static
 122   else
 123     LDFLAGS += -libpath:$(OUTPUTDIR)/tmp/java/jli/$(OBJDIRNAME)
 124   endif
 125   OTHER_LDLIBS += jli.lib
 126 endif
 127 
 128 #
 129 # Launcher specific files.
 130 #
 131 FILES_o = $(OBJDIR)/main.$(OBJECT_SUFFIX)
 132 
 133 $(ACTUAL_PROGRAM):: classes $(INIT) 
 134 
 135 #
 136 # Windows only
 137 #
 138 ifeq ($(PLATFORM), windows)
 139   # JDK name required here
 140   RC_FLAGS += /D "JDK_FNAME=$(PROGRAM)$(EXE_SUFFIX)" \
 141               /D "JDK_INTERNAL_NAME=$(PROGRAM)" \
 142               /D "JDK_FTYPE=0x1L"
 143 
 144   $(OBJDIR)/$(PROGRAM).res: $(VERSIONINFO_RESOURCE)
 145         @$(prep-target)
 146   ifndef LOCAL_RESOURCE_FILE
 147         $(RC) $(RC_FLAGS) $(CC_OBJECT_OUTPUT_FLAG)$(@) $(VERSIONINFO_RESOURCE)
 148   endif
 149 
 150   $(OBJDIR)/$(PROGRAM).lcf: $(OBJDIR)/$(PROGRAM).res $(FILES_o)
 151         @$(prep-target)
 152         @$(ECHO) $(FILES_o) > $@ 
 153   ifndef LOCAL_RESOURCE_FILE
 154         @$(ECHO) $(OBJDIR)/$(PROGRAM).res >> $@
 155   endif
 156         @$(ECHO) Created $@ 
 157 
 158   $(ACTUAL_PROGRAM):: $(OBJDIR)/$(PROGRAM)$(EXE_SUFFIX)
 159         @$(install-file)
 160 
 161   ifeq ($(ARCH_DATA_MODEL), 32)
 162     STACK_SIZE=327680
 163   else
 164     # We need more Stack for Windows 64bit
 165     STACK_SIZE=1048576
 166   endif
 167 
 168   IMVERSION=$(JDK_MINOR_VERSION).$(JDK_MICRO_VERSION).$(JDK_UPDATE_VER).$(COOKED_BUILD_NUMBER)
 169   $(OBJDIR)/$(PROGRAM).exe.manifest: $(JDK_TOPDIR)/src/windows/resource/java.manifest
 170         @$(prep-target)
 171         $(SED) 's%IMVERSION%$(IMVERSION)%g;s%PROGRAM%$(PROGRAM)%g' $< > $@
 172 
 173 ifeq ($(ENABLE_FULL_DEBUG_SYMBOLS),1)
 174   MAP_OPTION="-map:$(OBJDIR)/$(PROGRAM).map"
 175 endif
 176 
 177   # We used a hand-crafted manifest file for all executables.
 178   # It is tweaked to embed the build number and executable name.
 179   # Use ";#2" for .dll and ";#1" for .exe in the MT command below:
 180   $(OBJDIR)/$(PROGRAM)$(EXE_SUFFIX):: $(OBJDIR)/$(PROGRAM).lcf $(FILES_o) $(JLI_LCF) $(OBJDIR)/$(PROGRAM).exe.manifest
 181         @$(prep-target)
 182         @set -- $?; \
 183             $(ECHO) Rebuilding $@ because of $$1 $$2 $$3 $$4 $$5 $$6 $${7:+...};
 184         $(LINK) -out:$@ /STACK:$(STACK_SIZE) \
 185             $(MAP_OPTION) $(LFLAGS) $(LDFLAGS) \
 186             @$(OBJDIR)/$(PROGRAM).lcf $(LDLIBS)
 187   ifdef MT
 188         $(MT) /manifest $(OBJDIR)/$(PROGRAM).exe.manifest /outputresource:$@;#1
 189   endif
 190         @$(call binary_file_verification,$@)
 191   ifeq ($(ENABLE_FULL_DEBUG_SYMBOLS),1)
 192     ifeq ($(ZIP_DEBUGINFO_FILES),1)
 193         (set -e ; \
 194          $(CD) $(OBJDIR) ; \
 195          $(ZIPEXE) -q $(PROGRAM).diz $(PROGRAM).map $(PROGRAM).pdb ; \
 196          $(RM) $(PROGRAM).map $(PROGRAM).pdb ; \
 197         )
 198     endif
 199   endif
 200 else
 201   #
 202   # Note that we have to link -lthread even when USE_PTHREADS is true.
 203   # This is becuase checkForCorrectLibthread() croaks otherwise.
 204   #
 205   LIBTHREAD = -lthread
 206   ifeq ($(USE_PTHREADS),true)
 207     THREADLIBS = -lpthread $(LIBTHREAD)
 208   else
 209     THREADLIBS = $(LIBTHREAD)
 210   endif
 211 
 212   ifeq ($(PLATFORM), macosx)
 213     THREADLIBS = -pthread
 214     # Needed for linking the various launchers
 215     LDFLAGS += -framework Cocoa -framework Security \
 216                -framework ApplicationServices
 217     OTHER_CPPFLAGS += -DPACKAGE_PATH='"$(PACKAGE_PATH)"'
 218 
 219     # Default Info.plist file for the command line tools. This gets overridden by
 220     # some of the jvmstat tools so that they have task_for_pid() privileges
 221     ifndef INFO_PLIST_FILE
 222       INFO_PLIST_FILE = Info-cmdline.plist
 223     endif
 224     LDFLAGS += -sectcreate __TEXT __info_plist $(LAUNCHER_PLATFORM_SRC)/lib/$(INFO_PLIST_FILE)
 225   else 
 226     INFO_PLIST_FILE=
 227   endif
 228 
 229   #
 230   # This rule only applies on unix.  It supports quantify and its ilk.
 231   #
 232 
 233   ifeq ($(PLATFORM), solaris)
 234     ifeq ($(PROGRAM_SUPPORTS_FULL_DEBUG_SYMBOLS),1)
 235   $(ACTUAL_PROGRAM):: $(ADD_GNU_DEBUGLINK) $(FIX_EMPTY_SEC_HDR_FLAGS)
 236     endif
 237   endif
 238 
 239   $(ACTUAL_PROGRAM):: $(FILES_o)
 240         @$(prep-target)
 241         @set -- $?; \
 242         $(ECHO) Rebuilding $@ because of $$1 $$2 $$3 $$4 $$5 $$6 $${7:+...};
 243         @$(MKDIR) -p $(TEMPDIR)
 244         $(LINK_PRE_CMD) $(CC) $(CC_OBJECT_OUTPUT_FLAG)$@ $(LDFLAGS) \
 245         $(sort $(FILES_o)) $(THREADLIBS) $(LDLIBS)
 246   ifeq ($(findstring privileged, $(INFO_PLIST_FILE)), privileged)
 247         -codesign -s openjdk_codesign $@
 248   endif
 249         @$(call binary_file_verification,$@)
 250   ifneq ($(PLATFORM), macosx)
 251     ifeq ($(ENABLE_FULL_DEBUG_SYMBOLS),1)
 252       ifeq ($(PROGRAM_SUPPORTS_FULL_DEBUG_SYMBOLS),1)
 253         ifeq ($(PLATFORM), solaris)
 254 # gobjcopy crashes on "empty" section headers with the SHF_ALLOC flag set.
 255 # Use $(FIX_EMPTY_SEC_HDR_FLAGS) to clear the SHF_ALLOC flag (if set) from
 256 # empty section headers until a fixed $(OBJCOPY) is available.
 257 # An empty section header has sh_addr == 0 and sh_size == 0.
 258 # This problem has only been seen on Solaris X64, but we call this tool
 259 # on all Solaris builds just in case.
 260 #
 261 # $(OBJCOPY) --add-gnu-debuglink=... corrupts SUNW_* sections.
 262 # Use $(ADD_GNU_DEBUGLINK) until a fixed $(OBJCOPY) is available.
 263         (set -e ; \
 264          $(CD) $(@D) ; \
 265          $(FIX_EMPTY_SEC_HDR_FLAGS) $(@F) ; \
 266          $(OBJCOPY) --only-keep-debug $(@F) $(@F).debuginfo ; \
 267          $(ADD_GNU_DEBUGLINK) $(@F).debuginfo $(@F) ; \
 268         )
 269         else # PLATFORM != solaris
 270         (set -e ; \
 271          $(CD) $(@D) ; \
 272          $(OBJCOPY) --only-keep-debug $(@F) $(@F).debuginfo ; \
 273          $(OBJCOPY) --add-gnu-debuglink=$(@F).debuginfo $(@F) ; \
 274         )
 275         endif # PLATFORM == solaris
 276         ifeq ($(STRIP_POLICY),all_strip)
 277           $(STRIP) $@
 278         else
 279           ifeq ($(STRIP_POLICY),min_strip)
 280             ifeq ($(PLATFORM), solaris)
 281               $(STRIP) -x $@
 282             else
 283               # assume Linux
 284               $(STRIP) -g $@
 285             endif
 286           # implied else here is no stripping at all
 287           endif
 288         endif
 289         ifeq ($(ZIP_DEBUGINFO_FILES),1)
 290           (set -e ; \
 291            $(CD) $(@D) ; \
 292            $(ZIPEXE) -q $(@F).diz $(@F).debuginfo ; \
 293            $(RM) $(@F).debuginfo ; \
 294           )
 295           # save ZIP'ed debug info with rest of the program's build artifacts
 296           $(MV) $@.diz $(OBJDIR)
 297         else
 298           # save debug info with rest of the program's build artifacts
 299           $(MV) $@.debuginfo $(OBJDIR)
 300         endif
 301       endif # PROGRAM_SUPPORTS_FULL_DEBUG_SYMBOLS
 302     endif # ENABLE_FULL_DEBUG_SYMBOLS
 303   endif # PLATFORM-!macosx
 304 endif # PLATFORM
 305 
 306 clean:: 
 307 ifeq ($(PLATFORM), windows)
 308         $(RM) $(OBJDIR)/$(PROGRAM).rc
 309         $(RM) $(OBJDIR)/$(PROGRAM).ico
 310         $(RM) $(OBJDIR)/$(PROGRAM).lcf
 311         $(RM) $(OBJDIR)/$(PROGRAM).map
 312         $(RM) $(OBJDIR)/$(PROGRAM).pdb
 313         $(RM) $(OBJDIR)/$(PROGRAM).exp
 314         $(RM) $(OBJDIR)/$(PROGRAM).lib
 315         $(RM) $(OBJDIR)/$(PROGRAM)$(EXE_SUFFIX)
 316         $(RM) $(OBJDIR)/$(PROGRAM).ilk
 317         $(RM) *.pdb
 318 else
 319         $(RM) $(OBJDIR)/$(PROGRAM).debuginfo
 320 endif
 321         $(RM) $(OBJDIR)/$(PROGRAM).diz
 322 
 323 
 324 clobber:: 
 325         $(RM) $(ACTUAL_PROGRAM)
 326 
 327 #
 328 # Now include make dependencies (created during compilation, see Rules.gmk)
 329 #
 330 ifeq ($(INCREMENTAL_BUILD),true)
 331   # Workaround: gnumake sometimes says files is empty when it shouldn't
 332   #    was:  files := $(foreach file, $(wildcard */$(ARCH)/*.$(DEPEND_SUFFIX)), $(file))
 333   files := $(shell $(LS) $(OBJDIR)/*.$(DEPEND_SUFFIX) 2>/dev/null)
 334   ifneq ($(strip $(files)),)
 335     include $(files)
 336   endif
 337 endif
 338 
 339 ifdef JAVA_ARGS
 340   OTHER_CPPFLAGS += -DJAVA_ARGS='$(JAVA_ARGS)'
 341   OTHER_CPPFLAGS += -DLAUNCHER_NAME='"$(LAUNCHER_NAME)"'
 342 endif
 343 
 344 ifeq ($(PLATFORM), windows)
 345   ifdef RELEASE
 346     OTHER_CPPFLAGS += -DVERSION='"$(RELEASE)"'
 347   endif
 348 endif
 349 
 350 
 351 ifneq ($(PLATFORM), windows)
 352   HAVE_GETHRTIME=true
 353 endif
 354 
 355 ifeq ($(HAVE_GETHRTIME),true)
 356   OTHER_CPPFLAGS += -DHAVE_GETHRTIME
 357 endif
 358 
 359 OTHER_INCLUDES += -I$(LAUNCHER_SHARE_SRC)/bin -I$(LAUNCHER_PLATFORM_SRC)/bin
 360 ifeq ($(PLATFORM), macosx)
 361   OTHER_INCLUDES += -I$(LAUNCHER_SOLARIS_PLATFORM_SRC)/bin
 362   ifneq ($(SYSTEM_ZLIB), true)
 363     OTHER_INCLUDES += -I$(SHARE_SRC)/native/java/util/zip/zlib-1.1.3
 364   endif
 365 else
 366   OTHER_INCLUDES += -I$(SHARE_SRC)/native/java/util/zip/zlib-1.1.3
 367 endif
 368 
 369 OTHER_CPPFLAGS  += -DPROGNAME='"$(PROGRAM)"'
 370 VERSION_DEFINES += -DFULL_VERSION='"$(FULL_VERSION)"'
 371 
 372 VERSION_DEFINES += -DJDK_MAJOR_VERSION='"$(JDK_MAJOR_VERSION)"' \
 373                    -DJDK_MINOR_VERSION='"$(JDK_MINOR_VERSION)"'
 374 
 375 $(OBJDIR)/main.$(OBJECT_SUFFIX): $(LAUNCHER_SHARE_SRC)/bin/main.c
 376         @$(prep-target)
 377         $(COMPILE.c) $(CC_OBJECT_OUTPUT_FLAG)$(OBJDIR)/main.$(OBJECT_SUFFIX) \
 378                 $(VERSION_DEFINES) $<
 379 
 380 #
 381 # Default dependencies
 382 #
 383 
 384 all: build
 385 
 386 build: program
 387 
 388 debug:
 389         $(MAKE) VARIANT=DBG build
 390 
 391 fastdebug:
 392         $(MAKE) VARIANT=DBG FASTDEBUG=true build
 393 
 394 .PHONY: all build program clean clobber debug fastdebug