summaryrefslogtreecommitdiffabout
path: root/bootstrap
blob: c5d0106e5ebde68b2b5e71ee7bf2b4d9051c188f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
#! /bin/sh
############################
## Configuration
############################

GNULIB_DATE=2007-05-12

MODLIST="argp\
 fprintftime\
 getline\
 gettext\
 malloc\
 memrchr\
 mkdtemp\
 obstack\
 realloc\
 regex\
 save-cwd\
 snprintf\
 strtok_r"

MODAVOID="xalloc-die openat-die"

# Other locale categories that need message catalogs.
EXTRA_LOCALE_CATEGORIES=

NLS_MARKERS="\
 MF_THROW:2\
 MF_ASSERT:3\
 parse_error:1\
 parse_error_locus:2\
 mu_error:1\
 gacopyz_io_log:3\
 gacopyz_logmsg:2\
 gacopyz_log:3"

# Additional xgettext options to use.  Use "\\\newline" to break lines.
XGETTEXT_OPTIONS='\\\
 --flag=_:1:pass-c-format\\\
 --flag=N_:1:pass-c-format\\\
 --flag=error:3:c-format --flag=error_at_line:5:c-format\\\
'

COPYRIGHT_HOLDER="Sergey Poznyakoff"

# Translation Project URL, for the registry of all projects
# and for the translation-team master directory.
# (for future use)
tp_url() {
	echo "http://translationproject.org/domain/$1.html"
}

############################
## Implementation
############################

usage() {
  echo >&2 "\
Usage: $0 [OPTION]...  GNULIB_DIR
Bootstrap this package from the checked-out sources.

 --copy                   Copy files instead of creating symbolic links.
 --force                  Attempt to bootstrap even if the sources seem
                          not to have been checked out.
 --skip-po                Do not download po files.
 --update-po[=LANG]       Update po file(s) and exit.

The only argument specifes the file name of the directory were gnulib
sources are located.  You will have to check out them beforehand, \`bootstrap'
won't do this for you.

Local defaults can be provided by placing the file \`.bootstrap' in the
current working directory.  The file is read, comments and empty lines are
removed, shell variables expanded and the result is prepended to the command
line options. 

Running without arguments will suffice in most cases.
"
}

# Read local configuration file
if [ -r .bootstrap ]; then
  echo "$0: Reading configuration file .bootstrap"
  eval set -- "`sed 's/#.*$//;/^$/d' .bootstrap | tr '\n' ' '` $*"
fi

extract_package_name='
  /^AC_INIT(/{
     /.*,.*,.*,/{
       s///
       s/[][]//g
       p
       q
     }
     s/AC_INIT(\[*//
     s/]*,.*//
     s/^GNU //
     y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/
     s/[^A-Za-z0-9_]/-/g
     p
  }
'
package=`sed -n "$extract_package_name" configure.ac` || exit

# Whether to use copies instead of symlinks.
copy=false

GNULIB_OPTION=
DOWNLOAD_PO=

for option
do
  case $option in
  --help)
    usage
    exit;;
  --skip-po | --no-po) # --no-po is for compatibility with 'tar' tradition.
    DOWNLOAD_PO=skip;;
  --update-po=*)
    DOWNLOAD_PO=`expr "$option" : '--update-po=\(.*\)'`;;
  --update-po)
    DOWNLOAD_PO=only;;
  --copy)
    copy=true;;
  -*)
    echo >&2 "$0: $option: unknown option"
    exit 1;;
  *)
    if [ -n "$NULIB_OPTION" ]; then
       echo "$0: gnulib directory specified twice">&2
       exit 1
    fi
    GNULIB_DIR=$option;;
  esac
done

datecmp() {
  test `echo "1 $1
2 $2" | tr '-' ' ' | sort -n -k2 -k3 -k4 -k1 | sed -n '1s/ .*//p'` -eq 1
}

if [ -n "$GNULIB_DIR" ]; then
  if [ -d "$GNULIB_DIR" ]; then
    PATH="$GNULIB_DIR:$PATH"
    if [ -r "$GNULIB_DIR/ChangeLog" ]; then
      GNULIB_REV=`sed '/^[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}/q' "$GNULIB_DIR/ChangeLog"`
      if datecmp "$GNULIB_DATE" "$GNULIB_REV"; then :;
      else
        echo "$0: Gnulib version is too old: $GNULIB_REV">&2
        echo "$0: It should not be older than $GNULIB_DATE">&2
        echo "$0: Please, update gnulib and retry">&2
	exit
      fi
    else
      echo "$0: No $GNULIB_DIR/ChangeLog file found">&2  
    fi
  else
    echo "$0: specified gnulib location is not a directory">&2
  fi      
else
  echo "$0: warning: gnulib source directory not specified">&2
  echo "$0: warning: looking for gnulib-tool in PATH...">&2
fi

gnulib-tool --version >/dev/null 2>&1 
if [ $? -ne 0 ]; then
  echo "$0: Cannot run gnulib-tool.  Try \`$0 --help' for more info.">&2
  exit 1
