Library.gmk 10.3 KB
Newer Older
D
duke 已提交
1
#
X
xdono 已提交
2
# Copyright 1995-2008 Sun Microsystems, Inc.  All Rights Reserved.
D
duke 已提交
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# This code is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2 only, as
# published by the Free Software Foundation.  Sun designates this
# particular file as subject to the "Classpath" exception as provided
# by Sun in the LICENSE file that accompanied this code.
#
# This code is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
# version 2 for more details (a copy is included in the LICENSE file that
# accompanied this code).
#
# You should have received a copy of the GNU General Public License version
# 2 along with this work; if not, write to the Free Software Foundation,
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
# CA 95054 USA or visit www.sun.com if you need additional information or
# have any questions.
#

#
# Generic makefile for building shared libraries.
#

# WARNING: This file is shared with other workspaces.
#          So when it includes other files, it must use JDK_TOPDIR.
#

include $(JDK_TOPDIR)/make/common/Classes.gmk

#
# It is important to define these *after* including Classes.gmk
# in order to override the values defined inthat makefile.
#

ifeq ($(LIBRARY), fdlibm)
ifeq ($(PLATFORM),windows)
ACTUAL_LIBRARY_NAME = $(LIB_PREFIX)$(LIBRARY).$(FDDLIBM_SUFFIX)
ACTUAL_LIBRARY_DIR = $(OBJDIR)
else # PLATFORM
ACTUAL_LIBRARY_NAME = $(LIB_PREFIX)$(LIBRARY).$(ARCH).$(FDDLIBM_SUFFIX)
ACTUAL_LIBRARY_DIR = $(OBJDIR)
endif #PLATFORM
else # LIBRARY
ACTUAL_LIBRARY_NAME = $(LIB_PREFIX)$(LIBRARY).$(LIBRARY_SUFFIX)
ACTUAL_LIBRARY_DIR = $(LIB_LOCATION)
endif
ACTUAL_LIBRARY = $(ACTUAL_LIBRARY_DIR)/$(ACTUAL_LIBRARY_NAME)

library:: $(ACTUAL_LIBRARY)

FILES_o   = $(patsubst %.c,   %.$(OBJECT_SUFFIX), $(addprefix $(OBJDIR)/, $(notdir $(FILES_c))))
FILES_o  += $(patsubst %.s,   %.$(OBJECT_SUFFIX), $(addprefix $(OBJDIR)/, $(notdir $(FILES_s))))
FILES_o  += $(patsubst %.cpp, %.$(OBJECT_SUFFIX), $(addprefix $(OBJDIR)/, $(notdir $(FILES_cpp))))

ifeq ($(INCREMENTAL_BUILD),true)
FILES_d   = $(patsubst %.c,   %.$(DEPEND_SUFFIX), $(addprefix $(OBJDIR)/, $(notdir $(FILES_c))))
FILES_d  += $(patsubst %.cpp, %.$(DEPEND_SUFFIX), $(addprefix $(OBJDIR)/, $(notdir $(FILES_cpp))))
endif # INCREMENTAL_BUILD

ifeq ($(PLATFORM),solaris)
# List of all lint files, one for each .c file (only for C)
FILES_ln   = $(patsubst %.c,   %.$(LINT_SUFFIX), $(addprefix $(OBJDIR)/, $(notdir $(FILES_c))))
endif

#
# C++ libraries must be linked with CC.
#
ifdef CPLUSPLUSLIBRARY
LINKER=$(LINK.cc)
else
LINKER=$(LINK.c)
endif

# FIXUP: unpack needs the zip .o files. So we must build zip?
#     or fix unpack makefile so it uses Program.gmk.
ifneq ($(IMPORT_NATIVE_BINARIES),true)
  COMPILE_IT=true
else
  ifeq ($(LIBRARY),zip)
    COMPILE_IT=true
  else
    COMPILE_IT=false
  endif
endif

# If a Makefile has specified a pre-compiled closed src lib, just copy it.
ifdef USE_BINARY_PLUG_LIBRARY
  COMPILE_IT=false
endif

# We either need to import (copy) libraries in, or build them
ifeq ($(COMPILE_IT),true)

$(ACTUAL_LIBRARY):: $(INIT) $(TEMPDIR) $(LIBDIR) $(BINDIR) $(EXTDIR) classheaders

#
# COMPILE_APPROACH: Different approaches to compile up the native object
#   files as quickly as possible.
#   The setting of parallel works best on Unix, batch on Windows.
#

COMPILE_FILES_o = $(OBJDIR)/.files_compiled
$(COMPILE_FILES_o): $(FILES_d) $(FILES_o)
	@$(ECHO) "$<" >> $@
clean::
	$(RM) $(COMPILE_FILES_o)

