1 #
   2 # Copyright (c) 1995, 2011, 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 ifndef LAUNCHER_PLATFORM_SRC
  42 LAUNCHER_PLATFORM_SRC = $(PLATFORM_SRC)
  43 endif
  44 
  45 ifndef LAUNCHER_SHARE_SRC
  46 LAUNCHER_SHARE_SRC = $(SHARE_SRC)
  47 endif
  48 
  49 ACTUAL_PROGRAM_NAME = $(PROGRAM)$(EXE_SUFFIX)
  50 ACTUAL_PROGRAM_DIR  = $(BINDIR)
  51 ACTUAL_PROGRAM      = $(ACTUAL_PROGRAM_DIR)/$(ACTUAL_PROGRAM_NAME)
  52 
  53 # Make sure the default rule is all
  54 program_default_rule: all
  55 
  56 program: $(ACTUAL_PROGRAM)
  57 
  58 # Work-around for missing processor specific mapfiles
  59 ifndef CROSS_COMPILE_ARCH
  60   # reuse the mapfiles in the launcher's directory, the same should
  61   # be applicable to the tool launchers as well.
  62   FILES_m = $(BUILDDIR)/java/main/java/mapfile-$(ARCH)
  63   include $(BUILDDIR)/common/Mapfile-vers.gmk
  64 endif
  65 
  66 include $(JDK_TOPDIR)/make/common/Rules.gmk
  67 
  68 ifdef NEVER_ACT_AS_SERVER_CLASS_MACHINE
  69 OTHER_CPPFLAGS += -DNEVER_ACT_AS_SERVER_CLASS_MACHINE
  70 endif
  71 
  72 #
  73 # Create a dependency on libjli (Java Launcher Infrastructure)
  74 #
  75 # On UNIX, this is a relative dependency using $ORIGIN. Unfortunately, to
  76 # do this reliably on Linux takes a different syntax than Solaris.
  77 #
  78 # On Windows, this is done by using the same directory as the executable
  79 # itself, as with all the Windows libraries.
  80 #
  81 ifneq (,$(findstring $(PLATFORM), linux solaris))       # UNIX systems
  82     LDFLAGS += -L $(LIBDIR)/$(LIBARCH)/jli
  83     OTHER_LDLIBS += -ljli
  84     ifeq ($(PLATFORM), solaris)
  85         ifeq ($(ARCH_DATA_MODEL), 32)
  86                 LDFLAGS += -R \$$ORIGIN/../lib/$(LIBARCH)/jli
  87                 LDFLAGS += -R \$$ORIGIN/../jre/lib/$(LIBARCH)/jli
  88         else
  89                 LDFLAGS += -R \$$ORIGIN/../../lib/$(LIBARCH)/jli
  90                 LDFLAGS += -R \$$ORIGIN/../../jre/lib/$(LIBARCH)/jli
  91         endif
  92     endif
  93     ifeq ($(PLATFORM), linux)
  94         LDFLAGS += $(LDFLAG_Z_ORIGIN)
  95         LDFLAGS += -Wl,--allow-shlib-undefined
  96         LDFLAGS += -Wl,-rpath -Wl,\$$ORIGIN/../lib/$(LIBARCH)/jli
  97         LDFLAGS += -Wl,-rpath -Wl,\$$ORIGIN/../jre/lib/$(LIBARCH)/jli
  98     endif
  99 endif
 100 ifeq ($(PLATFORM), windows)
 101         JLI_LCF = $(OUTPUTDIR)/tmp/java/jli/$(OBJDIRNAME)/jli.lcf
 102         ifdef STATIC_JLI
 103             LDFLAGS += -libpath:$(OUTPUTDIR)/tmp/java/jli/$(OBJDIRNAME)/static
 104         else
 105             LDFLAGS += -libpath:$(OUTPUTDIR)/tmp/java/jli/$(OBJDIRNAME)
 106         endif
 107         OTHER_LDLIBS += jli.lib
 108 endif
 109 
 110 #
 111 # Launcher specific files.
 112 #
 113 FILES_o = \
 114         $(OBJDIR)/main.$(OBJECT_SUFFIX)
 115 
 116 $(ACTUAL_PROGRAM):: classes $(INIT)
 117 
 118 #
 119 # Windows only
 120 #
 121 ifeq ($(PLATFORM), windows)
 122 
 123 # JDK name required here
 124 RC_FLAGS += /D "JDK_FNAME=$(PROGRAM)$(EXE_SUFFIX)" \
 125             /D "JDK_INTERNAL_NAME=$(PROGRAM)" \
 126             /D "JDK_FTYPE=0x1L"
 127 
 128 $(OBJDIR)/$(PROGRAM).res: $(VERSIONINFO_RESOURCE)
 129         @$(prep-target)
 130 ifndef LOCAL_RESOURCE_FILE
 131         $(RC) $(RC_FLAGS) $(CC_OBJECT_OUTPUT_FLAG)$(@) $(VERSIONINFO_RESOURCE)
 132 endif
 133 
 134 $(OBJDIR)/$(PROGRAM).lcf: $(OBJDIR)/$(PROGRAM).res $(FILES_o)
 135         @$(prep-target)
 136         @$(ECHO) $(FILES_o) > $@
 137   ifndef LOCAL_RESOURCE_FILE
 138         @$(ECHO) $(OBJDIR)/$(PROGRAM).res >> $@
 139   endif
 140         @$(ECHO) setargv.obj >> $@
 141         @$(ECHO) Created $@
 142 
 143 #$(ACTUAL_PROGRAM):: $(OBJDIR)/$(PROGRAM)$(EXE_SUFFIX)
 144 #       @$(install-non-module-file)
 145 #       @$(install-module-cmd-file)
 146 
 147 $(ACTUAL_PROGRAM):: $(OBJDIR)/$(PROGRAM)$(EXE_SUFFIX)
 148         @$(install-cmd-file)
 149 
 150 ifeq ($(ARCH_DATA_MODEL), 32)
 151   STACK_SIZE=327680
 152 else
 153 # We need more Stack for Windows 64bit
 154   STACK_SIZE=1048576
 155 endif
 156 
 157 IMVERSION=$(JDK_MINOR_VERSION).$(JDK_MICRO_VERSION).$(JDK_UPDATE_VER).$(COOKED_BUILD_NUMBER)
 158 $(OBJDIR)/$(PROGRAM).exe.manifest: $(JDK_TOPDIR)/src/windows/resource/java.manifest
 159         @$(prep-target)
 160         $(SED) 's%IMVERSION%$(IMVERSION)%g;s%PROGRAM%$(PROGRAM)%g' $< > $@
 161 
 162 # We used a hand-crafted manifest file for all executables.
 163 # It is tweaked to embed the build number and executable name.
 164 # Use ";#2" for .dll and ";#1" for .exe in the MT command below:
 165 $(OBJDIR)/$(PROGRAM)$(EXE_SUFFIX):: $(OBJDIR)/$(PROGRAM).lcf $(FILES_o) $(JLI_LCF) $(OBJDIR)/$(PROGRAM).exe.manifest
 166         @$(prep-target)
 167         @set -- $?; \
 168             $(ECHO) Rebuilding $@ because of $$1 $$2 $$3 $$4 $$5 $$6 $${7:+...};
 169         $(LINK) -out:$@ /STACK:$(STACK_SIZE) \
 170             -map:$(OBJDIR)/$(PROGRAM).map $(LFLAGS) $(LDFLAGS) \
 171             @$(OBJDIR)/$(PROGRAM).lcf $(LDLIBS)
 172 ifdef MT
 173         $(MT) /manifest $(OBJDIR)/$(PROGRAM).exe.manifest /outputresource:$@;#1
 174 endif
 175         @$(call binary_file_verification,$@)
 176 
 177 else # PLATFORM
 178 
 179 #
 180 # Note that we have to link -lthread even when USE_PTHREADS is true.
 181 # This is becuase checkForCorrectLibthread() croaks otherwise.
 182 #
 183 LIBTHREAD = -lthread
 184 ifeq ($(USE_PTHREADS),true)
 185   THREADLIBS = -lpthread $(LIBTHREAD)
 186 else # USE_PTHREADS
 187   THREADLIBS = $(LIBTHREAD)
 188 endif # USE_PTHREADS
 189 
 190 #
 191 # This rule only applies on unix.  It supports quantify and its ilk.
 192 #
 193 $(ACTUAL_PROGRAM):: $(FILES_o)
 194         @$(prep-target)
 195         @set -- $?; \
 196             $(ECHO) Rebuilding $@ because of $$1 $$2 $$3 $$4 $$5 $$6 $${7:+...};
 197         @$(MKDIR) -p $(TEMPDIR)
 198         $(LINK_PRE_CMD) $(CC) $(CC_OBJECT_OUTPUT_FLAG)$@ $(LDFLAGS) \
 199             $(FILES_o) $(THREADLIBS) $(LDLIBS)
 200         @$(call binary_file_verification,$@)
 201         $(install-module-file)
 202 
 203 endif # PLATFORM
 204 
 205 clean::
 206 ifeq ($(PLATFORM), windows)
 207         $(RM) $(OBJDIR)/$(PROGRAM).rc
 208         $(RM) $(OBJDIR)/$(PROGRAM).ico
 209         $(RM) $(OBJDIR)/$(PROGRAM).lcf
 210         $(RM) $(OBJDIR)/$(PROGRAM).map
 211         $(RM) $(OBJDIR)/$(PROGRAM).exp
 212         $(RM) $(OBJDIR)/$(PROGRAM).lib
 213         $(RM) $(OBJDIR)/$(PROGRAM)$(EXE_SUFFIX)
 214         $(RM) $(OBJDIR)/$(PROGRAM).ilk
 215         $(RM) *.pdb
 216 endif
 217 
 218 
 219 clobber::
 220         $(RM) $(ACTUAL_PROGRAM)
 221 
 222 #
 223 # Now include make dependencies (created during compilation, see Rules.gmk)
 224 #
 225 ifeq ($(INCREMENTAL_BUILD),true)
 226 # Workaround: gnumake sometimes says files is empty when it shouldn't
 227 #    was:  files := $(foreach file, $(wildcard */$(ARCH)/*.$(DEPEND_SUFFIX)), $(file))
 228 files := $(shell $(LS) $(OBJDIR)/*.$(DEPEND_SUFFIX) 2>/dev/null)
 229 ifneq ($(strip $(files)),)
 230 include $(files)
 231 endif # files
 232 endif # INCREMENTAL_BUILD
 233 
 234 ifdef JAVA_ARGS
 235 OTHER_CPPFLAGS += -DJAVA_ARGS='$(JAVA_ARGS)'
 236 OTHER_CPPFLAGS += -DLAUNCHER_NAME='"$(LAUNCHER_NAME)"'
 237 endif
 238 
 239 ifdef PROGRAM_MODULE
 240 OTHER_CPPFLAGS += -DMODULE_NAME='"$(PROGRAM_MODULE)"'
 241 OTHER_CPPFLAGS += -DMODULE_VERSION='"$(MODULE_VERSION)"'
 242 endif
 243 
 244 ifeq ($(PLATFORM), windows)
 245 ifdef RELEASE
 246 OTHER_CPPFLAGS += -DVERSION='"$(RELEASE)"'
 247 endif
 248 endif
 249 
 250 
 251 ifneq ($(PLATFORM), windows)
 252 HAVE_GETHRTIME=true
 253 endif
 254 
 255 ifeq ($(HAVE_GETHRTIME),true)
 256 OTHER_CPPFLAGS += -DHAVE_GETHRTIME
 257 endif
 258 
 259 OTHER_INCLUDES += -I$(LAUNCHER_SHARE_SRC)/bin -I$(LAUNCHER_PLATFORM_SRC)/bin
 260 OTHER_INCLUDES += -I$(SHARE_SRC)/native/java/util/zip/zlib-1.1.3
 261 
 262 OTHER_CPPFLAGS += -DPROGNAME='"$(PROGRAM)"'
 263 VERSION_DEFINES += -DFULL_VERSION='"$(FULL_VERSION)"'
 264 
 265 VERSION_DEFINES += -DJDK_MAJOR_VERSION='"$(JDK_MAJOR_VERSION)"' \
 266                    -DJDK_MINOR_VERSION='"$(JDK_MINOR_VERSION)"'
 267 
 268 
 269 
 270 $(OBJDIR)/main.$(OBJECT_SUFFIX): $(LAUNCHER_SHARE_SRC)/bin/main.c
 271         @$(prep-target)
 272         $(COMPILE.c) $(CC_OBJECT_OUTPUT_FLAG)$(OBJDIR)/main.$(OBJECT_SUFFIX) \
 273                 $(VERSION_DEFINES) $<
 274 
 275 #
 276 # Default dependencies
 277 #
 278 
 279 all: build
 280 
 281 build: program
 282 
 283 debug:
 284         $(MAKE) VARIANT=DBG build
 285 
 286 fastdebug:
 287         $(MAKE) VARIANT=DBG FASTDEBUG=true build
 288 
 289 .PHONY: all build program clean clobber debug fastdebug