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