Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb3a0d83

Browse files
committed
Move snowball_create.sql creation into perl file
This is in preparation for building postgres with meson / ninja.We already have duplicated code for this between the make and msvcbuilds. Adding a third copy seems like a bad plan, thus move the generationinto a perl script.As we don't want to rely on perl being available for builds from tarballs,generate the file during distprep.Author: Peter Eisentraut <peter@eisentraut.org>Author: Andres Freund <andres@anarazel.de>Discussion:https://postgr.es/m/5e216522-ba3c-f0e6-7f97-5276d0270029@enterprisedb.com
1 parentdb0a272 commitb3a0d83

File tree

3 files changed

+179
-111
lines changed

3 files changed

+179
-111
lines changed

‎src/backend/snowball/Makefile

Lines changed: 28 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -72,40 +72,22 @@ OBJS += \
7272
stem_UTF_8_turkish.o\
7373
stem_UTF_8_yiddish.o
7474

75-
# first column is language name and also name of dictionary for not-all-ASCII
76-
# words, second is name of dictionary for all-ASCII words
77-
# Note order dependency: use of some other language as ASCII dictionary
78-
# must come after creation of that language
79-
LANGUAGES=\
80-
arabicarabic\
81-
armenianarmenian\
82-
basquebasque\
83-
catalancatalan\
84-
danishdanish\
85-
dutchdutch\
86-
englishenglish\
87-
finnishfinnish\
88-
frenchfrench\
89-
germangerman\
90-
greekgreek\
91-
hindienglish\
92-
hungarianhungarian\
93-
indonesianindonesian\
94-
irishirish\
95-
italianitalian\
96-
lithuanianlithuanian\
97-
nepalinepali\
98-
norwegiannorwegian\
99-
portugueseportuguese\
100-
romanianromanian\
101-
russianenglish\
102-
serbianserbian\
103-
spanishspanish\
104-
swedishswedish\
105-
tamiltamil\
106-
turkishturkish\
107-
yiddishyiddish
108-
75+
stop_files =\
76+
danish.stop\
77+
dutch.stop\
78+
english.stop\
79+
finnish.stop\
80+
french.stop\
81+
german.stop\
82+
hungarian.stop\
83+
italian.stop\
84+
nepali.stop\
85+
norwegian.stop\
86+
portuguese.stop\
87+
russian.stop\
88+
spanish.stop\
89+
swedish.stop\
90+
turkish.stop
10991

11092
SQLSCRIPT= snowball_create.sql
11193
DICTDIR=tsearch_data
@@ -119,56 +101,24 @@ all: all-shared-lib $(SQLSCRIPT)
119101

120102
include$(top_srcdir)/src/Makefile.shlib
121103

122-
$(SQLSCRIPT): Makefile snowball_func.sql.in snowball.sql.in
123-
echo'-- Language-specific snowball dictionaries'>$@
124-
cat$(srcdir)/snowball_func.sql.in>>$@
125-
@set -e;\
126-
set$(LANGUAGES);\
127-
while ["$$#"-gt 0 ]; \
128-
do\
129-
lang=$$1;shift;\
130-
nonascdictname=$$lang;\
131-
ascdictname=$$1;shift;\
132-
if [-s$(srcdir)/stopwords/$${lang}.stop ];then \
133-
stop=", StopWords=$${lang}";\
134-
else\
135-
stop="";\
136-
fi;\
137-
cat$(srcdir)/snowball.sql.in|\
138-
sed -e"s#_LANGNAME_#$$lang#g"|\
139-
sed -e"s#_DICTNAME_#$${lang}_stem#g"|\
140-
sed -e"s#_CFGNAME_#$$lang#g"|\
141-
sed -e"s#_ASCDICTNAME_#$${ascdictname}_stem#g"|\
142-
sed -e"s#_NONASCDICTNAME_#$${nonascdictname}_stem#g"|\
143-
sed -e"s#_STOPWORDS_#$$stop#g";\
144-
done>>$@
104+
$(SQLSCRIPT): snowball_create.pl snowball_func.sql.in snowball.sql.in
105+
$(PERL)$< --input${srcdir} --outdir.
106+
107+
distprep:$(SQLSCRIPT)
145108

