## Makefile.in for ICU data
## Copyright (c) 1999-2009, International Business Machines Corporation and
## others. All Rights Reserved.

## Source directory information
srcdir = @srcdir@
top_srcdir = @top_srcdir@

# So that you have $(top_builddir)/config.status
top_builddir = ..

## All the flags and other definitions are included here.
include $(top_builddir)/icudefs.mk



## Build directory information
# So that  $(top_builddir)/$(subdir) ~= "here"
subdir = data

#lib icu data for link
LIB_ICUDATA_NAME=$(LIBICU)$(DATA_STUBNAME)$(ICULIBSUFFIX)
LIB_STATIC_ICUDATA_NAME=$(LIBSICU)$(DATA_STUBNAME)$(ICULIBSUFFIX)

# Allow Windows to override these options
ifeq ($(PKGDATA_OPTS),)
PKGDATA_OPTS = -O $(top_builddir)/data/icupkg.inc
endif
ifeq ($(PKGDATA_VERSIONING),)
PKGDATA_VERSIONING = -r $(SO_TARGET_VERSION)
endif

# This allows all the data to be in one directory
ifeq ($(PKGDATA_MODE),dll)
ICUPKGDATA_OUTDIR = $(LIBDIR)
else
ICUPKGDATA_OUTDIR = $(OUTDIR)
endif

CURDIR:=$(CURR_FULL_DIR)
PKGDATA = $(TOOLBINDIR)/pkgdata $(PKGDATA_OPTS) -q -c -s $(CURDIR)/out/build/$(ICUDATA_PLATFORM_NAME) -d $(ICUPKGDATA_OUTDIR)

ifeq ($(OS390_STUBDATA),1)
OS390PKG=package390
OS390INSTALL=install390

# Additional data for 390
OS390LIST=$(OUTTMPDIR)/icudata390.lst
OUTTMPDIR_390STUB=$(top_builddir)/data/out/tmp_390stub
endif

# OBJDATADIR must be a short path (with ..'s) to the data.

ifeq ($(top_srcdir),..)
SRCDATADIR=.
else
SRCDATADIR=$(top_srcdir)/data
endif
ifeq ($(top_builddir),..)
OUTDIR=./out
else
OUTDIR=$(top_builddir)/data/out
endif

OUTTMPDIR=$(OUTDIR)/tmp
MAINBUILDDIR=$(OUTDIR)/build
BUILDDIR=$(MAINBUILDDIR)/$(ICUDATA_PLATFORM_NAME)
UNICODEDATADIR=$(SRCDATADIR)/unidata
LOCSRCDIR=$(SRCDATADIR)/locales
COLSRCDIR=$(SRCDATADIR)/coll
COLBLDDIR=$(BUILDDIR)/coll
RBNFSRCDIR=$(SRCDATADIR)/rbnf
RBNFBLDDIR=$(BUILDDIR)/rbnf
TRANSLITSRCDIR=$(SRCDATADIR)/translit
TRANSLITBLDDIR=$(BUILDDIR)/translit
MISCSRCDIR=$(SRCDATADIR)/misc
BRKSRCDIR=$(SRCDATADIR)/brkitr
BRKBLDDIR=$(BUILDDIR)/brkitr
MISCSRCDIR=$(SRCDATADIR)/misc
UCMSRCDIR=$(SRCDATADIR)/mappings
SPREPSRCDIR=$(SRCDATADIR)/sprep
COMINCDIR=$(top_srcdir)/common/unicode
SRCLISTDEPS=Makefile $(srcdir)/Makefile.in
BUILD_DIRS=$(OUTDIR) $(MAINBUILDDIR) $(BUILDDIR) $(BRKBLDDIR) $(COLBLDDIR) $(RBNFBLDDIR) $(TRANSLITBLDDIR) $(OUTTMPDIR) $(OUTTMPDIR_390STUB) $(OUTTMPDIR)/$(COLLATION_TREE) $(OUTTMPDIR)/$(RBNF_TREE) $(OUTTMPDIR)/$(TRANSLIT_TREE) $(OUTTMPDIR)/$(BREAK_TREE)

# relative lib links from pkgdata are the same as for tmp
TOOLDIR=$(top_builddir)/tools

## List of phony targets
.PHONY : all all-local all-recursive install install-local install-files	\
install-recursive clean clean-local clean-recursive distclean		\
distclean-local distclean-recursive dist dist-local dist-recursive	\
check check-local check-recursive build-local clean-resindex build-dir

## Clear suffix list
.SUFFIXES :

## List of standard targets
all: all-local
install: all-local install-local 
clean: clean-local
distclean : distclean-local
dist: 
check: all


distclean-local: clean
	$(RMV) Makefile

all-local: build-dir icupkg.inc build-local packagedata $(POST_DATA_BUILD) $(OS390PKG)

dist-local:

clean-map:
	-test -z *.map || $(RMV) *.map

clean-local: cleanpackage cleanfiles clean-map

cleanfiles:
	test -z "$(CLEANFILES)" || $(RMV) $(CLEANFILES)

cleanpackage:
	$(RMV) $(OUTDIR)
	$(RMV) $(LIBDIR)/$(LIB_ICUDATA_NAME)*.$(SO)* $(LIBDIR)/$(LIB_STATIC_ICUDATA_NAME).$(A)

check-local:

# Find out if we have a source archive.
# If we have that, then use that instead of building everything from scratch.
ICUDATA_SOURCE_ARCHIVE = $(wildcard $(srcdir)/in/$(ICUDATA_PLATFORM_NAME).dat)
ifeq ($(ICUDATA_SOURCE_ARCHIVE),)
ICUDATA_ARCHIVE = $(firstword $(wildcard $(srcdir)/in/$(ICUDATA_BASENAME_VERSION)*.dat))
# We don't have the data in the current endianess or charset.
# See if we can find data of any archive type,
# and convert it to the current type.
ifneq ($(ICUDATA_ARCHIVE),)
ICUDATA_SOURCE_ARCHIVE = $(OUTDIR)/$(ICUDATA_PLATFORM_NAME).dat
$(ICUDATA_SOURCE_ARCHIVE): $(ICUDATA_ARCHIVE) $(OUTDIR)
	$(INVOKE) $(TOOLBINDIR)/icupkg -t$(ICUDATA_CHAR) $(ICUDATA_ARCHIVE) $(ICUDATA_SOURCE_ARCHIVE)
endif
else
ifneq ($(ENABLE_STATIC),YES)
ifeq ($(PKGDATA_MODE),common)
# We have a source data common archive in the native endianess,
# and it's what we want to build. Try to not run any of ICU's tools.
ICUDATA_SOURCE_IS_NATIVE_TARGET=YES
endif
endif
endif

packagedata: icupkg.inc $(PKGDATA_LIST) build-local
ifneq ($(ENABLE_STATIC),)
ifeq ($(PKGDATA_MODE),dll)
	$(PKGDATA_INVOKE) $(PKGDATA) -e $(ICUDATA_ENTRY_POINT) -T $(OUTTMPDIR) -p $(ICUDATA_NAME) $(PKGDATA_LIBSTATICNAME) -m static $(PKGDATA_LIST)
endif
endif
ifneq ($(ICUDATA_SOURCE_IS_NATIVE_TARGET),YES)
	$(PKGDATA_INVOKE) $(PKGDATA) -e $(ICUDATA_ENTRY_POINT) -T $(OUTTMPDIR) -p $(ICUDATA_NAME) -m $(PKGDATA_MODE) $(PKGDATA_VERSIONING) $(PKGDATA_LIBNAME) $(PKGDATA_LIST)
else
	$(INSTALL_DATA) $(ICUDATA_SOURCE_ARCHIVE) $(OUTDIR)
endif

## Install ICU data.
install-local: $(PKGDATA_LIST) ./icupkg.inc packagedata $(OS390INSTALL)
	$(MKINSTALLDIRS) $(TMPDATADIR) $(DESTDIR)$(ICUPKGDATA_DIR)
ifeq ($(PKGDATA_MODE),files)
	$(MKINSTALLDIRS) $(ICUPKGDATA_DIR)/$(ICUDATA_NAME)
	$(MKINSTALLDIRS) $(ICUPKGDATA_DIR)/$(ICUDATA_NAME)/$(BREAK_TREE)
	$(MKINSTALLDIRS) $(ICUPKGDATA_DIR)/$(ICUDATA_NAME)/$(COLLATION_TREE)
	$(MKINSTALLDIRS) $(ICUPKGDATA_DIR)/$(ICUDATA_NAME)/$(RBNF_TREE)
	$(MKINSTALLDIRS) $(ICUPKGDATA_DIR)/$(ICUDATA_NAME)/$(TRANSLIT_TREE)
endif
ifneq ($(ENABLE_STATIC),)
ifeq ($(PKGDATA_MODE),dll)
	$(PKGDATA_INVOKE) $(PKGDATA) -m static -e $(ICUDATA_ENTRY_POINT) -T $(OUTTMPDIR) -s $(BUILDDIR) -p $(ICUDATA_NAME) $(PKGDATA_LIBSTATICNAME) $(PKGDATA_LIST) -I $(ICUPKGDATA_INSTALL_LIBDIR)
endif
endif
ifneq ($(ICUDATA_SOURCE_IS_NATIVE_TARGET),YES)
	$(PKGDATA_INVOKE) $(PKGDATA) -m $(PKGDATA_MODE) $(PKGDATA_VERSIONING) -e $(ICUDATA_ENTRY_POINT) -T $(OUTTMPDIR) -s $(BUILDDIR) -p $(ICUDATA_NAME) $(PKGDATA_LIBNAME) $(PKGDATA_LIST) -I $(ICUPKGDATA_INSTALL_DIR)
else
	$(INSTALL_DATA) $(ICUDATA_SOURCE_ARCHIVE) $(DESTDIR)$(ICUPKGDATA_DIR)
endif


####
####
#### 390 support
install390: package390
	$(MKINSTALLDIRS) $(TMPDATADIR) $(DESTDIR)$(libdir)
	$(INVOKE) $(PKGDATA) -s $(BUILDDIR)$(STUB_SUFFIX) -T $(OUTTMPDIR_390STUB) -p $(ICUDATA_NAME)$(STUB_SUFFIX) $(PKGDATA_LIBNAME)$(STUB_SUFFIX) -e $(ICUDATA_ENTRY_POINT) $(OS390LIST) -m dll $(PKGDATA_VERSIONING) -I $(DESTDIR)$(ICUPKGDATA_DIR)
ifeq ($(PKGDATA_MODE),dll)
	$(INSTALL-L) $(ICUPKGDATA_OUTDIR)/$(FINAL_IMPORT_LIB) $(DESTDIR)$(ICUPKGDATA_DIR)/$(FINAL_IMPORT_LIB)
endif

