ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/App-Staticperl/staticperl.sh
Revision: 1.23
Committed: Sat Dec 18 13:58:12 2010 UTC (13 years, 6 months ago) by root
Content type: application/x-sh
Branch: MAIN
Changes since 1.22: +11 -4 lines
Log Message:
*** empty log message ***

File Contents

# Content
1 #!/bin/sh
2
3 #############################################################################
4 # configuration to fill in
5
6 STATICPERL=~/.staticperl
7 CPAN=http://mirror.netcologne.de/cpan # which mirror to use
8 EMAIL="read the documentation <rtfm@example.org>"
9
10 # perl build variables
11 MAKE=make
12 PERL_VERSION=5.12.2 # 5.8.9 is also a good choice
13 PERL_CC=cc
14 PERL_CONFIGURE="" # additional Configure arguments
15 PERL_CCFLAGS="-DPERL_DISABLE_PMC -DPERL_ARENA_SIZE=65536 -D_GNU_SOURCE -DNDEBUG"
16 PERL_OPTIMIZE="-Os -ffunction-sections -fdata-sections -finline-limit=8 -ffast-math"
17
18 ARCH="$(uname -m)"
19
20 case "$ARCH" in
21 i*86 | x86_64 | amd64 )
22 PERL_OPTIMIZE="$PERL_OPTIMIZE -mpush-args -mno-inline-stringops-dynamically -mno-align-stringops -mno-ieee-fp" # x86/amd64
23 case "$ARCH" in
24 i*86 )
25 PERL_OPTIMIZE="$PERL_OPTIMIZE -fomit-frame-pointer -march=pentium3 -mtune=i386" # x86 only
26 ;;
27 esac
28 ;;
29 esac
30
31 # -Wl,--gc-sections makes it impossible to check for undefined references
32 # for some reason so we need to patch away the "-no" after Configure and before make :/
33 # --allow-multiple-definition exists to work around uclibc's pthread static linking bug
34 PERL_LDFLAGS="-Wl,--no-gc-sections -Wl,--allow-multiple-definition"
35 PERL_LIBS="-lm -lcrypt" # perl loves to add lotsa crap itself
36
37 # some configuration options for modules
38 export PERL_MM_USE_DEFAULT=1
39 #export CORO_INTERFACE=p # needed without nptl on x86, due to bugs in linuxthreads - very slow
40 export EV_EXTRA_DEFS='-DEV_FEATURES=4+8+16+64 -DEV_USE_SELECT=0 -DEV_USE_POLL=1 -DEV_USE_EPOLL=1 -DEV_NO_LOOPS -DEV_COMPAT3=0'
41
42 # which extra modules to install by default from CPAN that are
43 # required by mkbundle
44 STATICPERL_MODULES="common::sense Pod::Strip PPI::XS Pod::Usage"
45
46 # which extra modules you might want to install
47 EXTRA_MODULES=""
48
49 # overridable functions
50 preconfigure() { : ; }
51 postconfigure() { : ; }
52 postbuild() { : ; }
53 postinstall() { : ; }
54
55 # now source user config, if any
56 if [ "$STATICPERLRC" ]; then
57 . "$STATICPERLRC"
58 else
59 [ -r /etc/staticperlrc ] && . /etc/staticperlrc
60 [ -r ~/.staticperlrc ] && . ~/.staticperlrc
61 [ -r "$STATICPERL/rc" ] && . "$STATICPERL/rc"
62 fi
63
64 #############################################################################
65 # support
66
67 MKBUNDLE="${MKBUNDLE:=$STATICPERL/mkbundle}"
68 PERL_PREFIX="${PERL_PREFIX:=$STATICPERL/perl}" # where the perl gets installed
69
70 unset PERL5OPT PERL5LIB PERLLIB PERL_UNICODE PERLIO_DEBUG
71 export LC_ALL=C # just to be on the safe side
72
73 # set version in a way that Makefile.PL can extract
74 VERSION=VERSION; eval \
75 $VERSION=0.912
76
77 BZ2=bz2
78 BZIP2=bzip2
79
80 fatal() {
81 printf -- "\nFATAL: %s\n\n" "$*" >&2
82 exit 1
83 }
84
85 verbose() {
86 printf -- "%s\n" "$*"
87 }
88
89 verblock() {
90 verbose
91 verbose "***"
92 while read line; do
93 verbose "*** $line"
94 done
95 verbose "***"
96 verbose
97 }
98
99 rcd() {
100 cd "$1" || fatal "$1: cannot enter"
101 }
102
103 trace() {
104 prefix="$1"; shift
105 # "$@" 2>&1 | while read line; do
106 # echo "$prefix: $line"
107 # done
108 "$@"
109 }
110
111 trap wait 0
112
113 #############################################################################
114 # clean
115
116 distclean() {
117 verblock <<EOF
118 deleting everything installed by this script (rm -rf $STATICPERL)
119 EOF
120
121 rm -rf "$STATICPERL"
122 }
123
124 #############################################################################
125 # download/configure/compile/install perl
126
127 clean() {
128 rm -rf "$STATICPERL/src/perl-$PERL_VERSION"
129 }
130
131 realclean() {
132 rm -f "$PERL_PREFIX/staticstamp.postinstall"
133 rm -f "$PERL_PREFIX/staticstamp.install"
134 rm -f "$STATICPERL/src/perl-"*"/staticstamp.configure"
135 }
136
137 fetch() {
138 rcd "$STATICPERL"
139
140 mkdir -p src
141 rcd src
142
143 if ! [ -d "perl-$PERL_VERSION" ]; then
144 if ! [ -e "perl-$PERL_VERSION.tar.$BZ2" ]; then
145
146 URL="$CPAN/src/5.0/perl-$PERL_VERSION.tar.$BZ2"
147
148 verblock <<EOF
149 downloading perl
150 to manually download perl yourself, place
151 perl-$PERL_VERSION.tar.$BZ2 in $STATICPERL
152 trying $URL
153 EOF
154
155 rm -f perl-$PERL_VERSION.tar.$BZ2~ # just to be on the safe side
156 wget -O perl-$PERL_VERSION.tar.$BZ2~ "$URL" \
157 || curl >perl-$PERL_VERSION.tar.$BZ2~ "$URL" \
158 || fatal "$URL: unable to download"
159 rm -f perl-$PERL_VERSION.tar.$BZ2
160 mv perl-$PERL_VERSION.tar.$BZ2~ perl-$PERL_VERSION.tar.$BZ2
161 fi
162
163 verblock <<EOF
164 unpacking perl
165 EOF
166
167 mkdir -p unpack
168 rm -rf unpack/perl-$PERL_VERSION
169 $BZIP2 -d <perl-$PERL_VERSION.tar.bz2 | tar xfC - unpack \
170 || fatal "perl-$PERL_VERSION.tar.bz2: error during unpacking"
171 chmod -R u+w unpack/perl-$PERL_VERSION
172 mv unpack/perl-$PERL_VERSION perl-$PERL_VERSION
173 rmdir -p unpack
174 fi
175 }
176
177 # similar to GNU-sed -i or perl -pi
178 sedreplace() {
179 sed -e "$1" <"$2" > "$2~" || fatal "error while running sed"
180 rm -f "$2"
181 mv "$2~" "$2"
182 }
183
184 configure_failure() {
185 cat <<EOF
186
187
188 ***
189 *** Configure failed - see above for the exact error message(s).
190 ***
191 *** Most commonly, this is because the default PERL_CCFLAGS or PERL_OPTIMIZE
192 *** flags are not supported by your compiler. Less often, this is because
193 *** PERL_LIBS either contains a library not available on your system (such as
194 *** -lcrypt), or because it lacks a required library (e.g. -lsocket or -lnsl).
195 ***
196 *** You can provide your own flags by creating a ~/.staticperlrc file with
197 *** variable assignments. For example (these are the actual values used):
198 ***
199
200 PERL_CC="$PERL_CC"
201 PERL_CCFLAGS="$PERL_CCFLAGS"
202 PERL_OPTIMIZE="$PERL_OPTIMIZE"
203 PERL_LDFLAGS="$PERL_LDFLAGS"
204 PERL_LIBS="$PERL_LIBS"
205
206 EOF
207 exit 1
208 }
209
210 configure() {
211 fetch
212
213 rcd "$STATICPERL/src/perl-$PERL_VERSION"
214
215 [ -e staticstamp.configure ] && return
216
217 verblock <<EOF
218 configuring $STATICPERL/src/perl-$PERL_VERSION
219 EOF
220
221 rm -f "$PERL_PREFIX/staticstamp.install"
222
223 "$MAKE" distclean >/dev/null 2>&1
224
225 sedreplace '/^#define SITELIB/d' config_h.SH
226
227 # I hate them for this
228 grep -q -- -fstack-protector Configure && \
229 sedreplace 's/-fstack-protector/-fno-stack-protector/g' Configure
230
231 preconfigure
232
233 # trace configure \
234 sh Configure -Duselargefiles \
235 -Uuse64bitint \
236 -Dusemymalloc=n \
237 -Uusedl \
238 -Uusethreads \
239 -Uuseithreads \
240 -Uusemultiplicity \
241 -Uusesfio \
242 -Uuseshrplib \
243 -A ccflags=" $PERL_CCFLAGS" \
244 -Dcc="$PERL_CC" \
245 -Doptimize="$PERL_OPTIMIZE" \
246 -Dldflags="$PERL_LDFLAGS" \
247 -Dlibs="$PERL_LIBS" \
248 -Dprefix="$PERL_PREFIX" \
249 -Dbin="$PERL_PREFIX/bin" \
250 -Dprivlib="$PERL_PREFIX/lib" \
251 -Darchlib="$PERL_PREFIX/lib" \
252 -Uusevendorprefix \
253 -Dsitelib="$PERL_PREFIX/lib" \
254 -Dsitearch="$PERL_PREFIX/lib" \
255 -Uman1dir \
256 -Uman3dir \
257 -Usiteman1dir \
258 -Usiteman3dir \
259 -Dpager=/usr/bin/less \
260 -Demail="$EMAIL" \
261 -Dcf_email="$EMAIL" \
262 -Dcf_by="$EMAIL" \
263 $PERL_CONFIGURE \
264 -Duseperlio \
265 -dE || configure_failure
266
267 sedreplace '
268 s/-Wl,--no-gc-sections/-Wl,--gc-sections/g
269 s/ *-fno-stack-protector */ /g
270 ' config.sh
271
272 sh Configure -S || fatal "Configure -S failed"
273
274 postconfigure || fatal "postconfigure hook failed"
275
276 touch staticstamp.configure
277 }
278
279 build() {
280 configure
281
282 rcd "$STATICPERL/src/perl-$PERL_VERSION"
283
284 verblock <<EOF
285 building $STATICPERL/src/perl-$PERL_VERSION
286 EOF
287
288 rm -f "$PERL_PREFIX/staticstamp.install"
289
290 "$MAKE" || fatal "make: error while building perl"
291
292 postbuild || fatal "postbuild hook failed"
293 }
294
295 install() {
296 if ! [ -e "$PERL_PREFIX/staticstamp.install" ]; then
297 build
298
299 verblock <<EOF
300 installing $STATICPERL/src/perl-$PERL_VERSION
301 to $PERL_PREFIX
302 EOF
303
304 ln -sf "perl/bin/" "$STATICPERL/bin"
305 ln -sf "perl/lib/" "$STATICPERL/lib"
306
307 ln -sf "$PERL_PREFIX" "$STATICPERL/perl" # might get overwritten
308 rm -rf "$PERL_PREFIX" # by this rm -rf
309
310 "$MAKE" install || fatal "make install: error while installing"
311
312 rcd "$PERL_PREFIX"
313
314 # create a "make install" replacement for CPAN
315 cat >"$PERL_PREFIX"/bin/cpan-make-install <<EOF
316 "$MAKE" || exit
317
318 if find blib/arch/auto -type f | grep -q -v .exists; then
319 echo Probably an XS module, rebuilding perl
320 if "$MAKE" perl; then
321 mv perl "$PERL_PREFIX"/bin/perl~ \
322 && rm -f "$PERL_PREFIX"/bin/perl \
323 && mv "$PERL_PREFIX"/bin/perl~ "$PERL_PREFIX"/bin/perl
324 "$MAKE" -f Makefile.aperl map_clean
325 else
326 "$MAKE" -f Makefile.aperl map_clean
327 exit 1
328 fi
329 fi
330
331 "$MAKE" install UNINST=1
332 EOF
333 chmod 755 "$PERL_PREFIX"/bin/cpan-make-install
334
335 # trick CPAN into avoiding ~/.cpan completely
336 echo 1 >"$PERL_PREFIX/lib/CPAN/MyConfig.pm"
337
338 "$PERL_PREFIX"/bin/perl -MCPAN -e '
339 CPAN::Shell->o (conf => urllist => push => "'"$CPAN"'");
340 CPAN::Shell->o (conf => q<cpan_home>, "'"$STATICPERL"'/cpan");
341 CPAN::Shell->o (conf => q<init>);
342 CPAN::Shell->o (conf => q<cpan_home>, "'"$STATICPERL"'/cpan");
343 CPAN::Shell->o (conf => q<build_dir>, "'"$STATICPERL"'/cpan/build");
344 CPAN::Shell->o (conf => q<prefs_dir>, "'"$STATICPERL"'/cpan/prefs");
345 CPAN::Shell->o (conf => q<histfile> , "'"$STATICPERL"'/cpan/histfile");
346 CPAN::Shell->o (conf => q<keep_source_where>, "'"$STATICPERL"'/cpan/sources");
347 CPAN::Shell->o (conf => q<make_install_make_command>, "'"$PERL_PREFIX"'/bin/cpan-make-install");
348 CPAN::Shell->o (conf => q<prerequisites_policy>, q<follow>);
349 CPAN::Shell->o (conf => q<build_requires_install_policy>, q<no>);
350 CPAN::Shell->o (conf => q<commit>);
351 ' || fatal "error while initialising CPAN"
352
353 touch "$PERL_PREFIX/staticstamp.install"
354 fi
355
356 if ! [ -e "$PERL_PREFIX/staticstamp.postinstall" ]; then
357 NOCHECK_INSTALL=+
358 instcpan $STATICPERL_MODULES
359 [ $EXTRA_MODULES ] && instcpan $EXTRA_MODULES
360
361 postinstall || fatal "postinstall hook failed"
362
363 touch "$PERL_PREFIX/staticstamp.postinstall"
364 fi
365 }
366
367 #############################################################################
368 # install a module from CPAN
369
370 instcpan() {
371 [ $NOCHECK_INSTALL ] || install
372
373 verblock <<EOF
374 installing modules from CPAN
375 $@
376 EOF
377
378 for mod in "$@"; do
379 "$PERL_PREFIX"/bin/perl -MCPAN -e 'notest install => "'"$mod"'"' \
380 || fatal "$mod: unable to install from CPAN"
381 done
382 rm -rf "$STATICPERL/build"
383 }
384
385 #############################################################################
386 # install a module from unpacked sources
387
388 instsrc() {
389 [ $NOCHECK_INSTALL ] || install
390
391 verblock <<EOF
392 installing modules from source
393 $@
394 EOF
395
396 for mod in "$@"; do
397 echo
398 echo $mod
399 (
400 rcd $mod
401 "$MAKE" -f Makefile.aperl map_clean >/dev/null 2>&1
402 "$MAKE" distclean >/dev/null 2>&1
403 "$PERL_PREFIX"/bin/perl Makefile.PL || fatal "$mod: error running Makefile.PL"
404 "$MAKE" || fatal "$mod: error building module"
405 "$PERL_PREFIX"/bin/cpan-make-install || fatal "$mod: error installing module"
406 "$MAKE" distclean >/dev/null 2>&1
407 exit 0
408 ) || exit $?
409 done
410 }
411
412 #############################################################################
413 # main
414
415 podusage() {
416 echo
417
418 if [ -e "$PERL_PREFIX/bin/perl" ]; then
419 "$PERL_PREFIX/bin/perl" -MPod::Usage -e \
420 'pod2usage -input => *STDIN, -output => *STDOUT, -verbose => '$1', -exitval => 0, -noperldoc => 1' <"$0" \
421 2>/dev/null && exit
422 fi
423
424 # try whatever perl we can find
425 perl -MPod::Usage -e \
426 'pod2usage -input => *STDIN, -output => *STDOUT, -verbose => '$1', -exitval => 0, -noperldoc => 1' <"$0" \
427 2>/dev/null && exit
428
429 fatal "displaying documentation requires a working perl - try '$0 install' to build one in a safe location"
430 }
431
432 usage() {
433 podusage 0
434 }
435
436 catmkbundle() {
437 {
438 read dummy
439 echo "#!$PERL_PREFIX/bin/perl"
440 cat
441 } <<'MKBUNDLE'
442 #CAT mkbundle
443 MKBUNDLE
444 }
445
446 bundle() {
447 catmkbundle >"$MKBUNDLE~" || fatal "$MKBUNDLE~: cannot create"
448 chmod 755 "$MKBUNDLE~" && mv "$MKBUNDLE~" "$MKBUNDLE"
449 CACHE="$STATICPERL/cache"
450 mkdir -p "$CACHE"
451 "$PERL_PREFIX/bin/perl" -- "$MKBUNDLE" --cache "$CACHE" "$@"
452 }
453
454 if [ $# -gt 0 ]; then
455 while [ $# -gt 0 ]; do
456 mkdir -p "$STATICPERL" || fatal "$STATICPERL: cannot create"
457 mkdir -p "$PERL_PREFIX" || fatal "$PERL_PREFIX: cannot create"
458
459 command="${1#--}"; shift
460 case "$command" in
461 version )
462 echo "staticperl version $VERSION"
463 ;;
464 fetch | configure | build | install | clean | realclean | distclean)
465 ( "$command" ) || exit
466 ;;
467 instsrc )
468 ( instsrc "$@" ) || exit
469 exit
470 ;;
471 instcpan )
472 ( instcpan "$@" ) || exit
473 exit
474 ;;
475 cpan )
476 ( install ) || exit
477 "$PERL_PREFIX/bin/cpan" "$@"
478 exit
479 ;;
480 mkbundle )
481 ( install ) || exit
482 bundle "$@"
483 exit
484 ;;
485 mkperl )
486 ( install ) || exit
487 bundle --perl "$@"
488 exit
489 ;;
490 mkapp )
491 ( install ) || exit
492 bundle --app "$@"
493 exit
494 ;;
495 help )
496 podusage 2
497 ;;
498 * )
499 exec 1>&2
500 echo
501 echo "Unknown command: $command"
502 podusage 0
503 ;;
504 esac
505 done
506 else
507 usage
508 fi
509
510 exit 0
511
512 #CAT staticperl.pod
513