make/common/Rules.gmk

changeset 1
55540e827aef
child 56
53d5b45f73ab
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/make/common/Rules.gmk	Sat Dec 01 00:00:00 2007 +0000
     1.3 @@ -0,0 +1,292 @@
     1.4 +#
     1.5 +# Copyright 1995-2007 Sun Microsystems, Inc.  All Rights Reserved.
     1.6 +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 +#
     1.8 +# This code is free software; you can redistribute it and/or modify it
     1.9 +# under the terms of the GNU General Public License version 2 only, as
    1.10 +# published by the Free Software Foundation.  Sun designates this
    1.11 +# particular file as subject to the "Classpath" exception as provided
    1.12 +# by Sun in the LICENSE file that accompanied this code.
    1.13 +#
    1.14 +# This code is distributed in the hope that it will be useful, but WITHOUT
    1.15 +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.16 +# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.17 +# version 2 for more details (a copy is included in the LICENSE file that
    1.18 +# accompanied this code).
    1.19 +#
    1.20 +# You should have received a copy of the GNU General Public License version
    1.21 +# 2 along with this work; if not, write to the Free Software Foundation,
    1.22 +# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.23 +#
    1.24 +# Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    1.25 +# CA 95054 USA or visit www.sun.com if you need additional information or
    1.26 +# have any questions.
    1.27 +#
    1.28 +
    1.29 +#
    1.30 +#
    1.31 +# Rules shared by all Java makefiles.
    1.32 +#
    1.33 +# Used to apply to source file $<, checks code conventions, issues warnings.
    1.34 +define check-conventions
    1.35 +  if [ "$(CONVENTION_WATCH)" = "true" ] ; then \
    1.36 +    if [ "`$(CAT) -n -v -t $< | $(EGREP) -v '\@\(\#\)' | $(EGREP) '\^[MLI]'`" != "" ] ; then \
    1.37 +      $(ECHO) "WARNING: File contains tabs, ^M, or ^L characters: $<"; \
    1.38 +      if [ "$(CONVENTION_DETAILS)" = "true" ] ; then \
    1.39 +        $(CAT) -n -v -t $< | $(EGREP) -v '\@\(\#\)' | $(EGREP) '\^[MLI]' ; \
    1.40 +      fi; \
    1.41 +    fi; \
    1.42 +  fi
    1.43 +endef
    1.44 +
    1.45 +# Make sure the default rule is all
    1.46 +rules_default_rule: all
    1.47 +
    1.48 +#
    1.49 +# Directory set up.  (Needed by deploy workspace)
    1.50 +# 
    1.51 +$(CLASSDESTDIR) $(CLASSHDRDIR) $(OBJDIR) $(OUTPUTDIR) $(BINDIR) $(LIBDIR) $(LIBDIR)/$(LIBARCH) $(TEMPDIR) $(EXTDIR):
    1.52 +	$(MKDIR) -p $@ 
    1.53 +
    1.54 +#
    1.55 +# All source tree areas for java/properties files 
    1.56 +#
    1.57 +ALL_CLASSES_SRC = $(SHARE_SRC)/classes $(PLATFORM_SRC)/classes
    1.58 +
    1.59 +#
    1.60 +# If AUTO_FILES_PROPERTIES_DIRS used, automatically find properties files
    1.61 +#
    1.62 +ifdef AUTO_FILES_PROPERTIES_DIRS
    1.63 +  AUTO_FILES_PROPERTIES_FILTERS1  = $(SCM_DIRs) 'X-*' '*-X-*' ',*'
    1.64 +  AUTO_FILES_PROPERTIES_FILTERS1 += $(AUTO_PROPERTIES_PRUNE)
    1.65 +  FILES_properties_find_filters1 = $(AUTO_FILES_PROPERTIES_FILTERS1:%=-name % -prune -o)
    1.66 +  FILES_properties_auto1 := \
    1.67 +     $(shell \
    1.68 +        for dir in $(ALL_CLASSES_SRC) ; do \
    1.69 +          if [ -d $$dir ] ; then \
    1.70 +            ( $(CD) $$dir; \
    1.71 +              for sdir in $(AUTO_FILES_PROPERTIES_DIRS); do \
    1.72 +                if [ -d $$sdir ] ; then \
    1.73 +                  $(FIND) $$sdir $(FILES_properties_find_filters1) \
    1.74 +                                 -name '*.properties' -print ; \
    1.75 +                fi ; \
    1.76 +              done \
    1.77 +            ); \
    1.78 +          fi; \
    1.79 +        done \
    1.80 +      )
    1.81 +else
    1.82 +  FILES_properties_auto1 =
    1.83 +endif # AUTO_FILES_PROPERTIES_DIRS
    1.84 +
    1.85 +# Add any automatically found properties files to the properties file list
    1.86 +FILES_properties += $(FILES_properties_auto1)
    1.87 +
    1.88 +#
    1.89 +# Get Resources help
    1.90 +#
    1.91 +include $(TOPDIR)/make/common/internal/Resources.gmk
    1.92 +
    1.93 +#
    1.94 +# Compiling .java files.
    1.95 +#
    1.96 +
    1.97 +#
    1.98 +# Automatically add to FILES_java if AUTO_FILES_JAVA_DIRS is defined
    1.99 +#
   1.100 +#    There are two basic types of sources, normal source files and the
   1.101 +#    generated ones. The Normal sources will be located in:
   1.102 +#         $(ALL_CLASSES_SRC)
   1.103 +#    The generated sources, which might show up late to dinner, are at:
   1.104 +#         $(GENSRCDIR)
   1.105 +#    and since they could be generated late, we need to be careful that
   1.106 +#    we look for these sources late and not use the ':=' assignment which
   1.107 +#    might miss their generation.
   1.108 +
   1.109 +ifdef AUTO_FILES_JAVA_DIRS
   1.110 +  # Filter out these files or directories
   1.111 +  AUTO_FILES_JAVA_SOURCE_FILTERS1  = $(SCM_DIRs) 'X-*' '*-X-*' '*-template.java' ',*'
   1.112 +  AUTO_FILES_JAVA_SOURCE_FILTERS2  = 
   1.113 +  AUTO_FILES_JAVA_SOURCE_FILTERS1 += $(AUTO_JAVA_PRUNE)
   1.114 +  AUTO_FILES_JAVA_SOURCE_FILTERS2 += $(AUTO_JAVA_PRUNE)
   1.115 +
   1.116 +  # First list is the normal sources that should always be there,
   1.117 +  #   by using the ':=', which means we do this processing once.
   1.118 +  FILES_java_find_filters1 = $(AUTO_FILES_JAVA_SOURCE_FILTERS1:%=-name % -prune -o)
   1.119 +  FILES_java_auto1 := \
   1.120 +     $(shell \
   1.121 +        for dir in $(ALL_CLASSES_SRC) ; do \
   1.122 +          if [ -d $$dir ] ; then \
   1.123 +            ( $(CD) $$dir; \
   1.124 +              for sdir in $(AUTO_FILES_JAVA_DIRS); do \
   1.125 +                if [ -d $$sdir ] ; then \
   1.126 +                  $(FIND) $$sdir $(FILES_java_find_filters1) \
   1.127 +                                 -name '*.java' -print ; \
   1.128 +                fi ; \
   1.129 +              done \
   1.130 +            ); \
   1.131 +          fi; \
   1.132 +        done \
   1.133 +      )
   1.134 +  # Second list is the generated sources that should be rare, but will likely
   1.135 +  #   show up late and we need to look for them at the last minute, so we
   1.136 +  #   cannot use the ':=' assigment here. But if this gets expanded multiple
   1.137 +  #   times, the if tests should make them relatively cheap.
   1.138 +  FILES_java_find_filters2 = $(AUTO_FILES_JAVA_SOURCE_FILTERS2:%=-name % -prune -o)
   1.139 +  FILES_java_auto2 = \
   1.140 +     $(shell \
   1.141 +        for dir in $(GENSRCDIR); do \
   1.142 +          if [ -d $$dir ] ; then \
   1.143 +            ( $(CD) $$dir; \
   1.144 +              for sdir in $(AUTO_FILES_JAVA_DIRS); do \
   1.145 +                if [ -d $$sdir ] ; then \
   1.146 +                  $(FIND) $$sdir $(FILES_java_find_filters2) \
   1.147 +                                 -name '*.java' -print ; \
   1.148 +                fi ; \
   1.149 +              done \
   1.150 +            ); \
   1.151 +          fi; \
   1.152 +        done \
   1.153 +      )
   1.154 +else
   1.155 +  FILES_java_auto1 =
   1.156 +  FILES_java_auto2 =
   1.157 +endif
   1.158 +
   1.159 +# Add all found java sources to FILES_java macro (if AUTO_FILES_JAVA_DIRS used)
   1.160 +FILES_java += $(FILES_java_auto1) $(FILES_java_auto2)
   1.161 +
   1.162 +# File that will hold java source names that need compiling
   1.163 +JAVA_SOURCE_LIST=$(TEMPDIR)/.classes.list
   1.164 +
   1.165 +# Add a java source to the list
   1.166 +define add-java-file
   1.167 +$(ECHO) "$?" >> $(JAVA_SOURCE_LIST)
   1.168 +$(check-conventions)
   1.169 +endef
   1.170 +
   1.171 +$(CLASSDESTDIR)/%.class: $(GENSRCDIR)/%.java
   1.172 +	@$(add-java-file)
   1.173 +$(CLASSDESTDIR)/%.class: $(PLATFORM_SRC)/classes/%.java
   1.174 +	@$(add-java-file)
   1.175 +$(CLASSDESTDIR)/%.class: $(SHARE_SRC)/classes/%.java
   1.176 +	@$(add-java-file)
   1.177 +
   1.178 +# List of class files needed
   1.179 +FILES_class = $(FILES_java:%.java=$(CLASSDESTDIR)/%.class)
   1.180 +
   1.181 +# Got to include exported files.
   1.182 +FILES_class += $(FILES_export:%.java=$(CLASSDESTDIR)/%.class)
   1.183 +
   1.184 +# Construct list of java sources we need to compile
   1.185 +source_list_prime:
   1.186 +	@$(MKDIR) -p $(TEMPDIR)
   1.187 +# Note that we slip resources in so that compiled properties files get created:
   1.188 +$(JAVA_SOURCE_LIST) : source_list_prime resources $(FILES_class)
   1.189 +	@$(TOUCH) $@
   1.190 +
   1.191 +.delete.classlist:
   1.192 +	@$(RM) $(JAVA_SOURCE_LIST)
   1.193 +
   1.194 +# Make sure all newer sources are compiled (in a batch)
   1.195 +classes : $(CLASSES_INIT) .delete.classlist .compile.classlist
   1.196 +
   1.197 +.compile.classlist : $(JAVA_SOURCE_LIST)
   1.198 +	@$(MKDIR) -p $(CLASSDESTDIR)
   1.199 +	@if [ `$(CAT) $(JAVA_SOURCE_LIST) | $(WC) -l` -ge 1 ] ; then \
   1.200 +	  $(ECHO) "# Java sources to be compiled: (listed in file $(JAVA_SOURCE_LIST))"; \
   1.201 +	  $(CAT) $(JAVA_SOURCE_LIST); \
   1.202 +	  $(ECHO) "# Running javac:"; \
   1.203 +	  $(ECHO) $(JAVAC_CMD) -sourcepath "$(SOURCEPATH)" -d $(CLASSDESTDIR) @$(JAVA_SOURCE_LIST); \
   1.204 +	  $(JAVAC_CMD) -sourcepath "$(SOURCEPATH)" -d $(CLASSDESTDIR) @$(JAVA_SOURCE_LIST); \
   1.205 +	fi
   1.206 +	@$(java-vm-cleanup)
   1.207 +
   1.208 +clobber clean::
   1.209 +	$(RM) $(JAVA_SOURCE_LIST)
   1.210 +
   1.211 +ifndef DONT_CLOBBER_CLASSES
   1.212 +  ifndef PACKAGE
   1.213 +    DONT_CLOBBER_CLASSES = true
   1.214 +  else
   1.215 +    DONT_CLOBBER_CLASSES = false
   1.216 +  endif
   1.217 +endif
   1.218 +
   1.219 +packages.clean:
   1.220 +ifeq ($(DONT_CLOBBER_CLASSES),false)
   1.221 +  ifdef AUTO_FILES_JAVA_DIRS
   1.222 +	@for sdir in $(AUTO_FILES_JAVA_DIRS); do \
   1.223 +	  $(ECHO) "$(RM) -r $(CLASSDESTDIR)/$$sdir"; \
   1.224 +	  $(RM) -r $(CLASSDESTDIR)/$$sdir; \
   1.225 +        done
   1.226 +  else
   1.227 +	$(RM) -r $(CLASSDESTDIR)/$(PKGDIR)
   1.228 +  endif
   1.229 +endif
   1.230 +
   1.231 +classes.clean: packages.clean
   1.232 +	$(RM) $(JAVA_SOURCE_LIST)
   1.233 +
   1.234 +#
   1.235 +# C and C++ make dependencies
   1.236 +#
   1.237 +include $(TOPDIR)/make/common/internal/NativeCompileRules.gmk
   1.238 +
   1.239 +#
   1.240 +# Running Javah to generate stuff into CClassHeaders.
   1.241 +#
   1.242 +
   1.243 +ifdef FILES_export
   1.244 +
   1.245 +CLASSES.export  = $(subst /,.,$(FILES_export:%.java=%))
   1.246 +CLASSES.export += $(subst /,.,$(FILES_export2:%.java=%))
   1.247 +CLASSES.export += $(subst /,.,$(FILES_export3:%.java=%))
   1.248 +CLASSES_export  = $(FILES_export:%.java=$(CLASSDESTDIR)/%.class)
   1.249 +CLASSES_export += $(FILES_export2:%.java=$(CLASSDESTDIR)/%.class)
   1.250 +CLASSES_export += $(FILES_export3:%.java=$(CLASSDESTDIR)/%.class)
   1.251 +
   1.252 +# Fix when deploy workspace makefiles don't depend on this name
   1.253 +#CLASSHDR_DOTFILE=$(CLASSHDRDIR)/.classheaders
   1.254 +
   1.255 +CLASSHDR_DOTFILE=$(OBJDIR)/.class.headers.$(ARCH)
   1.256 +
   1.257 +classheaders: classes $(CLASSHDR_DOTFILE)
   1.258 +
   1.259 +$(CLASSHDR_DOTFILE): $(CLASSES_export)
   1.260 +	$(prep-target)
   1.261 +	@$(ECHO) "# Running javah:"
   1.262 +	$(JAVAH_CMD) -d $(CLASSHDRDIR)/ \
   1.263 +		$(CLASSES.export) $(subst $$,\$$,$(EXPORTED_inner))
   1.264 +	@$(java-vm-cleanup)
   1.265 +	@$(TOUCH) $@
   1.266 +
   1.267 +classheaders.clean:
   1.268 +	$(RM) $(CLASSHDR_DOTFILE)
   1.269 +	$(RM) -r $(CLASSHDRDIR)
   1.270 +
   1.271 +else # FILES_export
   1.272 +
   1.273 +classheaders: classes
   1.274 +
   1.275 +classheaders.clean: 
   1.276 +
   1.277 +endif # FILES_export
   1.278 +
   1.279 +clean clobber:: classheaders.clean classes.clean .delete.classlist
   1.280 +
   1.281 +# 
   1.282 +# Default dependencies
   1.283 +#
   1.284 +
   1.285 +all: build
   1.286 +
   1.287 +build: classheaders
   1.288 +
   1.289 +default: all
   1.290 +
   1.291 +.PHONY: all build clean clobber \
   1.292 +        .delete.classlist classes .compile.classlist classes.clean \
   1.293 +	 classheaders classheaders.clean \
   1.294 +	 batch_compile
   1.295 +

mercurial