## Makefile.in for ICU data
## Copyright (c) 1999-2004, 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

top_builddir_from_tmp = $(patsubst ..%,../..%,$(top_builddir))
CURDIR:=$(CURR_FULL_DIR)
PKGDATA = $(BINDIR)/pkgdata $(PKGDATA_OPTS) -q -c -s $(CURDIR)/out/build/$(ICUDATA_PLATFORM_NAME) -d $(ICUPKGDATA_OUTDIR)


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

SRCDATADIR=$(top_srcdir)/data
OUTDIR=$(top_builddir)/data/out
OUTTMPDIR=$(top_builddir)/data/out/tmp
BUILDDIR=$(OUTDIR)/build/$(ICUDATA_PLATFORM_NAME)
UNICODEDATADIR=$(SRCDATADIR)/unidata
LOCSRCDIR=$(SRCDATADIR)/locales
COLSRCDIR=$(SRCDATADIR)/coll
COLBLDDIR=$(BUILDDIR)/coll
TRNSSRCDIR=$(SRCDATADIR)/translit
MISCSRCDIR=$(SRCDATADIR)/misc
BRKSRCDIR=$(SRCDATADIR)/brkitr
MISCSRCDIR=$(SRCDATADIR)/misc
UCMSRCDIR=$(SRCDATADIR)/mappings
COMINCDIR=$(top_srcdir)/common/unicode
SRCLISTDEPS=Makefile $(srcdir)/Makefile.in

# 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-dlls build-cmnfile build-dll		\
install-recursive clean clean-local clean-recursive distclean		\
distclean-local distclean-recursive dist dist-local dist-recursive	\
check check-local check-recursive build-testdlls build-basetestdata build-local clean-resindex

## 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

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

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

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

dist-local:

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

clean-local: cleanpackage cleanfiles clean-map
	$(RMV) $(TESTOUTDIR)/testdata.dat

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

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

check-local:

# During this INVOKE we only want to use stubdata.
# We don't want to try to write over files that we are using.
PKGDATA_INVOKE:=$(subst $(LIBDIR):$(top_builddir)/stubdata,$(top_builddir)/stubdata:$(LIBDIR),$(INVOKE)) $(PKGDATA_INVOKE_OPTS)

packagedata: icupkg.inc $(OUTTMPDIR)/icudata.lst build-local
ifneq ($(ENABLE_STATIC),)
	$(PKGDATA_INVOKE) $(PKGDATA) -e $(ICUDATA_ENTRY_POINT) -T $(OUTTMPDIR) -p $(ICUDATA_NAME) $(PKGDATA_LIBSTATICNAME) -m static $(OUTTMPDIR)/icudata.lst
endif
	$(PKGDATA_INVOKE) $(PKGDATA) -e $(ICUDATA_ENTRY_POINT) -T $(OUTTMPDIR) -p $(ICUDATA_NAME) -m $(PKGDATA_MODE) $(PKGDATA_VERSIONING) $(PKGDATA_LIBNAME) $(OUTTMPDIR)/icudata.lst

## Install ICU data.
install-local: $(OUTTMPDIR)/icudata.lst ./icupkg.inc packagedata $(OS390INSTALL)
	$(MKINSTALLDIRS) $(TMPDATADIR) $(DESTDIR)$(ICUPKGDATA_DIR)
ifneq ($(ENABLE_STATIC),)
	$(PKGDATA_INVOKE) $(PKGDATA) -m static -e $(ICUDATA_ENTRY_POINT) -T $(OUTTMPDIR) -s $(BUILDDIR) -p $(ICUDATA_NAME) $(PKGDATA_LIBSTATICNAME) $(OUTTMPDIR)/icudata.lst -I $(ICUPKGDATA_INSTALL_LIBDIR)
endif
	$(PKGDATA_INVOKE) $(PKGDATA) -m $(PKGDATA_MODE) $(PKGDATA_VERSIONING) -e $(ICUDATA_ENTRY_POINT) -T $(OUTTMPDIR) -s $(BUILDDIR) -p $(ICUDATA_NAME) $(PKGDATA_LIBNAME) $(OUTTMPDIR)/icudata.lst -I $(ICUPKGDATA_INSTALL_DIR)


