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