1 #
   2 # Copyright (c) 1995, 2008, 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 #
  27 #
  28 # Rules shared by all Java makefiles.
  29 #
  30 # Used to apply to source file $<, checks code conventions, issues warnings.
  31 define check-conventions
  32   if [ "$(CONVENTION_WATCH)" = "true" ] ; then \
  33     if [ "`$(CAT) -n -v -t $< | $(EGREP) -v '\@\(\#\)' | $(EGREP) '\^[MLI]'`" != "" ] ; then \
  34       $(ECHO) "WARNING: File contains tabs, ^M, or ^L characters: $<"; \
  35       if [ "$(CONVENTION_DETAILS)" = "true" ] ; then \
  36         $(CAT) -n -v -t $< | $(EGREP) -v '\@\(\#\)' | $(EGREP) '\^[MLI]' ; \
  37       fi; \
  38     fi; \
  39   fi
  40 endef
  41 
  42 # Make sure the default rule is all
  43 rules_default_rule: all
  44 
  45 #
  46 # Directory set up.  (Needed by deploy workspace)
  47 # 
  48 $(CLASSDESTDIR) $(CLASSHDRDIR) $(OBJDIR) $(OUTPUTDIR) $(BINDIR) $(LIBDIR) $(LIBDIR)/$(LIBARCH) $(TEMPDIR) $(EXTDIR):
  49         $(MKDIR) -p $@ 
  50 
  51 #
  52 # All source tree areas for java/properties files (a few may be closed)
  53 #
  54 ifdef OPENJDK
  55   ALL_CLASSES_SRC = $(SHARE_SRC)/classes $(PLATFORM_SRC)/classes
  56 else
  57   ALL_CLASSES_SRC = \
  58         $(CLOSED_SHARE_SRC)/classes $(CLOSED_PLATFORM_SRC)/classes \
  59         $(SHARE_SRC)/classes $(PLATFORM_SRC)/classes
  60 endif
  61 
  62 #
  63 # If AUTO_FILES_PROPERTIES_DIRS used, automatically find properties files
  64 #
  65 ifdef AUTO_FILES_PROPERTIES_DIRS
  66   AUTO_FILES_PROPERTIES_FILTERS1  = $(SCM_DIRs) ',*'
  67   AUTO_FILES_PROPERTIES_FILTERS1 += $(AUTO_PROPERTIES_PRUNE)
  68   FILES_properties_find_filters1 = $(AUTO_FILES_PROPERTIES_FILTERS1:%=-name % -prune -o)
  69   FILES_properties_auto1 := \
  70      $(shell \
  71         for dir in $(ALL_CLASSES_SRC) ; do \
  72           if [ -d $$dir ] ; then \
  73             ( $(CD) $$dir; \
  74               for sdir in $(AUTO_FILES_PROPERTIES_DIRS); do \
  75                 if [ -d $$sdir ] ; then \
  76                   $(FIND) $$sdir $(FILES_properties_find_filters1) \
  77                                  -name '*.properties' -print ; \
  78                 fi ; \
  79               done \
  80             ); \
  81           fi; \
  82         done \
  83       )
  84 else
  85   FILES_properties_auto1 =
  86 endif # AUTO_FILES_PROPERTIES_DIRS
  87 
  88 # Add any automatically found properties files to the properties file list
  89 FILES_properties += $(FILES_properties_auto1)
  90 
  91 #
  92 # Get Resources help
  93 #
  94 include $(JDK_TOPDIR)/make/common/internal/Resources.gmk
  95 
  96 #
  97 # Compiling .java files.
  98 #
  99 
 100 #
 101 # Automatically add to FILES_java if AUTO_FILES_JAVA_DIRS is defined
 102 #
 103 #    There are two basic types of sources, normal source files and the
 104 #    generated ones. The Normal sources will be located in:
 105 #         $(ALL_CLASSES_SRC)
 106 #    The generated sources, which might show up late to dinner, are at:
 107 #         $(GENSRCDIR)
 108 #    and since they could be generated late, we need to be careful that
 109 #    we look for these sources late and not use the ':=' assignment which
 110 #    might miss their generation.
 111 
 112 ifdef AUTO_FILES_JAVA_DIRS
 113   # Filter out these files or directories
 114   AUTO_FILES_JAVA_SOURCE_FILTERS1  = $(SCM_DIRs) ',*'
 115   AUTO_FILES_JAVA_SOURCE_FILTERS2  = 
 116   AUTO_FILES_JAVA_SOURCE_FILTERS1 += $(AUTO_JAVA_PRUNE)
 117   AUTO_FILES_JAVA_SOURCE_FILTERS2 += $(AUTO_JAVA_PRUNE)
 118 
 119   # First list is the normal sources that should always be there,
 120   #   by using the ':=', which means we do this processing once.
 121   FILES_java_find_filters1 = $(AUTO_FILES_JAVA_SOURCE_FILTERS1:%=-name % -prune -o)
 122   FILES_java_auto1 := \
 123      $(shell \
 124         for dir in $(ALL_CLASSES_SRC) ; do \
 125           if [ -d $$dir ] ; then \
 126             ( $(CD) $$dir; \
 127               for sdir in $(AUTO_FILES_JAVA_DIRS); do \
 128                 if [ -d $$sdir ] ; then \
 129                   $(FIND) $$sdir $(FILES_java_find_filters1) \
 130                                  -name '*.java' -print ; \
 131                 fi ; \
 132               done \
 133             ); \
 134           fi; \
 135         done \
 136       )
 137   # Second list is the generated sources that should be rare, but will likely
 138   #   show up late and we need to look for them at the last minute, so we
 139   #   cannot use the ':=' assigment here. But if this gets expanded multiple
 140   #   times, the if tests should make them relatively cheap.
 141   FILES_java_find_filters2 = $(AUTO_FILES_JAVA_SOURCE_FILTERS2:%=-name % -prune -o)
 142   FILES_java_auto2 = \
 143      $(shell \
 144         for dir in $(GENSRCDIR); do \
 145           if [ -d $$dir ] ; then \
 146             ( $(CD) $$dir; \
 147               for sdir in $(AUTO_FILES_JAVA_DIRS); do \
 148                 if [ -d $$sdir ] ; then \
 149                   $(FIND) $$sdir $(FILES_java_find_filters2) \
 150                                  -name '*.java' -print ; \
 151                 fi ; \
 152               done \
 153             ); \
 154           fi; \
 155         done \
 156       )
 157 else
 158   FILES_java_auto1 =
 159   FILES_java_auto2 =
 160 endif
 161 
 162 # Add all found java sources to FILES_java macro (if AUTO_FILES_JAVA_DIRS used)
 163 FILES_java += $(FILES_java_auto1) $(FILES_java_auto2)
 164 
 165 # File that will hold java source names that need compiling
 166 JAVA_SOURCE_LIST=$(TEMPDIR)/.classes.list
 167 
 168 # Add a java source to the list
 169 define add-java-file
 170 $(ECHO) "$?" >> $(JAVA_SOURCE_LIST)
 171 $(check-conventions)
 172 endef
 173 
 174 ifdef DEMOS
 175 $(CLASSDESTDIR)/%.class: $(SOURCEPATH)/%.java
 176         @$(add-java-file)
 177 #Redirect zh_HK java files to tmp directory which created from zh_TW
 178 #$(CLASSDESTDIR)/%_zh_HK.class: $(JDK_L10N_TMP_OUTPUTDIR)/%_zh_HK.java
 179 #       @$(add-java-file)
 180 else
 181 
 182 #
 183 # Rules for closed files
 184 #
 185 # If filenames are duplicated between open/closed workspaces, prefer
 186 # the closed files.
 187 #
 188 # Rule ordering in this Makefile is important: some targets depend
 189 # on closed files replacing open ones, and thus the closed file rules
 190 # must be found before the open ones.
 191 #
 192 # Don't reorder without consulting teams that depend on this behavior.
 193 #
 194 ifndef OPENJDK
 195 $(CLASSDESTDIR)/%.class: $(CLOSED_PLATFORM_SRC)/classes/%.java
 196         @$(add-java-file)
 197 $(CLASSDESTDIR)/%.class: $(CLOSED_SHARE_SRC)/classes/%.java
 198         @$(add-java-file)
 199 endif
 200 
 201 $(CLASSDESTDIR)/%.class: $(GENSRCDIR)/%.java
 202         @$(add-java-file)
 203 $(CLASSDESTDIR)/%.class: $(PLATFORM_SRC)/classes/%.java
 204         @$(add-java-file)
 205 $(CLASSDESTDIR)/%.class: $(SHARE_SRC)/classes/%.java
 206         @$(add-java-file)
 207 
 208 #Redirect zh_HK java files to tmp directory which created from zh_TW
 209 $(CLASSDESTDIR)/%_zh_HK.class: $(JDK_L10N_TMP_OUTPUTDIR)/%_zh_HK.java
 210         @$(add-java-file)
 211 endif
 212 
 213 # List of class files needed
 214 FILES_class = $(FILES_java:%.java=$(CLASSDESTDIR)/%.class)
 215 
 216 # Got to include exported files.
 217 FILES_class += $(FILES_export:%.java=$(CLASSDESTDIR)/%.class)
 218 
 219 # Construct list of java sources we need to compile
 220 source_list_prime:
 221         @$(MKDIR) -p $(TEMPDIR)
 222 # Note that we slip resources in so that compiled properties files get created:
 223 $(JAVA_SOURCE_LIST) : source_list_prime resources $(FILES_class)
 224         @$(TOUCH) $@
 225 
 226 .delete.classlist:
 227         @$(RM) $(JAVA_SOURCE_LIST)
 228 
 229 # Make sure all newer sources are compiled (in a batch)
 230 classes : $(CLASSES_INIT) .delete.classlist .compile.classlist
 231 
 232 .compile.classlist : $(JAVA_SOURCE_LIST)
 233         @$(MKDIR) -p $(CLASSDESTDIR)
 234         @$(RM) $<.filtered
 235         @$(CAT) $< | $(NAWK) 'length>0' | $(SORT) -u > $<.filtered
 236         @if [ `$(CAT) $<.filtered | $(WC) -l` -ge 1 ] ; then \
 237           $(ECHO) "# Java sources to be compiled: (listed in file $<)"; \
 238           $(CAT) $<.filtered; \
 239           $(ECHO) "# Running javac:"; \
 240           $(ECHO) $(JAVAC_CMD) -sourcepath "$(SOURCEPATH)" -d $(CLASSDESTDIR) @$<.filtered; \
 241           $(JAVAC_CMD) -sourcepath "$(SOURCEPATH)" -d $(CLASSDESTDIR) @$<.filtered; \
 242           $(TouchModule); \
 243         fi
 244         @$(java-vm-cleanup)
 245 
 246 clobber clean::
 247         $(RM) $(JAVA_SOURCE_LIST)
 248 
 249 ifndef DONT_CLOBBER_CLASSES
 250   ifndef PACKAGE
 251     DONT_CLOBBER_CLASSES = true
 252   else
 253     DONT_CLOBBER_CLASSES = false
 254   endif
 255 endif
 256 
 257 packages.clean:
 258 ifeq ($(DONT_CLOBBER_CLASSES),false)
 259   ifdef AUTO_FILES_JAVA_DIRS
 260         @for sdir in $(AUTO_FILES_JAVA_DIRS); do \
 261           $(ECHO) "$(RM) -r $(CLASSDESTDIR)/$$sdir"; \
 262           $(RM) -r $(CLASSDESTDIR)/$$sdir; \
 263         done
 264   else
 265         $(RM) -r $(CLASSDESTDIR)/$(PKGDIR)
 266   endif
 267 endif
 268 
 269 ifdef DEMOS
 270 classes.clean:
 271         $(RM) -r $(DEMODST) $(CLASSDESTDIR)
 272 else
 273 classes.clean: packages.clean
 274         $(RM) $(JAVA_SOURCE_LIST)
 275 endif
 276 
 277 #
 278 # C and C++ make dependencies
 279 #
 280 include $(JDK_TOPDIR)/make/common/internal/NativeCompileRules.gmk
 281 
 282 #
 283 # Running Javah to generate stuff into CClassHeaders.
 284 #
 285 
 286 ifdef FILES_export
 287 
 288 CLASSES.export  = $(subst /,.,$(FILES_export:%.java=%))
 289 CLASSES.export += $(subst /,.,$(FILES_export2:%.java=%))
 290 CLASSES.export += $(subst /,.,$(FILES_export3:%.java=%))
 291 CLASSES_export  = $(FILES_export:%.java=$(CLASSDESTDIR)/%.class)
 292 CLASSES_export += $(FILES_export2:%.java=$(CLASSDESTDIR)/%.class)
 293 CLASSES_export += $(FILES_export3:%.java=$(CLASSDESTDIR)/%.class)
 294 
 295 # Fix when deploy workspace makefiles don't depend on this name
 296 #CLASSHDR_DOTFILE=$(CLASSHDRDIR)/.classheaders
 297 
 298 CLASSHDR_DOTFILE=$(OBJDIR)/.class.headers.$(ARCH)
 299 
 300 classheaders: classes $(CLASSHDR_DOTFILE)
 301 
 302 $(CLASSHDR_DOTFILE): $(CLASSES_export)
 303         $(prep-target)
 304         @$(ECHO) "# Running javah:"
 305         $(JAVAH_CMD) -d $(CLASSHDRDIR)/ \
 306                 $(CLASSES.export) $(subst $$,\$$,$(EXPORTED_inner))
 307         @$(java-vm-cleanup)
 308         @$(TOUCH) $@
 309 
 310 classheaders.clean:
 311         $(RM) $(CLASSHDR_DOTFILE)
 312         $(RM) -r $(CLASSHDRDIR)
 313 
 314 else # FILES_export
 315 
 316 classheaders: classes
 317 
 318 classheaders.clean: 
 319 
 320 endif # FILES_export
 321 
 322 clean clobber:: classheaders.clean classes.clean .delete.classlist
 323 
 324 # 
 325 # Default dependencies
 326 #
 327 
 328 all: build
 329 
 330 build: classheaders
 331 
 332 default: all
 333 
 334 .PHONY: all build clean clobber \
 335         .delete.classlist classes .compile.classlist classes.clean \
 336          classheaders classheaders.clean \
 337          batch_compile
 338