source: trunk/openjdk/jdk/make/common/Demo.gmk

Last change on this file was 278, checked in by dmik, 14 years ago

trunk: Merged in openjdk6 b22 from branches/vendor/oracle.

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