146109
install: all installdirs install-lib
147110
$(INSTALL_DATA)$(SQLSCRIPT)'$(DESTDIR)$(datadir)'
148-
@set -e;\
149-
set$(LANGUAGES);\
150-
while ["$$#"-gt 0 ]; \
151-
do\
152-
lang=$$1;shift;shift;\
153-
if [-s$(srcdir)/stopwords/$${lang}.stop ];then \
154-
$(INSTALL_DATA)$(srcdir)/stopwords/$${lang}.stop'$(DESTDIR)$(datadir)/$(DICTDIR)';\
155-
fi\
156-
done
111+
$(INSTALL_DATA)$(addprefix$(srcdir)/stopwords/,$(stop_files))'$(DESTDIR)$(datadir)/$(DICTDIR)'
157112

158113
installdirs: installdirs-lib
159114
$(MKDIR_P)'$(DESTDIR)$(datadir)''$(DESTDIR)$(datadir)/$(DICTDIR)'
160115

161116
uninstall: uninstall-lib
162117
rm -f'$(DESTDIR)$(datadir)/$(SQLSCRIPT)'
163-
@set -e;\
164-
set$(LANGUAGES);\
165-
while ["$$#"-gt 0 ]; \
166-
do\
167-
lang=$$1;shift;shift;\
168-
if [-s$(srcdir)/stopwords/$${lang}.stop ];then \
169-
rm -f'$(DESTDIR)$(datadir)/$(DICTDIR)/'$${lang}.stop;\
170-
fi\
171-
done
172-
173-
cleandistcleanmaintainer-clean: clean-lib
174-
rm -f$(OBJS)$(SQLSCRIPT)
118+
rm -f$(addprefix '$(DESTDIR)$(datadir)/$(DICTDIR)/',$(stop_files))
119+
120+
cleandistclean: clean-lib
121+
rm -f$(OBJS)
122+
123+
maintainer-clean: distclean
124+
rm -f$(SQLSCRIPT)
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
#!/usr/bin/perl
2+
3+
use strict;
4+
use warnings;
5+
use Getopt::Long;
6+
7+
my$outdir_path ='';
8+
my$makefile_path ='';
9+
my$input_path ='';
10+
my$depfile;
11+
12+
our@languages =qw(
13+
arabic
14+
armenian
15+
basque
16+
catalan
17+
danish
18+
dutch
19+
english
20+
finnish
21+
french
22+
german
23+
greek
24+
hindi
25+
hungarian
26+
indonesian
27+
irish
28+
italian
29+
lithuanian
30+
nepali
31+
norwegian
32+
portuguese
33+
romanian
34+
russian
35+
serbian
36+
spanish
37+
swedish
38+
tamil
39+
turkish
40+
yiddish
41+
);
42+
43+
# Names of alternative dictionaries for all-ASCII words. If not
44+
# listed, the language itself is used. Note order dependency: Use of
45+
# some other language as ASCII dictionary must come after creation of
46+
# that language, so the "backup" language must be listed earlier in
47+
# @languages.
48+
49+
our%ascii_languages = (
50+
'hindi'=>'english',
51+
'russian'=>'english',
52+
);
53+
54+
GetOptions(
55+
'depfile'=> \$depfile,
56+
'outdir:s'=> \$outdir_path,
57+
'input:s'=> \$input_path) || usage();
58+
59+
# Make sure input_path ends in a slash if needed.
60+
if ($input_pathne'' &&substr($input_path, -1)ne'/')
61+
{
62+
$outdir_path .='/';
63+
}
64+
65+
# Make sure outdir_path ends in a slash if needed.
66+
if ($outdir_pathne'' &&substr($outdir_path, -1)ne'/')
67+
{
68+
$outdir_path .='/';
69+
}
70+
71+
GenerateTsearchFiles();
72+
73+
subusage
74+
{
75+
die<<EOM;
76+
Usage: snowball_create.pl --input/-i <path> --outdir/-o <path>
77+
--depfile Write dependency file
78+
--outdir Output directory (default '.')
79+
--input Input directory
80+
81+
snowball_create.pl creates snowball.sql from snowball.sql.in
82+
EOM
83+
}
84+
85+
subGenerateTsearchFiles
86+
{
87+
my$target =shift;
88+
my$outdir_file ="$outdir_path/snowball_create.sql";
89+
90+
my$F;
91+
my$D;
92+
my$tmpl = read_file("$input_path/snowball.sql.in");
93+
94+
if ($depfile)
95+
{
96+
open($D,'>',"$outdir_path/snowball_create.dep")
97+
||die"Could not write snowball_create.dep";
98+
}
99+
100+
print$D"$outdir_file:$input_path/snowball.sql.in\n"if$depfile;
101+
print$D"$outdir_file:$input_path/snowball_func.sql.in\n"if$depfile;
102+
103+
open($F,'>',$outdir_file)
104+
||die"Could not write snowball_create.sql";
105+
106+
print$F"-- Language-specific snowball dictionaries\n";
107+
108+
print$F read_file("$input_path/snowball_func.sql.in");
109+
110+
foreachmy$lang (@languages)
111+
{
112+
my$asclang =$ascii_languages{$lang} ||$lang;
113+
my$txt =$tmpl;
114+
my$stop ='';
115+
my$stopword_path ="$input_path/stopwords/$lang.stop";
116+
117+
if (-s"$stopword_path")
118+
{
119+
$stop =", StopWords=$lang";
120+
121+
print$D"$outdir_file:$stopword_path\n"if$depfile;
122+
}
123+
124+
$txt =~s#_LANGNAME_#${lang}#gs;
125+
$txt =~s#_DICTNAME_#${lang}_stem#gs;
126+
$txt =~s#_CFGNAME_#${lang}#gs;
127+
$txt =~s#_ASCDICTNAME_#${asclang}_stem#gs;
128+
$txt =~s#_NONASCDICTNAME_#${lang}_stem#gs;
129+
$txt =~s#_STOPWORDS_#$stop#gs;
130+
print$F$txt;
131+
}
132+
close($F);
133+
close($D)if$depfile;
134+
return;
135+
}
136+
137+
138+
subread_file
139+
{
140+
my$filename =shift;
141+
my$F;
142+
local$/ =undef;
143+
open($F,'<',$filename) ||die"Could not open file$filename\n";
144+
my$txt = <$F>;
145+
close($F);
146+
147+
return$txt;
148+
}

