jdk/make/common/Rules.gmk
changeset 2 90ce3da70b43
child 313 4ca328b9cf83
equal deleted inserted replaced
0:fd16c54261b3 2:90ce3da70b43
       
     1 #
       
     2 # Copyright 1995-2007 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 #
       
    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) 'X-*' '*-X-*' ',*'
       
    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) 'X-*' '*-X-*' '*-template.java' ',*'
       
   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 	@if [ `$(CAT) $(JAVA_SOURCE_LIST) | $(WC) -l` -ge 1 ] ; then \
       
   235 	  $(ECHO) "# Java sources to be compiled: (listed in file $(JAVA_SOURCE_LIST))"; \
       
   236 	  $(CAT) $(JAVA_SOURCE_LIST); \
       
   237 	  $(ECHO) "# Running javac:"; \
       
   238 	  $(ECHO) $(JAVAC_CMD) -sourcepath "$(SOURCEPATH)" -d $(CLASSDESTDIR) @$(JAVA_SOURCE_LIST); \
       
   239 	  $(JAVAC_CMD) -sourcepath "$(SOURCEPATH)" -d $(CLASSDESTDIR) @$(JAVA_SOURCE_LIST); \
       
   240 	fi
       
   241 	@$(java-vm-cleanup)
       
   242 
       
   243 clobber clean::
       
   244 	$(RM) $(JAVA_SOURCE_LIST)
       
   245 
       
   246 ifndef DONT_CLOBBER_CLASSES
       
   247   ifndef PACKAGE
       
   248     DONT_CLOBBER_CLASSES = true
       
   249   else
       
   250     DONT_CLOBBER_CLASSES = false
       
   251   endif
       
   252 endif
       
   253 
       
   254 packages.clean:
       
   255 ifeq ($(DONT_CLOBBER_CLASSES),false)
       
   256   ifdef AUTO_FILES_JAVA_DIRS
       
   257 	@for sdir in $(AUTO_FILES_JAVA_DIRS); do \
       
   258 	  $(ECHO) "$(RM) -r $(CLASSDESTDIR)/$$sdir"; \
       
   259 	  $(RM) -r $(CLASSDESTDIR)/$$sdir; \
       
   260         done
       
   261   else
       
   262 	$(RM) -r $(CLASSDESTDIR)/$(PKGDIR)
       
   263   endif
       
   264 endif
       
   265 
       
   266 ifdef DEMOS
       
   267 classes.clean:
       
   268 	$(RM) -r $(DEMODST) $(CLASSDESTDIR)
       
   269 else
       
   270 classes.clean: packages.clean
       
   271 	$(RM) $(JAVA_SOURCE_LIST)
       
   272 endif
       
   273 
       
   274 #
       
   275 # C and C++ make dependencies
       
   276 #
       
   277 include $(JDK_TOPDIR)/make/common/internal/NativeCompileRules.gmk
       
   278 
       
   279 #
       
   280 # Running Javah to generate stuff into CClassHeaders.
       
   281 #
       
   282 
       
   283 ifdef FILES_export
       
   284 
       
   285 CLASSES.export  = $(subst /,.,$(FILES_export:%.java=%))
       
   286 CLASSES.export += $(subst /,.,$(FILES_export2:%.java=%))
       
   287 CLASSES.export += $(subst /,.,$(FILES_export3:%.java=%))
       
   288 CLASSES_export  = $(FILES_export:%.java=$(CLASSDESTDIR)/%.class)
       
   289 CLASSES_export += $(FILES_export2:%.java=$(CLASSDESTDIR)/%.class)
       
   290 CLASSES_export += $(FILES_export3:%.java=$(CLASSDESTDIR)/%.class)
       
   291 
       
   292 # Fix when deploy workspace makefiles don't depend on this name
       
   293 #CLASSHDR_DOTFILE=$(CLASSHDRDIR)/.classheaders
       
   294 
       
   295 CLASSHDR_DOTFILE=$(OBJDIR)/.class.headers.$(ARCH)
       
   296 
       
   297 classheaders: classes $(CLASSHDR_DOTFILE)
       
   298 
       
   299 $(CLASSHDR_DOTFILE): $(CLASSES_export)
       
   300 	$(prep-target)
       
   301 	@$(ECHO) "# Running javah:"
       
   302 	$(JAVAH_CMD) -d $(CLASSHDRDIR)/ \
       
   303 		$(CLASSES.export) $(subst $$,\$$,$(EXPORTED_inner))
       
   304 	@$(java-vm-cleanup)
       
   305 	@$(TOUCH) $@
       
   306 
       
   307 classheaders.clean:
       
   308 	$(RM) $(CLASSHDR_DOTFILE)
       
   309 	$(RM) -r $(CLASSHDRDIR)
       
   310 
       
   311 else # FILES_export
       
   312 
       
   313 classheaders: classes
       
   314 
       
   315 classheaders.clean: 
       
   316 
       
   317 endif # FILES_export
       
   318 
       
   319 clean clobber:: classheaders.clean classes.clean .delete.classlist
       
   320 
       
   321 # 
       
   322 # Default dependencies
       
   323 #
       
   324 
       
   325 all: build
       
   326 
       
   327 build: classheaders
       
   328 
       
   329 default: all
       
   330 
       
   331 .PHONY: all build clean clobber \
       
   332         .delete.classlist classes .compile.classlist classes.clean \
       
   333 	 classheaders classheaders.clean \
       
   334 	 batch_compile
       
   335