####
####
#### 390 support
install390: package390
	$(MKINSTALLDIRS) $(TMPDATADIR) $(DESTDIR)$(libdir)
	$(INVOKE) $(PKGDATA) -s $(BUILDDIR)$(STUB_SUFFIX) -T $(OUTTMPDIR) -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)/$(LIB_ICUDATA_NAME)$(STUB_SUFFIX)$(SO_TARGET_VERSION)$(IMPORT_LIB_EXT) $(DESTDIR)$(ICUPKGDATA_DIR)/$(LIB_ICUDATA_NAME)$(STUB_SUFFIX)$(SO_TARGET_VERSION)$(IMPORT_LIB_EXT)
endif

#### $(LIB_ICUDATA_NAME)$(STUB_SUFFIX) is the subset data for batch mode
package390: $(OUTTMPDIR)/icudata390.lst $(OUTTMPDIR)/icudata.lst ./icupkg.inc packagedata
	ln -s $(ICUDATA_NAME) $(OUTDIR)/build/$(ICUDATA_NAME)$(STUB_SUFFIX)
	$(INVOKE) $(PKGDATA) -s $(BUILDDIR)$(STUB_SUFFIX) -T $(OUTTMPDIR) -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.
DAT_FILES_SHORT=uprops.icu pnames.icu unames.icu unorm.icu cnvalias.icu ucadata.icu invuca.icu uidna.spp 
DAT_FILES=$(DAT_FILES_SHORT:%=$(BUILDDIR)/%)

## BRK files
# ALL of these files can be deleted (the following BRK files) - they are copied
BRK_FILES_SHORT=char.brk line.brk line_th.brk sent.brk word.brk title.brk word_th.brk
BRK_FILES=$(BRK_FILES_SHORT:%=$(BUILDDIR)/%)
# don't include thaidict.brk - it goes into a resource bundle - plus it isn't deleted

## UCM files 
-include $(UCMSRCDIR)/ucmcore.mk
-include $(UCMSRCDIR)/ucmfiles.mk
-include $(UCMSRCDIR)/ucmebcdic.mk
-include $(UCMSRCDIR)/ucmlocal.mk
ALL_UCM_SOURCE=ibm-37_P100-1995.ucm ibm-1047_P100-1995.ucm $(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 $(LOCSRCDIR)/reslocal.mk
-include $(COLSRCDIR)/collocal.mk
RES_SOURCE= root.txt $(GENRB_SOURCE) $(GENRB_ALIAS_SOURCE) $(GENRB_SOURCE_LOCAL)
RES_SRC_FILES = $(RES_SOURCE:%=$(LOCSRCDIR)/%)
INSTALLED_RB_FILES = $(GENRB_SOURCE:%.txt=%) $(GENRB_SOURCE_LOCAL:%.txt=%)
COL_SOURCE= root.txt $(COLLATION_SOURCE) $(COLLATION_ALIAS_SOURCE) $(COLLATION_SOURCE_LOCAL)
COL_SRC_FILES = $(COL_SOURCE:%=$(COLSRCDIR)/%)
INSTALLED_COL_FILES = $(COLLATION_SOURCE:%.txt=%)  $(COLLATION_SOURCE_LOCAL:%.txt=%)
GENRBOPTS=-k -q

## TRNS files
-include $(TRNSSRCDIR)/trnsfiles.mk
-include $(TRNSSRCDIR)/trnslocal.mk
TRNS_SOURCE= $(TRANSLIT_SOURCE) $(TRANSLIT_SOURCE_LOCAL) 
TRNS_SRC_FILES=$(TRNS_SOURCE:%=$(TRNSSRCDIR)/%)

## 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$@ $(SOURCE_FILE)
endif
endif

ALL_RES_SOURCE= $(RES_SOURCE) $(TRNS_SOURCE) $(MSC_SOURCE)
RES_FILES = $(ALL_RES_SOURCE:%.txt=$(BUILDDIR)/%.res)
RES_FILES_SHORT = $(ALL_RES_SOURCE:%.txt=%.res)

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_SOURCE:%.txt=$(COLBLDDIR)/%.res) $(COLLATION_INDEX_RES)
COLLATION_FILES_SHORT = $(COL_SOURCE:%.txt=$(COLLATION_TREE)/%.res)

