… | |
… | |
2 | |
2 | |
3 | ############################################################################# |
3 | ############################################################################# |
4 | # configuration to fill in |
4 | # configuration to fill in |
5 | |
5 | |
6 | STATICPERL=~/.staticperl |
6 | STATICPERL=~/.staticperl |
7 | CPAN=http://mirror.netcologne.de/cpan/ # which mirror to use |
7 | CPAN=http://mirror.netcologne.de/cpan # which mirror to use |
8 | EMAIL="read the documentation <rtfm@example.org>" |
8 | EMAIL="read the documentation <rtfm@example.org>" |
9 | |
9 | |
10 | MKBUNDLE="$STATICPERL/mkbundle" |
|
|
11 | |
|
|
12 | # perl build variables |
10 | # perl build variables |
13 | PERL_PREFIX="$STATICPERL/perl" # where the perl gets installed |
11 | MAKE=make |
14 | PERL_VERSION=5.12.2 # 5.8.9 is also a good choice |
12 | PERL_VERSION=5.12.2 # 5.8.9 is also a good choice |
|
|
13 | PERL_CC=cc |
15 | PERL_CONFIGURE="" # additional Configure arguments |
14 | PERL_CONFIGURE="" # additional Configure arguments |
16 | PERL_CPPFLAGS="-DPERL_DISABLE_PMC -DPERL_ARENA_SIZE=65536 -D_GNU_SOURCE -DNDEBUG -USITELIB_EXP -USITEARCHEXP -UARCHLIB_EXP" |
15 | PERL_CPPFLAGS="-DPERL_DISABLE_PMC -DPERL_ARENA_SIZE=65536 -D_GNU_SOURCE -DNDEBUG -USITELIB_EXP -USITEARCHEXP -UARCHLIB_EXP" |
17 | PERL_OPTIMIZE="-Os -ffunction-sections -fdata-sections -finline-limit=8 -ffast-math" |
16 | PERL_OPTIMIZE="-Os -ffunction-sections -fdata-sections -finline-limit=8 -ffast-math" |
18 | |
17 | |
19 | ARCH="$(uname -m)" |
18 | ARCH="$(uname -m)" |
20 | |
19 | |
21 | case "$ARCH" in |
20 | case "$ARCH" in |
22 | i*86 | x86_64 | amd64 ) |
21 | i*86 | x86_64 | amd64 ) |
23 | PERL_OPTIMIZE="$PERL_OPTIMIZE -mpush-args -mno-inline-stringops-dynamically -mno-align-stringops -mno-ieee-fp" # x86/amd64 |
22 | #PERL_OPTIMIZE="$PERL_OPTIMIZE -mpush-args -mno-inline-stringops-dynamically -mno-align-stringops -mno-ieee-fp" # x86/amd64 |
|
|
23 | PERL_OPTIMIZE="$PERL_OPTIMIZE" # x86/amd64 |
24 | case "$ARCH" in |
24 | case "$ARCH" in |
25 | i*86 ) |
25 | i*86 ) |
26 | PERL_OPTIMIZE="$PERL_OPTIMIZE -fomit-frame-pointer -march=pentium3 -mtune=i386" # x86 only |
26 | PERL_OPTIMIZE="$PERL_OPTIMIZE -fomit-frame-pointer -march=pentium3 -mtune=i386" # x86 only |
27 | ;; |
27 | ;; |
28 | esac |
28 | esac |
29 | ;; |
29 | ;; |
30 | esac |
30 | esac |
31 | |
31 | |
32 | # -Wl,--gc-sections makes it impossible to check for undefined references |
32 | # -Wl,--gc-sections makes it impossible to check for undefined references |
33 | # for some reason so we need to patch away the "-no" after Configure and before make :/ |
33 | # for some reason so we need to patch away the "-no" after Configure and before make :/ |
34 | # -z muldefs is to work around uclibc's pthread static linking bug |
34 | # --allow-multiple-definition exists to work around uclibc's pthread static linking bug |
35 | PERL_LDFLAGS="-Wl,--no-gc-sections -z muldefs" |
35 | PERL_LDFLAGS="-Wl,--no-gc-sections -Wl,--allow-multiple-definition" |
36 | PERL_LIBS="-lm -lcrypt" # perl loves to add lotsa crap itself |
36 | PERL_LIBS="-lm -lcrypt" # perl loves to add lotsa crap itself |
37 | |
37 | |
38 | # some configuration options for modules |
38 | # some configuration options for modules |
39 | export PERL_MM_USE_DEFAULT=1 |
39 | export PERL_MM_USE_DEFAULT=1 |
40 | #export CORO_INTERFACE=p # needed without nptl on x86, due to bugs in linuxthreads - very slow |
40 | #export CORO_INTERFACE=p # needed without nptl on x86, due to bugs in linuxthreads - very slow |
… | |
… | |
52 | postconfigure() { : ; } |
52 | postconfigure() { : ; } |
53 | postbuild() { : ; } |
53 | postbuild() { : ; } |
54 | postinstall() { : ; } |
54 | postinstall() { : ; } |
55 | |
55 | |
56 | # now source user config, if any |
56 | # now source user config, if any |
|
|
57 | if [ "$STATICPERLRC" ]; then |
|
|
58 | . "$STATICPERLRC" |
|
|
59 | else |
57 | [ -r /etc/staticperlrc ] && . /etc/staticperlrc |
60 | [ -r /etc/staticperlrc ] && . /etc/staticperlrc |
58 | [ -r ~/.staticperlrc ] && . ~/.staticperlrc |
61 | [ -r ~/.staticperlrc ] && . ~/.staticperlrc |
59 | [ -r "$STATICPERL/rc" ] && . "$STATICPERL/rc" |
62 | [ -r "$STATICPERL/rc" ] && . "$STATICPERL/rc" |
|
|
63 | fi |
60 | |
64 | |
61 | ############################################################################# |
65 | ############################################################################# |
62 | # support |
66 | # support |
|
|
67 | |
|
|
68 | MKBUNDLE="${MKBUNDLE:=$STATICPERL/mkbundle}" |
|
|
69 | PERL_PREFIX="${PERL_PREFIX:=$STATICPERL/perl}" # where the perl gets installed |
|
|
70 | |
|
|
71 | unset PERL5OPT PERL5LIB PERLLIB PERL_UNICODE PERLIO_DEBUG |
|
|
72 | export LC_ALL=C # just to be on the safe side |
63 | |
73 | |
64 | # set version in a way that Makefile.PL can extract |
74 | # set version in a way that Makefile.PL can extract |
65 | VERSION=VERSION; eval \ |
75 | VERSION=VERSION; eval \ |
66 | $VERSION=0.1 |
76 | $VERSION=0.911 |
67 | |
77 | |
68 | BZ2=bz2 |
78 | BZ2=bz2 |
69 | BZIP2=bzip2 |
79 | BZIP2=bzip2 |
70 | |
80 | |
71 | fatal() { |
81 | fatal() { |
… | |
… | |
104 | ############################################################################# |
114 | ############################################################################# |
105 | # clean |
115 | # clean |
106 | |
116 | |
107 | distclean() { |
117 | distclean() { |
108 | verblock <<EOF |
118 | verblock <<EOF |
109 | deleting everything installed by this script |
119 | deleting everything installed by this script (rm -rf $STATICPERL) |
110 | EOF |
120 | EOF |
111 | |
121 | |
112 | rm -rf "$STATICPERL" |
122 | rm -rf "$STATICPERL" |
113 | } |
123 | } |
114 | |
124 | |
… | |
… | |
139 | |
149 | |
140 | rm -f perl-$PERL_VERSION.tar.$BZ2~ # just to be on the safe side |
150 | rm -f perl-$PERL_VERSION.tar.$BZ2~ # just to be on the safe side |
141 | wget -O perl-$PERL_VERSION.tar.$BZ2~ "$URL" \ |
151 | wget -O perl-$PERL_VERSION.tar.$BZ2~ "$URL" \ |
142 | || curl >perl-$PERL_VERSION.tar.$BZ2~ "$URL" \ |
152 | || curl >perl-$PERL_VERSION.tar.$BZ2~ "$URL" \ |
143 | || fatal "$URL: unable to download" |
153 | || fatal "$URL: unable to download" |
|
|
154 | rm -f perl-$PERL_VERSION.tar.$BZ2 |
144 | mv perl-$PERL_VERSION.tar.$BZ2~ perl-$PERL_VERSION.tar.$BZ2 |
155 | mv perl-$PERL_VERSION.tar.$BZ2~ perl-$PERL_VERSION.tar.$BZ2 |
145 | fi |
156 | fi |
146 | |
157 | |
147 | verblock <<EOF |
158 | verblock <<EOF |
148 | unpacking perl |
159 | unpacking perl |
149 | EOF |
160 | EOF |
150 | |
161 | |
151 | mkdir -p unpack |
162 | mkdir -p unpack |
|
|
163 | rm -rf unpack/perl-$PERL_VERSION |
152 | $BZIP2 -d <perl-$PERL_VERSION.tar.bz2 | tar xC unpack \ |
164 | $BZIP2 -d <perl-$PERL_VERSION.tar.bz2 | tar xfC - unpack \ |
153 | || fatal "perl-$PERL_VERSION.tar.bz2: error during unpacking" |
165 | || fatal "perl-$PERL_VERSION.tar.bz2: error during unpacking" |
154 | chmod -R u+w unpack/perl-$PERL_VERSION |
166 | chmod -R u+w unpack/perl-$PERL_VERSION |
155 | mv unpack/perl-$PERL_VERSION perl-$PERL_VERSION |
167 | mv unpack/perl-$PERL_VERSION perl-$PERL_VERSION |
156 | rmdir -p unpack |
168 | rmdir -p unpack |
157 | fi |
169 | fi |
158 | } |
170 | } |
159 | |
171 | |
160 | # similar to GNU-sed -i or perl -pi |
172 | # similar to GNU-sed -i or perl -pi |
161 | sedreplace() { |
173 | sedreplace() { |
162 | sed -e "$1" <"$2" > "$2~" || fatal "error while running sed" |
174 | sed -e "$1" <"$2" > "$2~" || fatal "error while running sed" |
|
|
175 | rm -f "$2" |
163 | mv "$2~" "$2" |
176 | mv "$2~" "$2" |
164 | } |
177 | } |
165 | |
178 | |
166 | configure() { |
179 | configure() { |
167 | fetch |
180 | fetch |
… | |
… | |
174 | configuring $STATICPERL/src/perl-$PERL_VERSION |
187 | configuring $STATICPERL/src/perl-$PERL_VERSION |
175 | EOF |
188 | EOF |
176 | |
189 | |
177 | rm -f "$PERL_PREFIX/staticstamp.install" |
190 | rm -f "$PERL_PREFIX/staticstamp.install" |
178 | |
191 | |
179 | make distclean >/dev/null 2>&1 |
192 | "$MAKE" distclean >/dev/null 2>&1 |
180 | |
193 | |
181 | # I hate them |
194 | # I hate them |
182 | grep -q -- -fstack-protector Configure && \ |
195 | grep -q -- -fstack-protector Configure && \ |
183 | sedreplace 's/-fstack-protector/-fno-stack-protector/g' Configure |
196 | sedreplace 's/-fstack-protector/-fno-stack-protector/g' Configure |
184 | |
197 | |
… | |
… | |
190 | -Dusemymalloc=n \ |
203 | -Dusemymalloc=n \ |
191 | -Uusedl \ |
204 | -Uusedl \ |
192 | -Uusethreads \ |
205 | -Uusethreads \ |
193 | -Uuseithreads \ |
206 | -Uuseithreads \ |
194 | -Uusemultiplicity \ |
207 | -Uusemultiplicity \ |
195 | -Duseperlio \ |
|
|
196 | -Uusesfio \ |
208 | -Uusesfio \ |
197 | -Uuseshrplib \ |
209 | -Uuseshrplib \ |
|
|
210 | -Dcc="$PERL_CC" \ |
198 | -Dcppflags="$PERL_CPPFLAGS" \ |
211 | -Dcppflags="$PERL_CPPFLAGS" \ |
199 | -Dccflags="-g2 -fno-strict-aliasing" \ |
212 | -Dccflags="-g2 -fno-strict-aliasing" \ |
200 | -Doptimize="$PERL_OPTIMIZE" \ |
213 | -Doptimize="$PERL_OPTIMIZE" \ |
201 | -Dldflags="$PERL_LDFLAGS" \ |
214 | -Dldflags="$PERL_LDFLAGS" \ |
202 | -Dlibs="$PERL_LIBS" \ |
215 | -Dlibs="$PERL_LIBS" \ |
… | |
… | |
215 | -Dpager=/usr/bin/less \ |
228 | -Dpager=/usr/bin/less \ |
216 | -Demail="$EMAIL" \ |
229 | -Demail="$EMAIL" \ |
217 | -Dcf_email="$EMAIL" \ |
230 | -Dcf_email="$EMAIL" \ |
218 | -Dcf_by="$EMAIL" \ |
231 | -Dcf_by="$EMAIL" \ |
219 | $PERL_CONFIGURE \ |
232 | $PERL_CONFIGURE \ |
|
|
233 | -Duseperlio \ |
220 | -dE || fatal "Configure failed" |
234 | -dE || fatal "Configure failed" |
221 | |
235 | |
222 | sedreplace ' |
236 | sedreplace ' |
223 | s/-Wl,--no-gc-sections/-Wl,--gc-sections/g |
237 | s/-Wl,--no-gc-sections/-Wl,--gc-sections/g |
224 | s/ *-fno-stack-protector */ /g |
238 | s/ *-fno-stack-protector */ /g |
… | |
… | |
240 | building $STATICPERL/src/perl-$PERL_VERSION |
254 | building $STATICPERL/src/perl-$PERL_VERSION |
241 | EOF |
255 | EOF |
242 | |
256 | |
243 | rm -f "$PERL_PREFIX/staticstamp.install" |
257 | rm -f "$PERL_PREFIX/staticstamp.install" |
244 | |
258 | |
245 | make || fatal "make: error while building perl" |
259 | "$MAKE" || fatal "make: error while building perl" |
246 | |
260 | |
247 | postbuild || fatal "postbuild hook failed" |
261 | postbuild || fatal "postbuild hook failed" |
248 | } |
262 | } |
249 | |
263 | |
250 | install() { |
264 | install() { |
… | |
… | |
254 | verblock <<EOF |
268 | verblock <<EOF |
255 | installing $STATICPERL/src/perl-$PERL_VERSION |
269 | installing $STATICPERL/src/perl-$PERL_VERSION |
256 | to $PERL_PREFIX |
270 | to $PERL_PREFIX |
257 | EOF |
271 | EOF |
258 | |
272 | |
259 | rm -rf "$PERL_PREFIX" |
273 | ln -sf "perl/bin/" "$STATICPERL/bin" |
260 | |
274 | ln -sf "perl/lib/" "$STATICPERL/lib" |
|
|
275 | |
|
|
276 | ln -sf "$PERL_PREFIX" "$STATICPERL/perl" # might get overwritten |
|
|
277 | rm -rf "$PERL_PREFIX" # by this rm -rf |
|
|
278 | |
261 | make install || fatal "make install: error while installing" |
279 | "$MAKE" install || fatal "make install: error while installing" |
262 | |
280 | |
263 | rcd "$PERL_PREFIX" |
281 | rcd "$PERL_PREFIX" |
264 | |
282 | |
265 | # create a "make install" replacement for CPAN |
283 | # create a "make install" replacement for CPAN |
266 | cat >"$PERL_PREFIX"/bin/cpan-make-install <<EOF |
284 | cat >"$PERL_PREFIX"/bin/cpan-make-install <<EOF |
267 | make install UNINST=1 |
285 | "$MAKE" || exit |
|
|
286 | |
268 | if find blib/arch/auto -type f | grep -q -v .exists; then |
287 | if find blib/arch/auto -type f | grep -q -v .exists; then |
269 | echo Probably an XS module, rebuilding perl |
288 | echo Probably an XS module, rebuilding perl |
270 | make perl |
289 | if "$MAKE" perl; then |
|
|
290 | mv perl "$PERL_PREFIX"/bin/perl~ \ |
271 | rm -f "$PERL_PREFIX"/bin/perl |
291 | && rm -f "$PERL_PREFIX"/bin/perl \ |
272 | make -f Makefile.aperl inst_perl |
292 | && mv "$PERL_PREFIX"/bin/perl~ "$PERL_PREFIX"/bin/perl |
273 | make -f Makefile.aperl map_clean |
293 | "$MAKE" -f Makefile.aperl map_clean |
|
|
294 | else |
|
|
295 | "$MAKE" -f Makefile.aperl map_clean |
|
|
296 | exit 1 |
|
|
297 | fi |
274 | fi |
298 | fi |
|
|
299 | |
|
|
300 | "$MAKE" install UNINST=1 |
275 | EOF |
301 | EOF |
276 | chmod 755 "$PERL_PREFIX"/bin/cpan-make-install |
302 | chmod 755 "$PERL_PREFIX"/bin/cpan-make-install |
277 | |
303 | |
278 | # trick CPAN into avoiding ~/.cpan completely |
304 | # trick CPAN into avoiding ~/.cpan completely |
279 | echo 1 >"$PERL_PREFIX/lib/CPAN/MyConfig.pm" |
305 | echo 1 >"$PERL_PREFIX/lib/CPAN/MyConfig.pm" |
… | |
… | |
294 | ' || fatal "error while initialising CPAN" |
320 | ' || fatal "error while initialising CPAN" |
295 | |
321 | |
296 | touch "$PERL_PREFIX/staticstamp.install" |
322 | touch "$PERL_PREFIX/staticstamp.install" |
297 | fi |
323 | fi |
298 | |
324 | |
299 | if ! [ -e "$PERL_PREFIX/staticstamp.postinstall"; then |
325 | if ! [ -e "$PERL_PREFIX/staticstamp.postinstall" ]; then |
300 | NOCHECK_INSTALL=+ |
326 | NOCHECK_INSTALL=+ |
301 | instcpan $STATICPERL_MODULES |
327 | instcpan $STATICPERL_MODULES |
302 | [ $EXTRA_MODULES ] && instcpan $EXTRA_MODULES |
328 | [ $EXTRA_MODULES ] && instcpan $EXTRA_MODULES |
303 | |
329 | |
304 | postinstall || fatal "postinstall hook failed" |
330 | postinstall || fatal "postinstall hook failed" |
… | |
… | |
339 | for mod in "$@"; do |
365 | for mod in "$@"; do |
340 | echo |
366 | echo |
341 | echo $mod |
367 | echo $mod |
342 | ( |
368 | ( |
343 | rcd $mod |
369 | rcd $mod |
344 | make -f Makefile.aperl map_clean >/dev/null 2>&1 |
370 | "$MAKE" -f Makefile.aperl map_clean >/dev/null 2>&1 |
345 | make distclean >/dev/null 2>&1 |
371 | "$MAKE" distclean >/dev/null 2>&1 |
346 | "$PERL_PREFIX"/bin/perl Makefile.PL || fatal "$mod: error running Makefile.PL" |
372 | "$PERL_PREFIX"/bin/perl Makefile.PL || fatal "$mod: error running Makefile.PL" |
347 | make || fatal "$mod: error building module" |
373 | "$MAKE" || fatal "$mod: error building module" |
348 | "$PERL_PREFIX"/bin/cpan-make-install || fatal "$mod: error installing module" |
374 | "$PERL_PREFIX"/bin/cpan-make-install || fatal "$mod: error installing module" |
349 | make distclean >/dev/null 2>&1 |
375 | "$MAKE" distclean >/dev/null 2>&1 |
350 | exit 0 |
376 | exit 0 |
351 | ) || exit $? |
377 | ) || exit $? |
352 | done |
378 | done |
353 | } |
379 | } |
354 | |
380 | |
355 | ############################################################################# |
381 | ############################################################################# |
356 | # main |
382 | # main |
357 | |
383 | |
358 | podusage() { |
384 | podusage() { |
359 | echo |
385 | echo |
|
|
386 | |
360 | if [ -e "$PERL_PREFIX/bin/perl" ]; then |
387 | if [ -e "$PERL_PREFIX/bin/perl" ]; then |
361 | "$PERL_PREFIX/bin/perl" -MPod::Usage -e \ |
388 | "$PERL_PREFIX/bin/perl" -MPod::Usage -e \ |
362 | 'pod2usage -input => *STDIN, -output => *STDOUT, -verbose => '$1', -exitval => 0, -noperldoc => 1' <"$0" \ |
389 | 'pod2usage -input => *STDIN, -output => *STDOUT, -verbose => '$1', -exitval => 0, -noperldoc => 1' <"$0" \ |
363 | 2>/dev/null && exit |
390 | 2>/dev/null && exit |
364 | fi |
391 | fi |
|
|
392 | |
365 | # try whatever perl we can find |
393 | # try whatever perl we can find |
366 | perl -MPod::Usage -e \ |
394 | perl -MPod::Usage -e \ |
367 | 'pod2usage -input => *STDIN, -output => *STDOUT, -verbose => '$1', -exitval => 0, -noperldoc => 1' <"$0" \ |
395 | 'pod2usage -input => *STDIN, -output => *STDOUT, -verbose => '$1', -exitval => 0, -noperldoc => 1' <"$0" \ |
368 | 2>/dev/null && exit |
396 | 2>/dev/null && exit |
369 | |
397 | |
370 | fatal "displaying documentation requires a working perl - try '$0 install' first" |
398 | fatal "displaying documentation requires a working perl - try '$0 install' to build one in a safe location" |
371 | } |
399 | } |
372 | |
400 | |
373 | usage() { |
401 | usage() { |
374 | podusage 0 |
402 | podusage 0 |
375 | } |
403 | } |
… | |
… | |
385 | } |
413 | } |
386 | |
414 | |
387 | bundle() { |
415 | bundle() { |
388 | catmkbundle >"$MKBUNDLE~" || fatal "$MKBUNDLE~: cannot create" |
416 | catmkbundle >"$MKBUNDLE~" || fatal "$MKBUNDLE~: cannot create" |
389 | chmod 755 "$MKBUNDLE~" && mv "$MKBUNDLE~" "$MKBUNDLE" |
417 | chmod 755 "$MKBUNDLE~" && mv "$MKBUNDLE~" "$MKBUNDLE" |
|
|
418 | CACHE="$STATICPERL/cache" |
|
|
419 | mkdir -p "$CACHE" |
390 | "$PERL_PREFIX/bin/perl" -- "$MKBUNDLE" "$@" |
420 | "$PERL_PREFIX/bin/perl" -- "$MKBUNDLE" --cache "$CACHE" "$@" |
391 | } |
421 | } |
392 | |
422 | |
393 | if [ $# -gt 0 ]; then |
423 | if [ $# -gt 0 ]; then |
394 | while [ $# -gt 0 ]; do |
424 | while [ $# -gt 0 ]; do |
395 | mkdir -p "$STATICPERL" || fatal "$STATICPERL: cannot create" |
425 | mkdir -p "$STATICPERL" || fatal "$STATICPERL: cannot create" |
396 | mkdir -p "$PERL_PREFIX" || fatal "$PERL_PREFIX: cannot create" |
426 | mkdir -p "$PERL_PREFIX" || fatal "$PERL_PREFIX: cannot create" |
397 | |
427 | |
398 | command="${1#--}"; shift |
428 | command="${1#--}"; shift |
399 | case "$command" in |
429 | case "$command" in |
|
|
430 | version ) |
|
|
431 | echo "staticperl version $VERSION" |
|
|
432 | ;; |
400 | fetch | configure | build | install | clean | distclean) |
433 | fetch | configure | build | install | clean | distclean) |
401 | verblock <<EOF |
|
|
402 | $command |
|
|
403 | EOF |
|
|
404 | ( "$command" ) |
434 | ( "$command" ) |
405 | ;; |
435 | ;; |
406 | instsrc ) |
436 | instsrc ) |
407 | ( instsrc "$@" ) |
437 | ( instsrc "$@" ) |
408 | exit |
438 | exit |
… | |
… | |
422 | exit |
452 | exit |
423 | ;; |
453 | ;; |
424 | mkperl ) |
454 | mkperl ) |
425 | ( install ) |
455 | ( install ) |
426 | bundle --perl "$@" |
456 | bundle --perl "$@" |
|
|
457 | exit |
|
|
458 | ;; |
|
|
459 | mkapp ) |
|
|
460 | ( install ) |
|
|
461 | bundle --app "$@" |
427 | exit |
462 | exit |
428 | ;; |
463 | ;; |
429 | help ) |
464 | help ) |
430 | podusage 2 |
465 | podusage 2 |
431 | ;; |
466 | ;; |