#### $(LIB_ICUDATA_NAME)$(STUB_SUFFIX) is the subset data for batch mode
package390: $(OUTTMPDIR)/icudata390.lst $(PKGDATA_LIST) ./icupkg.inc packagedata
	ln -s $(ICUDATA_NAME) $(OUTDIR)/build/$(ICUDATA_NAME)$(STUB_SUFFIX)
	$(INVOKE) $(PKGDATA) -s $(BUILDDIR)$(STUB_SUFFIX) -T $(OUTTMPDIR_390STUB) -p $(ICUDATA_NAME)$(STUB_SUFFIX) $(PKGDATA_LIBNAME)$(STUB_SUFFIX) -e $(ICUDATA_ENTRY_POINT) $(OS390LIST) -m dll $(PKGDATA_VERSIONING)
	cp $(ICUPKGDATA_OUTDIR)/$(LIB_ICUDATA_NAME)$(STUB_SUFFIX).$(SO) $(top_builddir)/stubdata/$(LIB_ICUDATA_NAME)$(STUB_SUFFIX).$(SO)


##### Define all the data files. the build rule that depends on them is below.
# X_FILES_SHORT = just the base names (for lists)
# X_FILES = full paths (for dependency)

## DAT files - Misc. data files.
#  2005-may-05 Removed Unicode properties files (unorm.icu, uprops.icu, ucase.icu, ubidi.icu)
#  from data build. See Jitterbug 4497. (makedata.mak revision 1.117)
#
# CHROME: unames.icu are excluded from the icu data file
DAT_FILES_SHORT=pnames.icu cnvalias.icu coll/ucadata.icu coll/invuca.icu
DAT_FILES=$(DAT_FILES_SHORT:%=$(BUILDDIR)/%)

## BRK files
BREAK_TREE=brkitr
-include $(BRKSRCDIR)/brkfiles.mk
-include $(BRKSRCDIR)/brklocal.mk
ALL_BRK_SOURCE= $(BRK_SOURCE) $(BRK_SOURCE_LOCAL)
BRK_FILES_SHORT=$(ALL_BRK_SOURCE:%.txt=$(BREAK_TREE)/%.brk)
BRK_FILES=$(ALL_BRK_SOURCE:%.txt=$(BRKBLDDIR)/%.brk)
ifdef BRK_CTD_SOURCE
ALL_CTD_SOURCE=$(BRK_CTD_SOURCE) $(BRK_CTD_SOURCE_LOCAL)
CTD_FILES_SHORT=$(ALL_CTD_SOURCE:%.txt=$(BREAK_TREE)/%.ctd)
CTD_FILES=$(ALL_CTD_SOURCE:%.txt=$(BRKBLDDIR)/%.ctd)
endif
ifdef BRK_RES_SOURCE
BRS_SRC= root.txt $(BRK_RES_SOURCE) $(BRK_RES_SOURCE_LOCAL)
BRS_SRC_FILES = $(BRS_SRC:%=$(BRKSRCDIR)/%)
INSTALLED_BRS_FILES = $(BRK_RES_SOURCE:%.txt=%)  $(BRK_RES_SOURCE_LOCAL:%.txt=%)
endif

## Confusables (Spoofing) files
ALL_CFU_SOURCE=$(UNICODEDATADIR)/confusables.txt $(UNICODEDATADIR)/confusablesWholeScript.txt
CFU_FILES_SHORT=confusables.cfu
CFU_FILES=$(BUILDDIR)/$(CFU_FILES_SHORT)

## UCM files
# CHROME : do not include ucmebcdic.mk and two IBM EBCDIC code pages  
-include $(UCMSRCDIR)/ucmcore.mk
-include $(UCMSRCDIR)/ucmfiles.mk
# -include $(UCMSRCDIR)/ucmebcdic.mk
-include $(UCMSRCDIR)/ucmlocal.mk
ALL_UCM_SOURCE= $(UCM_SOURCE_CORE) $(UCM_SOURCE_FILES) $(UCM_SOURCE_EBCDIC) $(UCM_SOURCE_LOCAL)
UCM_FILES = $(ALL_UCM_SOURCE:%=$(SRCDATADIR)/%)
CNV_FILES = $(ALL_UCM_SOURCE:%.ucm=$(BUILDDIR)/%.cnv)
CNV_FILES_SHORT = $(ALL_UCM_SOURCE:%.ucm=%.cnv)

