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