#
# COMPILE_APPROACH=parallel: Will trigger compilations (just compilations) to
#   happen in parallel. Greatly decreases Unix build time, even on single CPU
#   machines, more so on multiple CPU machines. Default is 2 compiles
#   at a time, but can be adjusted with ALT_PARALLEL_COMPILE_JOBS.
#   Note that each .d file will also be dependent on it's .o file, see
#   Rules.gmk.
#   Note this does not depend on Rules.gmk to work like batch (below)
#   and this technique doesn't seem to help Windows build time nor does
#   it work very well, it's possible the Windows Visual Studio compilers
#   don't work well in a parallel situation, this needs investigation.
#

ifeq ($(COMPILE_APPROACH),parallel)

.PHONY: library_parallel_compile

library_parallel_compile:
	@$(ECHO) "Begin parallel compiles: $(shell $(PWD))"
	@$(MAKE) -j $(PARALLEL_COMPILE_JOBS) $(COMPILE_FILES_o)
	@$(ECHO) "Done with parallel compiles: $(shell $(PWD))"

$(ACTUAL_LIBRARY):: library_parallel_compile

endif

#
# COMPILE_APPROACH=batch: Will trigger compilations (just compilations) to
#   happen in batch mode. Greatly decreases Windows build time.
#   See logic in Rules.gmk for how compiles happen, the $(MAKE) in
#   library_batch_compile below triggers the actions in Rules.gmk.
#   Note that each .d file will also be dependent on it's .o file, see
#   Rules.gmk.
#
ifeq ($(COMPILE_APPROACH),batch)

.PHONY: library_batch_compile

library_batch_compile:
	@$(ECHO) "Begin BATCH compiles: $(shell $(PWD))"
	$(MAKE) $(COMPILE_FILES_o)
	$(MAKE) batch_compile
	@$(ECHO) "Done with BATCH compiles: $(shell $(PWD))"
	$(MAKE) COMPILE_APPROACH=normal $(COMPILE_FILES_o)

$(ACTUAL_LIBRARY):: library_batch_compile

endif

ifeq ($(PLATFORM), windows)

#
# Library building rules.
#

$(LIBRARY).lib:: $(OBJDIR)

ifeq ($(LIBRARY), fdlibm)
$(ACTUAL_LIBRARY):: $(OBJDIR)/$(LIBRARY).lib

$(OBJDIR)/$(LIBRARY).lib:: $(OBJDIR)/$(LIBRARY).lcf
	@$(prep-target)
	$(LIBEXE) -NODEFAULTLIB:MSVCRT -out:$@ -nologo \
		@$(OBJDIR)/$(LIBRARY).lcf $(OTHER_LCF) $(LDLIBS_COMMON)
else # LIBRARY
# build it into $(OBJDIR) so that the other generated files get put 
# there, then copy just the DLL (and MAP file) to the requested directory.
#
182 183 184
# In VS2005 or VS2008 the link command creates a .manifest file that we want
# to insert into the linked artifact so we do not need to track it separately.
# Use ";#2" for .dll and ";#1" for .exe in the MT command below:
D
duke 已提交
185 186 187 188 189 190 191
$(ACTUAL_LIBRARY):: $(OBJDIR)/$(LIBRARY).lcf
	@$(prep-target)
	@$(MKDIR) -p $(OBJDIR)
	$(LINK) -dll -out:$(OBJDIR)/$(@F) \
	  -map:$(OBJDIR)/$(LIBRARY).map \
	  $(LFLAGS) @$(OBJDIR)/$(LIBRARY).lcf \
	  $(OTHER_LCF) $(JAVALIB) $(LDLIBS)
192 193 194
ifdef MT
	$(MT) /manifest $(OBJDIR)/$(@F).manifest /outputresource:$(OBJDIR)/$(@F);#2
endif
D
duke 已提交
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209
	$(CP) $(OBJDIR)/$(@F) $@
	$(CP) $(OBJDIR)/$(LIBRARY).map $(@D)
	$(CP) $(OBJDIR)/$(LIBRARY).pdb $(@D)

endif # LIBRARY

$(OBJDIR)/$(LIBRARY).lcf: $(OBJDIR)/$(LIBRARY).res $(COMPILE_FILES_o) $(FILES_m)
	@$(prep-target)
	@$(MKDIR) -p $(TEMPDIR)
	@$(ECHO) $(FILES_o) > $@ 
ifndef LOCAL_RESOURCE_FILE
	@$(ECHO) $(OBJDIR)/$(LIBRARY).res >> $@
endif
	@$(ECHO) Created $@ 

210 211 212 213
# JDK name required here
RC_FLAGS += /D "JDK_FNAME=$(LIBRARY).dll" \
            /D "JDK_INTERNAL_NAME=$(LIBRARY)" \
            /D "JDK_FTYPE=0x2L"
D
duke 已提交
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246

$(OBJDIR)/$(LIBRARY).res: $(VERSIONINFO_RESOURCE)
ifndef LOCAL_RESOURCE_FILE
	@$(prep-target)
	$(RC) $(RC_FLAGS) $(CC_OBJECT_OUTPUT_FLAG)$(@) $(VERSIONINFO_RESOURCE)
endif

