Makefile
author jenda
Thu, 19 May 2011 11:33:24 +0200
changeset 135 d7f2a801f9fe
parent 134 455f05a692fc
child 138 dff2e32f3bca
permissions -rw-r--r--
7040301 ... remove redundant chars from LC_CTYPE categories (equivalent but smaller localedef files)

#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at OPENSOLARIS.LICENSE
# or http://www.opensolaris.org/os/licensing.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
# Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved.
#


# common applications
JAVA		?= java
ANT		?= ant
LOCALEDEF	?= localedef
WGET		?= wget
GNU_PATCH	?= gpatch
UNZIP		?= unzip
ZIP		?= zip
PERL		?= perl
GNU_TAR		?= gtar
CC		= /opt/SUNWspro/bin/cc


# internal applications
GEN_CHARMAP	= $(JAVA) $(CLDR_JAVAFLAGS) -cp $(call classpath) org.unicode.cldr.posix.GenerateCharmap 
GEN_POSIX	= $(JAVA) $(CLDR_JAVAFLAGS) -cp $(call classpath) org.unicode.cldr.posix.GeneratePOSIX 
GEN_DESCRIPTION	= $(JAVA) $(CLDR_JAVAFLAGS) -cp $(call classpath) org.unicode.cldr.tool.LocaleDescription
XMLVALIDATOR	= $(JAVA) $(CLDR_JAVAFLAGS) -cp $(call classpath) org.unicode.cldr.util.XMLValidator


# software versions
CLDR_VERSION		:= 1.9.0
ICU4J_VERSION		:= 4.6.1
XALAN_VERSION		:= 2.7.1

CLDR_CORE_SOURCE	:= core_$(subst .,_,$(CLDR_VERSION)).zip
CLDR_CORE_SITE		:= http://unicode.org/Public/cldr/$(CLDR_VERSION)/core.zip

CLDR_TOOLS_SOURCE	:= tools_$(subst .,_,$(CLDR_VERSION)).zip
CLDR_TOOLS_SITE		:= http://unicode.org/Public/cldr/$(CLDR_VERSION)/tools.zip

ICU4J_SOURCE		:= icu4j-$(subst .,_,$(ICU4J_VERSION)).tgz
ICU4J_SITE		:= http://download.icu-project.org/files/icu4j/$(ICU4J_VERSION)/$(ICU4J_SOURCE)

XALAN_SOURCE		:= xalan-j_$(subst .,_,$(XALAN_VERSION))-bin.zip
XALAN_SITE		:= http://apache.mirrors.airband.net/xml/xalan-j/$(XALAN_SOURCE)

CLDR_DTD_SOURCE		:= cldr_dtd.$(subst .,_,$(CLDR_VERSION)).zip


# architecture
MACH		:= $(shell uname -p)
MACH64_sparc	= sparcv9
MACH64_i386	= amd64
MACH64		= $(MACH64_$(MACH))


# compile flags
#
#	CFLAGS_*:	flags for both (32/64bit) targets
#	CFLAGS32_*:	flags for 32bit target
#	CFLAGS64_*:	flags for 64bit target
#	CFLAGS*_common:	flags for both (i386/sparc) architectures
#	CFLAGS*_sparc:	flags for sparc architecture only
#	CFLAGS*_i386:	flags for i386 architecture only
CFLAGS_common	= -xO3 -Xa -xildoff -xc99=%none -v -K pic -D PIC -G -I. -z defs -z text -z ignore -D_REENTRANT
CFLAGS32_common	= -m32
CFLAGS64_common	= -m64

CFLAGS_sparc	= -xarch=sparc -xspace -W0\,-Lt -W2\,-Rcond_elim -Wd\,-xsafe=unboundsym -xregs=no%appl
CFLAGS64_sparc	= -dalign -v  -Wc\,-Qiselect-regsym=0

CFLAGS32_i386	= -xspace
CFLAGS64_i386	= -xarch=sse2 -Ui386 -U__i386  


# java flags
# for cldr posix locale generator
JAVAFLAGS	= -Xmx512m

# misc
DOWNLOADS	?= .
FILEROOT	= proto/$(MACH)/fileroot


# ==== END OF CONFIGURATION ====

# To put more focus on warnings, be less verbose as default
# Use 'make V=1' to see the full commands
ifeq ($(V),1)
  M=@\#
  Q=