## RES files
-include $(LOCSRCDIR)/resfiles.mk
-include $(COLSRCDIR)/colfiles.mk
-include $(RBNFSRCDIR)/rbnffiles.mk
-include $(TRANSLITSRCDIR)/trnsfiles.mk
-include $(LOCSRCDIR)/reslocal.mk
-include $(COLSRCDIR)/collocal.mk
-include $(BRKSRCDIR)/brslocal.mk
-include $(RBNFSRCDIR)/rbnflocal.mk
-include $(TRANSLITSRCDIR)/trnslocal.mk
ifdef GENRB_SOURCE
RES_SRC= root.txt $(GENRB_SOURCE) $(GENRB_ALIAS_SOURCE) $(GENRB_SOURCE_LOCAL)
RES_SRC_FILES = $(RES_SRC:%=$(LOCSRCDIR)/%)
INSTALLED_RB_FILES = $(GENRB_SOURCE:%.txt=%) $(GENRB_SOURCE_LOCAL:%.txt=%)
endif
ifdef COLLATION_SOURCE
COL_SRC= root.txt $(COLLATION_SOURCE) $(COLLATION_ALIAS_SOURCE) $(COLLATION_SOURCE_LOCAL)
COL_SRC_FILES = $(COL_SRC:%=$(COLSRCDIR)/%)
INSTALLED_COL_FILES = $(COLLATION_SOURCE:%.txt=%)  $(COLLATION_SOURCE_LOCAL:%.txt=%)
endif
ifdef RBNF_SOURCE
RBNF_SRC= root.txt $(RBNF_SOURCE) $(RBNF_ALIAS_SOURCE) $(RBNF_SOURCE_LOCAL)
RBNF_SRC_FILES = $(RBNF_SRC:%=$(RBNFSRCDIR)/%)
INSTALLED_RBNF_FILES = $(RBNF_SOURCE:%.txt=%)  $(RBNF_SOURCE_LOCAL:%.txt=%)
endif
ifdef TRANSLIT_SOURCE
TRANSLIT_SRC= $(TRANSLIT_SOURCE) $(TRANSLIT_ALIAS_SOURCE) $(TRANSLIT_SOURCE_LOCAL)
TRANSLIT_SRC_FILES = $(TRANSLIT_SRC:%=$(TRANSLITSRCDIR)/%)
INSTALLED_TRANSLIT_FILES = $(TRANSLIT_SOURCE:%.txt=%)  $(TRANSLIT_SOURCE_LOCAL:%.txt=%)
endif
# CHROME : To save space, use '-R' option
GENRBOPTS=-k -R

## MISC files
-include $(MISCSRCDIR)/miscfiles.mk
-include $(MISCSRCDIR)/misclocal.mk
MSC_SOURCE= $(MISC_SOURCE) $(MISC_SOURCE_LOCAL) 
MSC_SRC_FILES=$(MSC_SOURCE:%=$(MISCSRCDIR)/%)

ifeq ($(ENABLE_SO_VERSION_DATA),1)
ifeq ($(PKGDATA_MODE),dll)
SO_VERSION_DATA = $(OUTTMPDIR)/icudata.res
$(SO_VERSION_DATA) : $(MISCSRCDIR)/icudata.rc
	rc.exe /i$(srcdir)/../common /fo$@ $(CPPFLAGS) $(SOURCE_FILE)
endif
endif

ALL_RES_SRC= $(RES_SRC) $(TRNS_SOURCE) $(MSC_SOURCE)
RES_FILES = $(ALL_RES_SRC:%.txt=$(BUILDDIR)/%.res)
RES_FILES_SHORT = $(ALL_RES_SRC:%.txt=%.res)
PKGDATA_LIST = $(OUTTMPDIR)/icudata.lst

INDEX_NAME=res_index
INDEX_FILE=$(OUTTMPDIR)/$(INDEX_NAME).txt
INDEX_RES_FILE=$(INDEX_FILE:$(OUTTMPDIR)/%.txt=$(BUILDDIR)/%.res)
INDEX_RES_FILE_SHORT=$(INDEX_FILE:$(OUTTMPDIR)/%.txt=%.res)

COLLATION_TREE=coll
COLLATION_INDEX_FILE=$(OUTTMPDIR)/$(COLLATION_TREE)/$(INDEX_NAME).txt
COLLATION_INDEX_RES=$(COLBLDDIR)/$(INDEX_NAME).res
COLLATION_INDEX_RES_SHORT=$(COLLATION_TREE)/$(INDEX_NAME).res
COLLATION_FILES = $(COL_SRC:%.txt=$(COLBLDDIR)/%.res) $(COLLATION_INDEX_RES)
COLLATION_FILES_SHORT = $(COL_SRC:%.txt=$(COLLATION_TREE)/%.res)

BRK_RES_INDEX_FILE=$(OUTTMPDIR)/$(BREAK_TREE)/$(INDEX_NAME).txt
BRK_RES_INDEX_RES=$(BRKBLDDIR)/$(INDEX_NAME).res
BRK_RES_INDEX_RES_SHORT=$(BREAK_TREE)/$(INDEX_NAME).res
BRK_RES_FILES = $(BRS_SRC:%.txt=$(BRKBLDDIR)/%.res) $(BRK_RES_INDEX_RES)
BRK_RES_FILES_SHORT = $(BRS_SRC:%.txt=$(BREAK_TREE)/%.res)

RBNF_TREE=rbnf
RBNF_INDEX_FILE=$(OUTTMPDIR)/$(RBNF_TREE)/$(INDEX_NAME).txt
RBNF_INDEX_RES=$(RBNFBLDDIR)/$(INDEX_NAME).res
RBNF_INDEX_RES_SHORT=$(RBNF_TREE)/$(INDEX_NAME).res
RBNF_FILES = $(RBNF_SRC:%.txt=$(RBNFBLDDIR)/%.res) $(RBNF_INDEX_RES)
RBNF_FILES_SHORT = $(RBNF_SRC:%.txt=$(RBNF_TREE)/%.res)

TRANSLIT_TREE=translit
#TRANSLIT_INDEX_FILE=$(OUTTMPDIR)/$(TRANSLIT_TREE)/$(INDEX_NAME).txt
#TRANSLIT_INDEX_RES=$(TRANSLITBLDDIR)/$(INDEX_NAME).res
#TRANSLIT_INDEX_RES_SHORT=$(TRANSLIT_TREE)/$(INDEX_NAME).res
TRANSLIT_FILES = $(TRANSLIT_SRC:%.txt=$(TRANSLITBLDDIR)/%.res)
TRANSLIT_FILES_SHORT = $(TRANSLIT_SRC:%.txt=$(TRANSLIT_TREE)/%.res)

