Skip to content

Commit e752727

Browse files
committed
Make Unicode makefile parallel-safe
Fix the rules so that each rule is parallel safe, using the same trickery that we use elsewhere in the tree for rules that produce more than one output file. Refactor the whole makefile so that there is less repetition. Discussion: https://www.postgresql.org/message-id/18e34084-aab1-1b4c-edd1-c4f9fb04f714%40enterprisedb.com
1 parent 36d1a84 commit e752727

File tree

1 file changed

+45
-89
lines changed

1 file changed

+45
-89
lines changed

src/backend/utils/mb/Unicode/Makefile

Lines changed: 45 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -12,101 +12,57 @@ subdir = src/backend/utils/mb/Unicode
1212
top_builddir = ../../../../..
1313
include $(top_builddir)/src/Makefile.global
1414

15-
ISO8859MAPS = iso8859_2_to_utf8.map utf8_to_iso8859_2.map \
16-
iso8859_3_to_utf8.map utf8_to_iso8859_3.map \
17-
iso8859_4_to_utf8.map utf8_to_iso8859_4.map \
18-
iso8859_5_to_utf8.map utf8_to_iso8859_5.map \
19-
iso8859_6_to_utf8.map utf8_to_iso8859_6.map \
20-
iso8859_7_to_utf8.map utf8_to_iso8859_7.map \
21-
iso8859_8_to_utf8.map utf8_to_iso8859_8.map \
22-
iso8859_9_to_utf8.map utf8_to_iso8859_9.map \
23-
iso8859_10_to_utf8.map utf8_to_iso8859_10.map \
24-
iso8859_13_to_utf8.map utf8_to_iso8859_13.map \
25-
iso8859_14_to_utf8.map utf8_to_iso8859_14.map \
26-
iso8859_15_to_utf8.map utf8_to_iso8859_15.map \
27-
iso8859_16_to_utf8.map utf8_to_iso8859_16.map
28-
29-
WINMAPS = win866_to_utf8.map utf8_to_win866.map \
30-
win874_to_utf8.map utf8_to_win874.map \
31-
win1250_to_utf8.map utf8_to_win1250.map \
32-
win1251_to_utf8.map utf8_to_win1251.map \
33-
win1252_to_utf8.map utf8_to_win1252.map \
34-
win1253_to_utf8.map utf8_to_win1253.map \
35-
win1254_to_utf8.map utf8_to_win1254.map \
36-
win1255_to_utf8.map utf8_to_win1255.map \
37-
win1256_to_utf8.map utf8_to_win1256.map \
38-
win1257_to_utf8.map utf8_to_win1257.map \
39-
win1258_to_utf8.map utf8_to_win1258.map
40-
41-
GENERICMAPS = $(ISO8859MAPS) $(WINMAPS) \
42-
gbk_to_utf8.map utf8_to_gbk.map \
43-
koi8r_to_utf8.map utf8_to_koi8r.map \
44-
koi8u_to_utf8.map utf8_to_koi8u.map
45-
46-
SPECIALMAPS = euc_cn_to_utf8.map utf8_to_euc_cn.map \
47-
euc_jp_to_utf8.map utf8_to_euc_jp.map \
48-
euc_kr_to_utf8.map utf8_to_euc_kr.map \
49-
euc_tw_to_utf8.map utf8_to_euc_tw.map \
50-
sjis_to_utf8.map utf8_to_sjis.map \
51-
gb18030_to_utf8.map utf8_to_gb18030.map \
52-
big5_to_utf8.map utf8_to_big5.map \
53-
johab_to_utf8.map utf8_to_johab.map \
54-
uhc_to_utf8.map utf8_to_uhc.map \
55-
euc_jis_2004_to_utf8.map utf8_to_euc_jis_2004.map \
56-
shift_jis_2004_to_utf8.map utf8_to_shift_jis_2004.map
57-
58-
MAPS = $(GENERICMAPS) $(SPECIALMAPS)
59-
60-
ISO8859TEXTS = 8859-2.TXT 8859-3.TXT 8859-4.TXT 8859-5.TXT \
61-
8859-6.TXT 8859-7.TXT 8859-8.TXT 8859-9.TXT \
62-
8859-10.TXT 8859-13.TXT 8859-14.TXT 8859-15.TXT \
63-
8859-16.TXT
64-
65-
WINTEXTS = CP866.TXT CP874.TXT CP936.TXT \
66-
CP1250.TXT CP1251.TXT \
67-
CP1252.TXT CP1253.TXT CP1254.TXT CP1255.TXT \
68-
CP1256.TXT CP1257.TXT CP1258.TXT
69-
70-
GENERICTEXTS = $(ISO8859TEXTS) $(WINTEXTS) \
71-
KOI8-R.TXT KOI8-U.TXT
7215

73-
all: $(MAPS)
74-
75-
$(GENERICMAPS): UCS_to_most.pl $(GENERICTEXTS)
76-
$(PERL) -I $(srcdir) $<
77-
78-
johab_to_utf8.map utf8_to_johab.map: UCS_to_JOHAB.pl JOHAB.TXT
79-
$(PERL) -I $(srcdir) $<
80-
81-
uhc_to_utf8.map utf8_to_uhc.map: UCS_to_UHC.pl windows-949-2000.xml
82-
$(PERL) -I $(srcdir) $<
83-
84-
euc_jp_to_utf8.map utf8_to_euc_jp.map: UCS_to_EUC_JP.pl CP932.TXT JIS0212.TXT
85-
$(PERL) -I $(srcdir) $<
16+
# Define a rule to create the map files from downloaded text input
17+
# files using a script. Arguments:
18+
#
19+
# 1: encoding name used in output files (lower case)
20+
# 2: script name
21+
# 3: input text files
22+
# 4: argument to pass to script (optional)
23+
#
24+
# We also collect all the input and output files in variables to
25+
# define the build and clean rules below.
26+
#
27+
# Note that while each script call produces two output files, to be
28+
# parallel-make safe we need to split this into two rules. (See for
29+
# example gram.y for more explanation.)
30+
#
31+
define map_rule
32+
MAPS += $(1)_to_utf8.map utf8_to_$(1).map
33+
ALL_TEXTS += $(3)
8634

87-
euc_cn_to_utf8.map utf8_to_euc_cn.map: UCS_to_EUC_CN.pl gb-18030-2000.xml
88-
$(PERL) -I $(srcdir) $<
35+
$(1)_to_utf8.map: $(2) $(3)
36+
$(PERL) -I $$(srcdir) $$< $(4)
8937

90-
euc_kr_to_utf8.map utf8_to_euc_kr.map: UCS_to_EUC_KR.pl KSX1001.TXT
91-
$(PERL) -I $(srcdir) $<
38+
utf8_to_$(1).map: $(1)_to_utf8.map
39+
@touch $$@
40+
endef
9241

93-
euc_tw_to_utf8.map utf8_to_euc_tw.map: UCS_to_EUC_TW.pl CNS11643.TXT
94-
$(PERL) -I $(srcdir) $<
42+
$(foreach n,2 3 4 5 6 7 8 9 10 13 14 15 16,$(eval $(call map_rule,iso8859_$(n),UCS_to_most.pl,8859-$(n).TXT,ISO8859_$(n))))
9543

96-
sjis_to_utf8.map utf8_to_sjis.map: UCS_to_SJIS.pl CP932.TXT
97-
$(PERL) -I $(srcdir) $<
44+
$(foreach n,866 874 1250 1251 1252 1253 1254 1255 1256 1257 1258,$(eval $(call map_rule,win$(n),UCS_to_most.pl,CP$(n).TXT,WIN$(n))))
9845

99-
gb18030_to_utf8.map utf8_to_gb18030.map: UCS_to_GB18030.pl gb-18030-2000.xml
100-
$(PERL) -I $(srcdir) $<
46+
$(eval $(call map_rule,koi8r,UCS_to_most.pl,KOI8-R.TXT,KOI8R))
47+
$(eval $(call map_rule,koi8u,UCS_to_most.pl,KOI8-U.TXT,KOI8U))
48+
$(eval $(call map_rule,gbk,UCS_to_most.pl,CP936.TXT,GBK))
10149

102-
big5_to_utf8.map utf8_to_big5.map: UCS_to_BIG5.pl BIG5.TXT CP950.TXT
103-
$(PERL) -I $(srcdir) $<
50+
$(eval $(call map_rule,johab,UCS_to_JOHAB.pl,JOHAB.TXT))
51+
$(eval $(call map_rule,uhc,UCS_to_UHC.pl,windows-949-2000.xml))
52+
$(eval $(call map_rule,euc_jp,UCS_to_EUC_JP.pl,CP932.TXT JIS0212.TXT))
53+
$(eval $(call map_rule,euc_cn,UCS_to_EUC_CN.pl,gb-18030-2000.xml))
54+
$(eval $(call map_rule,euc_kr,UCS_to_EUC_KR.pl,KSX1001.TXT))
55+
$(eval $(call map_rule,euc_tw,UCS_to_EUC_TW.pl,CNS11643.TXT))
56+
$(eval $(call map_rule,sjis,UCS_to_SJIS.pl,CP932.TXT))
57+
$(eval $(call map_rule,gb18030,UCS_to_GB18030.pl,gb-18030-2000.xml))
58+
$(eval $(call map_rule,big5,UCS_to_BIG5.pl,CP950.TXT BIG5.TXT CP950.TXT))
59+
$(eval $(call map_rule,euc_jis_2004,UCS_to_EUC_JIS_2004.pl,euc-jis-2004-std.txt))
60+
$(eval $(call map_rule,shift_jis_2004,UCS_to_SHIFT_JIS_2004.pl,sjis-0213-2004-std.txt))
10461

105-
euc_jis_2004_to_utf8.map utf8_to_euc_jis_2004.map: UCS_to_EUC_JIS_2004.pl euc-jis-2004-std.txt
106-
$(PERL) -I $(srcdir) $<
62+
# remove duplicates
63+
TEXTS = $(sort $(ALL_TEXTS))
10764

108-
shift_jis_2004_to_utf8.map utf8_to_shift_jis_2004.map: UCS_to_SHIFT_JIS_2004.pl sjis-0213-2004-std.txt
109-
$(PERL) -I $(srcdir) $<
65+
all: $(MAPS)
11066

11167
distclean: clean
11268
rm -f $(TEXTS)
@@ -136,11 +92,11 @@ JOHAB.TXT KSX1001.TXT:
13692
KOI8-R.TXT KOI8-U.TXT:
13793
$(DOWNLOAD) https://www.unicode.org/Public/MAPPINGS/VENDORS/MISC/$(@F)
13894

139-
$(ISO8859TEXTS):
95+
$(filter 8859-%.TXT,$(TEXTS)):
14096
$(DOWNLOAD) https://www.unicode.org/Public/MAPPINGS/ISO8859/$(@F)
14197

142-
$(filter-out CP8%,$(WINTEXTS)) CP932.TXT CP950.TXT:
98+
$(filter CP9%.TXT CP12%.TXT,$(TEXTS)):
14399
$(DOWNLOAD) https://www.unicode.org/Public/MAPPINGS/VENDORS/MICSFT/WINDOWS/$(@F)
144100

145-
$(filter CP8%,$(WINTEXTS)):
101+
$(filter CP8%.TXT,$(TEXTS)):
146102
$(DOWNLOAD) https://www.unicode.org/Public/MAPPINGS/VENDORS/MICSFT/PC/$(@F)

0 commit comments

Comments
 (0)