1 # 2 # Copyright (c) 2004, 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 # JDK Demo building jar file. 27 28 # Some names are defined with LIBRARY inside the Defs.gmk file 29 LIBRARY=$(DEMONAME) 30 OBJDIR=$(TEMPDIR)/$(DEMONAME) 31 32 # Input: 33 # DEMONAME - name of the demo 34 # DEMO_ROOT - path to root of all demo files 35 # DEMO_DESTDIR - path to final demo destination directory 36 # 37 # Optional Input: 38 # DEMO_SRCDIR - path to source if different from DEMO_ROOT 39 # DEMO_PSRCDIR - path to additional platform specific source 40 # DEMO_PKGDIR - sub directory of sources we want 41 # DEMO_TOPFILES - names of top-level files relative to DEMO_ROOT 42 # DEMO_MAINCLASS - name of the main class for the jar manifest 43 # DEMO_NATIVECLASS - name of the class with native methods 44 # DEMO_DESCRIPTOR - name of service file for jar (relative to DEMO_SRCDIR) 45 # DEMO_EXTRA_SRCDIR - path to directory that holds extra sources to add 46 # DEMO_EXTRA_FILES - extra sources relative to DEMO_EXTRA_SRCDIR 47 # DEMO_OBJECTS - extra native object files needed 48 # DEMO_MANIFEST_ATTR - extra line to add to the jar manifest file 49 50 # Assume the source directory is the root directory if not set 51 ifndef DEMO_SRCDIR 52 DEMO_SRCDIR = $(DEMO_ROOT) 53 endif 54 ifndef DEMO_PKGDIR 55 DEMO_PKGDIR = . 56 endif 57 58 # Some demos have special needs 59 ifneq ($(DEMONAME),agent_util) 60 DEMO_NEEDS_AGENT_UTIL = $(findstring agent_util,$(DEMO_OBJECTS)) 61 endif 62 ifneq ($(DEMONAME),java_crw_demo) 63 DEMO_NEEDS_JAVA_CRW_DEMO = $(findstring java_crw_demo,$(DEMO_OBJECTS)) 64 endif 65 ifeq ($(DEMONAME),hprof) 66 DEMO_NEEDS_NPT = true 67 endif 68 69 # Place to hold the build area (kind of a temp area) 70 DEMO_BUILD_AREA = $(DEMOCLASSDIR)/$(PRODUCT)/$(DEMONAME) 71 72 # Destination "src" directory 73 DEMO_BUILD_SRCDIR = $(DEMO_BUILD_AREA)/src 74 75 ifndef DEMO_SKIP_SRCZIP 76 DEMO_BUILD_SRCZIP = $(DEMO_BUILD_AREA)/src.zip 77 DEMO_SOURCE_ZIP = $(DEMO_DESTDIR)/src.zip 78 endif 79 80 # Place to hold the jar image we are creating 81 DEMO_JAR_IMAGE = $(DEMO_BUILD_AREA)/jar_image 82 83 # The jar manifest file we will create and use 84 DEMO_MANIFEST = $(DEMO_BUILD_AREA)/manifest.mf 85 86 # The list of source files or options we will supply to javac 87 DEMO_JAVAC_INPUT = $(DEMO_BUILD_AREA)/javac_input.txt 88 89 # Any name of javah file 90 DEMO_JAVAH_FILE = $(DEMO_NATIVECLASS:%=$(DEMO_BUILD_SRCDIR)/%.h) 91 92 # Get complete list of files for this demo 93 ifdef DEMO_PSRCDIR 94 DEMO_ALL_FILES2 := $(shell ( $(CD) $(DEMO_PSRCDIR) \ 95 && $(FIND) $(DEMO_PKGDIR) $(SCM_DIRS_prune) -o -type f -print ) \ 96 | $(SED) 's@^\./@@' ) 97 DEMO_ALL_FILES += $(DEMO_ALL_FILES2) 98 endif 99 ifdef DEMO_EXTRA_SRCDIR 100 DEMO_ALL_FILES += $(DEMO_EXTRA_FILES) 101 endif 102 DEMO_ALL_FILES1 := $(shell ( $(CD) $(DEMO_SRCDIR) \ 103 && $(FIND) $(DEMO_PKGDIR) $(SCM_DIRS_prune) -o -type f -print ) \ 104 | $(SED) 's@^\./@@' ) 105 DEMO_ALL_FILES += $(DEMO_ALL_FILES1) 106 107 # Just the java sources 108 DEMO_JAVA_SOURCES = $(filter %.java,$(DEMO_ALL_FILES)) 109 110 # Just the C and C++ sources 111 DEMO_C_SRC_FILES = $(filter %.c,$(DEMO_ALL_FILES)) 112 DEMO_CPP_SRC_FILES = $(filter %.cpp,$(DEMO_ALL_FILES)) 113 114 # All the native source files 115 DEMO_ALL_NATIVE_SOURCES = $(DEMO_C_SRC_FILES) 116 DEMO_ALL_NATIVE_SOURCES += $(DEMO_CPP_SRC_FILES) 117 DEMO_ALL_NATIVE_SOURCES += $(filter %.h,$(DEMO_ALL_FILES)) 118 DEMO_ALL_NATIVE_SOURCES += $(filter %.hpp,$(DEMO_ALL_FILES)) 119 120 # If we have java sources, then define the jar file we will create 121 ifndef DEMO_JAR_NAME 122 DEMO_JAR_NAME = $(DEMONAME).jar 123 endif 124 ifneq ($(strip $(DEMO_JAVA_SOURCES)),) 125 DEMO_JAR = $(DEMO_DESTDIR)/$(DEMO_JAR_NAME) 126 endif 127 128 # If we have native sources, define the native library we will create 129 ifneq ($(strip $(DEMO_ALL_NATIVE_SOURCES)),) 130 # Path to native library we will create 131 DEMO_LIBRARY = \ 132 $(DEMO_DESTDIR)/lib$(ISA_DIR)/$(LIB_PREFIX)$(DEMONAME).$(LIBRARY_SUFFIX) 133 # C and C++ compiler flags we need to add to standard flags 134 DEMO_CPPFLAGS += -I$(DEMO_BUILD_SRCDIR) 135 # If the npt library is used we need to find the npt.h file 136 ifneq ($(DEMO_NEEDS_NPT),) 137 # The npt library is delivered as part of the JRE 138 DEMO_CPPFLAGS += -I$(SHARE_SRC)/npt -I$(PLATFORM_SRC)/npt 139 endif 140 # Is the shared agent_util code needed 141 ifneq ($(DEMO_NEEDS_AGENT_UTIL),) 142 DEMO_FULL_SOURCES += $(DEMO_BUILD_SRCDIR)/agent_util.c 143 DEMO_FULL_SOURCES += $(DEMO_BUILD_SRCDIR)/agent_util.h 144 endif 145 # Is the shared java_crw_demo code needed 146 ifneq ($(DEMO_NEEDS_JAVA_CRW_DEMO),) 147 DEMO_FULL_SOURCES += $(DEMO_BUILD_SRCDIR)/java_crw_demo.c 148 DEMO_FULL_SOURCES += $(DEMO_BUILD_SRCDIR)/java_crw_demo.h 149 endif 150 # All the native object files we need to build the library 151 DEMO_OBJECTS += $(DEMO_C_SRC_FILES:%.c=%.$(OBJECT_SUFFIX)) \ 152 $(DEMO_CPP_SRC_FILES:%.cpp=%.$(OBJECT_SUFFIX)) 153 # Linking is special depending on whether we had C++ code or on windows 154 DEMO_NEEDS_CPP = $(strip $(DEMO_CPP_SRC_FILES)) 155 CPPFLAGS += $(DEMO_CPPFLAGS) 156 ifeq ($(PLATFORM),windows) 157 # Note: This is a link with cl.exe, not link.exe, options differ quite 158 # bit between them. 159 LINK.demo = $(LINK.c) 160 LDLIBS.demo = $(EXTRA_LIBS) $(LFLAGS_$(COMPILER_VERSION)) 161 DEMO_VERSION_INFO = $(OBJDIR)/$(LIBRARY).res 162 LDLIBS.demo += $(DEMO_VERSION_INFO) 163 else 164 ifneq ($(DEMO_NEEDS_CPP),) 165 LINK.demo = $(LINK.cpp) 166 LDLIBS.demo = $(LIBCXX) 167 ifeq ($(PLATFORM),solaris) 168 LDLIBS.demo += -lc 169 endif 170 else 171 LINK.demo = $(LINK.c) 172 LDLIBS.demo = $(LDLIBS) 173 endif 174 endif 175 endif 176 177 # Files that are considered resources (need to be in the jar file) 178 DEMO_RESOURCES += $(filter-out %.java,$(DEMO_ALL_FILES)) 179 180 # All destination files (top level readme files and all sources) 181 # Note: We exclude the topfiles from the src tree. 182 DEMO_DEST_TOPFILES = $(DEMO_TOPFILES:%=$(DEMO_DESTDIR)/%) 183 DEMO_FILTERED_SOURCES = $(filter-out $(DEMO_TOPFILES),$(DEMO_ALL_FILES)) 184 DEMO_FULL_SOURCES += $(DEMO_FILTERED_SOURCES:%=$(DEMO_BUILD_SRCDIR)/%) 185 186 # Default rule 187 all: build demo_info 188 189 # Used to populate the destination directories 190 $(DEMO_DESTDIR)/%: $(DEMO_ROOT)/% 191 $(install-file) 192 ifneq ($(DEMO_SRCDIR),$(DEMO_ROOT)) 193 $(DEMO_DESTDIR)/%: $(DEMO_SRCDIR)/% 194 $(install-file) 195 endif 196 $(DEMO_BUILD_SRCDIR)/%: $(DEMO_SRCDIR)/% 197 $(install-file) 198 ifdef DEMO_PSRCDIR 199 $(DEMO_BUILD_SRCDIR)/%: $(DEMO_PSRCDIR)/% 200 $(install-file) 201 endif 202 ifdef DEMO_EXTRA_SRCDIR 203 $(DEMO_BUILD_SRCDIR)/%: $(DEMO_EXTRA_SRCDIR)/% 204 $(install-file) 205 endif 206 ifneq ($(DEMO_NEEDS_AGENT_UTIL),) 207 $(DEMO_BUILD_SRCDIR)/%: $(DEMO_SRCDIR)/../agent_util/% 208 $(install-file) 209 endif 210 ifneq ($(DEMO_NEEDS_JAVA_CRW_DEMO),) 211 $(DEMO_BUILD_SRCDIR)/%: $(DEMO_SRCDIR)/../java_crw_demo/% 212 $(install-file) 213 endif 214 215 # Jar manifest file 216 MAINMANIFEST = $(JDK_TOPDIR)/make/tools/manifest.mf 217 $(DEMO_MANIFEST): $(MAINMANIFEST) 218 @$(prep-target) 219 $(SED) -e "s#@@RELEASE@@#$(RELEASE)#" \ 220 -e "s#@@COMPANY_NAME@@#$(COMPANY_NAME)#" \ 221 $(MAINMANIFEST) >> $@ 222 $(ECHO) "Main-Class: $(DEMO_MAINCLASS)" >> $@ 223 ifdef DEMO_MANIFEST_ATTR 224 $(ECHO) "$(DEMO_MANIFEST_ATTR)" >> $@ 225 endif 226 227 # Populating the jar image directory 228 $(DEMO_JAR_IMAGE)/%: $(DEMO_SRCDIR)/% 229 $(install-file) 230 ifdef DEMO_PSRCDIR 231 $(DEMO_JAR_IMAGE)/%: $(DEMO_PSRCDIR)/% 232 $(install-file) 233 endif 234 ifdef DEMO_EXTRA_SRCDIR 235 $(DEMO_JAR_IMAGE)/%: $(DEMO_EXTRA_SRCDIR)/% 236 $(install-file) 237 endif 238 ifdef DEMO_DESCRIPTOR 239 $(DEMO_JAR_IMAGE)/META-INF/services/$(DEMO_DESCRIPTOR): \ 240 $(DEMO_SRCDIR)/$(DEMO_DESCRIPTOR) 241 $(install-file) 242 endif 243 244 # If we are creating a jar file (we have java code) 245 ifdef DEMO_JAR 246 247 # Input file for javac 248 $(DEMO_JAVAC_INPUT): $(DEMO_JAVA_SOURCES:%=$(DEMO_BUILD_SRCDIR)/%) 249 @$(prep-target) 250 @for i in $(DEMO_JAVA_SOURCES) ; do \ 251 $(ECHO) "$(DEMO_BUILD_SRCDIR)/$$i" >> $@ ; \ 252 done 253 254 # Jar file creation 255 $(DEMO_JAR): \ 256 $(DEMO_JAVAC_INPUT) \ 257 $(DEMO_MANIFEST) \ 258 $(DEMO_DESCRIPTOR:%=$(DEMO_JAR_IMAGE)/META-INF/services/%) \ 259 $(DEMO_RESOURCES:%=$(DEMO_JAR_IMAGE)/%) 260 @$(prep-target) 261 $(MKDIR) -p $(DEMO_JAR_IMAGE) 262 $(JAVAC_CMD) -d $(DEMO_JAR_IMAGE) -sourcepath $(DEMO_BUILD_SRCDIR) \ 263 @$(DEMO_JAVAC_INPUT) 264 ifeq ($(DEMO_INCL_SRC),true) 265 $(CP) $(DEMO_JAVA_SOURCES:%=$(DEMO_BUILD_SRCDIR)/%) $(DEMO_JAR_IMAGE) 266 endif 267 ifeq ($(DEMO_ONLY_SRC),true) 268 $(RM) -r $(DEMO_JAR_IMAGE) 269 $(MKDIR) -p $(DEMO_JAR_IMAGE) 270 $(CP) -r $(DEMO_BUILD_SRCDIR)/* $(DEMO_JAR_IMAGE) 271 ifneq ($(DEMO_TOPFILES),) 272 $(CP) $(DEMO_ROOT)/$(DEMO_TOPFILES) $(DEMO_JAR_IMAGE) 273 endif 274 endif 275 $(BOOT_JAR_CMD) -cfm $@ $(DEMO_MANIFEST) \ 276 -C $(DEMO_JAR_IMAGE) . \ 277 $(BOOT_JAR_JFLAGS) 278 @$(java-vm-cleanup) 279 280 endif 281 282 ifndef DEMO_SKIP_SRCZIP 283 # Create a src.zip file 284 $(DEMO_BUILD_SRCZIP): $(DEMO_FULL_SOURCES) 285 @$(prep-target) 286 $(CD) $(DEMO_BUILD_AREA)/src && $(ZIPEXE) -q -r ../$(@F) . 287 288 # Install the destination src.zip file and create the src tree 289 $(DEMO_SOURCE_ZIP): $(DEMO_BUILD_SRCZIP) 290 $(install-file) 291 endif 292 293 ifeq ($(PLATFORM),windows) 294 # JDK name required here 295 RC_FLAGS += /D "JDK_FNAME=$(LIBRARY).dll" \ 296 /D "JDK_INTERNAL_NAME=$(LIBRARY)" \ 297 /D "JDK_FTYPE=0x2L" 298 endif 299 300 # Native library building 301 ifdef DEMO_LIBRARY 302 303 # Full paths to object files 304 DEMO_FULL_OBJECTS = $(DEMO_OBJECTS:%=$(OBJDIR)/%) 305 VPATH= 306 307 # Native compile rules 308 $(OBJDIR)/%.$(OBJECT_SUFFIX): $(DEMO_BUILD_SRCDIR)/%.c 309 @$(prep-target) 310 $(COMPILE.c) $(CC_OBJECT_OUTPUT_FLAG)$@ $< 311 ifneq ($(DEMO_NEEDS_CPP),) 312 $(OBJDIR)/%.$(OBJECT_SUFFIX): $(DEMO_BUILD_SRCDIR)/%.cpp 313 @$(prep-target) 314 $(COMPILE.cpp) $(CC_OBJECT_OUTPUT_FLAG)$@ $< 315 endif 316 317 # Actual creation of the native shared library (C++ and C are different) 318 $(DEMO_LIBRARY): $(DEMO_FULL_OBJECTS) 319 @$(prep-target) 320 ifeq ($(PLATFORM),windows) 321 $(RC) $(RC_FLAGS) $(CC_OBJECT_OUTPUT_FLAG)$(DEMO_VERSION_INFO) $(VERSIONINFO_RESOURCE) 322 endif 323 $(LINK.demo) $(SHARED_LIBRARY_FLAG) $(CC_PROGRAM_OUTPUT_FLAG)$@ \ 324 $(DEMO_FULL_OBJECTS) $(LDLIBS.demo) 325 @$(call binary_file_verification,$@) 326 327 # Generation of any javah include file, make sure objects are dependent on it 328 ifdef DEMO_NATIVECLASS 329 $(DEMO_JAVAH_FILE): $(DEMO_JAR) 330 @$(prep-target) 331 $(JAVAH_CMD) -d $(DEMO_BUILD_SRCDIR) -classpath $(DEMO_JAR) \ 332 $(DEMO_NATIVECLASS) 333 @$(java-vm-cleanup) 334 $(DEMO_FULL_OBJECTS): $(DEMO_JAVAH_FILE) 335 endif 336 337 endif 338 339 # Build involves populating the destination "src" tree, building the jar and 340 # native library, and creating a source bundle 341 342 sources: $(DEMO_FULL_SOURCES) 343 @$(ECHO) "Created $@" 344 345 objects: 346 @$(ECHO) "Created $@" 347 348 # Why the nested make here? It only works this way, don't know why. 349 bundles: $(DEMO_BUILD_SRCZIP) 350 $(RM) -r $(DEMO_DESTDIR) 351 $(MKDIR) -p $(DEMO_DESTDIR) 352 $(MAKE) $(DEMO_LIBRARY) $(DEMO_JAR) $(DEMO_SOURCE_ZIP) $(DEMO_DEST_TOPFILES) 353 # Applets are special, no jar file, no src.zip, everything expanded. 354 ifdef DEMO_IS_APPLET 355 @$(ECHO) "Expanding jar file into demos area at $(DEMO_DESTDIR)" 356 ( $(CD) $(DEMO_DESTDIR) && \ 357 $(BOOT_JAR_CMD) -xfv $(DEMO_JAR_NAME) \ 358 $(BOOT_JAR_JFLAGS) && \ 359 $(RM) -r META-INF $(DEMO_JAR_NAME) && \ 360 $(java-vm-cleanup) ) 361 @( $(CD) $(DEMO_DESTDIR) && $(java-vm-cleanup) ) 362 @$(ECHO) "Expanding source into demos area at $(DEMO_DESTDIR)" 363 ( $(CD) $(DEMO_DESTDIR) && $(UNZIP) -o src.zip && $(RM) src.zip ) 364 endif 365 366 build: sources bundles 367 368 # Printing out a demo information line 369 define printDemoSetting 370 if [ "$2" != "" ] ; then $(PRINTF) "%-20s %s\n" "$1:" "$2"; fi 371 endef 372 373 # Print out the demo information 374 demo_info: 375 @$(ECHO) "=========================================================" 376 @$(call printDemoSetting,DEMONAME,$(DEMONAME)) 377 @$(call printDemoSetting,DEMO_ROOT,$(DEMO_ROOT)) 378 @$(call printDemoSetting,DEMO_SRCDIR,$(DEMO_SRCDIR)) 379 @$(call printDemoSetting,DEMO_DESTDIR,$(DEMO_DESTDIR)) 380 @$(call printDemoSetting,DEMO_JAR,$(DEMO_JAR)) 381 @$(call printDemoSetting,DEMO_MANIFEST_ATTR,$(DEMO_MANIFEST_ATTR)) 382 @$(call printDemoSetting,DEMO_PSRCDIR,$(DEMO_PSRCDIR)) 383 @$(call printDemoSetting,DEMO_EXTRA_SRCDIR,$(DEMO_EXTRA_SRCDIR)) 384 @$(call printDemoSetting,DEMO_EXTRA_FILES,$(DEMO_EXTRA_FILES)) 385 @$(call printDemoSetting,DEMO_TOPFILES,$(DEMO_TOPFILES)) 386 @$(call printDemoSetting,DEMO_MAINCLASS,$(DEMO_MAINCLASS)) 387 @$(call printDemoSetting,DEMO_DESCRIPTOR,$(DEMO_DESCRIPTOR)) 388 @$(call printDemoSetting,DEMO_NATIVECLASS,$(DEMO_NATIVECLASS)) 389 @$(call printDemoSetting,DEMO_LIBRARY,$(DEMO_LIBRARY)) 390 @$(call printDemoSetting,DEMO_OBJECTS,$(DEMO_OBJECTS)) 391 @$(call printDemoSetting,DEMO_SOURCE_ZIP,$(DEMO_SOURCE_ZIP)) 392 @$(ECHO) "=========================================================" 393 394 # Clean rule 395 clean clobber: 396 $(RM) -r $(DEMO_BUILD_AREA) 397 $(RM) -r $(DEMO_DESTDIR) 398 399 # This should not be needed, but some versions of GNU make have a bug that 400 # sometimes deleted these files for some strange and unknown reason 401 # (GNU make version 3.78.1 has the problem, GNU make version 3.80 doesn't?) 402 .PRECIOUS: $(DEMO_FULL_SOURCES) $(DEMO_BUILD_SRCZIP) $(DEMO_SOURCE_ZIP) 403 404 # List phony targets 405 .PHONY: all build clean clobber demo_info \ 406 sources bundles 407