make/common/Rules.gmk

Tue, 28 Dec 2010 15:52:36 -0800

author
ohair
date
Tue, 28 Dec 2010 15:52:36 -0800
changeset 240
f90b3e014e83
parent 194
0f60cf26c5b5
permissions
-rw-r--r--

6962318: Update copyright year
Reviewed-by: xdono

duke@1 1 #
ohair@240 2 # Copyright (c) 1995, 2010, Oracle and/or its affiliates. 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
ohair@158 7 # published by the Free Software Foundation. Oracle designates this
duke@1 8 # particular file as subject to the "Classpath" exception as provided
ohair@158 9 # by Oracle 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 #
ohair@158 21 # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ohair@158 22 # or visit www.oracle.com if you need additional information or have any
ohair@158 23 # 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
duke@1 31 # Make sure the default rule is all
duke@1 32 rules_default_rule: all
duke@1 33
duke@1 34 #
duke@1 35 # Directory set up. (Needed by deploy workspace)
duke@1 36 #
ohair@194 37 $(CLASSDESTDIR) $(OUTPUTDIR) $(TEMPDIR) $(EXTDIR):
duke@1 38 $(MKDIR) -p $@
duke@1 39
duke@1 40 #
duke@1 41 # All source tree areas for java/properties files
duke@1 42 #
duke@1 43 ALL_CLASSES_SRC = $(SHARE_SRC)/classes $(PLATFORM_SRC)/classes
duke@1 44
duke@1 45 #
duke@1 46 # If AUTO_FILES_PROPERTIES_DIRS used, automatically find properties files
duke@1 47 #
duke@1 48 ifdef AUTO_FILES_PROPERTIES_DIRS
ohair@118 49 AUTO_FILES_PROPERTIES_FILTERS1 = $(SCM_DIRs) 'X-*' '*-X-*' ',*'
ohair@118 50 AUTO_FILES_PROPERTIES_FILTERS1 += $(AUTO_PROPERTIES_PRUNE)
ohair@118 51 FILES_properties_find_filters1 = $(AUTO_FILES_PROPERTIES_FILTERS1:%=-name % -prune -o)
ohair@118 52 FILES_properties_auto1 := \
ohair@118 53 $(shell \
ohair@118 54 for dir in $(ALL_CLASSES_SRC) ; do \
ohair@118 55 if [ -d $$dir ] ; then \
ohair@118 56 ( $(CD) $$dir; \
ohair@118 57 for sdir in $(AUTO_FILES_PROPERTIES_DIRS); do \
ohair@118 58 if [ -d $$sdir ] ; then \
ohair@118 59 $(FIND) $$sdir $(FILES_properties_find_filters1) \
ohair@118 60 -name '*.properties' -print ; \
ohair@118 61 fi ; \
ohair@118 62 done \
ohair@118 63 ); \
ohair@118 64 fi; \
ohair@118 65 done \
ohair@118 66 )
duke@1 67 else
duke@1 68 FILES_properties_auto1 =
duke@1 69 endif # AUTO_FILES_PROPERTIES_DIRS
duke@1 70
duke@1 71 # Add any automatically found properties files to the properties file list
duke@1 72 FILES_properties += $(FILES_properties_auto1)
duke@1 73
duke@1 74 #
duke@1 75 # Get Resources help
duke@1 76 #
duke@1 77 include $(TOPDIR)/make/common/internal/Resources.gmk
duke@1 78
duke@1 79 #
duke@1 80 # Compiling .java files.
duke@1 81 #
duke@1 82
duke@1 83 #
duke@1 84 # Automatically add to FILES_java if AUTO_FILES_JAVA_DIRS is defined
duke@1 85 #
duke@1 86 # There are two basic types of sources, normal source files and the
duke@1 87 # generated ones. The Normal sources will be located in:
duke@1 88 # $(ALL_CLASSES_SRC)
duke@1 89 # The generated sources, which might show up late to dinner, are at:
duke@1 90 # $(GENSRCDIR)
duke@1 91 # and since they could be generated late, we need to be careful that
duke@1 92 # we look for these sources late and not use the ':=' assignment which
duke@1 93 # might miss their generation.
duke@1 94
duke@1 95 ifdef AUTO_FILES_JAVA_DIRS
ohair@118 96 # Filter out these files or directories
ohair@118 97 AUTO_FILES_JAVA_SOURCE_FILTERS1 = $(SCM_DIRs) 'X-*' '*-X-*' '*-template.java' ',*'
ohair@118 98 AUTO_FILES_JAVA_SOURCE_FILTERS2 =
ohair@118 99 AUTO_FILES_JAVA_SOURCE_FILTERS1 += $(AUTO_JAVA_PRUNE)
ohair@118 100 AUTO_FILES_JAVA_SOURCE_FILTERS2 += $(AUTO_JAVA_PRUNE)
duke@1 101
ohair@118 102 # First list is the normal sources that should always be there,
ohair@118 103 # by using the ':=', which means we do this processing once.
ohair@118 104 FILES_java_find_filters1 = $(AUTO_FILES_JAVA_SOURCE_FILTERS1:%=-name % -prune -o)
ohair@118 105 FILES_java_auto1 := \
ohair@118 106 $(shell \
ohair@118 107 for dir in $(ALL_CLASSES_SRC) ; do \
ohair@118 108 if [ -d $$dir ] ; then \
ohair@118 109 ( $(CD) $$dir; \
ohair@118 110 for sdir in $(AUTO_FILES_JAVA_DIRS); do \
ohair@118 111 if [ -d $$sdir ] ; then \
ohair@118 112 $(FIND) $$sdir $(FILES_java_find_filters1) \
ohair@118 113 -name '*.java' -print ; \
ohair@118 114 fi ; \
ohair@118 115 done \
ohair@118 116 ); \
ohair@118 117 fi; \
ohair@118 118 done \
ohair@118 119 )
duke@1 120 # Second list is the generated sources that should be rare, but will likely
duke@1 121 # show up late and we need to look for them at the last minute, so we
duke@1 122 # cannot use the ':=' assigment here. But if this gets expanded multiple
duke@1 123 # times, the if tests should make them relatively cheap.
ohair@118 124 FILES_java_find_filters2 = $(AUTO_FILES_JAVA_SOURCE_FILTERS2:%=-name % -prune -o)
ohair@118 125 FILES_java_auto2 = \
ohair@118 126 $(shell \
ohair@118 127 for dir in $(GENSRCDIR); do \
ohair@118 128 if [ -d $$dir ] ; then \
ohair@118 129 ( $(CD) $$dir; \
ohair@118 130 for sdir in $(AUTO_FILES_JAVA_DIRS); do \
ohair@118 131 if [ -d $$sdir ] ; then \
ohair@118 132 $(FIND) $$sdir $(FILES_java_find_filters2) \
ohair@118 133 -name '*.java' -print ; \
ohair@118 134 fi ; \
ohair@118 135 done \
ohair@118 136 ); \
ohair@118 137 fi; \
ohair@118 138 done \
ohair@118 139 )
duke@1 140 else
duke@1 141 FILES_java_auto1 =
duke@1 142 FILES_java_auto2 =
duke@1 143 endif
duke@1 144
duke@1 145 # Add all found java sources to FILES_java macro (if AUTO_FILES_JAVA_DIRS used)
duke@1 146 FILES_java += $(FILES_java_auto1) $(FILES_java_auto2)
duke@1 147
duke@1 148 # File that will hold java source names that need compiling
duke@1 149 JAVA_SOURCE_LIST=$(TEMPDIR)/.classes.list
duke@1 150
duke@1 151 # Add a java source to the list
duke@1 152 define add-java-file
duke@1 153 $(ECHO) "$?" >> $(JAVA_SOURCE_LIST)
duke@1 154 endef
duke@1 155
duke@1 156 $(CLASSDESTDIR)/%.class: $(GENSRCDIR)/%.java
duke@1 157 @$(add-java-file)
duke@1 158 $(CLASSDESTDIR)/%.class: $(PLATFORM_SRC)/classes/%.java
duke@1 159 @$(add-java-file)
duke@1 160 $(CLASSDESTDIR)/%.class: $(SHARE_SRC)/classes/%.java
duke@1 161 @$(add-java-file)
duke@1 162
duke@1 163 # List of class files needed
duke@1 164 FILES_class = $(FILES_java:%.java=$(CLASSDESTDIR)/%.class)
duke@1 165
duke@1 166 # Construct list of java sources we need to compile
duke@1 167 source_list_prime:
duke@1 168 @$(MKDIR) -p $(TEMPDIR)
duke@1 169 # Note that we slip resources in so that compiled properties files get created:
duke@1 170 $(JAVA_SOURCE_LIST) : source_list_prime resources $(FILES_class)
duke@1 171 @$(TOUCH) $@
duke@1 172
duke@1 173 .delete.classlist:
duke@1 174 @$(RM) $(JAVA_SOURCE_LIST)
duke@1 175
duke@1 176 # Make sure all newer sources are compiled (in a batch)
duke@1 177 classes : $(CLASSES_INIT) .delete.classlist .compile.classlist
duke@1 178
ohair@56 179 # Use this javac option to force it to favor the sourcepath file classes
ohair@56 180 # rather than any bootclasspath classes.
ohair@56 181 JAVAC_PREFER_SOURCE = -Xprefer:source
ohair@56 182
duke@1 183 .compile.classlist : $(JAVA_SOURCE_LIST)
duke@1 184 @$(MKDIR) -p $(CLASSDESTDIR)
ohair@114 185 if [ -s $(JAVA_SOURCE_LIST) ] ; then \
ohair@118 186 $(CAT) $(JAVA_SOURCE_LIST); \
ohair@56 187 $(JAVAC_CMD) $(JAVAC_PREFER_SOURCE) -sourcepath "$(SOURCEPATH)" -d $(CLASSDESTDIR) @$(JAVA_SOURCE_LIST); \
duke@1 188 fi
duke@1 189 @$(java-vm-cleanup)
duke@1 190
duke@1 191 clobber clean::
duke@1 192 $(RM) $(JAVA_SOURCE_LIST)
duke@1 193
duke@1 194 ifndef DONT_CLOBBER_CLASSES
duke@1 195 ifndef PACKAGE
duke@1 196 DONT_CLOBBER_CLASSES = true
duke@1 197 else
duke@1 198 DONT_CLOBBER_CLASSES = false
duke@1 199 endif
duke@1 200 endif
duke@1 201
duke@1 202 packages.clean:
duke@1 203 ifeq ($(DONT_CLOBBER_CLASSES),false)
duke@1 204 ifdef AUTO_FILES_JAVA_DIRS
ohair@114 205 $(RM) -r $(patsubst %, $(CLASSDESTDIR)/%, $(AUTO_FILES_JAVA_DIRS))
duke@1 206 else
duke@1 207 $(RM) -r $(CLASSDESTDIR)/$(PKGDIR)
duke@1 208 endif
duke@1 209 endif
duke@1 210
duke@1 211 classes.clean: packages.clean
duke@1 212 $(RM) $(JAVA_SOURCE_LIST)
duke@1 213
ohair@194 214 clean clobber:: classes.clean .delete.classlist
duke@1 215
duke@1 216 #
duke@1 217 # Default dependencies
duke@1 218 #
duke@1 219
duke@1 220 all: build
duke@1 221
ohair@194 222 build: classes
duke@1 223
duke@1 224 default: all
duke@1 225
duke@1 226 .PHONY: all build clean clobber \
duke@1 227 .delete.classlist classes .compile.classlist classes.clean \
duke@1 228 batch_compile
duke@1 229

mercurial