## All generated files
ALL_FILES = $(DAT_FILES) $(CNV_FILES) $(BRK_FILES) $(RES_FILES) $(INDEX_RES_FILE) $(COLLATION_FILES)
# a list to use in the .lst files (package-relative)
ALL_FILES_LIST = $(DAT_FILES_SHORT) $(CNV_FILES_SHORT) $(BRK_FILES_SHORT) $(RES_FILES_SHORT) $(INDEX_RES_FILE_SHORT) $(COLLATION_FILES_SHORT) $(COLLATION_INDEX_RES_SHORT)

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

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

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

build-local: build-dir $(SO_VERSION_DATA) build-data build-testdata

build-data: build-dir $(ALL_FILES) $(OUTTMPDIR)/icudata.lst $(OS390LIST)

build-dir:
	-$(MKINSTALLDIRS) $(OUTDIR) $(BUILDDIR) $(COLBLDDIR) $(TESTOUTDIR) $(TESTBUILDDIR) $(OUTTMPDIR) $(OUTTMPDIR)/$(COLLATION_TREE) 


# Now, sections for building each kind of data.

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

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

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

# unorm.icu
$(BUILDDIR)/unorm.icu: $(UNICODEDATADIR)/UnicodeData.txt $(UNICODEDATADIR)/DerivedNormalizationProps.txt $(UNICODEDATADIR)/BidiMirroring.txt $(BINDIR)/gennorm$(EXEEXT) $(BUILDDIR)/$(ICUDT)uprops.icu
	$(INVOKE) $(BINDIR)/gennorm -s $(UNICODEDATADIR) -d $(BUILDDIR) -u $(UNICODE_VERSION)

# ucadata.icu
$(BUILDDIR)/ucadata.icu $(BUILDDIR)/$(ICUDT)invuca.icu: $(UNICODEDATADIR)/FractionalUCA.txt $(BINDIR)/genuca$(EXEEXT) $(BUILDDIR)/$(ICUDT)unorm.icu
	$(INVOKE) $(BINDIR)/genuca -s $(UNICODEDATADIR) -d $(BUILDDIR) -i $(BUILDDIR) 

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

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

# uidna.spp
$(BUILDDIR)/uidna.spp: $(MISCSRCDIR)/NamePrepProfile.txt $(BINDIR)/gensprep$(EXEEXT) $(BUILDDIR)/uprops.icu $(BUILDDIR)/unames.icu $(BUILDDIR)/pnames.icu
	$(INVOKE) $(BINDIR)/gensprep -d $(BUILDDIR) -i $(BUILDDIR) -s $(MISCSRCDIR) -b uidna -n $(UNICODEDATADIR) -u 3.2.0 -k NamePrepProfile.txt

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

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

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

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

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

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

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

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



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

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

$(BUILDDIR)/%.res: $(TRNSSRCDIR)/%.txt $(BINDIR)/genrb$(EXEEXT) $(DAT_FILES)
	$(INVOKE) $(BINDIR)/genrb $(GENRBOPTS)  -i $(BUILDDIR) -s $(TRNSSRCDIR) -d $(BUILDDIR) $(<F)

$(BUILDDIR)/%.res: $(MISCSRCDIR)/%.txt $(BINDIR)/genrb$(EXEEXT)
	$(INVOKE) $(BINDIR)/genrb $(GENRBOPTS)  -i $(BUILDDIR) -s $(MISCSRCDIR) -d $(BUILDDIR) $(<F)

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

clean-resindex:
	-$(RMV) $(BUILDDIR)/$(INDEX_NAME).txt $(OUTTMPDIR)/icudata.lst

$(INDEX_RES_FILE): $(INDEX_FILE) $(BINDIR)/genrb$(EXEEXT)
	$(INVOKE) $(BINDIR)/genrb $(GENRBOPTS)  -i $(BUILDDIR) -d $(BUILDDIR) $(INDEX_FILE)

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

icupkg.inc: $(srcdir)/icupkg.inc.in  $(top_builddir)/config.status
	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
ALLFILES390=uprops.icu pnames.icu unorm.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;

#########################################################################
############################## Test ## stuff ############################

TESTSRCDATADIR=$(top_srcdir)/test/testdata
TESTOUTDIR=$(top_builddir)/test/testdata/out

# Contains all 'intermediate' files (and temp files) except for 'unpackaged data' below
TESTBUILDDIR=$(TESTOUTDIR)/build

