1 #
   2 # Copyright (c) 1995, 2008, 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 shared libraries.
  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 include $(JDK_TOPDIR)/make/common/Classes.gmk
  35 
  36 #
  37 # It is important to define these *after* including Classes.gmk
  38 # in order to override the values defined inthat makefile.
  39 #
  40 
  41 ifeq ($(LIBRARY), fdlibm)
  42 ifeq ($(PLATFORM),windows)
  43 ACTUAL_LIBRARY_NAME = $(LIB_PREFIX)$(LIBRARY).$(FDDLIBM_SUFFIX)
  44 ACTUAL_LIBRARY_DIR = $(OBJDIR)
  45 else # PLATFORM
  46 ACTUAL_LIBRARY_NAME = $(LIB_PREFIX)$(LIBRARY).$(ARCH).$(FDDLIBM_SUFFIX)
  47 ACTUAL_LIBRARY_DIR = $(OBJDIR)
  48 endif #PLATFORM
  49 else # LIBRARY
  50 ACTUAL_LIBRARY_NAME = $(LIB_PREFIX)$(LIBRARY).$(LIBRARY_SUFFIX)
  51 ACTUAL_LIBRARY_DIR = $(LIB_LOCATION)
  52 endif
  53 ACTUAL_LIBRARY = $(ACTUAL_LIBRARY_DIR)/$(ACTUAL_LIBRARY_NAME)
  54 
  55 library:: $(ACTUAL_LIBRARY)
  56         $(TouchModule)
  57 
  58 FILES_o   = $(patsubst %.c,   %.$(OBJECT_SUFFIX), $(addprefix $(OBJDIR)/, $(notdir $(FILES_c))))
  59 FILES_o  += $(patsubst %.s,   %.$(OBJECT_SUFFIX), $(addprefix $(OBJDIR)/, $(notdir $(FILES_s))))
  60 FILES_o  += $(patsubst %.cpp, %.$(OBJECT_SUFFIX), $(addprefix $(OBJDIR)/, $(notdir $(FILES_cpp))))
  61 
  62 ifeq ($(INCREMENTAL_BUILD),true)
  63 FILES_d   = $(patsubst %.c,   %.$(DEPEND_SUFFIX), $(addprefix $(OBJDIR)/, $(notdir $(FILES_c))))
  64 FILES_d  += $(patsubst %.cpp, %.$(DEPEND_SUFFIX), $(addprefix $(OBJDIR)/, $(notdir $(FILES_cpp))))
  65 endif # INCREMENTAL_BUILD
  66 
  67 ifeq ($(PLATFORM),solaris)
  68 # List of all lint files, one for each .c file (only for C)
  69 FILES_ln   = $(patsubst %.c,   %.$(LINT_SUFFIX), $(addprefix $(OBJDIR)/, $(notdir $(FILES_c))))
  70 endif
  71 
  72 #
  73 # C++ libraries must be linked with CC.
  74 #
  75 ifdef CPLUSPLUSLIBRARY
  76 LINKER=$(LINK.cc)
  77 else
  78 LINKER=$(LINK.c)
  79 endif
  80 
  81 # FIXUP: unpack needs the zip .o files. So we must build zip?
  82 #     or fix unpack makefile so it uses Program.gmk.
  83 ifneq ($(IMPORT_NATIVE_BINARIES),true)
  84   COMPILE_IT=true
  85 else
  86   ifeq ($(LIBRARY),zip)
  87     COMPILE_IT=true
  88   else
  89     COMPILE_IT=false
  90   endif
  91 endif
  92 
  93 # If a Makefile has specified a pre-compiled closed src lib, just copy it.
  94 ifdef USE_BINARY_PLUG_LIBRARY
  95   COMPILE_IT=false
  96 endif
  97 
  98 # We either need to import (copy) libraries in, or build them
  99 ifeq ($(COMPILE_IT),true)
 100 
 101 $(ACTUAL_LIBRARY):: $(INIT) $(TEMPDIR) $(LIBDIR) $(BINDIR) $(EXTDIR) classheaders
 102 
 103 #
 104 # COMPILE_APPROACH: Different approaches to compile up the native object
 105 #   files as quickly as possible.
 106 #   The setting of parallel works best on Unix, batch on Windows.
 107 #
 108 
 109 COMPILE_FILES_o = $(OBJDIR)/.files_compiled
 110 $(COMPILE_FILES_o): $(FILES_d) $(FILES_o)
 111         @$(ECHO) "$<" >> $@
 112 clean::
 113         $(RM) $(COMPILE_FILES_o)
 114 
 115 #
 116 # COMPILE_APPROACH=parallel: Will trigger compilations (just compilations) to
 117 #   happen in parallel. Greatly decreases Unix build time, even on single CPU
 118 #   machines, more so on multiple CPU machines. Default is 2 compiles
 119 #   at a time, but can be adjusted with ALT_PARALLEL_COMPILE_JOBS.
 120 #   Note that each .d file will also be dependent on it's .o file, see
 121 #   Rules.gmk.
 122 #   Note this does not depend on Rules.gmk to work like batch (below)
 123 #   and this technique doesn't seem to help Windows build time nor does
 124 #   it work very well, it's possible the Windows Visual Studio compilers
 125 #   don't work well in a parallel situation, this needs investigation.
 126 #
 127 
 128 ifeq ($(COMPILE_APPROACH),parallel)
 129 
 130 .PHONY: library_parallel_compile
 131 
 132 library_parallel_compile:
 133         @$(ECHO) "Begin parallel compiles: $(shell $(PWD))"
 134         @$(MAKE) -j $(PARALLEL_COMPILE_JOBS) $(COMPILE_FILES_o)
 135         @$(ECHO) "Done with parallel compiles: $(shell $(PWD))"
 136 
 137 $(ACTUAL_LIBRARY):: library_parallel_compile
 138 
 139 endif
 140 
 141 #
 142 # COMPILE_APPROACH=batch: Will trigger compilations (just compilations) to
 143 #   happen in batch mode. Greatly decreases Windows build time.
 144 #   See logic in Rules.gmk for how compiles happen, the $(MAKE) in
 145 #   library_batch_compile below triggers the actions in Rules.gmk.
 146 #   Note that each .d file will also be dependent on it's .o file, see
 147 #   Rules.gmk.
 148 #
 149 ifeq ($(COMPILE_APPROACH),batch)
 150 
 151 .PHONY: library_batch_compile
 152 
 153 library_batch_compile:
 154         @$(ECHO) "Begin BATCH compiles: $(shell $(PWD))"
 155         $(MAKE) $(COMPILE_FILES_o)
 156         $(MAKE) batch_compile
 157         @$(ECHO) "Done with BATCH compiles: $(shell $(PWD))"
 158         $(MAKE) COMPILE_APPROACH=normal $(COMPILE_FILES_o)
 159 
 160 $(ACTUAL_LIBRARY):: library_batch_compile
 161 
 162 endif
 163 
 164 ifeq ($(PLATFORM), windows)
 165 
 166 #
 167 # Library building rules.
 168 #
 169 
 170 $(LIBRARY).lib:: $(OBJDIR)
 171 
 172 ifeq ($(LIBRARY), fdlibm)
 173 $(ACTUAL_LIBRARY):: $(OBJDIR)/$(LIBRARY).lib
 174 
 175 $(OBJDIR)/$(LIBRARY).lib:: $(OBJDIR)/$(LIBRARY).lcf
 176         @$(prep-target)
 177         $(LIBEXE) -NODEFAULTLIB:MSVCRT -out:$@ -nologo \
 178                 @$(OBJDIR)/$(LIBRARY).lcf $(OTHER_LCF) $(LDLIBS_COMMON)
 179 else # LIBRARY
 180 # build it into $(OBJDIR) so that the other generated files get put 
 181 # there, then copy just the DLL (and MAP file) to the requested directory.
 182 #
 183 # In VS2005 or VS2008 the link command creates a .manifest file that we want
 184 # to insert into the linked artifact so we do not need to track it separately.
 185 # Use ";#2" for .dll and ";#1" for .exe in the MT command below:
 186 $(ACTUAL_LIBRARY):: $(OBJDIR)/$(LIBRARY).lcf
 187         @$(prep-target)
 188         @$(MKDIR) -p $(OBJDIR)
 189         $(LINK) -dll -out:$(OBJDIR)/$(@F) \
 190           -map:$(OBJDIR)/$(LIBRARY).map \
 191           $(LFLAGS) @$(OBJDIR)/$(LIBRARY).lcf \
 192           $(OTHER_LCF) $(JAVALIB) $(LDLIBS)
 193 ifdef MT
 194         $(MT) /manifest $(OBJDIR)/$(@F).manifest /outputresource:$(OBJDIR)/$(@F);#2
 195 endif
 196         $(CP) $(OBJDIR)/$(@F) $@
 197         $(install-module-file)
 198         $(CP) $(OBJDIR)/$(LIBRARY).map $(@D)
 199         $(CP) $(OBJDIR)/$(LIBRARY).pdb $(@D)
 200 
 201 $(ACTUAL_LIBRARY):: $(ACTUAL_LIBRARY_DIR)/$(LIBRARY).map $(ACTUAL_LIBRARY_DIR)/$(LIBRARY).pdb
 202 
 203 $(ACTUAL_LIBRARY_DIR)/%.map: FORCE
 204         $(install-module-file)
 205 
 206 $(ACTUAL_LIBRARY_DIR)/%.pdb: FORCE
 207         $(install-module-file)
 208 
 209 endif # LIBRARY
 210 
 211 $(OBJDIR)/$(LIBRARY).lcf: $(OBJDIR)/$(LIBRARY).res $(COMPILE_FILES_o) $(FILES_m)
 212         @$(prep-target)
 213         @$(MKDIR) -p $(TEMPDIR)
 214         @$(ECHO) $(FILES_o) > $@ 
 215 ifndef LOCAL_RESOURCE_FILE
 216         @$(ECHO) $(OBJDIR)/$(LIBRARY).res >> $@
 217 endif
 218         @$(ECHO) Created $@ 
 219 
 220 # JDK name required here
 221 RC_FLAGS += /D "JDK_FNAME=$(LIBRARY).dll" \
 222             /D "JDK_INTERNAL_NAME=$(LIBRARY)" \
 223             /D "JDK_FTYPE=0x2L"
 224 
 225 $(OBJDIR)/$(LIBRARY).res: $(VERSIONINFO_RESOURCE)
 226 ifndef LOCAL_RESOURCE_FILE
 227         @$(prep-target)
 228         $(RC) $(RC_FLAGS) $(CC_OBJECT_OUTPUT_FLAG)$(@) $(VERSIONINFO_RESOURCE)
 229 endif
 230 
 231 #
 232 # Install a .lib file if required.
 233 #
 234 ifeq ($(INSTALL_DOT_LIB), true)
 235 $(ACTUAL_LIBRARY):: $(LIBDIR)/$(LIBRARY).lib
 236 
 237 clean:: 
 238         -$(RM) $(LIBDIR)/$(LIBRARY).lib
 239 
 240 $(LIBDIR)/$(LIBRARY).lib:: $(OBJDIR)/$(LIBRARY).lib
 241         $(install-file)
 242 
 243 $(LIBDIR)/$(LIBRARY).dll:: $(OBJDIR)/$(LIBRARY).dll
 244         $(install-file)
 245 
 246 endif # INSTALL_DOT_LIB
 247 
 248 else # PLATFORM
 249 
 250 #
 251 # On Solaris, use mcs to write the version into the comment section of
 252 # the shared library.  On other platforms set this to false at the
 253 # make command line.
 254 #
 255 $(ACTUAL_LIBRARY):: $(COMPILE_FILES_o) $(FILES_m) $(FILES_reorder)
 256         @$(prep-target)
 257         @$(ECHO) "STATS: LIBRARY=$(LIBRARY), PRODUCT=$(PRODUCT), OPTIMIZATION_LEVEL=$(OPTIMIZATION_LEVEL)"
 258         @$(ECHO) "Rebuilding $@ because of $?"
 259 ifeq ($(LIBRARY), fdlibm)
 260         $(AR) -r $@ $(FILES_o)
 261 else # LIBRARY
 262         $(LINKER) $(SHARED_LIBRARY_FLAG) -o $@ $(FILES_o) $(LDLIBS)
 263         $(install-module-file)
 264 ifeq ($(WRITE_LIBVERSION),true)
 265         $(MCS) -d -a "$(FULL_VERSION)" $@
 266 endif # WRITE_LIBVERSION
 267 endif # LIBRARY
 268 
 269 endif # PLATFORM
 270 
 271 #
 272 # Cross check all linted files against each other
 273 #
 274 ifeq ($(PLATFORM),solaris)
 275 lint.errors : $(FILES_ln)
 276         $(LINT.c) $(FILES_ln) $(LDLIBS) 
 277 endif
 278 
 279 else  # COMPILE_IT
 280 
 281 # OpenJDK rule is first so any lib is preferentially copied from that location.
 282 ifndef USE_BINARY_PLUG_LIBRARY
 283 
 284 # In this case we are just copying the file.
 285 ifneq ($(LIBRARY), fdlibm)
 286 # Copies in the file from the JDK_IMPORT_PATH area
 287 $(ACTUAL_LIBRARY_DIR)/%: $(JDK_IMPORT_PATH)/$(ARCH_VM_SUBDIR)/%
 288         $(install-import-file)
 289 $(ACTUAL_LIBRARY_DIR)/%: $(JDK_IMPORT_PATH)/$(ARCH_VM_SUBDIR)/native_threads/%
 290         $(install-import-file)
 291 $(ACTUAL_LIBRARY_DIR)/%: $(JDK_IMPORT_PATH)/$(ARCH_VM_SUBDIR)/headless/%
 292         $(install-import-file)
 293 $(ACTUAL_LIBRARY_DIR)/%: $(JDK_IMPORT_PATH)/$(ARCH_VM_SUBDIR)/xawt/%
 294         $(install-import-file)
 295 else # fdlibm
 296 $(ACTUAL_LIBRARY_DIR)/%:
 297         $(prep-target)
 298 endif # fdlibm
 299 
 300 endif # USE_BINARY_PLUG_LIBRARY
 301 
 302 endif # COMPILE_IT
 303 
 304 #
 305 # Class libraries with JNI native methods get a include to the package.
 306 #
 307 ifdef PACKAGE
 308 vpath %.c $(PLATFORM_SRC)/native/$(PKGDIR)
 309 vpath %.c $(SHARE_SRC)/native/$(PKGDIR)
 310 OTHER_INCLUDES += -I$(SHARE_SRC)/native/common -I$(PLATFORM_SRC)/native/common
 311 OTHER_INCLUDES += -I$(SHARE_SRC)/native/$(PKGDIR) \
 312                   -I$(PLATFORM_SRC)/native/$(PKGDIR)
 313 endif
 314 
 315 #
 316 # Clean/clobber rules
 317 #
 318 clean::
 319         $(RM) -r $(ACTUAL_LIBRARY)
 320 
 321 clobber:: clean
 322 
 323 #
 324 # INCREMENTAL_BUILD means that this workspace will be built over and over
 325 #   possibly incrementally. This means tracking the object file dependencies
 326 #   on include files so that sources get re-compiled when the include files
 327 #   change. When building from scratch and doing a one time build (like
 328 #   release engineering or nightly builds) set INCREMENTAL_BUILD=false.
 329 #
 330 
 331 ifeq ($(INCREMENTAL_BUILD),true)
 332 
 333 #
 334 # Workaround: gnumake sometimes says files is empty when it shouldn't
 335 #    was:  files := $(foreach file, $(wildcard $(OBJDIR)/*.$(DEPEND_SUFFIX)), $(file))
 336 #
 337 files := $(shell $(LS) $(OBJDIR)/*.$(DEPEND_SUFFIX) 2>/dev/null)
 338 
 339 #
 340 # Only include these files if we have any.
 341 #
 342 ifneq ($(strip $(files)),)
 343 
 344 include $(files)
 345 
 346 endif # files
 347 
 348 endif # INCREMENTAL_BUILD
 349 
 350 #
 351 # Default dependencies
 352 #
 353 
 354 all: build
 355 
 356 build: library
 357 
 358 debug:
 359         $(MAKE) VARIANT=DBG build
 360 
 361 fastdebug:
 362         $(MAKE) VARIANT=DBG FASTDEBUG=true build
 363 
 364 openjdk:
 365         $(MAKE) OPENJDK=true build
 366 
 367 FORCE:
 368 
 369 .PHONY: all build debug fastdebug
 370