aboutsummaryrefslogtreecommitdiff
path: root/make/common/Demo.gmk
blob: 12a3ce105e4735080376fb8feeb21b8fdeb5858d (plain)
1
2
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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
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
247
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
358
359
360
361
362
363
364
365
366
367
368
369
370
371
#
# Copyright 2004-2008 Sun Microsystems, Inc.  All Rights Reserved.
# 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.
#

# JDK Demo building jar file.
  
# Some names are defined with LIBRARY inside the Defs.gmk file
LIBRARY=$(DEMONAME)
OBJDIR=$(TEMPDIR)/$(DEMONAME)

# Input:
#    DEMONAME           - name of the demo
#    DEMO_ROOT          - path to root of all demo files
#    DEMO_DESTDIR       - path to final demo destination directory
#
# Optional Input:
#    DEMO_SRCDIR        - path to source if different from DEMO_ROOT
#    DEMO_PSRCDIR       - path to additional platform specific source
#    DEMO_PKGDIR        - sub directory of sources we want
#    DEMO_TOPFILES      - names of top-level files relative to DEMO_ROOT
#    DEMO_MAINCLASS     - name of the main class for the jar manifest
#    DEMO_NATIVECLASS   - name of the class with native methods
#    DEMO_DESCRIPTOR    - name of service file for jar (relative to DEMO_SRCDIR)
#    DEMO_EXTRA_SRCDIR  - path to directory that holds extra sources to add
#    DEMO_EXTRA_FILES   - extra sources relative to DEMO_EXTRA_SRCDIR
#    DEMO_OBJECTS       - extra native object files needed
#    DEMO_MANIFEST_ATTR - extra line to add to the jar manifest file

# Assume the source directory is the root directory if not set
ifndef DEMO_SRCDIR
  DEMO_SRCDIR = $(DEMO_ROOT)
endif
ifndef DEMO_PKGDIR
  DEMO_PKGDIR = .
endif

# Some demos have special needs
ifneq ($(DEMONAME),agent_util)
  DEMO_NEEDS_AGENT_UTIL    = $(findstring agent_util,$(DEMO_OBJECTS))
endif
ifneq ($(DEMONAME),java_crw_demo)
  DEMO_NEEDS_JAVA_CRW_DEMO = $(findstring java_crw_demo,$(DEMO_OBJECTS))
endif
ifeq ($(DEMONAME),hprof)
  DEMO_NEEDS_NPT           = true
endif

# Place to hold the build area (kind of a temp area)
DEMO_BUILD_AREA     = $(DEMOCLASSDIR)/$(PRODUCT)/$(DEMONAME)

# Destination "src" directory
DEMO_BUILD_SRCDIR     = $(DEMO_BUILD_AREA)/src
DEMO_BUILD_SRCZIP     = $(DEMO_BUILD_AREA)/src.zip
DEMO_SOURCE_ZIP       = $(DEMO_DESTDIR)/src.zip

# Place to hold the jar image we are creating
DEMO_JAR_IMAGE      = $(DEMO_BUILD_AREA)/jar_image

# The jar manifest file we will create and use
DEMO_MANIFEST       = $(DEMO_BUILD_AREA)/manifest.mf

# The list of source files or options we will supply to javac
DEMO_JAVAC_INPUT    = $(DEMO_BUILD_AREA)/javac_input.txt

# Any name of javah file
DEMO_JAVAH_FILE = $(DEMO_NATIVECLASS:%=$(DEMO_BUILD_SRCDIR)/%.h)

# Get complete list of files for this demo
ifdef DEMO_PSRCDIR
  DEMO_ALL_FILES2  := $(shell ( $(CD) $(DEMO_PSRCDIR) \
    && $(FIND) $(DEMO_PKGDIR) $(SCM_DIRS_prune) -o -type f -print ) \
    | $(SED) 's@^\./@@' )
  DEMO_ALL_FILES   += $(DEMO_ALL_FILES2)
endif
ifdef DEMO_EXTRA_SRCDIR
  DEMO_ALL_FILES   += $(DEMO_EXTRA_FILES)
endif
DEMO_ALL_FILES1    := $(shell ( $(CD) $(DEMO_SRCDIR) \
  && $(FIND) $(DEMO_PKGDIR) $(SCM_DIRS_prune) -o -type f -print ) \
  | $(SED) 's@^\./@@' )
DEMO_ALL_FILES      += $(DEMO_ALL_FILES1)

# Just the java sources
DEMO_JAVA_SOURCES = $(filter %.java,$(DEMO_ALL_FILES))

# Just the C and C++ sources
DEMO_C_SRC_FILES   = $(filter %.c,$(DEMO_ALL_FILES))
DEMO_CPP_SRC_FILES = $(filter %.cpp,$(DEMO_ALL_FILES))

# All the native source files
DEMO_ALL_NATIVE_SOURCES  = $(DEMO_C_SRC_FILES)
DEMO_ALL_NATIVE_SOURCES += $(DEMO_CPP_SRC_FILES)
DEMO_ALL_NATIVE_SOURCES += $(filter %.h,$(DEMO_ALL_FILES))
DEMO_ALL_NATIVE_SOURCES += $(filter %.hpp,$(DEMO_ALL_FILES))

# If we have java sources, then define the jar file we will create
ifneq ($(strip $(DEMO_JAVA_SOURCES)),)
  DEMO_JAR            = $(DEMO_DESTDIR)/$(DEMONAME).jar
endif

# If we have native sources, define the native library we will create
ifneq ($(strip $(DEMO_ALL_NATIVE_SOURCES)),)
  # Path to native library we will create
  DEMO_LIBRARY = \
      $(DEMO_DESTDIR)/lib$(ISA_DIR)/$(LIB_PREFIX)$(DEMONAME).$(LIBRARY_SUFFIX)
  # C and C++ compiler flags we need to add to standard flags
  DEMO_CPPFLAGS     += -I$(DEMO_BUILD_SRCDIR)
  # If the npt library is used we need to find the npt.h file
  ifneq ($(DEMO_NEEDS_NPT),)
    # The npt library is delivered as part of the JRE
    DEMO_CPPFLAGS   += -I$(SHARE_SRC)/npt -I$(PLATFORM_SRC)/npt
  endif
  # Is the shared agent_util code needed
  ifneq ($(DEMO_NEEDS_AGENT_UTIL),)
    DEMO_FULL_SOURCES  += $(DEMO_BUILD_SRCDIR)/agent_util.c
    DEMO_FULL_SOURCES  += $(DEMO_BUILD_SRCDIR)/agent_util.h
  endif
  # Is the shared java_crw_demo code needed
  ifneq ($(DEMO_NEEDS_JAVA_CRW_DEMO),)
    DEMO_FULL_SOURCES  += $(DEMO_BUILD_SRCDIR)/java_crw_demo.c
    DEMO_FULL_SOURCES  += $(DEMO_BUILD_SRCDIR)/java_crw_demo.h
  endif
  # All the native object files we need to build the library
  DEMO_OBJECTS += $(DEMO_C_SRC_FILES:%.c=%.$(OBJECT_SUFFIX)) \
                  $(DEMO_CPP_SRC_FILES:%.cpp=%.$(OBJECT_SUFFIX))
  # Linking is special depending on whether we had C++ code or on windows
  DEMO_NEEDS_CPP = $(strip $(DEMO_CPP_SRC_FILES))
  CPPFLAGS      += $(DEMO_CPPFLAGS)
  ifeq ($(PLATFORM),windows)
    # Note: This is a link with cl.exe, not link.exe, options differ quite
    #       bit between them.
    LINK.demo   = $(LINK.c)
    LDLIBS.demo = $(EXTRA_LIBS) $(LFLAGS_$(COMPILER_VERSION))
  else
    ifneq ($(DEMO_NEEDS_CPP),)
      LINK.demo   = $(LINK.cpp)
      LDLIBS.demo = $(LIBCXX)
      ifeq ($(PLATFORM),solaris)
        LDLIBS.demo += -lc
      endif
    else
      LINK.demo   = $(LINK.c)
      LDLIBS.demo = $(LDLIBS)
    endif
  endif
endif

# Files that are considered resources (need to be in the jar file)
DEMO_RESOURCES        += $(filter-out %.java,$(DEMO_ALL_FILES))

# All destination files (top level readme files and all sources)
#   Note: We exclude the topfiles from the src tree.
DEMO_DEST_TOPFILES     = $(DEMO_TOPFILES:%=$(DEMO_DESTDIR)/%)
DEMO_FILTERED_SOURCES  = $(filter-out $(DEMO_TOPFILES),$(DEMO_ALL_FILES))
DEMO_FULL_SOURCES     += $(DEMO_FILTERED_SOURCES:%=$(DEMO_BUILD_SRCDIR)/%)

# Default rule
all: build demo_info

# Used to populate the destination directories
$(DEMO_DESTDIR)/%: $(DEMO_ROOT)/%
	$(install-file)
ifneq ($(DEMO_SRCDIR),$(DEMO_ROOT))
$(DEMO_DESTDIR)/%: $(DEMO_SRCDIR)/%
	$(install-file)
endif
$(DEMO_BUILD_SRCDIR)/%: $(DEMO_SRCDIR)/%
	$(install-file)
ifdef DEMO_PSRCDIR
$(DEMO_BUILD_SRCDIR)/%: $(DEMO_PSRCDIR)/%
	$(install-file)
endif
ifdef DEMO_EXTRA_SRCDIR
$(DEMO_BUILD_SRCDIR)/%: $(DEMO_EXTRA_SRCDIR)/%
	$(install-file)
endif
ifneq ($(DEMO_NEEDS_AGENT_UTIL),)
$(DEMO_BUILD_SRCDIR)/%: $(DEMO_SRCDIR)/../agent_util/%
	$(install-file)
endif
ifneq ($(DEMO_NEEDS_JAVA_CRW_DEMO),)
$(DEMO_BUILD_SRCDIR)/%: $(DEMO_SRCDIR)/../java_crw_demo/%
	$(install-file)
endif

# Jar manifest file
$(DEMO_MANIFEST): 
	@$(prep-target)
	$(ECHO) "Main-Class: $(DEMO_MAINCLASS)" > $@
ifdef DEMO_MANIFEST_ATTR
	$(ECHO) "$(DEMO_MANIFEST_ATTR)" >> $@
endif

# Populating the jar image directory
$(DEMO_JAR_IMAGE)/%: $(DEMO_SRCDIR)/%
	$(install-file)
ifdef DEMO_PSRCDIR
$(DEMO_JAR_IMAGE)/%: $(DEMO_PSRCDIR)/%
	$(install-file)
endif
ifdef DEMO_EXTRA_SRCDIR
$(DEMO_JAR_IMAGE)/%: $(DEMO_EXTRA_SRCDIR)/%
	$(install-file)
endif
ifdef DEMO_DESCRIPTOR
$(DEMO_JAR_IMAGE)/META-INF/services/$(DEMO_DESCRIPTOR): \
    $(DEMO_SRCDIR)/$(DEMO_DESCRIPTOR)
	$(install-file)
endif

# If we are creating a jar file (we have java code)
ifdef DEMO_JAR

# Input file for javac
$(DEMO_JAVAC_INPUT): $(DEMO_JAVA_SOURCES:%=$(DEMO_BUILD_SRCDIR)/%)
	@$(prep-target)
	@for i in $(DEMO_JAVA_SOURCES) ; do \
	  $(ECHO) "$(DEMO_BUILD_SRCDIR)/$$i" >> $@ ; \
	done

# Jar file creation
$(DEMO_JAR): \
    $(DEMO_JAVAC_INPUT) \
    $(DEMO_MANIFEST) \
    $(DEMO_DESCRIPTOR:%=$(DEMO_JAR_IMAGE)/META-INF/services/%) \
    $(DEMO_RESOURCES:%=$(DEMO_JAR_IMAGE)/%)
	@$(prep-target)
	$(MKDIR) -p $(DEMO_JAR_IMAGE)
	$(JAVAC_CMD) -d $(DEMO_JAR_IMAGE) -sourcepath $(DEMO_BUILD_SRCDIR) \
	    @$(DEMO_JAVAC_INPUT)
	$(BOOT_JAR_CMD) -cfm $@ $(DEMO_MANIFEST) \
	     -C $(DEMO_JAR_IMAGE) . \
	     $(BOOT_JAR_JFLAGS)
	@$(java-vm-cleanup)

endif

# Create a src.zip file
$(DEMO_BUILD_SRCZIP): $(DEMO_FULL_SOURCES)
	@$(prep-target)
	$(CD) $(DEMO_BUILD_AREA)/src && $(ZIPEXE) -q -r ../$(@F) .

# Install the destination src.zip file and create the src tree
$(DEMO_SOURCE_ZIP): $(DEMO_BUILD_SRCZIP)
	$(install-file)

# Native library building
ifdef DEMO_LIBRARY

  # Full paths to object files
  DEMO_FULL_OBJECTS = $(DEMO_OBJECTS:%=$(OBJDIR)/%)
  VPATH=

# Native compile rules
$(OBJDIR)/%.$(OBJECT_SUFFIX): $(DEMO_BUILD_SRCDIR)/%.c
	@$(prep-target)
	$(COMPILE.c) $(CC_OBJECT_OUTPUT_FLAG)$@ $<
  ifneq ($(DEMO_NEEDS_CPP),)
$(OBJDIR)/%.$(OBJECT_SUFFIX): $(DEMO_BUILD_SRCDIR)/%.cpp
	@$(prep-target)
	$(COMPILE.cpp) $(CC_OBJECT_OUTPUT_FLAG)$@ $<
  endif

  # Actual creation of the native shared library (C++ and C are different)
$(DEMO_LIBRARY): $(DEMO_FULL_OBJECTS)
	@$(prep-target)
	$(LINK.demo) $(SHARED_LIBRARY_FLAG) $(CC_PROGRAM_OUTPUT_FLAG)$@ \
	    $(DEMO_FULL_OBJECTS) $(LDLIBS.demo)

  # Generation of any javah include file, make sure objects are dependent on it
  ifdef DEMO_NATIVECLASS
$(DEMO_JAVAH_FILE): $(DEMO_JAR)
	@$(prep-target)
	$(JAVAH_CMD) -d $(DEMO_BUILD_SRCDIR) -classpath $(DEMO_JAR) \
	    $(DEMO_NATIVECLASS)
	@$(java-vm-cleanup)
$(DEMO_FULL_OBJECTS): $(DEMO_JAVAH_FILE)
  endif

endif

# Build involves populating the destination "src" tree, building the jar and
#     native library, and creating a source bundle

sources:  $(DEMO_FULL_SOURCES)
	@$(ECHO) "Created $@"

objects: 
	@$(ECHO) "Created $@"

# Why the nested make here? It only works this way, don't know why.
bundles: $(DEMO_BUILD_SRCZIP)
	$(RM) -r $(DEMO_DESTDIR)
	$(MKDIR) -p $(DEMO_DESTDIR)
	$(MAKE) $(DEMO_LIBRARY) $(DEMO_JAR) $(DEMO_SOURCE_ZIP) $(DEMO_DEST_TOPFILES)
# Applets are special, no jar file, no src.zip, everything expanded.
ifdef DEMO_IS_APPLET
	@$(ECHO) "Expanding jar file into demos area at $(DEMO_DESTDIR)"
	( $(CD) $(DEMO_DESTDIR) && \
	  $(BOOT_JAR_CMD) -xfv $(DEMONAME).jar \
	     $(BOOT_JAR_JFLAGS) && \
	  $(RM) -r META-INF $(DEMONAME).jar  && \
	  $(java-vm-cleanup) )
	@( $(CD) $(DEMO_DESTDIR) && $(java-vm-cleanup) )
	@$(ECHO) "Expanding source into demos area at $(DEMO_DESTDIR)"
	( $(CD) $(DEMO_DESTDIR) && $(UNZIP) -o src.zip && $(RM) src.zip )
endif

build: sources bundles

# Printing out a demo information line
define printDemoSetting
if [ "$2" != "" ] ; then $(PRINTF) "%-20s %s\n" "$1:" "$2"; fi
endef

# Print out the demo information
demo_info:
	@$(ECHO) "========================================================="
	@$(call printDemoSetting,DEMONAME,$(DEMONAME))
	@$(call printDemoSetting,DEMO_ROOT,$(DEMO_ROOT))
	@$(call printDemoSetting,DEMO_SRCDIR,$(DEMO_SRCDIR))
	@$(call printDemoSetting,DEMO_DESTDIR,$(DEMO_DESTDIR))
	@$(call printDemoSetting,DEMO_JAR,$(DEMO_JAR))
	@$(call printDemoSetting,DEMO_MANIFEST_ATTR,$(DEMO_MANIFEST_ATTR))
	@$(call printDemoSetting,DEMO_PSRCDIR,$(DEMO_PSRCDIR))
	@$(call printDemoSetting,DEMO_EXTRA_SRCDIR,$(DEMO_EXTRA_SRCDIR))
	@$(call printDemoSetting,DEMO_EXTRA_FILES,$(DEMO_EXTRA_FILES))
	@$(call printDemoSetting,DEMO_TOPFILES,$(DEMO_TOPFILES))
	@$(call printDemoSetting,DEMO_MAINCLASS,$(DEMO_MAINCLASS))
	@$(call printDemoSetting,DEMO_DESCRIPTOR,$(DEMO_DESCRIPTOR))
	@$(call printDemoSetting,DEMO_NATIVECLASS,$(DEMO_NATIVECLASS))
	@$(call printDemoSetting,DEMO_LIBRARY,$(DEMO_LIBRARY))
	@$(call printDemoSetting,DEMO_OBJECTS,$(DEMO_OBJECTS))
	@$(call printDemoSetting,DEMO_SOURCE_ZIP,$(DEMO_SOURCE_ZIP))
	@$(ECHO) "========================================================="

# Clean rule
clean clobber:
	$(RM) -r $(DEMO_BUILD_AREA)
	$(RM) -r $(DEMO_DESTDIR)

# This should not be needed, but some versions of GNU amke have a bug that
#   sometimes deleted these files  for some strange  and unknown reason 
#   (GNU make version 3.78.1 has the problem, GNU make version 3.80 doesn't?)
.PRECIOUS: $(DEMO_FULL_SOURCES) $(DEMO_BUILD_SRCZIP) $(DEMO_SOURCE_ZIP)

# List phony targets
.PHONY: all build clean clobber demo_info \
	sources bundles