fi

echo "$0: Bootstrapping $package"

echo "$0: Running autopoint"
autopoint -f || exit 1

# Create gettext configuration.
echo "$0: Creating po/Makevars from po/Makevars.template ..."
rm -f po/Makevars

if [ -n "$NLS_MARKERS" ]; then 
  XGETTEXT_OPTIONS="$XGETTEXT_OPTIONS "`echo $NLS_MARKERS | tr ' ' '\n' | sed 's/.*/ --flag=&:pass-c-format\\\\\\\\\\\\/'`"
"
fi

sed '
  1i\
# -*- buffer-read-only: t -*- vi: set ro:\
# DO NOT EDIT! GENERATED AUTOMATICALLY!

  /^COPYRIGHT_HOLDER *=/s/=.*/= '"$COPYRIGHT_HOLDER"'/
  /^EXTRA_LOCALE_CATEGORIES *=/s/=.*/= '"$EXTRA_LOCALE_CATEGORIES"'/
  /^MSGID_BUGS_ADDRESS *=/s/=.*/= bug-'"$package"'@gnu.org/
  /^XGETTEXT_OPTIONS *=/{
    s/$/ \\/
    a\
	'"$XGETTEXT_OPTIONS"' $${end_of_xgettext_options+}
  }
' po/Makevars.template >po/Makevars

# Get translations.

get_translations() {
  subdir=$1
  domain=$2
  po_file=$3

  case $WGET_COMMAND in
  '')
    echo "$0: wget not available; skipping translations";;
  ?*)
    url=`tp_url $domain`
    baseurl=`expr "$url" : '\(.*\)/.*'`
    echo "$0: getting translations into $subdir for $domain..." &&
    case $po_file in
    '') (cd $subdir && rm -f dummy `ls | sed -n '/\.gmo$/p; /\.po/p'`);;
    esac &&

    $WGET_COMMAND -O "$subdir/$domain.html" "$url" &&

    sed -n 's|.*href="\(.*\)/\([^/][^/]*\)/'"$domain"'-\([^/"]*\)\.[^."]*\.po".*|\2:\3:\1|p' <"$subdir/$domain.html" |
    sort -t: -k 1,1 -k 2,2n -k2,2 -k3,3n -k3,3 -k4,4n -k4,4 -k5,5n -k5.5 |
    awk -F: '
      { if (lang && $1 != lang) print lang, ver, $3 }
      { lang = $1; ver = $2 }
      END { if (lang) print lang, ver, $3 }
    ' | awk -v domain="$domain" -v baseurl="$baseurl" -v subdir="$subdir" \
            -v po_file="$po_file" '
      {
	lang = $1
        if (po_file && po_file != (lang ".po")) next
	ver = $2
	printf "{ $WGET_COMMAND -O %s/%s.po %s/%s/%s/%s-%s.%s.po &&\n", subdir, lang, baseurl, $3, lang, domain, ver, lang
	printf "  msgfmt -c -o /dev/null %s/%s.po || {\n", subdir, lang
	printf "    echo >&2 '\'"$0"': omitting translation for %s'\''\n", lang
	printf "    rm -f %s/%s.po; }; } &&\n", subdir, lang
      }
      END { print ":" }
    ' | WGET_COMMAND="$WGET_COMMAND" sh 
    ;;
  esac &&
  ls "$subdir"/*.po 2>/dev/null |
    sed 's|.*/||; s|\.po$||' >"$subdir/LINGUAS" &&
  rm -f "$subdir/$domain.html"
}

save_LC_ALL="$LC_ALL"
LC_ALL=C
case `wget --help` in
*'--no-cache'*)
    WGET_COMMAND='wget -nv --no-cache';;
*'--cache=on/off'*)
    WGET_COMMAND='wget -nv --cache=off';;
*'--non-verbose'*)
    WGET_COMMAND='wget -nv';;
*)
    WGET_COMMAND='';;
esac
LC_ALL="$save_LC_ALL"

case $DOWNLOAD_PO in
'skip')
  ;;
'')
  get_translations po $package || exit
  ;;
'only')
  get_translations po $package
  exit
  ;;
*.po)
  get_translations po $package "$DOWNLOAD_PO"
  exit
  ;;
*)
  get_translations po $package "${DOWNLOAD_PO}.po"
  exit
esac

echo "$0: Importing gnulib files ..."
if [ -n "$MODAVOID" ]; then
  gnulib_tool_options="`echo $MODAVOID | sed 's/\([^ ][^ ]*\)/--avoid &/g'`"
fi

gnulib-tool --import $gnulib_tool_options $MODLIST

echo "$0: Reconfiguring ..."

for command in \
  'aclocal --force -I m4' \
  'autoconf --force' \
  'autoheader --force' \
  'automake --add-missing --copy --force-missing';
do
  echo "$0: $command ..."
  $command || exit
done

echo "$0: done.  Now you can run './configure'."

Return to:

Send suggestions and report system problems to the System administrator.