1#
2# Copyright (c) 2000, 2013, 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# This Makefile is intended to produce new reordering files for the
27# reordering of jar files and shared libraries.  This is not part of the
28# standard build.  The objects produced by this Makefile must be copied
29# into their standard locations and checked in.
30
31BUILDDIR = ../..
32PACKAGE = tools.reorder
33PRODUCT = tools
34include $(BUILDDIR)/common/Defs.gmk
35
36OUTDIR = $(OUTPUTDIR)/reorder
37PRELOAD_DIR = $(ABS_OUTPUTDIR)/reorder/$(ARCH)
38
39ifeq ($(PLATFORM), windows)
40SEP = \\
41else
42SEP = /
43endif
44
45CLASSDIR = $(OUTDIR)/classes
46OBJDIR = $(OUTDIR)/$(ARCH)
47TESTS = Null Exit Hello Sleep IntToString \
48	LoadToolkit LoadFrame LoadJFrame JHello
49TEST_CLASSES = $(TESTS:%=$(CLASSDIR)/%.class)
50SWINGSET2 = $(OUTPUTDIR)/demo/jfc/SwingSet2/SwingSet2.jar
51
52# Run java from the JRE image because using rt.jar requires a
53# larger list of classes, and these should appear in the list.
54#   FIXUP: adding rt.jar into bootclasspath?
55JRE_LIB = $(JRE_IMAGE_DIR)/lib
56BOOTPATH = -Xbootclasspath:$(JRE_LIB)/rt.jar:$(JRE_LIB)/charsets.jar
57JRE_JAVA = $(JRE_IMAGE_DIR)/bin/java
58
59JAVA_BIN = $(BINDIR)/java
60
61all : jars.reorder libs.reorder
62
63tools : $(OBJDIR) $(OBJDIR)/libmcount.so $(OBJDIR)/remove_mcount
64
65copy : jars.copy libs.copy
66
67clean : 
68	$(RM) $(REORDER_JAR)
69
70clobber : clean
71	$(RM) -r $(OUTDIR)
72
73
74jars.reorder :
75	$(MAKE) JARFILE=rt.jar   reorder.jar
76	$(MAKE) JARFILE=charsets.jar reorder.jar
77
78jars.copy:
79	$(CP) $(OUTDIR)/reorder_rt_jar-$(PLATFORM)    reorder_rt_jar-$(PLATFORM)
80	$(CP) $(OUTDIR)/reorder_charsets_jar-$(PLATFORM)  reorder_charsets_jar-$(PLATFORM)
81
82REORDER_JAR = $(OUTDIR)/reorder_$(subst .,_,$(JARFILE))-$(PLATFORM)
83reorder.jar : $(REORDER_JAR)
84
85libs.reorder :
86ifeq ($(PLATFORM), solaris)
87	$(MAKE) LIBBLDDIR=java/zip        LIBTMPDIR=sun/java.util.zip/zip   reorder.lib
88	$(MAKE) LIBBLDDIR=java/java       LIBTMPDIR=java/java.lang/java     reorder.lib
89	$(MAKE) LIBBLDDIR=java/nio        LIBTMPDIR=java/java.nio/nio       reorder.lib
90	$(MAKE) LIBBLDDIR=sun/font        LIBTMPDIR=sun/sun.awt.font/fontmanager reorder.lib
91	$(MAKE) LIBBLDDIR=sun/jpeg        LIBTMPDIR=sun/sun.awt/jpeg        reorder.lib
92	$(MAKE) LIBBLDDIR=java/verify     LIBTMPDIR=java/verify             reorder.lib
93endif
94
95libs.copy:
96ifeq ($(PLATFORM), solaris)
97	$(CP) $(OUTDIR)/reorder_java_zip-$(ARCH) ../../java/zip/reorder-$(ARCH)
98	$(CP) $(OUTDIR)/reorder_java_java-$(ARCH) ../../java/java/reorder-$(ARCH)
99	$(CP) $(OUTDIR)/reorder_sun_font-$(ARCH) ../../sun/font/reorder-$(ARCH)
100	$(CP) $(OUTDIR)/reorder_sun_jpeg-$(ARCH) ../../sun/jpeg/reorder-$(ARCH)
101	$(CP) $(OUTDIR)/reorder_java_verify-$(ARCH) ../../java/verify/reorder-$(ARCH)
102endif
103
104REORDER_LIB = $(OUTDIR)/reorder_$(subst /,_,$(LIBBLDDIR))-$(ARCH)
105reorder.lib : $(OBJDIR) $(REORDER_LIB)
106
107
108# This target 'test_classes' also used by hotspot reordering.
109test_classes : $(TEST_CLASSES)
110
111# This target 'tool_classes' also used by hotspot reordering.
112tool_classes : $(CLASSDIR) $(CLASSDIR)/Combine.class $(CLASSDIR)/MaxTime.class
113
114$(REORDER_JAR) : $(CLASSDIR) test_classes tool_classes
115	$(RM) $(REORDER_JAR)
116
117	@$(ECHO) "# Ordered list of files to include in $(JARFILE)." > $(REORDER_JAR)
118	@$(ECHO) "# This is a generated file - do not edit."	    >> $(REORDER_JAR)
119	@$(ECHO) "#"						    >> $(REORDER_JAR)
120
121	@# Run each of a set of tests, extract the classes required and
122	@# append the new classes to the ClassList.
123
124	@for f in $(TESTS) ; do						  \
125	    $(ECHO) Running test $$f.;					  \
126	    $(RM) $(REORDER_JAR)_tmp1;					  \
127	    echo "# Test $$f" >> $(REORDER_JAR);			  \
128	    $(JRE_JAVA) -verbose -classpath $(CLASSDIR) $$f |		  \
129	      $(SED) -n -e 's=\[Loaded \(.*\) from .*$(SEP)lib$(SEP)$(JARFILE)]=\1=p' | \
130	      $(SED) -e 's=\.=/=g' -e 's=$$=.class='			  \
131		 > $(REORDER_JAR)_tmp1;					  \
132	    $(JRE_JAVA) -classpath $(CLASSDIR) Combine			  \
133		$(REORDER_JAR) $(REORDER_JAR)_tmp1			  \
134		 > $(REORDER_JAR)_tmp2;					  \
135	    $(MV) $(REORDER_JAR)_tmp2 $(REORDER_JAR);			  \
136	    $(RM) $(REORDER_JAR)_tmp1;					  \
137	done
138
139	@# Run SwingSet2, extract the classes required and
140	@# append the new classes to the ClassList.
141
142	@$(RM) $(REORDER_JAR)_tmp1
143	@$(RM) $(REORDER_JAR)_tmp2
144	@$(ECHO) "# SwingSet2" >> $(REORDER_JAR)
145
146	@$(ECHO) ""
147	@$(ECHO) ""
148	@$(ECHO) "When SwingSet2 has finished drawing, " \
149		 "you may terminate it (with your mouse)."
150	@$(ECHO) "Otherwise, it should be automatically terminated in 2 minutes."
151	@$(ECHO) ""
152	@$(ECHO) ""
153
154	$(JRE_JAVA) -verbose -classpath $(CLASSDIR) MaxTime $(SWINGSET2) 120 \
155		 > $(REORDER_JAR)_tmp2 
156
157	$(SED) -n -e 's=\[Loaded \(.*\) from .*$(SEP)lib$(SEP)$(JARFILE)]=\1=p'	   \
158	    < $(REORDER_JAR)_tmp2 |					   \
159	$(SED) -e 's=\.=/=g' -e 's=$$=.class=' > $(REORDER_JAR)_tmp1
160
161	$(RM) $(REORDER_JAR)_tmp2
162	$(JRE_JAVA) -classpath $(CLASSDIR) Combine			  \
163	    $(REORDER_JAR) $(REORDER_JAR)_tmp1 > $(REORDER_JAR)_tmp2
164	$(MV) $(REORDER_JAR)_tmp2 $(REORDER_JAR)
165	$(RM) $(REORDER_JAR)_tmp1
166
167$(CLASSDIR) :
168	$(MKDIR) -p $(CLASSDIR)
169
170$(CLASSDIR)/%.class : tools/%.java
171	$(JAVAC_CMD) -d $(CLASSDIR) $<
172$(CLASSDIR)/%.class : tests/%.java
173	$(JAVAC_CMD) -d $(CLASSDIR) $<
174
175$(OBJDIR) :
176	$(MKDIR) -p $(OBJDIR)
177
178
179MCOUNT_SRC = mcount.c
180MCOUNT_OBJ = $(MCOUNT_SRC:%.c=$(OBJDIR)/%.o)
181vpath %.c tools
182
183$(OBJDIR)/%.o : %.c tools/util-$(ARCH).il
184	$(COMPILE.c) $(CC_OBJECT_OUTPUT_FLAG)$@ $^
185
186# This library 'libmcount.so' also used by hotspot reordering.
187$(OBJDIR)/libmcount.so : $(MCOUNT_OBJ)
188	$(CC) -G -mt -zdefs -o $@ $^ $(LIBDL) -lelf $(EXTRA_LIBS)
189
190# This library 'libmcount.so' also used by hotspot reordering.
191$(OBJDIR)/remove_mcount : remove_mcount.c
192	$(CC) -g -o $@ $^ $(LIBDL) -lelf $(EXTRA_LIBS)
193
194
195# Reorder libraries.
196# + Delete all of the library's object files, and recompile them for profiling.
197# + Run the test sequence using libmcount to produce the mapfile.
198# + Delete all of the library's object files, and recompile them normally.
199
200$(REORDER_LIB): $(OBJDIR)/libmcount.so $(OBJDIR)/remove_mcount \
201		test_classes tool_classes
202
203ifeq ($(ARCH), i586)
204	@# On Solaris-i586 we need to remove the symbol _mcount from the command
205	$(OBJDIR)/remove_mcount $(BINDIR)/java
206endif
207
208	$(RM) $(OUTPUTDIR)/tmp/$(LIBTMPDIR)/$(OBJDIRNAME)/*.o
209	$(CD) $(BUILDDIR)/$(LIBBLDDIR) ; \
210	  $(MAKE) PARTIAL_GPROF=true LDNOMAP=true NO_ROBOT=true all
211
212	$(RM) $(REORDER_LIB)
213	@$(ECHO) "data = R0x2000;" > $(REORDER_LIB)
214	@$(ECHO) "text = LOAD ?RXO;" >> $(REORDER_LIB)
215
216	@# Run each of a set of tests, extract the classes required and
217	@# append the new classes to the ClassList.
218
219	for f in $(TESTS) ; do						  \
220	    $(ECHO) Running test $$f.;					  \
221	    $(RM) $(REORDER_LIB)_tmp1;					  \
222	    $(ECHO) "# Test $$f" >> $(REORDER_LIB);			  \
223	    LD_PRELOAD=$(PRELOAD_DIR)/libmcount.so			  \
224	      $(SETENV)							  \
225	      $(JAVA_BIN) $(BOOTPATH) -classpath $(CLASSDIR) $$f 	  \
226		 2> $(REORDER_LIB)_tmp1;				  \
227	    $(SED) -n -e 's=[./]*$(OUTPUTDIR)=OUTPUTDIR=' -e '/^text:/p'  \
228		 $(REORDER_LIB)_tmp1 > $(REORDER_LIB)_tmp2;		  \
229	    $(SED) -e '/^text:/d' $(REORDER_LIB)_tmp1;	 		  \
230	    $(JRE_JAVA) -classpath $(CLASSDIR) Combine			  \
231		$(REORDER_LIB) $(REORDER_LIB)_tmp2			  \
232		 > $(REORDER_LIB)_tmp3;					  \
233	    $(MV) $(REORDER_LIB)_tmp3 $(REORDER_LIB);			  \
234	    $(RM) $(REORDER_LIB)_tmp2;					  \
235	    $(RM) $(REORDER_LIB)_tmp1;					  \
236	done
237
238	@# Run SwingSet2, extract the classes required and
239	@# append the new classes to the ClassList.
240
241	@$(RM) $(REORDER_LIB)_tmp1
242	@$(RM) $(REORDER_JAR)_tmp2
243	@$(ECHO) "# SwingSet2" >> $(REORDER_LIB)
244
245	@$(ECHO) ""
246	@$(ECHO) ""
247	@$(ECHO) "When SwingSet2 has finished drawing, " \
248		 "you may terminate it (with your mouse)."
249	@$(ECHO) "Otherwise, it should be automatically terminated in 2 minutes."
250	@$(ECHO) ""
251	@$(ECHO) ""
252
253	LD_PRELOAD=$(PRELOAD_DIR)/libmcount.so				   \
254	  $(SETENV)							   \
255	  $(JAVA_BIN) $(BOOTPATH) -classpath $(CLASSDIR) MaxTime	   \
256		$(SWINGSET2) 120  2> $(REORDER_LIB)_tmp1
257
258	$(SED) -n -e 's=[./]*$(OUTPUTDIR)=OUTPUTDIR=' -e '/^text:/p'	  \
259	    $(REORDER_LIB)_tmp1 > $(REORDER_LIB)_tmp2
260	$(SED) -e '/^text:/d' $(REORDER_LIB)_tmp1
261	$(JRE_JAVA) -classpath $(CLASSDIR) Combine			  \
262	    $(REORDER_LIB) $(REORDER_LIB)_tmp2				  \
263	     > $(REORDER_LIB)_tmp3
264	$(MV) $(REORDER_LIB)_tmp3 $(REORDER_LIB)
265	$(RM) $(REORDER_LIB)_tmp2
266	$(RM) $(REORDER_LIB)_tmp1
267
268	$(RM) $(OUTPUTDIR)/tmp/$(LIBTMPDIR)/$(OBJDIRNAME)/*.o
269	$(CD) $(BUILDDIR)/$(LIBBLDDIR) ; $(MAKE) all
270
271.PHONY: test_classes tool_classes
272