‎src/tools/msvc/Install.pm

Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -389,39 +389,9 @@ sub GenerateTsearchFiles
389389
my$target =shift;
390390

391391
print"Generating tsearch script...";
392-
my$F;
393-
my$tmpl = read_file('src/backend/snowball/snowball.sql.in');
394-
my$mf = read_file('src/backend/snowball/Makefile');
395-
$mf =~s{\\\r?\n}{}g;
396-
$mf =~/^LANGUAGES\s*=\s*(.*)$/m
397-
||die"Could not find LANGUAGES line in snowball Makefile\n";
398-
my@pieces =split /\s+/,$1;
399-
open($F,'>',"$target/share/snowball_create.sql")
400-
||die"Could not write snowball_create.sql";
401-
print$F read_file('src/backend/snowball/snowball_func.sql.in');
402-
403-
while ($#pieces > 0)
404-
{
405-
my$lang =shift@pieces ||last;
406-
my$asclang =shift@pieces ||last;
407-
my$txt =$tmpl;
408-
my$stop ='';
409-
410-
if (-s"src/backend/snowball/stopwords/$lang.stop")
411-
{
412-
$stop =", StopWords=$lang";
413-
}
414-
415-
$txt =~s#_LANGNAME_#${lang}#gs;
416-
$txt =~s#_DICTNAME_#${lang}_stem#gs;
417-
$txt =~s#_CFGNAME_#${lang}#gs;
418-
$txt =~s#_ASCDICTNAME_#${asclang}_stem#gs;
419-
$txt =~s#_NONASCDICTNAME_#${lang}_stem#gs;
420-
$txt =~s#_STOPWORDS_#$stop#gs;
421-
print$F$txt;
422-
print".";
423-
}
424-
close($F);
392+
system('perl','src/backend/snowball/snowball_create.pl',
393+
'--input','src/backend/snowball/',
394+
'--outdir',"$target/share/");
425395
print"\n";
426396
return;
427397
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp