make/common/Rules.gmk

Wed, 02 Sep 2009 09:20:17 -0700

author
ohair
date
Wed, 02 Sep 2009 09:20:17 -0700
changeset 114
1c130e7b7a2e
parent 98
a12ea7c7b497
child 117
31ce3cac3cc1
permissions
-rw-r--r--

6875240: Reduce Makefile build time by limiting repeated exec's (mostly for cygwin building)
Reviewed-by: jjg, iris

     1 #
     2 # Copyright 1995-2009 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 #
    26 #
    27 #
    28 # Rules shared by all Java makefiles.
    29 #
    31 # Used with wildcard to look into a java package for files (assumes max 5 deep)
    32 _WC_DIRS  = * */* */*/* */*/*/* */*/*/*/*
    34 # Make sure the default rule is all
    35 rules_default_rule: all
    37 #
    38 # Directory set up.  (Needed by deploy workspace)
    39 # 
    40 $(CLASSDESTDIR) $(CLASSHDRDIR) $(OBJDIR) $(OUTPUTDIR) $(BINDIR) $(LIBDIR) $(LIBDIR)/$(LIBARCH) $(TEMPDIR) $(EXTDIR):
    41 	$(MKDIR) -p $@ 
    43 #
    44 # All source tree areas for java/properties files 
    45 #
    46 ALL_CLASSES_SRC = $(SHARE_SRC)/classes $(PLATFORM_SRC)/classes
    48 #
    49 # If AUTO_FILES_PROPERTIES_DIRS used, automatically find properties files
    50 #
    51 ifdef AUTO_FILES_PROPERTIES_DIRS
    52   # Wildcard all possible properties files
    53   _WC_PROP_FILES = $(patsubst %, %/*.properties, $(_WC_DIRS))
    54   # Wildcard package directories for this Makefile
    55   _AUTO_WC_PROP_FILES = $(foreach dir, $(AUTO_FILES_PROPERTIES_DIRS), \
    56           $(patsubst %, $(dir)/%, $(_WC_PROP_FILES)) )
    57   # Wildcard all source directories
    58   _AUTO_WC_ALL_PROP_FILES1 = $(foreach dir, $(ALL_CLASSES_SRC), \
    59           $(patsubst %, $(dir)/%,  $(_AUTO_WC_PROP_FILES)) )
    60   # Find all files meeting this pattern
    61   FILES_properties_auto1 := $(wildcard $(_AUTO_WC_ALL_PROP_FILES1))
    62 else
    63   FILES_properties_auto1 =
    64 endif # AUTO_FILES_PROPERTIES_DIRS
    66 # Add any automatically found properties files to the properties file list
    67 FILES_properties += $(FILES_properties_auto1)
    69 #
    70 # Get Resources help
    71 #
    72 include $(TOPDIR)/make/common/internal/Resources.gmk
    74 #
    75 # Compiling .java files.
    76 #
    78 #
    79 # Automatically add to FILES_java if AUTO_FILES_JAVA_DIRS is defined
    80 #
    81 #    There are two basic types of sources, normal source files and the
    82 #    generated ones. The Normal sources will be located in:
    83 #         $(ALL_CLASSES_SRC)
    84 #    The generated sources, which might show up late to dinner, are at:
    85 #         $(GENSRCDIR)
    86 #    and since they could be generated late, we need to be careful that
    87 #    we look for these sources late and not use the ':=' assignment which
    88 #    might miss their generation.
    90 ifdef AUTO_FILES_JAVA_DIRS
    91   # Wildcard all possible java files
    92   _WC_JAVA_FILES = $(patsubst %, %/*.java, $(_WC_DIRS))
    93   # Wildcard package directories for this Makefile
    94   _AUTO_WC_JAVA_FILES = $(foreach dir, $(AUTO_FILES_JAVA_DIRS), \
    95           $(patsubst %, $(dir)/%, $(_WC_JAVA_FILES)) )
    96   # Wildcard all source directories
    97   _AUTO_WC_ALL_JAVA_FILES1 = $(foreach dir, $(ALL_CLASSES_SRC), \
    98           $(patsubst %, $(dir)/%,  $(_AUTO_WC_JAVA_FILES)) )
    99   # Find all files meeting this pattern
   100   FILES_java_auto1 := $(wildcard $(_AUTO_WC_ALL_JAVA_FILES1))
   102   # Second list is the generated sources that should be rare, but will likely
   103   #   show up late and we need to look for them at the last minute, so we
   104   #   cannot use the ':=' assigment here. But if this gets expanded multiple
   105   #   times, the if tests should make them relatively cheap.
   106   # Wildcard the generated source directories
   107   _AUTO_WC_ALL_JAVA_FILES2 = $(patsubst %, $(GENSRCDIR)/%, $(_AUTO_WC_JAVA_FILES))
   108   # Find all files meeting this pattern
   109   FILES_java_auto2 = $(wildcard $(_AUTO_WC_ALL_JAVA_FILES2))
   110 else
   111   FILES_java_auto1 =
   112   FILES_java_auto2 =
   113 endif
   115 # Add all found java sources to FILES_java macro (if AUTO_FILES_JAVA_DIRS used)
   116 FILES_java += $(FILES_java_auto1) $(FILES_java_auto2)
   118 # File that will hold java source names that need compiling
   119 JAVA_SOURCE_LIST=$(TEMPDIR)/.classes.list
   121 # Add a java source to the list
   122 define add-java-file
   123 $(ECHO) "$?" >> $(JAVA_SOURCE_LIST)
   124 endef
   126 $(CLASSDESTDIR)/%.class: $(GENSRCDIR)/%.java
   127 	@$(add-java-file)
   128 $(CLASSDESTDIR)/%.class: $(PLATFORM_SRC)/classes/%.java
   129 	@$(add-java-file)
   130 $(CLASSDESTDIR)/%.class: $(SHARE_SRC)/classes/%.java
   131 	@$(add-java-file)
   133 # List of class files needed
   134 FILES_class = $(FILES_java:%.java=$(CLASSDESTDIR)/%.class)
   136 # Got to include exported files.
   137 FILES_class += $(FILES_export:%.java=$(CLASSDESTDIR)/%.class)
   139 # Construct list of java sources we need to compile
   140 source_list_prime:
   141 	@$(MKDIR) -p $(TEMPDIR)
   142 # Note that we slip resources in so that compiled properties files get created:
   143 $(JAVA_SOURCE_LIST) : source_list_prime resources $(FILES_class)
   144 	@$(TOUCH) $@
   146 .delete.classlist:
   147 	@$(RM) $(JAVA_SOURCE_LIST)
   149 # Make sure all newer sources are compiled (in a batch)
   150 classes : $(CLASSES_INIT) .delete.classlist .compile.classlist
   152 # Use this javac option to force it to favor the sourcepath file classes
   153 #   rather than any bootclasspath classes.
   154 JAVAC_PREFER_SOURCE = -Xprefer:source
   156 .compile.classlist : $(JAVA_SOURCE_LIST)
   157 	@$(MKDIR) -p $(CLASSDESTDIR)
   158 	if [ -s $(JAVA_SOURCE_LIST) ] ; then \
   159 	  $(JAVAC_CMD) $(JAVAC_PREFER_SOURCE) -sourcepath "$(SOURCEPATH)" -d $(CLASSDESTDIR) @$(JAVA_SOURCE_LIST); \
   160 	fi
   161 	@$(java-vm-cleanup)
   163 clobber clean::
   164 	$(RM) $(JAVA_SOURCE_LIST)
   166 ifndef DONT_CLOBBER_CLASSES
   167   ifndef PACKAGE
   168     DONT_CLOBBER_CLASSES = true
   169   else
   170     DONT_CLOBBER_CLASSES = false
   171   endif
   172 endif
   174 packages.clean:
   175 ifeq ($(DONT_CLOBBER_CLASSES),false)
   176   ifdef AUTO_FILES_JAVA_DIRS
   177 	$(RM) -r $(patsubst %, $(CLASSDESTDIR)/%, $(AUTO_FILES_JAVA_DIRS))
   178   else
   179 	$(RM) -r $(CLASSDESTDIR)/$(PKGDIR)
   180   endif
   181 endif
   183 classes.clean: packages.clean
   184 	$(RM) $(JAVA_SOURCE_LIST)
   186 #
   187 # C and C++ make dependencies
   188 #
   189 include $(TOPDIR)/make/common/internal/NativeCompileRules.gmk
   191 #
   192 # Running Javah to generate stuff into CClassHeaders.
   193 #
   195 ifdef FILES_export
   197 CLASSES.export  = $(subst /,.,$(FILES_export:%.java=%))
   198 CLASSES.export += $(subst /,.,$(FILES_export2:%.java=%))
   199 CLASSES.export += $(subst /,.,$(FILES_export3:%.java=%))
   200 CLASSES_export  = $(FILES_export:%.java=$(CLASSDESTDIR)/%.class)
   201 CLASSES_export += $(FILES_export2:%.java=$(CLASSDESTDIR)/%.class)
   202 CLASSES_export += $(FILES_export3:%.java=$(CLASSDESTDIR)/%.class)
   204 # Fix when deploy workspace makefiles don't depend on this name
   205 #CLASSHDR_DOTFILE=$(CLASSHDRDIR)/.classheaders
   207 CLASSHDR_DOTFILE=$(OBJDIR)/.class.headers.$(ARCH)
   209 classheaders: classes $(CLASSHDR_DOTFILE)
   211 $(CLASSHDR_DOTFILE): $(CLASSES_export)
   212 	$(prep-target)
   213 	$(JAVAH_CMD) -d $(CLASSHDRDIR)/ \
   214 		$(CLASSES.export) $(subst $$,\$$,$(EXPORTED_inner))
   215 	@$(java-vm-cleanup)
   216 	@$(TOUCH) $@
   218 classheaders.clean:
   219 	$(RM) -r $(CLASSHDRDIR) $(CLASSHDR_DOTFILE)
   221 else # FILES_export
   223 classheaders: classes
   225 classheaders.clean: 
   227 endif # FILES_export
   229 clean clobber:: classheaders.clean classes.clean .delete.classlist
   231 # 
   232 # Default dependencies
   233 #
   235 all: build
   237 build: classheaders
   239 default: all
   241 .PHONY: all build clean clobber \
   242         .delete.classlist classes .compile.classlist classes.clean \
   243 	 classheaders classheaders.clean \
   244 	 batch_compile

mercurial