## SPP files
-include $(SPREPSRCDIR)/sprepfiles.mk
-include $(SPREPSRCDIR)/spreplocal.mk
ALL_SPREP_SOURCE=$(SPREP_SOURCE) $(SPREP_SOURCE_LOCAL)
SPREP_FILES = $(ALL_SPREP_SOURCE:%.txt=$(BUILDDIR)/%.spp)
SPREP_FILES_SHORT = $(ALL_SPREP_SOURCE:%.txt=%.spp)

## All generated files
ALL_FILES = $(DAT_FILES) $(CNV_FILES) $(BRK_FILES) $(CTD_FILES) $(RES_FILES) $(INDEX_RES_FILE) $(COLLATION_FILES) $(BRK_RES_FILES) $(RBNF_FILES) $(TRANSLIT_FILES) $(SPREP_FILES) $(CFU_FILES)
ALL_INDEX_SRC_FILES = $(PKGDATA_LIST) $(INDEX_FILE) $(COLLATION_INDEX_FILE) $(BRK_RES_INDEX_FILE) $(RBNF_INDEX_FILE)
# a list to use in the .lst files (package-relative)
ALL_FILES_LIST = $(DAT_FILES_SHORT) $(CNV_FILES_SHORT) $(BRK_FILES_SHORT) $(CTD_FILES_SHORT) $(RES_FILES_SHORT) $(INDEX_RES_FILE_SHORT) $(COLLATION_FILES_SHORT) $(COLLATION_INDEX_RES_SHORT) $(BRK_RES_FILES_SHORT) $(BRK_RES_INDEX_RES_SHORT) $(RBNF_FILES_SHORT) $(RBNF_INDEX_RES_SHORT) $(TRANSLIT_FILES_SHORT) $(SPREP_FILES_SHORT) $(CFU_FILES_SHORT)

UNI_CORE_DATA=uprops.icu ucase.icu ubidi.icu unorm.icu
UNI_CORE_TARGET_DATA=$(UNI_CORE_DATA:%=$(BUILDDIR)/%)

ifneq ($(INCLUDE_UNI_CORE_DATA),)
ALL_FILES_LIST+=$(UNI_CORE_DATA)
build-local: uni-core-data
endif

#####################################################
# General data build rules

## Files to remove for 'make clean'
CLEANFILES = *~ icupkg.inc

ifeq ($(ICUDATA_SOURCE_ARCHIVE),)
build-local: build-dir $(SO_VERSION_DATA) $(ALL_FILES) $(PKGDATA_LIST) $(OS390LIST)
$(PKGDATA_LIST): $(SRCLISTDEPS)
	@echo "generating $@ (list of data files)"
	@-$(RMV) $@
	@for file in $(ALL_FILES_LIST); do \
	  echo $$file >> $@; \
	done;
else
build-local: build-dir $(SO_VERSION_DATA) $(PKGDATA_LIST) $(OS390LIST)
$(PKGDATA_LIST): $(SRCLISTDEPS) $(ICUDATA_SOURCE_ARCHIVE)
ifneq ($(ICUDATA_SOURCE_IS_NATIVE_TARGET),YES)
	@echo "Unpacking $(ICUDATA_SOURCE_ARCHIVE) and generating $@ (list of data files)"
	@-$(RMV) $@
	$(INVOKE) $(TOOLBINDIR)/icupkg -d $(BUILDDIR) --list -x \* $(ICUDATA_SOURCE_ARCHIVE) -o $@
else
	@echo "$@" > $@
endif
endif


$(BUILD_DIRS): build-dir

build-dir:
	@list='$(BUILD_DIRS)'; \
	for dir in $$list; do \
	  if ! test -d $$dir; then \
	    echo $(MKINSTALLDIRS) $(BUILD_DIRS); \
	    $(MKINSTALLDIRS) $(BUILD_DIRS); \
	  fi; \
	done

# The | is an order-only prerequisite. This helps when the -j option is used,
# and we don't want the files to be built before the directories are built.
ifneq ($(filter order-only,$(.FEATURES)),)
$(ALL_FILES) $(ALL_INDEX_SRC_FILES): | build-dir
endif

# Now, sections for building each kind of data.

####################################################    DAT
# DAT FILES

# uprops.icu
$(BUILDDIR)/uprops.icu: $(UNICODEDATADIR)/UnicodeData.txt $(UNICODEDATADIR)/BidiMirroring.txt $(TOOLBINDIR)/genprops$(TOOLEXEEXT) $(BUILDDIR)/$(ICUDT)pnames.icu
	$(INVOKE) $(TOOLBINDIR)/genprops -s $(UNICODEDATADIR) -i $(BUILDDIR) -d $(BUILDDIR) -u $(UNICODE_VERSION)
	$(INVOKE) $(TOOLBINDIR)/genprops --csource -s $(UNICODEDATADIR) -i $(BUILDDIR) -d $(OUTTMPDIR) -u $(UNICODE_VERSION)

# ubidi.icu
$(BUILDDIR)/ubidi.icu: $(UNICODEDATADIR)/UnicodeData.txt $(TOOLBINDIR)/genbidi$(TOOLEXEEXT)
	$(INVOKE) $(TOOLBINDIR)/genbidi -s $(UNICODEDATADIR) -i $(BUILDDIR) -d $(BUILDDIR) -u $(UNICODE_VERSION)
	$(INVOKE) $(TOOLBINDIR)/genbidi --csource -s $(UNICODEDATADIR) -i $(BUILDDIR) -d $(OUTTMPDIR) -u $(UNICODE_VERSION)

