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