#
# Install a .lib file if required.
#
ifeq ($(INSTALL_DOT_LIB), true)
$(ACTUAL_LIBRARY):: $(LIBDIR)/$(LIBRARY).lib

clean:: 
	-$(RM) $(LIBDIR)/$(LIBRARY).lib

$(LIBDIR)/$(LIBRARY).lib:: $(OBJDIR)/$(LIBRARY).lib
	$(install-file)

$(LIBDIR)/$(LIBRARY).dll:: $(OBJDIR)/$(LIBRARY).dll
	$(install-file)

endif # INSTALL_DOT_LIB

else # PLATFORM

#
# On Solaris, use mcs to write the version into the comment section of
# the shared library.  On other platforms set this to false at the
# make command line.
#
$(ACTUAL_LIBRARY):: $(COMPILE_FILES_o) $(FILES_m) $(FILES_reorder)
	@$(prep-target)
247
	@$(ECHO) "STATS: LIBRARY=$(LIBRARY), PRODUCT=$(PRODUCT), OPTIMIZATION_LEVEL=$(OPTIMIZATION_LEVEL)"
D
duke 已提交
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357
	@$(ECHO) "Rebuilding $@ because of $?"
ifeq ($(LIBRARY), fdlibm)
	$(AR) -r $@ $(FILES_o)
else # LIBRARY
	$(LINKER) $(SHARED_LIBRARY_FLAG) -o $@ $(FILES_o) $(LDLIBS)
ifeq ($(WRITE_LIBVERSION),true)
	$(MCS) -d -a "$(FULL_VERSION)" $@
endif # WRITE_LIBVERSION
endif # LIBRARY

endif # PLATFORM

#
# Cross check all linted files against each other
#
ifeq ($(PLATFORM),solaris)
lint.errors : $(FILES_ln)
	$(LINT.c) $(FILES_ln) $(LDLIBS) 
endif

else  # COMPILE_IT

# OpenJDK rule is first so any lib is preferentially copied from that location.
ifndef USE_BINARY_PLUG_LIBRARY

# In this case we are just copying the file.
ifneq ($(LIBRARY), fdlibm)
# Copies in the file from the JDK_IMPORT_PATH area
$(ACTUAL_LIBRARY_DIR)/%: $(JDK_IMPORT_PATH)/$(ARCH_VM_SUBDIR)/%
	$(install-import-file)
$(ACTUAL_LIBRARY_DIR)/%: $(JDK_IMPORT_PATH)/$(ARCH_VM_SUBDIR)/native_threads/%
	$(install-import-file)
$(ACTUAL_LIBRARY_DIR)/%: $(JDK_IMPORT_PATH)/$(ARCH_VM_SUBDIR)/headless/%
	$(install-import-file)
$(ACTUAL_LIBRARY_DIR)/%: $(JDK_IMPORT_PATH)/$(ARCH_VM_SUBDIR)/xawt/%
	$(install-import-file)
else # fdlibm
$(ACTUAL_LIBRARY_DIR)/%:
	$(prep-target)
endif # fdlibm

endif # USE_BINARY_PLUG_LIBRARY

endif # COMPILE_IT

#
# Class libraries with JNI native methods get a include to the package.
#
ifdef PACKAGE
vpath %.c $(PLATFORM_SRC)/native/$(PKGDIR)
vpath %.c $(SHARE_SRC)/native/$(PKGDIR)
OTHER_INCLUDES += -I$(SHARE_SRC)/native/common -I$(PLATFORM_SRC)/native/common
OTHER_INCLUDES += -I$(SHARE_SRC)/native/$(PKGDIR) \
		  -I$(PLATFORM_SRC)/native/$(PKGDIR)
endif

#
# Clean/clobber rules
#
clean::
	$(RM) -r $(ACTUAL_LIBRARY)

clobber:: clean

#
# INCREMENTAL_BUILD means that this workspace will be built over and over
#   possibly incrementally. This means tracking the object file dependencies
#   on include files so that sources get re-compiled when the include files
#   change. When building from scratch and doing a one time build (like
#   release engineering or nightly builds) set INCREMENTAL_BUILD=false.
#

ifeq ($(INCREMENTAL_BUILD),true)

#
# Workaround: gnumake sometimes says files is empty when it shouldn't
#    was:  files := $(foreach file, $(wildcard $(OBJDIR)/*.$(DEPEND_SUFFIX)), $(file))
#
files := $(shell $(LS) $(OBJDIR)/*.$(DEPEND_SUFFIX) 2>/dev/null)

#
# Only include these files if we have any.
#
ifneq ($(strip $(files)),)

include $(files)

endif # files

endif # INCREMENTAL_BUILD

#
# Default dependencies
#

all: build

build: library

debug:
	$(MAKE) VARIANT=DBG build

fastdebug:
	$(MAKE) VARIANT=DBG FASTDEBUG=true build

openjdk:
	$(MAKE) OPENJDK=true build

.PHONY: all build debug fastdebug