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

duke@1 1 #
xdono@98 2 # Copyright 1995-2009 Sun Microsystems, Inc. All Rights Reserved.
duke@1 3 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@1 4 #
duke@1 5 # This code is free software; you can redistribute it and/or modify it
duke@1 6 # under the terms of the GNU General Public License version 2 only, as
duke@1 7 # published by the Free Software Foundation. Sun designates this
duke@1 8 # particular file as subject to the "Classpath" exception as provided
duke@1 9 # by Sun in the LICENSE file that accompanied this code.
duke@1 10 #
duke@1 11 # This code is distributed in the hope that it will be useful, but WITHOUT
duke@1 12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@1 13 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@1 14 # version 2 for more details (a copy is included in the LICENSE file that
duke@1 15 # accompanied this code).
duke@1 16 #
duke@1 17 # You should have received a copy of the GNU General Public License version
duke@1 18 # 2 along with this work; if not, write to the Free Software Foundation,
duke@1 19 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@1 20 #
duke@1 21 # Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
duke@1 22 # CA 95054 USA or visit www.sun.com if you need additional information or
duke@1 23 # have any questions.
duke@1 24 #
duke@1 25
duke@1 26 #
duke@1 27 #
duke@1 28 # Rules shared by all Java makefiles.
duke@1 29 #
ohair@114 30
ohair@114 31 # Used with wildcard to look into a java package for files (assumes max 5 deep)
ohair@114 32 _WC_DIRS = * */* */*/* */*/*/* */*/*/*/*
duke@1 33
duke@1 34 # Make sure the default rule is all
duke@1 35 rules_default_rule: all
duke@1 36
duke@1 37 #
duke@1 38 # Directory set up. (Needed by deploy workspace)
duke@1 39 #
duke@1 40 $(CLASSDESTDIR) $(CLASSHDRDIR) $(OBJDIR) $(OUTPUTDIR) $(BINDIR) $(LIBDIR) $(LIBDIR)/$(LIBARCH) $(TEMPDIR) $(EXTDIR):
duke@1 41 $(MKDIR) -p $@
duke@1 42
duke@1 43 #
duke@1 44 # All source tree areas for java/properties files
duke@1 45 #
duke@1 46 ALL_CLASSES_SRC = $(SHARE_SRC)/classes $(PLATFORM_SRC)/classes
duke@1 47
duke@1 48 #
duke@1 49 # If AUTO_FILES_PROPERTIES_DIRS used, automatically find properties files
duke@1 50 #
duke@1 51 ifdef AUTO_FILES_PROPERTIES_DIRS
ohair@114 52 # Wildcard all possible properties files
ohair@114 53 _WC_PROP_FILES = $(patsubst %, %/*.properties, $(_WC_DIRS))
ohair@114 54 # Wildcard package directories for this Makefile
ohair@114 55 _AUTO_WC_PROP_FILES = $(foreach dir, $(AUTO_FILES_PROPERTIES_DIRS), \
ohair@114 56 $(patsubst %, $(dir)/%, $(_WC_PROP_FILES)) )
ohair@114 57 # Wildcard all source directories
ohair@114 58 _AUTO_WC_ALL_PROP_FILES1 = $(foreach dir, $(ALL_CLASSES_SRC), \
ohair@114 59 $(patsubst %, $(dir)/%, $(_AUTO_WC_PROP_FILES)) )
ohair@114 60 # Find all files meeting this pattern
ohair@114 61 FILES_properties_auto1 := $(wildcard $(_AUTO_WC_ALL_PROP_FILES1))
duke@1 62 else
duke@1 63 FILES_properties_auto1 =
duke@1 64 endif # AUTO_FILES_PROPERTIES_DIRS
duke@1 65
duke@1 66 # Add any automatically found properties files to the properties file list
duke@1 67 FILES_properties += $(FILES_properties_auto1)
duke@1 68
duke@1 69 #
duke@1 70 # Get Resources help
duke@1 71 #
duke@1 72 include $(TOPDIR)/make/common/internal/Resources.gmk
duke@1 73
duke@1 74 #
duke@1 75 # Compiling .java files.
duke@1 76 #
duke@1 77
duke@1 78 #
duke@1 79 # Automatically add to FILES_java if AUTO_FILES_JAVA_DIRS is defined
duke@1 80 #
duke@1 81 # There are two basic types of sources, normal source files and the
duke@1 82 # generated ones. The Normal sources will be located in:
duke@1 83 # $(ALL_CLASSES_SRC)
duke@1 84 # The generated sources, which might show up late to dinner, are at:
duke@1 85 # $(GENSRCDIR)
duke@1 86 # and since they could be generated late, we need to be careful that
duke@1 87 # we look for these sources late and not use the ':=' assignment which
duke@1 88 # might miss their generation.
duke@1 89
duke@1 90 ifdef AUTO_FILES_JAVA_DIRS
ohair@114 91 # Wildcard all possible java files
ohair@114 92 _WC_JAVA_FILES = $(patsubst %, %/*.java, $(_WC_DIRS))
ohair@114 93 # Wildcard package directories for this Makefile
ohair@114 94 _AUTO_WC_JAVA_FILES = $(foreach dir, $(AUTO_FILES_JAVA_DIRS), \
ohair@114 95 $(patsubst %, $(dir)/%, $(_WC_JAVA_FILES)) )
ohair@114 96 # Wildcard all source directories
ohair@114 97 _AUTO_WC_ALL_JAVA_FILES1 = $(foreach dir, $(ALL_CLASSES_SRC), \
ohair@114 98 $(patsubst %, $(dir)/%, $(_AUTO_WC_JAVA_FILES)) )
ohair@114 99 # Find all files meeting this pattern
ohair@114 100 FILES_java_auto1 := $(wildcard $(_AUTO_WC_ALL_JAVA_FILES1))
duke@1 101
duke@1 102 # Second list is the generated sources that should be rare, but will likely
duke@1 103 # show up late and we need to look for them at the last minute, so we
duke@1 104 # cannot use the ':=' assigment here. But if this gets expanded multiple
duke@1 105 # times, the if tests should make them relatively cheap.
ohair@114 106 # Wildcard the generated source directories
ohair@114 107 _AUTO_WC_ALL_JAVA_FILES2 = $(patsubst %, $(GENSRCDIR)/%, $(_AUTO_WC_JAVA_FILES))
ohair@114 108 # Find all files meeting this pattern
ohair@114 109 FILES_java_auto2 = $(wildcard $(_AUTO_WC_ALL_JAVA_FILES2))
duke@1 110 else
duke@1 111 FILES_java_auto1 =
duke@1 112 FILES_java_auto2 =
duke@1 113 endif
duke@1 114
duke@1 115 # Add all found java sources to FILES_java macro (if AUTO_FILES_JAVA_DIRS used)
duke@1 116 FILES_java += $(FILES_java_auto1) $(FILES_java_auto2)
duke@1 117
duke@1 118 # File that will hold java source names that need compiling
duke@1 119 JAVA_SOURCE_LIST=$(TEMPDIR)/.classes.list
duke@1 120
duke@1 121 # Add a java source to the list
duke@1 122 define add-java-file
duke@1 123 $(ECHO) "$?" >> $(JAVA_SOURCE_LIST)
duke@1 124 endef
duke@1 125
duke@1 126 $(CLASSDESTDIR)/%.class: $(GENSRCDIR)/%.java
duke@1 127 @$(add-java-file)
duke@1 128 $(CLASSDESTDIR)/%.class: $(PLATFORM_SRC)/classes/%.java
duke@1 129 @$(add-java-file)
duke@1 130 $(CLASSDESTDIR)/%.class: $(SHARE_SRC)/classes/%.java
duke@1 131 @$(add-java-file)
duke@1 132
duke@1 133 # List of class files needed
duke@1 134 FILES_class = $(FILES_java:%.java=$(CLASSDESTDIR)/%.class)
duke@1 135
duke@1 136 # Got to include exported files.
duke@1 137 FILES_class += $(FILES_export:%.java=$(CLASSDESTDIR)/%.class)
duke@1 138
duke@1 139 # Construct list of java sources we need to compile
duke@1 140 source_list_prime:
duke@1 141 @$(MKDIR) -p $(TEMPDIR)
duke@1 142 # Note that we slip resources in so that compiled properties files get created:
duke@1 143 $(JAVA_SOURCE_LIST) : source_list_prime resources $(FILES_class)
duke@1 144 @$(TOUCH) $@
duke@1 145
duke@1 146 .delete.classlist:
duke@1 147 @$(RM) $(JAVA_SOURCE_LIST)
duke@1 148
duke@1 149 # Make sure all newer sources are compiled (in a batch)
duke@1 150 classes : $(CLASSES_INIT) .delete.classlist .compile.classlist
duke@1 151
ohair@56 152 # Use this javac option to force it to favor the sourcepath file classes
ohair@56 153 # rather than any bootclasspath classes.
ohair@56 154 JAVAC_PREFER_SOURCE = -Xprefer:source
ohair@56 155
duke@1 156 .compile.classlist : $(JAVA_SOURCE_LIST)
duke@1 157 @$(MKDIR) -p $(CLASSDESTDIR)
ohair@114 158 if [ -s $(JAVA_SOURCE_LIST) ] ; then \
ohair@56 159 $(JAVAC_CMD) $(JAVAC_PREFER_SOURCE) -sourcepath "$(SOURCEPATH)" -d $(CLASSDESTDIR) @$(JAVA_SOURCE_LIST); \
duke@1 160 fi
duke@1 161 @$(java-vm-cleanup)
duke@1 162
duke@1 163 clobber clean::
duke@1 164 $(RM) $(JAVA_SOURCE_LIST)
duke@1 165
duke@1 166 ifndef DONT_CLOBBER_CLASSES
duke@1 167 ifndef PACKAGE
duke@1 168 DONT_CLOBBER_CLASSES = true
duke@1 169 else
duke@1 170 DONT_CLOBBER_CLASSES = false
duke@1 171 endif
duke@1 172 endif
duke@1 173
duke@1 174 packages.clean:
duke@1 175 ifeq ($(DONT_CLOBBER_CLASSES),false)
duke@1 176 ifdef AUTO_FILES_JAVA_DIRS
ohair@114 177 $(RM) -r $(patsubst %, $(CLASSDESTDIR)/%, $(AUTO_FILES_JAVA_DIRS))
duke@1 178 else
duke@1 179 $(RM) -r $(CLASSDESTDIR)/$(PKGDIR)
duke@1 180 endif
duke@1 181 endif
duke@1 182
duke@1 183 classes.clean: packages.clean
duke@1 184 $(RM) $(JAVA_SOURCE_LIST)
duke@1 185
duke@1 186 #
duke@1 187 # C and C++ make dependencies
duke@1 188 #
duke@1 189 include $(TOPDIR)/make/common/internal/NativeCompileRules.gmk
duke@1 190
duke@1 191 #
duke@1 192 # Running Javah to generate stuff into CClassHeaders.
duke@1 193 #
duke@1 194
duke@1 195 ifdef FILES_export
duke@1 196
duke@1 197 CLASSES.export = $(subst /,.,$(FILES_export:%.java=%))
duke@1 198 CLASSES.export += $(subst /,.,$(FILES_export2:%.java=%))
duke@1 199 CLASSES.export += $(subst /,.,$(FILES_export3:%.java=%))
duke@1 200 CLASSES_export = $(FILES_export:%.java=$(CLASSDESTDIR)/%.class)
duke@1 201 CLASSES_export += $(FILES_export2:%.java=$(CLASSDESTDIR)/%.class)
duke@1 202 CLASSES_export += $(FILES_export3:%.java=$(CLASSDESTDIR)/%.class)
duke@1 203
duke@1 204 # Fix when deploy workspace makefiles don't depend on this name
duke@1 205 #CLASSHDR_DOTFILE=$(CLASSHDRDIR)/.classheaders
duke@1 206
duke@1 207 CLASSHDR_DOTFILE=$(OBJDIR)/.class.headers.$(ARCH)
duke@1 208
duke@1 209 classheaders: classes $(CLASSHDR_DOTFILE)
duke@1 210
duke@1 211 $(CLASSHDR_DOTFILE): $(CLASSES_export)
duke@1 212 $(prep-target)
duke@1 213 $(JAVAH_CMD) -d $(CLASSHDRDIR)/ \
duke@1 214 $(CLASSES.export) $(subst $$,\$$,$(EXPORTED_inner))
duke@1 215 @$(java-vm-cleanup)
duke@1 216 @$(TOUCH) $@
duke@1 217
duke@1 218 classheaders.clean:
ohair@114 219 $(RM) -r $(CLASSHDRDIR) $(CLASSHDR_DOTFILE)
duke@1 220
duke@1 221 else # FILES_export
duke@1 222
duke@1 223 classheaders: classes
duke@1 224
duke@1 225 classheaders.clean:
duke@1 226
duke@1 227 endif # FILES_export
duke@1 228
duke@1 229 clean clobber:: classheaders.clean classes.clean .delete.classlist
duke@1 230
duke@1 231 #
duke@1 232 # Default dependencies
duke@1 233 #
duke@1 234
duke@1 235 all: build
duke@1 236
duke@1 237 build: classheaders
duke@1 238
duke@1 239 default: all
duke@1 240
duke@1 241 .PHONY: all build clean clobber \
duke@1 242 .delete.classlist classes .compile.classlist classes.clean \
duke@1 243 classheaders classheaders.clean \
duke@1 244 batch_compile
duke@1 245

mercurial