# ucase.icu
$(BUILDDIR)/ucase.icu: $(UNICODEDATADIR)/UnicodeData.txt $(TOOLBINDIR)/gencase$(TOOLEXEEXT)
	$(INVOKE) $(TOOLBINDIR)/gencase -s $(UNICODEDATADIR) -i $(BUILDDIR) -d $(BUILDDIR) -u $(UNICODE_VERSION)
	$(INVOKE) $(TOOLBINDIR)/gencase --csource -s $(UNICODEDATADIR) -i $(BUILDDIR) -d $(OUTTMPDIR) -u $(UNICODE_VERSION)

# pnames.icu
$(BUILDDIR)/pnames.icu: $(UNICODEDATADIR)/PropertyAliases.txt $(UNICODEDATADIR)/PropertyValueAliases.txt $(UNICODEDATADIR)/Blocks.txt $(COMINCDIR)/uscript.h $(COMINCDIR)/uchar.h $(TOOLBINDIR)/genpname$(TOOLEXEEXT)
	$(INVOKE) $(TOOLBINDIR)/genpname -d $(BUILDDIR)

# unorm.icu
$(BUILDDIR)/unorm.icu: $(UNICODEDATADIR)/UnicodeData.txt $(UNICODEDATADIR)/DerivedNormalizationProps.txt $(UNICODEDATADIR)/BidiMirroring.txt $(TOOLBINDIR)/gennorm$(TOOLEXEEXT) $(BUILDDIR)/$(ICUDT)pnames.icu $(BUILDDIR)/$(ICUDT)uprops.icu $(BUILDDIR)/$(ICUDT)ucase.icu
	$(INVOKE) $(TOOLBINDIR)/gennorm -s $(UNICODEDATADIR) -i $(BUILDDIR) -d $(BUILDDIR) -u $(UNICODE_VERSION)
	$(INVOKE) $(TOOLBINDIR)/gennorm --csource -s $(UNICODEDATADIR) -i $(BUILDDIR) -d $(OUTTMPDIR) -u $(UNICODE_VERSION)

# ucadata.icu
# used to depend on $(BUILDDIR)/$(ICUDT)unorm.icu $(BUILDDIR)/$(ICUDT)ucase.icu
# see Jitterbug 4497
# CHROME: We don't need invuca.icu
$(COLBLDDIR)/ucadata.icu: $(UNICODEDATADIR)/FractionalUCA.txt $(TOOLBINDIR)/genuca$(TOOLEXEEXT)
	$(INVOKE) $(TOOLBINDIR)/genuca -s $(UNICODEDATADIR) -d $(COLBLDDIR) -i $(BUILDDIR) 

# unames.icu
$(BUILDDIR)/unames.icu: $(UNICODEDATADIR)/UnicodeData.txt $(TOOLBINDIR)/gennames$(TOOLEXEEXT)
	$(INVOKE) $(TOOLBINDIR)/gennames -1 -d $(BUILDDIR) $(UNICODEDATADIR)/UnicodeData.txt -u $(UNICODE_VERSION)

# cnvalias.icu
$(BUILDDIR)/cnvalias.icu: $(UCMSRCDIR)/convrtrs.txt $(TOOLBINDIR)/gencnval$(TOOLEXEEXT)
	$(INVOKE) $(TOOLBINDIR)/gencnval -d $(BUILDDIR) $(UCMSRCDIR)/convrtrs.txt

####################################################    SPP
# SPP FILES

# CHROME: We don't need unames.icu.
# Do we need to have spp files other than uidna.spp?
$(BUILDDIR)/%.spp: $(SPREPSRCDIR)/%.txt $(TOOLBINDIR)/gensprep$(TOOLEXEEXT) $(BUILDDIR)/pnames.icu
	$(INVOKE) $(TOOLBINDIR)/gensprep -d $(BUILDDIR) -i $(BUILDDIR) -s $(SPREPSRCDIR) -b $(@F:%.spp=%) -m $(UNICODEDATADIR) -u 3.2.0 $(<F)

####################################################    BRK
# BRK FILES

#thaidict.brk: $(SRCDATADIR)/thaidict.brk
#	$(RMV) $@ && ln -s $(BUILDDIR) $@

$(BRKBLDDIR)/%.brk: $(BRKSRCDIR)/%.txt $(TOOLBINDIR)/genbrk$(TOOLEXEEXT) $(DAT_FILES)
	$(INVOKE) $(TOOLBINDIR)/genbrk -c -i $(BUILDDIR) -r $< -o $@

####################################################    CTD
# CTD FILES

# .ctd file now generated regardless of whether dictionary file exists
$(BRKBLDDIR)/%.ctd: $(TOOLBINDIR)/genctd$(TOOLEXEEXT) $(DAT_FILES)
	$(INVOKE) $(TOOLBINDIR)/genctd -c -i $(BUILDDIR) -o $@ $(BRKSRCDIR)/$(*F).txt

####################################################    CFU
# CFU FILES
#    Note: gencfu requires two input files to produce a single output file.
#          There will be exactly one target file and two source files.
#          The $(word n, ...) selects the nth word from the following stuff.
#          There must be a nicer way to do this.

$(CFU_FILES): $(ALL_CFU_SOURCE) $(TOOLBINDIR)/gencfu$(EXEEXT) $(DAT_FILES)
	$(INVOKE) echo ALL_CFU_SOURCE: $(ALL_CFU_SOURCE)
	$(INVOKE) echo CFU_FILES: $(CFU_FILES)
	$(INVOKE) echo CFU_FILES_SHORT: $(CFU_FILES_SHORT)
	$(INVOKE) $(TOOLBINDIR)/gencfu -c -i $(BUILDDIR) -r $(word 1,$(ALL_CFU_SOURCE)) -w $(word 2,$(ALL_CFU_SOURCE)) -o $@


