Rules.gmk 10.2 KB
Newer Older
D
duke 已提交
1
#
X
xdono 已提交
2
# Copyright 1995-2008 Sun Microsystems, Inc.  All Rights Reserved.
D
duke 已提交
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# This code is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2 only, as
# published by the Free Software Foundation.  Sun designates this
# particular file as subject to the "Classpath" exception as provided
# by Sun in the LICENSE file that accompanied this code.
#
# This code is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
# version 2 for more details (a copy is included in the LICENSE file that
# accompanied this code).
#
# You should have received a copy of the GNU General Public License version
# 2 along with this work; if not, write to the Free Software Foundation,
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
# CA 95054 USA or visit www.sun.com if you need additional information or
# have any questions.
#

#
#
# Rules shared by all Java makefiles.
#
# Used to apply to source file $<, checks code conventions, issues warnings.
define check-conventions
  if [ "$(CONVENTION_WATCH)" = "true" ] ; then \
    if [ "`$(CAT) -n -v -t $< | $(EGREP) -v '\@\(\#\)' | $(EGREP) '\^[MLI]'`" != "" ] ; then \
      $(ECHO) "WARNING: File contains tabs, ^M, or ^L characters: $<"; \
      if [ "$(CONVENTION_DETAILS)" = "true" ] ; then \
        $(CAT) -n -v -t $< | $(EGREP) -v '\@\(\#\)' | $(EGREP) '\^[MLI]' ; \
      fi; \
    fi; \
  fi
endef

# Make sure the default rule is all
rules_default_rule: all

#
# Directory set up.  (Needed by deploy workspace)
# 
$(CLASSDESTDIR) $(CLASSHDRDIR) $(OBJDIR) $(OUTPUTDIR) $(BINDIR) $(LIBDIR) $(LIBDIR)/$(LIBARCH) $(TEMPDIR) $(EXTDIR):
	$(MKDIR) -p $@ 

#
# All source tree areas for java/properties files (a few may be closed)
#
ifdef OPENJDK
  ALL_CLASSES_SRC = $(SHARE_SRC)/classes $(PLATFORM_SRC)/classes
else
  ALL_CLASSES_SRC = \
	$(CLOSED_SHARE_SRC)/classes $(CLOSED_PLATFORM_SRC)/classes \
	$(SHARE_SRC)/classes $(PLATFORM_SRC)/classes
endif

#
# If AUTO_FILES_PROPERTIES_DIRS used, automatically find properties files
#
ifdef AUTO_FILES_PROPERTIES_DIRS
66
  AUTO_FILES_PROPERTIES_FILTERS1  = $(SCM_DIRs) ',*'
D
duke 已提交
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
  AUTO_FILES_PROPERTIES_FILTERS1 += $(AUTO_PROPERTIES_PRUNE)
  FILES_properties_find_filters1 = $(AUTO_FILES_PROPERTIES_FILTERS1:%=-name % -prune -o)
  FILES_properties_auto1 := \
     $(shell \
        for dir in $(ALL_CLASSES_SRC) ; do \
          if [ -d $$dir ] ; then \
            ( $(CD) $$dir; \
              for sdir in $(AUTO_FILES_PROPERTIES_DIRS); do \
                if [ -d $$sdir ] ; then \
                  $(FIND) $$sdir $(FILES_properties_find_filters1) \
                                 -name '*.properties' -print ; \
                fi ; \
              done \
            ); \
          fi; \
        done \
      )
else
  FILES_properties_auto1 =
endif # AUTO_FILES_PROPERTIES_DIRS

# Add any automatically found properties files to the properties file list
FILES_properties += $(FILES_properties_auto1)

#
# Get Resources help
#
include $(JDK_TOPDIR)/make/common/internal/Resources.gmk

#
# Compiling .java files.
#

#
# Automatically add to FILES_java if AUTO_FILES_JAVA_DIRS is defined
#
#    There are two basic types of sources, normal source files and the
#    generated ones. The Normal sources will be located in:
#         $(ALL_CLASSES_SRC)
#    The generated sources, which might show up late to dinner, are at:
#         $(GENSRCDIR)
#    and since they could be generated late, we need to be careful that
#    we look for these sources late and not use the ':=' assignment which
#    might miss their generation.

ifdef AUTO_FILES_JAVA_DIRS
  # Filter out these files or directories
114
  AUTO_FILES_JAVA_SOURCE_FILTERS1  = $(SCM_DIRs) ',*'