else
  M=@echo ' '  
  Q=@
endif


# list of all locales
LOCALES = $(basename $(notdir $(wildcard locale/*.spec)))

# C flags
CFLAGS32	?= $(CFLAGS_common) $(CFLAGS32_common) $(CFLAGS_$(MACH)) $(CFLAGS32_$(MACH))
CFLAGS64	?= $(CFLAGS_common) $(CFLAGS64_common) $(CFLAGS_$(MACH)) $(CFLAGS64_$(MACH))


# java flags for cldr posix locale generator
#	'-DCLDR_DTD_CACHE=.dtd_cache':		cache dir for temporary files
#	'-Dhttp.proxyHost=webcache.sfbay -Dhttp.proxyPort=8080:		default web proxy
CLDR_JAVAFLAGS	= $(JAVAFLAGS) -Dhttp.proxyHost=emeacache.uk.oracle.com -Dhttp.proxyPort=80 -DCLDR_DTD_CACHE=build/.dtd_cache -DCLDR_DIR=build/cldr_core

# locale name parsing functions
locale_xxYY = $(firstword $(subst ., ,$(1)))
charmap = $(firstword $(subst @, ,$(lastword $(subst ., ,$(1)))))

# misrc
#   CLDR uses different names for some charmaps 
cldr_charmap = $(subst ANSI1251,ansi-1251,$(call charmap,$(1)))


# ************************
# ==== Public targets ====
# ************************

.PHONY: all install doc build_tools clean

all: build/pkgs.d build/cldr.d locale_objects

install: install_ips

doc: build/report_diff.html

build_tools: build/icu4j.jar build/xalan.jar build/xml-apis.jar build/utilities.jar build/cldr.jar build/cldr_core/.src

clean: 
	$(M)CLEAN
	$(Q)rm -Rf build pkgmaps proto



# ****************************************
# ==== generate makefile depend files ====
# ****************************************

-include build/pkgs.d
-include build/cldr.d

.PHONY: $(PKGS)

# little woo-doo: %pkg is hash of arrays, key is pkg_name, values are locales; 
# ... look to the generated 'build/pkgs.d'
build/pkgs.d: $(LOCALES:%=build/%/pkg_name) build/.dir
	$(M)GENERATE $@
	$(Q)$(PERL) -e 'push @{$$pkg{substr(`cat $$_`,0,-1)}},m!build/(.*)/pkg_name! foreach (glob "build/*/pkg_name"); \
		 print "PKGS ?= SUNWlocaledefsrc " . join(" ", keys %pkg) . "\n"; \
		 print "build/$$_/.installed: " . join(" ", map { "build/$$_/.installed" } @{$$pkg{$$_}}) ."\n" foreach (keys %pkg); \
		 print "build/$$_/manifest: " . join(" ", map { "build/$$_/manifest" } @{$$pkg{$$_}}) ."\n" foreach (keys %pkg); ' > $@

build/cldr.d: $(LOCALES:%=build/%/cldr_variant) build/.dir
	$(M)GENERATE $@
	$(Q)$(PERL) -e 'my %loc = map { m!build/(.*)/cldr_variant! => m!build/.+\.([^@]+).*/cldr_variant! } qw($^); \
		print "CHARMAPS ?= " . join(" ", grep { ! $$seen1{$$_}++ } values %loc) . "\n"; \
		print "build/$$k/32bit.so.3 build/$$k/64bit.so.3: build/$$v.cm misc/$$v.x\n" while(($$k,$$v) = each %loc);'  > $@

build/SUNWlocaledefsrc/manifest: misc/templates/manifest/header_localedefsrc $(LOCALES:%=build/%/manifest_src) $(CHARMAPS:%=build/manifest_charmap_%)



# ************************
# ==== Locale Objects ====
# ************************

.PHONY: posix locale_objects

locale_objects: $(LOCALES:%=build/%/32bit.so.3) $(LOCALES:%=build/%/64bit.so.3)

# all jars that CldrTools needs
CLDR_TOOLS_DEPS	= build/icu4j.jar build/xalan.jar build/xml-apis.jar build/utilities.jar build/cldr.jar build/cldr_core/.src

posix: $(LOCALES:%=build/%/posix.src)

$(LOCALES:%=build/%/posix.src): build/%/posix.src: build/%/cldr_variant $(CLDR_TOOLS_DEPS) build/.dtd_cache/.src
	$(M)GENERATE $@
	$(Q)$(GEN_POSIX) -d $(@D) -o $(@F) -c $(call cldr_charmap,$*) -m $(shell cat $<) 

$(LOCALES:%=build/%/32bit.so.3): build/%/32bit.so.3: build/%/posix.src build/%/32bit/.methods_so
	$(M)LOCALEDEF $@
	$(Q)cd $(@D)/32bit; $(LOCALEDEF) $(if $(Q),,-v) -P $(dir $(CC)) -W cc,"$(CFLAGS32)" -L "-R\\\$$ORIGIN" -x ../../../misc/$(call charmap, $*).x -f ../../$(call charmap, $*).cm -i ../posix.src $*; mv $*.so.3 ../32bit.so.3

# localedef reads the 32bit library for function definitions
# and then links against the 64bit library, so we need both 32bit and 64bit versions
$(LOCALES:%=build/%/64bit.so.3): build/%/64bit.so.3: build/%/posix.src build/%/64bit/.methods_so build/%/64bit/$(MACH64)/.methods_so
	$(M)LOCALEDEF $@
	$(Q)cd $(@D)/64bit; $(LOCALEDEF) $(if $(Q),,-v) -P $(dir $(CC)) -W cc,"$(CFLAGS64)" -L "-R\\\$$ORIGIN" -m lp64 -x ../../../misc/$(call charmap, $*).x -f ../../$(call charmap, $*).cm -i ../posix.src $*; mv $*.so.3 ../64bit.so.3



# ******************
# ==== Charmaps ====
# ******************

$(CHARMAPS:%=build/%.cm): build/%.cm: $(CLDR_TOOLS_DEPS) build/.dir build/.dtd_cache/.src
	$(M)GENERATE $@
	$(Q)$(GEN_CHARMAP) -d $(@D) -c $(call cldr_charmap,$*)
	$(Q)[ "$(call charmap,$*)" = "$(call cldr_charmap,$*)" ] || mv build/$(call cldr_charmap,$*).cm $@
	# Note: 0x07 and 0x1f514 chars have the same name (<BELL>) - Unicode 6.0 bug?
	$(Q)perl -i -ne 'print unless /^<BELL>(\s+\\x07)$$/' $@



# *****************************
# ==== Other package files ====
# *****************************

# manifest
$(PKGS:%=build/%/manifest): build/%/manifest: build/%/.dir
	$(M)GENERATE $@
	$(Q)cat $^ | $(PERL) -ne 'print unless $$a{$$_}++' > $@

# copyright
$(FILEROOT)/copyright.cddl+unicode: misc/copyright.cddl+unicode
	$(Q)[ -d $(@D) ] || mkdir -p $(@D)
	$(Q)cp $< $@



# **********************************************
# ==== Read params from locale/*.spec files ====
# **********************************************

# FIXME: this section is a bit too tricky ... probably will be rewritten as scripts
cldr_variant = $(call add_platform,$(call add_yesno,$(1)))
sep = $(call contains,$(1),@,$(comma),@)
add_platform = $(1)$(call contains,$(1),platform=,,$(call sep,$(1))platform=solaris)
add_yesno = $(1)$(call contains,$(1),yesno=,,$(call sep,$(1))yesno=solaris)

spec_key = $(if $(shell $(PERL) -ne 'print 1 if /^$(1)\s/' $<),$(shell $(PERL) -ne 'print if s/^$(1)\s+(.*)/\1/' $<),$(2))
spec_key_is_set = $(if $(shell $(PERL) -ne 'print 1 if /^$(1)\s/' $<),\# $(1) is set,)
spec_fkey = $(addprefix misc/templates/$(1)/,$(spec_key))

# if $(1) contains $(2), return $(3) else $(4)
contains = $(if $(filter-out xx,x$(subst $(1),,$(subst $(2),=-=,$(1))x)),$(3),$(4))
comma := ,


EXPAND_ENV = LOC=$* \
	     MACH=$(MACH) \
	     MACH64=$(MACH64) \
	     CHARMAP='$(call charmap,$*)' \
	     LCMESSAGES='$(call spec_key,lc_messages,default)' \
	     LCTIME='$(call spec_key,lc_time,default)' \
	     IS_SET_LC_MESSAGES='$(call spec_key_is_set,lc_messages)' \
	     IS_SET_LC_TIME='$(call spec_key_is_set,lc_time)' \
	     DESCRIPTION='$(shell cat build/$*/pkg_description)'

$(LOCALES:%=build/%/pkg_name): build/%/pkg_name: locale/%.spec build/%/.dir
	$(M)GENERATE $@
	$(Q)echo "$(call spec_key,pkg_name,SUNWlang-$(firstword $(subst _, ,$*)))" >$@

$(LOCALES:%=build/%/cldr_variant): build/%/cldr_variant: locale/%.spec build/%/.dir
	$(M)GENERATE $@
	$(Q)echo "$(call cldr_variant,$(call spec_key,cldr_variant,$(call locale_xxYY,$*)))" > $@

$(LOCALES:%=build/%/pkg_description): build/%/pkg_description: locale/%.spec build/%/locale_description build/%/.dir
	$(M)GENERATE $@
	$(Q)echo '$(call spec_key,pkg_desc,$(shell $(PERL) -pe "s/,.*/ language support/" build/$*/locale_description))' > $@

$(LOCALES:%=build/%/locale_map): build/%/locale_map: locale/%.spec build/%/pkg_description
	$(M)GENERATE $@
	$(Q)for src in $(call spec_fkey,locale_map,default); do \
		$(EXPAND_ENV) bash -c 'while read l; do eval "echo \"$$l\""; done' < $$src; \
	done > $@

$(LOCALES:%=build/%/locale_description): build/%/locale_description: locale/%.spec $(CLDR_TOOLS_DEPS) build/%/cldr_variant build/.dtd_cache/.src
	$(M)GENERATE $@
	$(Q)(if [ -z "$(shell $(PERL) -ne 'print if s/^locale_desc\s+(.*)/\1/' $<)" ] ; then \
			$(GEN_DESCRIPTION) build/cldr_core $(shell cat build/$*/cldr_variant); \
			echo " ($(call charmap,$*))"; \
		else \
			echo "$(shell $(PERL) -ne 'print if s/^locale_desc\s+(.*)/\1/' $<)"; \
		fi) > $@

$(LOCALES:%=build/%/manifest): build/%/manifest: locale/%.spec build/%/pkg_description
	$(M)GENERATE $@
	$(Q)for src in $(call spec_fkey,manifest,header_lang utf8); do \
		$(EXPAND_ENV) bash -c 'while read l; do eval "echo \"$$l\""; done' < $$src; \
	done > $@
	$(Q)$(PERL) -ne 'print if s/^manifest_raw\s+(.*)/\1/' $< >> $@

$(LOCALES:%=build/%/manifest_src): build/%/manifest_src: misc/templates/manifest/src locale/%.spec build/%/pkg_description
	$(M)GENERATE $@
	$(Q)$(EXPAND_ENV) bash -c 'while read l; do eval "echo \"$$l\""; done' < $< > $@

$(CHARMAPS:%=build/manifest_charmap_%): build/manifest_charmap_%: misc/templates/manifest/src_charmap locale/*.spec 
	$(M)GENERATE $@
	$(Q)CHARMAP=$* bash -c 'while read l; do eval "echo \"$$l\""; done' < $< >$@



# ********************************
# ==== Install/Build packages ====
# ********************************

.PHONY: install_ips

install_ips: build/pkgs.d $(PKGS:%=build/%/.installed_ips)


$(LOCALES:%=build/%/.installed): build/%/.installed: build/%/.installed_locale_object_32 build/%/.installed_locale_object_64 build/%/.installed_locale_description build/%/.installed_locale_map build/%/.installed_locale_src
	$(Q)touch $@


$(LOCALES:%=build/%/.installed_locale_object_32): build/%/.installed_locale_object_32: build/%/32bit.so.3 $(FILEROOT)/usr/lib/locale/%/.dir
	$(M)INSTALL $*.so.3
	$(Q)cp build/$*/32bit.so.3 $(FILEROOT)/usr/lib/locale/$*/$*.so.3
	$(Q)touch $@

$(LOCALES:%=build/%/.installed_locale_object_64): build/%/.installed_locale_object_64: build/%/64bit.so.3 $(FILEROOT)/usr/lib/locale/%/$(MACH64)/.dir
	$(M)INSTALL $(MACH64)/$*.so.3
	$(Q)cp build/$*/64bit.so.3 $(FILEROOT)/usr/lib/locale/$*/$(MACH64)/$*.so.3
	$(Q)touch $@

$(LOCALES:%=build/%/.installed_locale_description): build/%/.installed_locale_description: build/%/locale_description $(FILEROOT)/usr/lib/locale/%/.dir
	$(M)INSTALL $*/locale_description
	$(Q)cp build/$*/locale_description $(FILEROOT)/usr/lib/locale/$*/
	$(Q)touch $@
	
$(LOCALES:%=build/%/.installed_locale_map): build/%/.installed_locale_map: build/%/locale_map $(FILEROOT)/usr/lib/locale/%/.dir
	$(M)INSTALL $*/locale_map
	$(Q)cp build/$*/locale_map $(FILEROOT)/usr/lib/locale/$*/
	$(Q)touch $@
	
$(LOCALES:%=build/%/.installed_locale_src): build/%/.installed_locale_src: build/%/posix.src $(FILEROOT)/usr/lib/localedef/src/locales/.dir
	$(M)INSTALL $*/locale_src
	$(Q)cp $< $(FILEROOT)/usr/lib/localedef/src/locales/$*.src
	$(Q)touch $@

$(PKGS:%=build/%/.installed_ips): build/%/.installed_ips: build/%/manifest build/%/.installed $(FILEROOT)/copyright.cddl+unicode pkgmaps/.dir
	$(M)INSTALL $*/manifest
	$(Q)cp $< pkgmaps/manifest.$(subst SUNW,,$*)
	$(Q)touch $@

$(CHARMAPS:%=build/.installed_charmap_%): build/.installed_charmap_%: build/%.cm $(FILEROOT)/usr/lib/localedef/src/charmaps/.dir
	$(M)INSTALL charmap $*
	$(Q)cp $< $(FILEROOT)/usr/lib/localedef/src/charmaps/$*.charmap
	$(Q)touch $@

build/.installed_extensions: $(FILEROOT)/usr/lib/localedef/src/extensions/.dir
	$(M)INSTALL extensions
	$(Q)cp misc/*.x $(FILEROOT)/usr/lib/localedef/src/extensions/

build/SUNWlocaledefsrc/.installed: $(LOCALES:%=build/%/.installed_locale_src) $(CHARMAPS:%=build/.installed_charmap_%) build/.installed_extensions


# *********************************
# ==== Compile the build tools ====
# *********************************

classpath = $(subst $() $(),:,$(filter %.jar,$^))

# xalan
build/xalan/.src: downloads/$(XALAN_SOURCE)
	$(M)UNPACK $(@D)
	$(Q)rm -Rf $(@D)
	$(Q)$(UNZIP) -u $(if $(Q),-q) -d $(@D) $<
	$(Q)touch $@

build/xalan.jar: build/xalan/.src
	$(M)INSTALL $@
	$(Q)cp build/xalan/xalan-j_2_7_1/xalan.jar $@

build/xml-apis.jar: build/xalan/.src
	$(M)INSTALL $@
	$(Q)cp build/xalan/xalan-j_2_7_1/xml-apis.jar $@


# icu4j
build/icu4j/.src: downloads/$(ICU4J_SOURCE) $(wildcard misc/patches/icu4j/*.patch)
	$(M)UNPACK $(@D)
	$(Q)rm -Rf $(@D)
	$(Q)mkdir $(@D)
	$(Q)(cd $(@D);  $(GNU_TAR) x$(if $(Q),,v)zf ../../$<)
	$(M)PATCH icu4j
	$(Q)for a in $(filter %.patch, $(sort $^)); do \
		echo "   $$a"; \
		(cd $(@D); $(GNU_PATCH) -p1 $(if $(Q),-s)) < $$a; \
	done
	$(Q)touch $@

build/icu4j/.compiled: build/icu4j/.src
	$(M)COMPILE $(@D)
	$(Q)cd $(@D); $(ANT) $(if $(Q),-q) jar cldrUtil
	$(Q)touch $@

build/utilities.jar: build/icu4j/.compiled
	$(M)INSTALL $@
	$(Q)cp build/icu4j/out/cldr_util/lib/utilities.jar $@
	$(Q)touch $@

build/icu4j.jar: build/icu4j/.compiled 
	$(M)INSTALL $@
	$(Q)cp build/icu4j/icu4j.jar $@
	$(Q)touch $@


# cldr_tools
build/cldr_tools/.src: downloads/$(CLDR_TOOLS_SOURCE) $(wildcard misc/patches/cldr_tools/*.patch)
	$(M)UNPACK $(@D)
	$(Q)rm -Rf $(@D)
	$(Q)$(UNZIP) -u $(if $(Q),-q) -d $(@D) $<
	$(M)PATCH $(@D)
	$(Q)find $(@D) -type f -exec perl -pi -e 's,\r$$,,' {} \;
	$(Q)for a in $(filter %.patch, $(sort $^)); do  \
		echo "   $$a"; \
		(cd $(@D); $(GNU_PATCH) -p1 $(if $(Q),-s)) < $$a; \
	done
	$(Q)touch $@

build/cldr_tools/.compiled: build/icu4j.jar build/utilities.jar build/xalan.jar build/xml-apis.jar build/cldr_tools/.src
	$(M)COMPILE $(@D)
	$(Q)cd $(@D)/tools/java; ICU4J_JAR=../../../icu4j.jar UTILITIES_JAR=../../../utilities.jar CLDR_JAR=../../../xalan.jar XML_APIS_JAR=../../../xml-apis.jar $(ANT) $(if $(Q),-q) jar
	$(Q)touch $@

build/cldr.jar: build/cldr_tools/.compiled 
	$(M)INSTALL $@
	$(Q)cp build/cldr_tools/tools/java/cldr.jar $@
	$(Q)touch $@


# cldr_core
build/cldr_core/.src: downloads/$(CLDR_CORE_SOURCE) $(wildcard misc/patches/cldr_core/*.patch)
	$(M)UNPACK $(@D)
	$(Q)rm -Rf $(@D)
	$(Q)$(UNZIP) -u $(if $(Q),-q) -d $(@D) $<
	$(M)PATCH $(@D)
	$(Q)find $(@D) -type f -exec perl -pi -e 's,\r$$,,' {} \;
	$(Q)for a in $(filter %.patch, $(sort $^)); do  \
		echo "   $$a"; \
		(cd $(@D); $(GNU_PATCH) -p1 $(if $(Q),-s)) < $$a; \
	done
	$(Q)touch $@


# ldump and cmprint 
build/cmap.c: tools/cmap.pl $(CHARMAPS:%=build/%.cm)
	$(M)GENERATE $@
	$(Q)tools/cmap.pl $(filter %.cm,$^) > $@

build/cmap.o: build/cmap.c
	$(M)CC $@
	$(Q)$(CC) -c -o $@ $<

build/%.o: tools/%.c
	$(M)CC $@
	$(Q)$(CC) -c -o $@ $<

build/ldump: build/ldump.o build/cmap.o
	$(M)BUILD $@
	$(Q)$(CC) -o $@ $^

build/cmprint: build/cmprint.o build/cmap.o
	$(M)BUILD $@
	$(Q)$(CC) -o $@ $^



# *************************
# ==== Pack and Unpack ====
# *************************

build/.dtd_cache/.src: downloads/$(CLDR_DTD_SOURCE) build/.dtd_cache/.dir
	$(M)UNPACK $<
	$(Q)$(UNZIP) -u $(if $(Q),-q) -d $(@D) $<
	$(Q)touch $@



# ***********************************
# ==== Download sources from net ====
# ***********************************

downloads/$(CLDR_CORE_SOURCE): downloads/.dir
	$(M)DOWNLOAD $@
	$(Q)if [ -f $(DOWNLOADS)/$(@F) ]; then \
		cp $(DOWNLOADS)/$(@F) $(@D); \
	else \
		$(WGET) $(if $(Q),-q) -O $@ $(CLDR_CORE_SITE); \
	fi
	$(Q)touch -c $@


downloads/$(CLDR_TOOLS_SOURCE): downloads/.dir
	$(M)DOWNLOAD $@
	$(Q)if [ -f $(DOWNLOADS)/$(@F) ]; then \
		cp $(DOWNLOADS)/$(@F) $(@D); \
	else \
		$(WGET) $(if $(Q),-q) -O $@ $(CLDR_TOOLS_SITE); \
	fi
	$(Q)touch -c $@


downloads/$(ICU4J_SOURCE): downloads/.dir
	$(M)DOWNLOAD $@
	$(Q)if [ -f $(DOWNLOADS)/$(@F) ]; then \
		cp $(DOWNLOADS)/$(@F) $(@D); \
	else \
		$(WGET) $(if $(Q),-q) -O $@ $(ICU4J_SITE); \
	fi
	$(Q)touch -c $@


downloads/$(XALAN_SOURCE): downloads/.dir
	$(M)DOWNLOAD $@
	$(Q)if [ -f $(DOWNLOADS)/$(@F) ]; then \
		cp $(DOWNLOADS)/$(@F) $(@D); \
	else \
		$(WGET) $(if $(Q),-q) -O $@ $(XALAN_SITE); \
	fi
	$(Q)touch -c $@


# workaround for race condition in org.unicode.cldr.util.CachingEntityResolver
# - if more than one process use build/.dtd_cache dir, the second process could
# receive uncomplete dtd and parallel build could fail

downloads/$(CLDR_DTD_SOURCE): downloads/.dir $(CLDR_TOOLS_DEPS)
	$(M)DOWNLOAD DTDs
	$(Q)if [ -f $(DOWNLOADS)/$(@F) ]; then \
		cp $(DOWNLOADS)/$(@F) $(@D); \
	else \
		mkdir -p build/.dtd_cache; \
		$(XMLVALIDATOR) build/cldr_core/common/main/en.xml > /dev/null; \
		$(XMLVALIDATOR) build/cldr_core/common/supplemental/supplementalData.xml > /dev/null; \
		(cd build/.dtd_cache/; $(ZIP) $(if $(Q),-q) -o ../../$@ *.dtd); \
	fi
	$(Q)touch $@



# **************
# ==== Misc ====
# **************
%/.dir:
	$(Q)mkdir -p "$*"
	$(Q)touch $@

build/report_diff.html: all build/ldump tools/report_diff.pl
	$(M)GENERATE $@
	$(Q)tools/report_diff.pl $(LOCALES) > $@


METHODS_SO = methods_unicode.so.3

build/.methods_so: build/32bit/.dir build/64bit/.dir

ifeq ($(wildcard $(FILEROOT)/usr/lib/locale/common/$(METHODS_SO)),)
build/.methods_so:
	$(M)COPY_SYSTEM $(METHODS_SO)
	$(Q)cp -f /usr/lib/locale/common/$(METHODS_SO) build/32bit/
	$(Q)cp -f /usr/lib/locale/common/$(MACH64)/$(METHODS_SO) build/64bit/
	$(Q)touch $@
else
build/.methods_so: $(FILEROOT)/usr/lib/locale/common/$(METHODS_SO) $(FILEROOT)/usr/lib/locale/common/$(MACH64)/$(METHODS_SO)
	$(M)COPY $(METHODS_SO)
	$(Q)cp -f $(FILEROOT)/usr/lib/locale/common/$(METHODS_SO) build/32bit/
	$(Q)cp -f $(FILEROOT)/usr/lib/locale/common/$(MACH64)/$(METHODS_SO) build/64bit/
	$(Q)touch $@
endif

$(LOCALES:%=build/%/32bit/.methods_so) $(LOCALES:%=build/%/64bit/.methods_so): build/%/.methods_so: build/.methods_so build/%/.dir
	$(M)LINK $(@D)/$(METHODS_SO)
	$(Q)rm -f build/$*/$(METHODS_SO)
	$(Q)cp build/32bit/$(METHODS_SO) build/$*/$(METHODS_SO)
	$(Q)touch $@

$(LOCALES:%=build/%/64bit/$(MACH64)/.methods_so): build/%/.methods_so: build/.methods_so build/%/.dir
	$(M)LINK $(@D)/$(METHODS_SO)
	$(Q)rm -f build/$*/$(METHODS_SO)
	$(Q)cp build/64bit/$(METHODS_SO) build/$*/$(METHODS_SO)
	$(Q)touch $@