# unpackaged files  - live in 'out' so that the path can find them as part of the pkg
UNPACKAGEDTESTDATA=$(TESTOUTDIR)/$(TESTDT)nam.typ

# pkg name for testdata
TESTDATA=testdata
# prefix for files that are testdata
TESTDT=$(TESTDATA)_

# File definitions 
TEST_DAT_FILES=$(TESTBUILDDIR)/$(TESTDT)test.icu $(TESTBUILDDIR)/$(TESTDT)nfscsi.spp $(TESTBUILDDIR)/$(TESTDT)nfscss.spp $(TESTBUILDDIR)/$(TESTDT)nfscis.spp $(TESTBUILDDIR)/$(TESTDT)nfsmxs.spp $(TESTBUILDDIR)/$(TESTDT)nfsmxp.spp

TEST_UCM_SOURCE= test1.ucm test3.ucm test4.ucm test4x.ucm ibm9027.ucm
TEST_UCM_FILES=$(TEST_UCM_SOURCE:%=$(TESTSRCDATADIR)/data/%)
TEST_CNV_FILES=$(TEST_UCM_SOURCE:%.ucm=$(TESTBUILDDIR)/$(TESTDT)%.cnv)

TEST_RES = casing.txt mc.txt root.txt te.txt te_IN.txt testtypes.txt testaliases.txt testempty.txt DataDrivenCollationTest.txt idna_rules.txt conversion.txt icuio.txt testtable32.txt
TEST_RES_FILES=$(TEST_RES:%.txt=$(TESTBUILDDIR)/$(TESTDT)%.res) $(TESTBUILDDIR)/$(TESTDT)iscii.res $(TESTSRCDATADIR)/$(TESTDT)icu26_testtypes.res $(TESTSRCDATADIR)/$(TESTDT)icu26e_testtypes.res

ALL_TEST_FILES = $(TEST_DAT_FILES) $(TEST_BRK_FILES) $(TEST_CNV_FILES) $(TEST_RES_FILES) $(TESTOUTDIR)/$(TESTDT)nam.typ

# list

$(TESTBUILDDIR)/testdata.lst: $(SRCLISTDEPS)
	@echo "generating $@ (list of data files)"
	@-$(RMV) $@
	@for file in $(TEST_RES_FILES) $(TEST_DAT_FILES) $(TEST_CNV_FILES); do \
	  echo $$file >> $@; \
	done;


build-testdata:  $(ALL_TEST_FILES) $(TESTBUILDDIR)/testdata.lst $(TESTBUILDDIR)/$(TESTDT)iscii.res

# test.icu
$(TESTBUILDDIR)/$(TESTDT)test.icu: $(TOOLDIR)/gentest/gentest$(EXEEXT)
	$(INVOKE) $(TOOLDIR)/gentest/gentest -d $(TESTBUILDDIR) 

$(TESTBUILDDIR)/testtable32.txt:  $(TOOLDIR)/gentest/gentest$(EXEEXT)
	$(INVOKE) $(TOOLDIR)/gentest/gentest -r -d $(TESTBUILDDIR) 

$(TESTBUILDDIR)/$(TESTDT)testtable32.res: $(TESTBUILDDIR)/testtable32.txt $(BINDIR)/genrb$(EXEEXT)
	$(INVOKE) $(BINDIR)/genrb $(GENRBOPTS) -p $(TESTDATA) -q -s $(TESTBUILDDIR) -i $(BUILDDIR) -d $(TESTBUILDDIR) $(<F)

# Targets for nfscsi.spp
$(TESTBUILDDIR)/$(TESTDT)nfscsi.spp: $(BINDIR)/gensprep$(EXEEXT) $(TESTSRCDATADIR)/nfs4_cs_prep_ci.txt
	@echo Building nfscsi.icu
	$(INVOKE) $(BINDIR)/gensprep -s $(TESTSRCDATADIR) -i $(BUILDDIR) -d $(TESTBUILDDIR) -b nfscsi -p $(TESTDATA) -u 3.2.0 nfs4_cs_prep_ci.txt