D
duke 已提交
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233
  AUTO_FILES_JAVA_SOURCE_FILTERS2  = 
  AUTO_FILES_JAVA_SOURCE_FILTERS1 += $(AUTO_JAVA_PRUNE)
  AUTO_FILES_JAVA_SOURCE_FILTERS2 += $(AUTO_JAVA_PRUNE)

  # First list is the normal sources that should always be there,
  #   by using the ':=', which means we do this processing once.
  FILES_java_find_filters1 = $(AUTO_FILES_JAVA_SOURCE_FILTERS1:%=-name % -prune -o)
  FILES_java_auto1 := \
     $(shell \
        for dir in $(ALL_CLASSES_SRC) ; do \
          if [ -d $$dir ] ; then \
            ( $(CD) $$dir; \
              for sdir in $(AUTO_FILES_JAVA_DIRS); do \
                if [ -d $$sdir ] ; then \
                  $(FIND) $$sdir $(FILES_java_find_filters1) \
                                 -name '*.java' -print ; \
                fi ; \
              done \
            ); \
          fi; \
        done \
      )
  # Second list is the generated sources that should be rare, but will likely
  #   show up late and we need to look for them at the last minute, so we
  #   cannot use the ':=' assigment here. But if this gets expanded multiple
  #   times, the if tests should make them relatively cheap.
  FILES_java_find_filters2 = $(AUTO_FILES_JAVA_SOURCE_FILTERS2:%=-name % -prune -o)
  FILES_java_auto2 = \
     $(shell \
        for dir in $(GENSRCDIR); do \
          if [ -d $$dir ] ; then \
            ( $(CD) $$dir; \
              for sdir in $(AUTO_FILES_JAVA_DIRS); do \
                if [ -d $$sdir ] ; then \
                  $(FIND) $$sdir $(FILES_java_find_filters2) \
                                 -name '*.java' -print ; \
                fi ; \
              done \
            ); \
          fi; \
        done \
      )
else
  FILES_java_auto1 =
  FILES_java_auto2 =
endif

# Add all found java sources to FILES_java macro (if AUTO_FILES_JAVA_DIRS used)
FILES_java += $(FILES_java_auto1) $(FILES_java_auto2)

# File that will hold java source names that need compiling
JAVA_SOURCE_LIST=$(TEMPDIR)/.classes.list

# Add a java source to the list
define add-java-file
$(ECHO) "$?" >> $(JAVA_SOURCE_LIST)
$(check-conventions)
endef

ifdef DEMOS
$(CLASSDESTDIR)/%.class: $(SOURCEPATH)/%.java
	@$(add-java-file)
#Redirect zh_HK java files to tmp directory which created from zh_TW
#$(CLASSDESTDIR)/%_zh_HK.class: $(JDK_L10N_TMP_OUTPUTDIR)/%_zh_HK.java
#	@$(add-java-file)
else

#
# Rules for closed files
#
# If filenames are duplicated between open/closed workspaces, prefer
# the closed files.
#
# Rule ordering in this Makefile is important: some targets depend
# on closed files replacing open ones, and thus the closed file rules
# must be found before the open ones.
#
# Don't reorder without consulting teams that depend on this behavior.
#
ifndef OPENJDK
$(CLASSDESTDIR)/%.class: $(CLOSED_PLATFORM_SRC)/classes/%.java
	@$(add-java-file)
$(CLASSDESTDIR)/%.class: $(CLOSED_SHARE_SRC)/classes/%.java
	@$(add-java-file)
endif

$(CLASSDESTDIR)/%.class: $(GENSRCDIR)/%.java
	@$(add-java-file)
$(CLASSDESTDIR)/%.class: $(PLATFORM_SRC)/classes/%.java
	@$(add-java-file)
$(CLASSDESTDIR)/%.class: $(SHARE_SRC)/classes/%.java
	@$(add-java-file)

#Redirect zh_HK java files to tmp directory which created from zh_TW
$(CLASSDESTDIR)/%_zh_HK.class: $(JDK_L10N_TMP_OUTPUTDIR)/%_zh_HK.java
	@$(add-java-file)
endif

# List of class files needed
FILES_class = $(FILES_java:%.java=$(CLASSDESTDIR)/%.class)

# Got to include exported files.
FILES_class += $(FILES_export:%.java=$(CLASSDESTDIR)/%.class)

# Construct list of java sources we need to compile
source_list_prime:
	@$(MKDIR) -p $(TEMPDIR)
