xref: /freebsd/tools/tools/locale/Makefile (revision c5dee76368499b08f04ad55176170217a499541e)
1# See https://wiki.freebsd.org/LocaleNewApproach
2# Taken from FreeBSD svn [base]/user/edwin/locale/cldr
3#
4# needs:
5# devel/p5-Tie-IxHash
6#
7# Modified by John Marino to suit DragonFly needs
8#
9
10CLDRVERSION=	45.0
11UCDVERSION=	15.0.0
12
13.if ${.CURDIR} == ${.OBJDIR}
14.error Do make obj first.
15.endif
16
17LOCALESRCDIR?=	${SRCTOP}/share
18TMPDIR?=	/tmp
19
20BASEDIR=	${.CURDIR}
21ETCDIR=		${BASEDIR}/etc
22TOOLSDIR=	${BASEDIR}/tools
23PATCHDIR=	${BASEDIR}/patch
24UNIDIR=		${.OBJDIR:tA}/unicode
25
26PKGS=	openjdk11 p5-XML-Parser p5-Tie-IxHash p5-Text-Iconv utf8proc
27tools-test:
28	@pkg info -e ${PKGS} || ( echo required packages: ${PKGS}; exit 1 )
29
30KNOWN=		monetdef numericdef msgdef colldef ctypedef # timedef
31TYPES?=		${KNOWN}
32
33SETENV=	env -i \
34	PATH="${PATH}" \
35	TMPDIR="${TMPDIR}" \
36	UNIDIR="${UNIDIR}" \
37	BASEDIR="${BASEDIR}" \
38	TOOLSDIR="${TOOLSDIR}" \
39	ETCDIR="${ETCDIR}"
40
41all: tools-test posix build afterbuild widths
42.ORDER: tools-test posix build afterbuild widths
43
44afterbuild: build
45	@echo ""
46	@find . -name *failed
47
48.for t in ${TYPES}
49.  if ${KNOWN:M${t}}
50build: build-${t}
51.ORDER: build-${t} afterbuild
52.  endif
53.endfor
54
55diff:
56.for t in ${TYPES}
57.  if ${KNOWN:M${t}}
58diff: diff-${t}
59diff-${t}:
60	-/usr/bin/diff -ruN -x Makefile -x Makefile.depend \
61	    ${LOCALESRCDIR}/${t} ${t}
62.  endif
63.endfor
64
65install:
66.for t in ${TYPES:Nctypedef}
67.  if ${KNOWN:M${t}}
68install: install-${t}
69install-${t}:
70	cd ${LOCALESRCDIR}/${t}_unicode && \
71	    rm -f Makefile *.src && \
72	    cd ${.OBJDIR} && \
73	    install -m 644 ${t}/* ${LOCALESRCDIR}/${t}_unicode
74.  endif
75.endfor
76install: install-ctypedef
77install-ctypedef:
78	cd ${LOCALESRCDIR}/ctypedef && \
79		rm -f C.UTF-8.src && \
80		cd ${.OBJDIR} && \
81		install -m 644 ctypedef/C.UTF-8.src ${LOCALESRCDIR}/ctypedef
82
83post-install:
84.for t in ${TYPES}
85.  if ${KNOWN:M${t}}
86	cd ${LOCALSRCDIR}/${t} && \
87	    make && make install && make clean
88.  endif
89.endfor
90
91.for t in ${TYPES}
92CLEANDIRS+=	${t} ${t}.draft
93${t}:
94	mkdir -p ${t} ${t}.draft && \
95	perl -I ${TOOLSDIR} ${TOOLSDIR}/cldr2def.pl \
96		--unidir=${UNIDIR:tA} \
97		--etc=${ETCDIR:tA} \
98		--type=${t}
99
100build-${t}: ${t}
101	${SETENV} OUTBASEDIR="${.OBJDIR}/${t}" ${TOOLSDIR}/finalize ${t}
102.endfor
103
104BASE_LOCALES_OF_INTEREST?= \
105	af_ZA am_ET ar_AE ar_EG ar_JO ar_MA ar_QA ar_SA \
106	be_BY bg_BG ca_AD ca_ES ca_FR ca_IT \
107	cs_CZ da_DK de_AT de_CH de_DE el_GR en_AU en_CA \
108	en_GB en_HK en_IE en_NZ en_PH en_SG en_US en_ZA \
109	es_AR es_CR es_ES es_MX et_EE eu_ES fa_AF fa_IR fi_FI fr_BE \
110	fr_CA fr_CH fr_FR ga_IE he_IL hi_IN hr_HR hu_HU hy_AM \
111	is_IS it_CH it_IT ja_JP ko_KR lt_LT lv_LV \
112	nb_NO nl_BE nl_NL nn_NO pl_PL pt_BR pt_PT ro_RO \
113	ru_RU se_FI se_NO sk_SK sl_SI sv_FI sv_SE tr_TR \
114	uk_UA \
115	kk_KZ mn_MN sr_Cyrl_RS sr_Latn_RS \
116	zh_Hans_CN zh_Hant_HK zh_Hant_TW \
117	bn_IN gu_IN or_IN ta_IN te_IN kn_IN ml_IN si_LK \
118	th_TH lo_LA bo_IN my_MM pa_Guru_IN ka_GE chr_US \
119	km_KH shi_Tfng_MA ii_CN vai_Vaii_LR vi_VN
120
121ENCODINGS=	UTF-8 \
122		UTF-32
123
124# CLDR files
125CLDRFILES_CORE= https://unicode.org/Public/cldr/${CLDRVERSION:R}/core.zip
126CLDRFILES_KEY=	https://unicode.org/Public/cldr/${CLDRVERSION:R}/cldr-keyboards-${CLDRVERSION}.zip
127CLDRFILES_TOOLS=https://unicode.org/Public/cldr/${CLDRVERSION:R}/cldr-tools-${CLDRVERSION}.jar
128CLDRFILES_UCD=	https://www.unicode.org/Public/zipped/${UCDVERSION}/UCD.zip
129
130# fetch and extract targets
131${UNIDIR}:
132	mkdir -p ${UNIDIR}
133.for N in CORE KEY TOOLS UCD
134${CLDRFILES_${N}:T}:
135	fetch ${CLDRFILES_${N}}
136fetch: ${CLDRFILES_${N}:T}
137extract-${CLDRFILES_${N}:T}:: ${CLDRFILES_${N}:T} ${UNIDIR}
138	cd ${UNIDIR} && unzip -o ../${CLDRFILES_${N}:T}
139extract: extract-${CLDRFILES_${N}:T}
140.endfor
141	echo ${CLDRVERSION} > ${UNIDIR}/cldr-version
142	mkdir -p ${UNIDIR}/seed/main
143patch::
144.if exists(${PATCHDIR})
145	cd ${UNIDIR} && cat ${PATCHDIR}/patch-* | patch
146.endif
147
148JAVA_CLDR= java -DCLDR_DIR=${UNIDIR:Q} -jar ${.OBJDIR:tA}/${CLDRFILES_TOOLS:T}
149
150posix: posixcm post-posixcm posixsrc
151.ORDER: posixcm post-posixcm posixsrc
152${UNIDIR}/posix: ${UNIDIR}
153	ln -s -f ../posix ${.TARGET}
154clean-posix:
155	rm -rf posix ${UNIDIR}/posix
156${UNIDIR}/posix/xx_Comm_C.UTF-8.src: ${UNIDIR}/posix
157	perl -I ${TOOLSDIR} ${TOOLSDIR}/utf8-rollup.pl \
158	    --unidir=${UNIDIR}
159post-posixcm: ${UNIDIR}/posix/xx_Comm_C.UTF-8.src
160.for enc in ${ENCODINGS}
161posixcm: posix/${enc}.cm
162.ORDER: posix/${enc}.cm
163posix/${enc}.cm:
164	mkdir -p posix && \
165	    ${JAVA_CLDR} org.unicode.cldr.posix.GenerateCharmap \
166		-d posix -c ${enc}
167.endfor
168.for area in ${BASE_LOCALES_OF_INTEREST}
169posixsrc: posix/${area}.UTF-8.src
170.ORDER: posix/${area}.UTF-8.src
171posix/${area}.UTF-8.src:
172	mkdir -p posix && \
173	    ${JAVA_CLDR} org.unicode.cldr.posix.GeneratePOSIX \
174		-d posix -m ${area} -c UTF-8
175.endfor
176
177# generate widths.txt using the data from libut8proc
178GETWIDTHS=${TOOLSDIR}/getwidths
179MKWIDTHS=${TOOLSDIR}/mkwidths.pl
180WIDTHS=	${ETCDIR}/final-maps/widths.txt
181
182U8CFLAGS!=pkgconf --cflags libutf8proc
183U8LIBS!=pkgconf --libs libutf8proc
184CFLAGS+=${U8CFLAGS}
185LDFLAGS+=${U8LIBS}
186
187CLEANFILES+=${TOOLSDIR}/getwidths
188
189widths:	${WIDTHS}
190${WIDTHS}: posixcm ${GETWIDTHS}
191	${GETWIDTHS} | ${MKWIDTHS} ${.OBJDIR}/posix/UTF-8.cm ${.TARGET}
192
193.include <bsd.obj.mk>
194