# Targets for nfscss.spp
$(TESTBUILDDIR)/$(TESTDT)nfscss.spp: $(BINDIR)/gensprep$(EXEEXT) $(TESTSRCDATADIR)/nfs4_cs_prep_cs.txt
	@echo Building nfscss.icu
	$(INVOKE) $(BINDIR)/gensprep -s $(TESTSRCDATADIR) -i $(BUILDDIR) -d $(TESTBUILDDIR) -b nfscss -p $(TESTDATA) -u 3.2.0 nfs4_cs_prep_cs.txt

# Targets for nfscis.spp
$(TESTBUILDDIR)/$(TESTDT)nfscis.spp: $(BINDIR)/gensprep$(EXEEXT) $(TESTSRCDATADIR)/nfs4_cis_prep.txt
	@echo Building nfscis.spp
	$(INVOKE) $(BINDIR)/gensprep -s $(TESTSRCDATADIR) -i $(BUILDDIR) -d $(TESTBUILDDIR) -b nfscis -p $(TESTDATA) -k -n $(UNICODEDATADIR) -u 3.2.0 nfs4_cis_prep.txt

# Targets for nfsmxs.spp
$(TESTBUILDDIR)/$(TESTDT)nfsmxs.spp: $(BINDIR)/gensprep$(EXEEXT) $(TESTSRCDATADIR)/nfs4_mixed_prep_s.txt
	@echo Building nfsmxs.spp
	$(INVOKE) $(BINDIR)/gensprep -s $(TESTSRCDATADIR) -i $(BUILDDIR) -d $(TESTBUILDDIR) -b nfsmxs -p $(TESTDATA) -k -n $(UNICODEDATADIR) -u 3.2.0 nfs4_mixed_prep_s.txt

# Targets for nfsmxp.spp
$(TESTBUILDDIR)/$(TESTDT)nfsmxp.spp: $(BINDIR)/gensprep$(EXEEXT) $(TESTSRCDATADIR)/nfs4_mixed_prep_p.txt
	@echo Building nfsmxp.spp
	$(INVOKE) $(BINDIR)/gensprep -s $(TESTSRCDATADIR) -i $(BUILDDIR) -d $(TESTBUILDDIR) -b nfsmxp -p $(TESTDATA) -k -n $(UNICODEDATADIR) -u 3.2.0 nfs4_mixed_prep_p.txt

$(TESTBUILDDIR)/$(TESTDT)%.cnv: $(TESTSRCDATADIR)/%.ucm $(BINDIR)/makeconv$(EXEEXT)
	$(INVOKE) $(BINDIR)/makeconv -p $(TESTDATA) -c -d $(TESTBUILDDIR) $(TESTSRCDATADIR)/$(<F)

$(TESTBUILDDIR)/$(TESTDT)%.res: $(TESTSRCDATADIR)/%.txt $(BINDIR)/genrb$(EXEEXT) $(DAT_FILES)
	$(INVOKE) $(BINDIR)/genrb $(GENRBOPTS) -p $(TESTDATA) -q -s $(TESTSRCDATADIR) -i $(BUILDDIR) -d $(TESTBUILDDIR) $(<F)

$(TESTBUILDDIR)/$(TESTDT)iscii.res:  $(TESTSRCDATADIR)/iscii.bin $(BINDIR)/genrb$(EXEEXT)
	@echo Testing genrb -e option
	@ICU_DATA=$(BUILDDIR) $(INVOKE) $(BINDIR)/genrb $(GENRBOPTS) -s $(TESTSRCDATADIR) -p $(TESTDATA) -eISCII,version=0 -d $(TESTBUILDDIR) $(<F) >/dev/null  || ( echo "WARNING: could not open ISCII - it may have been disabled." | tee $@ )
	@echo Finished testing genrb -e option

################################################################### TYP
# TYP FILES

$(TESTOUTDIR)/$(TESTDT)nam.typ: $(TESTBUILDDIR)/$(TESTDT)te_IN.res
	cp $< $@


testdata: packagedata $(ALL_TEST_FILES) $(UNPACKAGEDTESTDATA)

packagetest: testdata icupkg.inc $(TESTBUILDDIR)/testdata.lst 
	$(PKGDATA_INVOKE) $(PKGDATA) -T $(TESTBUILDDIR) -d $(TESTOUTDIR) -s $(TESTBUILDDIR) -p $(TESTDATA) -m common $(TESTBUILDDIR)/testdata.lst

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

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