####################################################    CNV
# CNV FILES
$(BUILDDIR)/%.cnv: $(UCMSRCDIR)/%.ucm $(TOOLBINDIR)/makeconv$(TOOLEXEEXT)
	$(INVOKE) $(TOOLBINDIR)/makeconv -c -d $(BUILDDIR) $(UCMSRCDIR)/$(<F)

####################################################    RES
# RES FILES

### collation res
$(COLBLDDIR)/%.res: $(COLSRCDIR)/%.txt  $(TOOLBINDIR)/genrb$(TOOLEXEEXT) $(DAT_FILES)
	$(INVOKE) $(TOOLBINDIR)/genrb $(GENRBOPTS) -i $(BUILDDIR) -s $(COLSRCDIR) -d $(COLBLDDIR) $(<F)

$(COLBLDDIR)/$(INDEX_NAME).res: $(OUTTMPDIR)/$(COLLATION_TREE)/$(INDEX_NAME).txt $(TOOLBINDIR)/genrb$(TOOLEXEEXT)
	$(INVOKE) $(TOOLBINDIR)/genrb $(GENRBOPTS) -i $(BUILDDIR) -s $(OUTTMPDIR)/$(COLLATION_TREE) -d $(COLBLDDIR) $(INDEX_NAME).txt

$(COLLATION_INDEX_FILE): $(SRCLISTDEPS)
	@echo "generating $@ (list of installed collation locales)"; \
	$(RMV) $@; \
	echo "// Warning this file is automatically generated" > $@; \
	echo "$(INDEX_NAME):table(nofallback) {" >> $@; \
	echo "    InstalledLocales {" >> $@; \
	for file in $(INSTALLED_COL_FILES); do \
	  echo "        $$file {\"\"}" >> $@; \
	done; \
	echo "    }" >> $@; \
	echo "}" >> $@;

### brk res
$(BRKBLDDIR)/%.res: $(BRKSRCDIR)/%.txt $(TOOLBINDIR)/genrb$(TOOLEXEEXT) $(BRK_FILES) $(DAT_FILES)
	$(INVOKE) $(TOOLBINDIR)/genrb $(GENRBOPTS) -i $(BUILDDIR) -s $(BRKSRCDIR) -d $(BRKBLDDIR) $(<F)

$(BRKBLDDIR)/$(INDEX_NAME).res: $(OUTTMPDIR)/$(BREAK_TREE)/$(INDEX_NAME).txt $(TOOLBINDIR)/genrb$(TOOLEXEEXT)
	$(INVOKE) $(TOOLBINDIR)/genrb $(GENRBOPTS) -i $(BUILDDIR) -s $(OUTTMPDIR)/$(BREAK_TREE) -d $(BRKBLDDIR) $(INDEX_NAME).txt

$(BRK_RES_INDEX_FILE): $(SRCLISTDEPS)
	@echo "generating $@ (list of installed break locales)"; \
	$(RMV) $@; \
	echo "// Warning this file is automatically generated" > $@; \
	echo "$(INDEX_NAME):table(nofallback) {" >> $@; \
	echo "    InstalledLocales {" >> $@; \
	for file in $(INSTALLED_BRS_FILES); do \
	  echo "        $$file {\"\"}" >> $@; \
	done; \
	echo "    }" >> $@; \
	echo "}" >> $@;

### RBNF res
$(RBNFBLDDIR)/%.res: $(RBNFSRCDIR)/%.txt  $(TOOLBINDIR)/genrb$(TOOLEXEEXT) $(DAT_FILES)
	$(INVOKE) $(TOOLBINDIR)/genrb $(GENRBOPTS) -i $(BUILDDIR) -s $(RBNFSRCDIR) -d $(RBNFBLDDIR) $(<F)

$(RBNFBLDDIR)/$(INDEX_NAME).res: $(OUTTMPDIR)/$(RBNF_TREE)/$(INDEX_NAME).txt $(TOOLBINDIR)/genrb$(TOOLEXEEXT)
	$(INVOKE) $(TOOLBINDIR)/genrb $(GENRBOPTS) -i $(BUILDDIR) -s $(OUTTMPDIR)/$(RBNF_TREE) -d $(RBNFBLDDIR) $(INDEX_NAME).txt

$(RBNF_INDEX_FILE): $(SRCLISTDEPS)
	@echo "generating $@ (list of installed RBNF locales)"; \
	$(RMV) $@; \
	echo "// Warning this file is automatically generated" > $@; \
	echo "$(INDEX_NAME):table(nofallback) {" >> $@; \
	echo "    InstalledLocales {" >> $@; \
	for file in $(INSTALLED_RBNF_FILES); do \
	  echo "        $$file {\"\"}" >> $@; \
	done; \
	echo "    }" >> $@; \
	echo "}" >> $@;

### TRANSLIT res
$(TRANSLITBLDDIR)/%.res: $(TRANSLITSRCDIR)/%.txt  $(TOOLBINDIR)/genrb$(TOOLEXEEXT) $(DAT_FILES)
	$(INVOKE) $(TOOLBINDIR)/genrb $(GENRBOPTS) -i $(BUILDDIR) -s $(TRANSLITSRCDIR) -d $(TRANSLITBLDDIR) $(<F)

### normal (locale) res
all-RES:  $(RES_FILES)

