ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/App-Staticperl/staticperl.sh
Revision: 1.21
Committed: Mon Dec 13 18:08:01 2010 UTC (13 years, 7 months ago) by root
Content type: application/x-sh
Branch: MAIN
Changes since 1.20: +13 -12 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_CPPFLAGS="-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 PERL_OPTIMIZE="$PERL_OPTIMIZE" # x86/amd64
24 case "$ARCH" in
25 i*86 )
26 PERL_OPTIMIZE="$PERL_OPTIMIZE -fomit-frame-pointer -march=pentium3 -mtune=i386" # x86 only
27 ;;
28 esac
29 ;;
30 esac
31
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 :/
34 # --allow-multiple-definition exists to work around uclibc's pthread static linking bug
35 PERL_LDFLAGS="-Wl,--no-gc-sections -Wl,--allow-multiple-definition"
36 PERL_LIBS="-lm -lcrypt" # perl loves to add lotsa crap itself
37
38 # some configuration options for modules
39 export PERL_MM_USE_DEFAULT=1
40 #export CORO_INTERFACE=p # needed without nptl on x86, due to bugs in linuxthreads - very slow
41 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'
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 export LC_ALL=C # 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.911
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 fetch() {
133 rcd "$STATICPERL"
134
135 mkdir -p src
136 rcd src
137
138 if ! [ -d "perl-$PERL_VERSION" ]; then
139 if ! [ -e "perl-$PERL_VERSION.tar.$BZ2" ]; then
140
141 URL="$CPAN/src/5.0/perl-$PERL_VERSION.tar.$BZ2"
142
143 verblock <<EOF
144 downloading perl
145 to manually download perl yourself, place
146 perl-$PERL_VERSION.tar.$BZ2 in $STATICPERL
147 trying $URL
148 EOF
149
150 rm -f perl-$PERL_VERSION.tar.$BZ2~ # just to be on the safe side
151 wget -O perl-$PERL_VERSION.tar.$BZ2~ "$URL" \
152 || curl >perl-$PERL_VERSION.tar.$BZ2~ "$URL" \
153 || fatal "$URL: unable to download"
154 rm -f perl-$PERL_VERSION.tar.$BZ2
155 mv perl-$PERL_VERSION.tar.$BZ2~ perl-$PERL_VERSION.tar.$BZ2
156 fi
157
158 verblock <<EOF
159 unpacking perl
160 EOF
161
162 mkdir -p unpack
163 rm -rf unpack/perl-$PERL_VERSION
164 $BZIP2 -d <perl-$PERL_VERSION.tar.bz2 | tar xfC - unpack \
165 || fatal "perl-$PERL_VERSION.tar.bz2: error during unpacking"
166 chmod -R u+w unpack/perl-$PERL_VERSION
167 mv unpack/perl-$PERL_VERSION perl-$PERL_VERSION
168 rmdir -p unpack
169 fi
170 }
171
172 # similar to GNU-sed -i or perl -pi
173 sedreplace() {
174 sed -e "$1" <"$2" > "$2~" || fatal "error while running sed"
175 rm -f "$2"
176 mv "$2~" "$2"
177 }
178
179 configure() {
180 fetch
181
182 rcd "$STATICPERL/src/perl-$PERL_VERSION"
183
184 [ -e staticstamp.configure ] && return
185
186 verblock <<EOF
187 configuring $STATICPERL/src/perl-$PERL_VERSION
188 EOF
189
190 rm -f "$PERL_PREFIX/staticstamp.install"
191
192 "$MAKE" distclean >/dev/null 2>&1
193
194 # I hate them
195 grep -q -- -fstack-protector Configure && \
196 sedreplace 's/-fstack-protector/-fno-stack-protector/g' Configure
197
198 preconfigure
199
200 # trace configure \
201 sh Configure -Duselargefiles \
202 -Uuse64bitint \
203 -Dusemymalloc=n \
204 -Uusedl \
205 -Uusethreads \
206 -Uuseithreads \
207 -Uusemultiplicity \
208 -Uusesfio \
209 -Uuseshrplib \
210 -Dcc="$PERL_CC" \
211 -Dcppflags="$PERL_CPPFLAGS" \
212 -Dccflags="-g2 -fno-strict-aliasing" \
213 -Doptimize="$PERL_OPTIMIZE" \
214 -Dldflags="$PERL_LDFLAGS" \
215 -Dlibs="$PERL_LIBS" \
216 -Dprefix="$PERL_PREFIX" \
217 -Dbin="$PERL_PREFIX/bin" \
218 -Dprivlib="$PERL_PREFIX/lib" \
219 -Darchlib="$PERL_PREFIX/lib" \
220 -Uusevendorprefix \
221 -Dsitelib="$PERL_PREFIX/lib" \
222 -Dsitearch="$PERL_PREFIX/lib" \
223 -Usitelibexp \
224 -Uman1dir \
225 -Uman3dir \
226 -Usiteman1dir \
227 -Usiteman3dir \
228 -Dpager=/usr/bin/less \
229 -Demail="$EMAIL" \
230 -Dcf_email="$EMAIL" \
231 -Dcf_by="$EMAIL" \
232 $PERL_CONFIGURE \
233 -Duseperlio \
234 -dE || fatal "Configure failed"
235
236 sedreplace '
237 s/-Wl,--no-gc-sections/-Wl,--gc-sections/g
238 s/ *-fno-stack-protector */ /g
239 ' config.sh
240
241 sh Configure -S || fatal "Configure -S failed"
242
243 postconfigure || fatal "postconfigure hook failed"
244
245 touch staticstamp.configure
246 }
247
248 build() {
249 configure
250
251 rcd "$STATICPERL/src/perl-$PERL_VERSION"
252
253 verblock <<EOF
254 building $STATICPERL/src/perl-$PERL_VERSION
255 EOF
256
257 rm -f "$PERL_PREFIX/staticstamp.install"
258
259 "$MAKE" || fatal "make: error while building perl"
260
261 postbuild || fatal "postbuild hook failed"
262 }
263
264 install() {
265 if ! [ -e "$PERL_PREFIX/staticstamp.install" ]; then
266 build
267
268 verblock <<EOF
269 installing $STATICPERL/src/perl-$PERL_VERSION
270 to $PERL_PREFIX
271 EOF
272
273 ln -sf "perl/bin/" "$STATICPERL/bin"
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
279 "$MAKE" install || fatal "make install: error while installing"
280
281 rcd "$PERL_PREFIX"
282
283 # create a "make install" replacement for CPAN
284 cat >"$PERL_PREFIX"/bin/cpan-make-install <<EOF
285 "$MAKE" || exit
286
287 if find blib/arch/auto -type f | grep -q -v .exists; then
288 echo Probably an XS module, rebuilding perl
289 if "$MAKE" perl; then
290 mv perl "$PERL_PREFIX"/bin/perl~ \
291 && rm -f "$PERL_PREFIX"/bin/perl \
292 && mv "$PERL_PREFIX"/bin/perl~ "$PERL_PREFIX"/bin/perl
293 "$MAKE" -f Makefile.aperl map_clean
294 else
295 "$MAKE" -f Makefile.aperl map_clean
296 exit 1
297 fi
298 fi
299
300 "$MAKE" install UNINST=1
301 EOF
302 chmod 755 "$PERL_PREFIX"/bin/cpan-make-install
303
304 # trick CPAN into avoiding ~/.cpan completely
305 echo 1 >"$PERL_PREFIX/lib/CPAN/MyConfig.pm"
306
307 "$PERL_PREFIX"/bin/perl -MCPAN -e '
308 CPAN::Shell->o (conf => urllist => push => "'"$CPAN"'");
309 CPAN::Shell->o (conf => q<cpan_home>, "'"$STATICPERL"'/cpan");
310 CPAN::Shell->o (conf => q<init>);
311 CPAN::Shell->o (conf => q<cpan_home>, "'"$STATICPERL"'/cpan");
312 CPAN::Shell->o (conf => q<build_dir>, "'"$STATICPERL"'/cpan/build");
313 CPAN::Shell->o (conf => q<prefs_dir>, "'"$STATICPERL"'/cpan/prefs");
314 CPAN::Shell->o (conf => q<histfile> , "'"$STATICPERL"'/cpan/histfile");
315 CPAN::Shell->o (conf => q<keep_source_where>, "'"$STATICPERL"'/cpan/sources");
316 CPAN::Shell->o (conf => q<make_install_make_command>, "'"$PERL_PREFIX"'/bin/cpan-make-install");
317 CPAN::Shell->o (conf => q<prerequisites_policy>, q<follow>);
318 CPAN::Shell->o (conf => q<build_requires_install_policy>, q<no>);
319 CPAN::Shell->o (conf => q<commit>);
320 ' || fatal "error while initialising CPAN"
321
322 touch "$PERL_PREFIX/staticstamp.install"
323 fi
324
325 if ! [ -e "$PERL_PREFIX/staticstamp.postinstall" ]; then
326 NOCHECK_INSTALL=+
327 instcpan $STATICPERL_MODULES
328 [ $EXTRA_MODULES ] && instcpan $EXTRA_MODULES
329
330 postinstall || fatal "postinstall hook failed"
331
332 touch "$PERL_PREFIX/staticstamp.postinstall"
333 fi
334 }
335
336 #############################################################################
337 # install a module from CPAN
338
339 instcpan() {
340 [ $NOCHECK_INSTALL ] || install
341
342 verblock <<EOF
343 installing modules from CPAN
344 $@
345 EOF
346
347 for mod in "$@"; do
348 "$PERL_PREFIX"/bin/perl -MCPAN -e 'notest install => "'"$mod"'"' \
349 || fatal "$mod: unable to install from CPAN"
350 done
351 rm -rf "$STATICPERL/build"
352 }
353
354 #############################################################################
355 # install a module from unpacked sources
356
357 instsrc() {
358 [ $NOCHECK_INSTALL ] || install
359
360 verblock <<EOF
361 installing modules from source
362 $@
363 EOF
364
365 for mod in "$@"; do
366 echo
367 echo $mod
368 (
369 rcd $mod
370 "$MAKE" -f Makefile.aperl map_clean >/dev/null 2>&1
371 "$MAKE" distclean >/dev/null 2>&1
372 "$PERL_PREFIX"/bin/perl Makefile.PL || fatal "$mod: error running Makefile.PL"
373 "$MAKE" || fatal "$mod: error building module"
374 "$PERL_PREFIX"/bin/cpan-make-install || fatal "$mod: error installing module"
375 "$MAKE" distclean >/dev/null 2>&1
376 exit 0
377 ) || exit $?
378 done
379 }
380
381 #############################################################################
382 # main
383
384 podusage() {
385 echo
386
387 if [ -e "$PERL_PREFIX/bin/perl" ]; then
388 "$PERL_PREFIX/bin/perl" -MPod::Usage -e \
389 'pod2usage -input => *STDIN, -output => *STDOUT, -verbose => '$1', -exitval => 0, -noperldoc => 1' <"$0" \
390 2>/dev/null && exit
391 fi
392
393 # try whatever perl we can find
394 perl -MPod::Usage -e \
395 'pod2usage -input => *STDIN, -output => *STDOUT, -verbose => '$1', -exitval => 0, -noperldoc => 1' <"$0" \
396 2>/dev/null && exit
397
398 fatal "displaying documentation requires a working perl - try '$0 install' to build one in a safe location"
399 }
400
401 usage() {
402 podusage 0
403 }
404
405 catmkbundle() {
406 {
407 read dummy
408 echo "#!$PERL_PREFIX/bin/perl"
409 cat
410 } <<'MKBUNDLE'
411 #CAT mkbundle
412 MKBUNDLE
413 }
414
415 bundle() {
416 catmkbundle >"$MKBUNDLE~" || fatal "$MKBUNDLE~: cannot create"
417 chmod 755 "$MKBUNDLE~" && mv "$MKBUNDLE~" "$MKBUNDLE"
418 CACHE="$STATICPERL/cache"
419 mkdir -p "$CACHE"
420 "$PERL_PREFIX/bin/perl" -- "$MKBUNDLE" --cache "$CACHE" "$@"
421 }
422
423 if [ $# -gt 0 ]; then
424 while [ $# -gt 0 ]; do
425 mkdir -p "$STATICPERL" || fatal "$STATICPERL: cannot create"
426 mkdir -p "$PERL_PREFIX" || fatal "$PERL_PREFIX: cannot create"
427
428 command="${1#--}"; shift
429 case "$command" in
430 version )
431 echo "staticperl version $VERSION"
432 ;;
433 fetch | configure | build | install | clean | distclean)
434 ( "$command" )
435 ;;
436 instsrc )
437 ( instsrc "$@" )
438 exit
439 ;;
440 instcpan )
441 ( instcpan "$@" )
442 exit
443 ;;
444 cpan )
445 ( install )
446 "$PERL_PREFIX/bin/cpan" "$@"
447 exit
448 ;;
449 mkbundle )
450 ( install )
451 bundle "$@"
452 exit
453 ;;
454 mkperl )
455 ( install )
456 bundle --perl "$@"
457 exit
458 ;;
459 mkapp )
460 ( install )
461 bundle --app "$@"
462 exit
463 ;;
464 help )
465 podusage 2
466 ;;
467 * )
468 exec 1>&2
469 echo
470 echo "Unknown command: $command"
471 podusage 0
472 ;;
473 esac
474 done
475 else
476 usage
477 fi
478
479 exit 0
480
481 #CAT staticperl.pod
482