# Note that we slip resources in so that compiled properties files get created:
$(JAVA_SOURCE_LIST) : source_list_prime resources $(FILES_class)
	@$(TOUCH) $@

.delete.classlist:
	@$(RM) $(JAVA_SOURCE_LIST)

# Make sure all newer sources are compiled (in a batch)
classes : $(CLASSES_INIT) .delete.classlist .compile.classlist

.compile.classlist : $(JAVA_SOURCE_LIST)
	@$(MKDIR) -p $(CLASSDESTDIR)
234 235 236 237 238
	@$(RM) $<.filtered
	@$(CAT) $< | $(NAWK) 'length>0' | $(SORT) -u > $<.filtered
	@if [ `$(CAT) $<.filtered | $(WC) -l` -ge 1 ] ; then \
	  $(ECHO) "# Java sources to be compiled: (listed in file $<)"; \
	  $(CAT) $<.filtered; \
D
duke 已提交
239
	  $(ECHO) "# Running javac:"; \
240 241
	  $(ECHO) $(JAVAC_CMD) -sourcepath "$(SOURCEPATH)" -d $(CLASSDESTDIR) @$<.filtered; \
	  $(JAVAC_CMD) -sourcepath "$(SOURCEPATH)" -d $(CLASSDESTDIR) @$<.filtered; \
D
duke 已提交
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337
	fi
	@$(java-vm-cleanup)

clobber clean::
	$(RM) $(JAVA_SOURCE_LIST)

ifndef DONT_CLOBBER_CLASSES
  ifndef PACKAGE
    DONT_CLOBBER_CLASSES = true
  else
    DONT_CLOBBER_CLASSES = false
  endif
endif

packages.clean:
ifeq ($(DONT_CLOBBER_CLASSES),false)
  ifdef AUTO_FILES_JAVA_DIRS
	@for sdir in $(AUTO_FILES_JAVA_DIRS); do \
	  $(ECHO) "$(RM) -r $(CLASSDESTDIR)/$$sdir"; \
	  $(RM) -r $(CLASSDESTDIR)/$$sdir; \
        done
  else
	$(RM) -r $(CLASSDESTDIR)/$(PKGDIR)
  endif
endif

ifdef DEMOS
classes.clean:
	$(RM) -r $(DEMODST) $(CLASSDESTDIR)
else
classes.clean: packages.clean
	$(RM) $(JAVA_SOURCE_LIST)
endif

#
# C and C++ make dependencies
#
include $(JDK_TOPDIR)/make/common/internal/NativeCompileRules.gmk

#
# Running Javah to generate stuff into CClassHeaders.
#

ifdef FILES_export

CLASSES.export  = $(subst /,.,$(FILES_export:%.java=%))
CLASSES.export += $(subst /,.,$(FILES_export2:%.java=%))
CLASSES.export += $(subst /,.,$(FILES_export3:%.java=%))
CLASSES_export  = $(FILES_export:%.java=$(CLASSDESTDIR)/%.class)
CLASSES_export += $(FILES_export2:%.java=$(CLASSDESTDIR)/%.class)
CLASSES_export += $(FILES_export3:%.java=$(CLASSDESTDIR)/%.class)

# Fix when deploy workspace makefiles don't depend on this name
#CLASSHDR_DOTFILE=$(CLASSHDRDIR)/.classheaders

CLASSHDR_DOTFILE=$(OBJDIR)/.class.headers.$(ARCH)

classheaders: classes $(CLASSHDR_DOTFILE)

$(CLASSHDR_DOTFILE): $(CLASSES_export)
	$(prep-target)
	@$(ECHO) "# Running javah:"
	$(JAVAH_CMD) -d $(CLASSHDRDIR)/ \
		$(CLASSES.export) $(subst $$,\$$,$(EXPORTED_inner))
	@$(java-vm-cleanup)
	@$(TOUCH) $@

classheaders.clean:
	$(RM) $(CLASSHDR_DOTFILE)
	$(RM) -r $(CLASSHDRDIR)

else # FILES_export

classheaders: classes

classheaders.clean: 

endif # FILES_export

clean clobber:: classheaders.clean classes.clean .delete.classlist

# 
# Default dependencies
#

all: build

build: classheaders

default: all

.PHONY: all build clean clobber \
        .delete.classlist classes .compile.classlist classes.clean \
	 classheaders classheaders.clean \
	 batch_compile