$(BUILDDIR)/%.res: $(LOCSRCDIR)/%.txt $(TOOLBINDIR)/genrb$(TOOLEXEEXT) $(DAT_FILES)
	$(INVOKE) $(TOOLBINDIR)/genrb $(GENRBOPTS) -i $(BUILDDIR) -s $(LOCSRCDIR) -d $(BUILDDIR) $(<F)

# if the tzcode directory contains a new tzdata*.tar.gz file, use it for zoneinfo.txt
TZDATA = $(firstword $(wildcard $(top_builddir)/tools/tzcode/tzdata*.tar.gz) $(wildcard $(top_srcdir)/tools/tzcode/tzdata*.tar.gz))

ifneq ($(TZDATA),)

TZCODE_DIR=$(top_builddir)/tools/tzcode
ZONEINFO=$(TZCODE_DIR)/zoneinfo.txt

# Override the normal genrb for zoneinfo.txt to always pull from
# icu/source/tools/tzcode/zoneinfo.txt
$(BUILDDIR)/zoneinfo.res: $(ZONEINFO) $(TOOLBINDIR)/genrb$(TOOLEXEEXT)
	@echo Note: $(MISCSRCDIR)/zoneinfo.txt is IGNORED because $(TZDATA) is present.
	$(INVOKE) $(TOOLBINDIR)/genrb $(GENRBOPTS) -q -i $(BUILDDIR) -d $(BUILDDIR) $(ZONEINFO)

# Create the tzcode tool and zoneinfo.txt as needed.
$(ZONEINFO): $(TZDATA)
	@echo "$(MAKE)[$(MAKELEVEL)]: Making \`$(ZONEINFO)' in \`$(TZCODE_DIR)'"; \
	(cd $(TZCODE_DIR) && $(MAKE)) || exit; \

# end of zoneinfo.txt-generation
endif

# zoneinfo has some issues. Ignore some warnings with -q
$(BUILDDIR)/%.res: $(MISCSRCDIR)/%.txt $(TOOLBINDIR)/genrb$(TOOLEXEEXT)
	$(INVOKE) $(TOOLBINDIR)/genrb $(GENRBOPTS) -q -i $(BUILDDIR) -s $(MISCSRCDIR) -d $(BUILDDIR) $(<F)



$(INDEX_FILE): $(SRCLISTDEPS)
	@echo "generating $@ (list of installed locales)"; \
	$(RMV) $@; \
	echo "// Warning this file is automatically generated" > $@; \
	echo "$(INDEX_NAME):table(nofallback) {" >> $@; \
        echo "    CLDRVersion { \"$(GENRB_CLDR_VERSION)\" }" >> $@; \
	echo "    InstalledLocales {" >> $@; \
	for file in $(INSTALLED_RB_FILES); do \
	  echo "        $$file {\"\"}" >> $@; \
	done; \
	echo "    }" >> $@; \
	echo "}" >> $@;

clean-resindex:
	-$(RMV) $(BUILDDIR)/$(INDEX_NAME).txt $(PKGDATA_LIST)

$(INDEX_RES_FILE): $(INDEX_FILE) $(TOOLBINDIR)/genrb$(TOOLEXEEXT)
	$(INVOKE) $(TOOLBINDIR)/genrb $(GENRBOPTS) -i $(BUILDDIR) -d $(BUILDDIR) $(INDEX_FILE)

# Starting with ICU4C 3.4, the core Unicode properties files (uprops.icu, ucase.icu, ubidi.icu, unorm.icu)
# are hardcoded in the common DLL and therefore not included in the data package any more.
# They are not built by default but need to be built for ICU4J data and for getting the .c source files
# when updating the Unicode data.
# Changed in Makefile.in revision 1.147. See Jitterbug 4497.
uni-core-data: build-dir $(UNI_CORE_TARGET_DATA)
	@echo Unicode .icu files built to $(BUILDDIR)
	@echo Unicode .c source files built to $(OUTTMPDIR)

build-icu4j: all
	$(MAKE) -C ../tools/genrb $@

###################################################################
Makefile: $(srcdir)/Makefile.in  $(top_builddir)/config.status
	cd $(top_builddir) \
	&& CONFIG_FILES=$(subdir)/$@ CONFIG_HEADERS= $(SHELL) ./config.status

icupkg.inc: pkgdataMakefile
	$(MAKE) -f pkgdataMakefile

pkgdataMakefile:
	cd $(top_builddir) \
	&& CONFIG_FILES=$(subdir)/$@ CONFIG_HEADERS= $(SHELL) ./config.status

###########
########### 390 (z/OS) support
UCMFILES390=ebcdic-xml-us.ucm ibm-37_P100-1995.ucm ibm-1047_P100-1995.ucm ibm-4909_P100-1999.ucm
# used to depend on uprops.icu ucase.icu ubidi.icu unorm.icu
# see Jitterbug 4497
ALLFILES390=pnames.icu cnvalias.icu $(UCMFILES390:.ucm=.cnv)

$(OUTTMPDIR)/icudata390.lst: $(SRCLISTDEPS)
	@echo "generating $@ (list of 390 data files)"
	@-$(RMV) $@
	@for file in $(ALLFILES390); do \
	  echo $$file >> $@; \
	done;

ifeq ($(POST_DATA_BUILD), os400-data-rebind)
os400-data-rebind: $(LIBICUUC)

$(LIBICUUC): $(LIBICUDT)
	$(RMV) $(LIBICUUC)
	(cd ../common && $(MAKE) RECURSIVE=YES) || exit;
endif
