src/utils/reorder/Makefile
changeset 47216 71c04702a3d5
parent 23010 6dadb192ad81
equal deleted inserted replaced
47215:4ebc2e2fb97c 47216:71c04702a3d5
       
     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 
       
    31 BUILDDIR = ../..
       
    32 PACKAGE = tools.reorder
       
    33 PRODUCT = tools
       
    34 include $(BUILDDIR)/common/Defs.gmk
       
    35 
       
    36 OUTDIR = $(OUTPUTDIR)/reorder
       
    37 PRELOAD_DIR = $(ABS_OUTPUTDIR)/reorder/$(ARCH)
       
    38 
       
    39 ifeq ($(PLATFORM), windows)
       
    40 SEP = \\
       
    41 else
       
    42 SEP = /
       
    43 endif
       
    44 
       
    45 CLASSDIR = $(OUTDIR)/classes
       
    46 OBJDIR = $(OUTDIR)/$(ARCH)
       
    47 TESTS = Null Exit Hello Sleep IntToString \
       
    48 	LoadToolkit LoadFrame LoadJFrame JHello
       
    49 TEST_CLASSES = $(TESTS:%=$(CLASSDIR)/%.class)
       
    50 SWINGSET2 = $(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?
       
    55 JRE_LIB = $(JRE_IMAGE_DIR)/lib
       
    56 BOOTPATH = -Xbootclasspath:$(JRE_LIB)/rt.jar:$(JRE_LIB)/charsets.jar
       
    57 JRE_JAVA = $(JRE_IMAGE_DIR)/bin/java
       
    58 
       
    59 JAVA_BIN = $(BINDIR)/java
       
    60 
       
    61 all : jars.reorder libs.reorder
       
    62 
       
    63 tools : $(OBJDIR) $(OBJDIR)/libmcount.so $(OBJDIR)/remove_mcount
       
    64 
       
    65 copy : jars.copy libs.copy
       
    66 
       
    67 clean : 
       
    68 	$(RM) $(REORDER_JAR)
       
    69 
       
    70 clobber : clean
       
    71 	$(RM) -r $(OUTDIR)
       
    72 
       
    73 
       
    74 jars.reorder :
       
    75 	$(MAKE) JARFILE=rt.jar   reorder.jar
       
    76 	$(MAKE) JARFILE=charsets.jar reorder.jar
       
    77 
       
    78 jars.copy:
       
    79 	$(CP) $(OUTDIR)/reorder_rt_jar-$(PLATFORM)    reorder_rt_jar-$(PLATFORM)
       
    80 	$(CP) $(OUTDIR)/reorder_charsets_jar-$(PLATFORM)  reorder_charsets_jar-$(PLATFORM)
       
    81 
       
    82 REORDER_JAR = $(OUTDIR)/reorder_$(subst .,_,$(JARFILE))-$(PLATFORM)
       
    83 reorder.jar : $(REORDER_JAR)
       
    84 
       
    85 libs.reorder :
       
    86 ifeq ($(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
       
    93 endif
       
    94 
       
    95 libs.copy:
       
    96 ifeq ($(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)
       
   102 endif
       
   103 
       
   104 REORDER_LIB = $(OUTDIR)/reorder_$(subst /,_,$(LIBBLDDIR))-$(ARCH)
       
   105 reorder.lib : $(OBJDIR) $(REORDER_LIB)
       
   106 
       
   107 
       
   108 # This target 'test_classes' also used by hotspot reordering.
       
   109 test_classes : $(TEST_CLASSES)
       
   110 
       
   111 # This target 'tool_classes' also used by hotspot reordering.
       
   112 tool_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 
       
   179 MCOUNT_SRC = mcount.c
       
   180 MCOUNT_OBJ = $(MCOUNT_SRC:%.c=$(OBJDIR)/%.o)
       
   181 vpath %.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 
       
   203 ifeq ($(ARCH), i586)
       
   204 	@# On Solaris-i586 we need to remove the symbol _mcount from the command
       
   205 	$(OBJDIR)/remove_mcount $(BINDIR)/java
       
   206 endif
       
   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