ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/App-Staticperl/staticperl.sh
Revision: 1.20
Committed: Mon Dec 13 17:35:51 2010 UTC (13 years, 7 months ago) by root
Content type: application/x-sh
Branch: MAIN
Changes since 1.19: +6 -1 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 PERL_VERSION=5.12.2 # 5.8.9 is also a good choice
12 PERL_CC=cc
13 PERL_CONFIGURE="" # additional Configure arguments
14 PERL_CPPFLAGS="-DPERL_DISABLE_PMC -DPERL_ARENA_SIZE=65536 -D_GNU_SOURCE -DNDEBUG -USITELIB_EXP -USITEARCHEXP -UARCHLIB_EXP"
15 PERL_OPTIMIZE="-Os -ffunction-sections -fdata-sections -finline-limit=8 -ffast-math"
16
17 ARCH="$(uname -m)"
18
19 case "$ARCH" in
20 i*86 | x86_64 | amd64 )
21 #PERL_OPTIMIZE="$PERL_OPTIMIZE -mpush-args -mno-inline-stringops-dynamically -mno-align-stringops -mno-ieee-fp" # x86/amd64
22 PERL_OPTIMIZE="$PERL_OPTIMIZE" # 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.911
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() {
179 fetch
180
181 rcd "$STATICPERL/src/perl-$PERL_VERSION"
182
183 [ -e staticstamp.configure ] && return
184
185 verblock <<EOF
186 configuring $STATICPERL/src/perl-$PERL_VERSION
187 EOF
188
189 rm -f "$PERL_PREFIX/staticstamp.install"
190
191 make distclean >/dev/null 2>&1
192
193 # I hate them
194 grep -q -- -fstack-protector Configure && \
195 sedreplace 's/-fstack-protector/-fno-stack-protector/g' Configure
196
197 preconfigure
198
199 # trace configure \
200 sh Configure -Duselargefiles \
201 -Uuse64bitint \
202 -Dusemymalloc=n \
203 -Uusedl \
204 -Uusethreads \
205 -Uuseithreads \
206 -Uusemultiplicity \
207 -Uusesfio \
208 -Uuseshrplib \
209 -Dcc="$PERL_CC" \
210 -Dcppflags="$PERL_CPPFLAGS" \
211 -Dccflags="-g2 -fno-strict-aliasing" \
212 -Doptimize="$PERL_OPTIMIZE" \
213 -Dldflags="$PERL_LDFLAGS" \
214 -Dlibs="$PERL_LIBS" \
215 -Dprefix="$PERL_PREFIX" \
216 -Dbin="$PERL_PREFIX/bin" \
217 -Dprivlib="$PERL_PREFIX/lib" \
218 -Darchlib="$PERL_PREFIX/lib" \
219 -Uusevendorprefix \
220 -Dsitelib="$PERL_PREFIX/lib" \
221 -Dsitearch="$PERL_PREFIX/lib" \
222 -Usitelibexp \
223 -Uman1dir \
224 -Uman3dir \
225 -Usiteman1dir \
226 -Usiteman3dir \
227 -Dpager=/usr/bin/less \
228 -Demail="$EMAIL" \
229 -Dcf_email="$EMAIL" \
230 -Dcf_by="$EMAIL" \
231 $PERL_CONFIGURE \
232 -Duseperlio \
233 -dE || fatal "Configure failed"
234
235 sedreplace '
236 s/-Wl,--no-gc-sections/-Wl,--gc-sections/g
237 s/ *-fno-stack-protector */ /g
238 ' config.sh
239
240 sh Configure -S || fatal "Configure -S failed"
241
242 postconfigure || fatal "postconfigure hook failed"
243
244 touch staticstamp.configure
245 }
246
247 build() {
248 configure
249
250 rcd "$STATICPERL/src/perl-$PERL_VERSION"
251
252 verblock <<EOF
253 building $STATICPERL/src/perl-$PERL_VERSION
254 EOF
255
256 rm -f "$PERL_PREFIX/staticstamp.install"
257
258 make || fatal "make: error while building perl"
259
260 postbuild || fatal "postbuild hook failed"
261 }
262
263 install() {
264 if ! [ -e "$PERL_PREFIX/staticstamp.install" ]; then
265 build
266
267 verblock <<EOF
268 installing $STATICPERL/src/perl-$PERL_VERSION
269 to $PERL_PREFIX
270 EOF
271
272 ln -sf "perl/bin/" "$STATICPERL/bin"
273 ln -sf "perl/lib/" "$STATICPERL/lib"
274
275 ln -sf "$PERL_PREFIX" "$STATICPERL/perl" # might get overwritten
276 rm -rf "$PERL_PREFIX" # by this rm -rf
277
278 make install || fatal "make install: error while installing"
279
280 rcd "$PERL_PREFIX"
281
282 # create a "make install" replacement for CPAN
283 cat >"$PERL_PREFIX"/bin/cpan-make-install <<EOF
284 make || exit
285
286 if find blib/arch/auto -type f | grep -q -v .exists; then
287 echo Probably an XS module, rebuilding perl
288 if make perl; then
289 mv perl "$PERL_PREFIX"/bin/perl~ \
290 && rm -f "$PERL_PREFIX"/bin/perl \
291 && mv "$PERL_PREFIX"/bin/perl~ "$PERL_PREFIX"/bin/perl
292 make -f Makefile.aperl map_clean
293 else
294 make -f Makefile.aperl map_clean
295 exit 1
296 fi
297 fi
298
299 make install UNINST=1
300 EOF
301 chmod 755 "$PERL_PREFIX"/bin/cpan-make-install
302
303 # trick CPAN into avoiding ~/.cpan completely
304 echo 1 >"$PERL_PREFIX/lib/CPAN/MyConfig.pm"
305
306 "$PERL_PREFIX"/bin/perl -MCPAN -e '
307 CPAN::Shell->o (conf => urllist => push => "'"$CPAN"'");
308 CPAN::Shell->o (conf => q<cpan_home>, "'"$STATICPERL"'/cpan");
309 CPAN::Shell->o (conf => q<init>);
310 CPAN::Shell->o (conf => q<cpan_home>, "'"$STATICPERL"'/cpan");
311 CPAN::Shell->o (conf => q<build_dir>, "'"$STATICPERL"'/cpan/build");
312 CPAN::Shell->o (conf => q<prefs_dir>, "'"$STATICPERL"'/cpan/prefs");
313 CPAN::Shell->o (conf => q<histfile> , "'"$STATICPERL"'/cpan/histfile");
314 CPAN::Shell->o (conf => q<keep_source_where>, "'"$STATICPERL"'/cpan/sources");
315 CPAN::Shell->o (conf => q<make_install_make_command>, "'"$PERL_PREFIX"'/bin/cpan-make-install");
316 CPAN::Shell->o (conf => q<prerequisites_policy>, q<follow>);
317 CPAN::Shell->o (conf => q<build_requires_install_policy>, q<no>);
318 CPAN::Shell->o (conf => q<commit>);
319 ' || fatal "error while initialising CPAN"
320
321 touch "$PERL_PREFIX/staticstamp.install"
322 fi
323
324 if ! [ -e "$PERL_PREFIX/staticstamp.postinstall" ]; then
325 NOCHECK_INSTALL=+
326 instcpan $STATICPERL_MODULES
327 [ $EXTRA_MODULES ] && instcpan $EXTRA_MODULES
328
329 postinstall || fatal "postinstall hook failed"
330
331 touch "$PERL_PREFIX/staticstamp.postinstall"
332 fi
333 }
334
335 #############################################################################
336 # install a module from CPAN
337
338 instcpan() {
339 [ $NOCHECK_INSTALL ] || install
340
341 verblock <<EOF
342 installing modules from CPAN
343 $@
344 EOF
345
346 for mod in "$@"; do
347 "$PERL_PREFIX"/bin/perl -MCPAN -e 'notest install => "'"$mod"'"' \
348 || fatal "$mod: unable to install from CPAN"
349 done
350 rm -rf "$STATICPERL/build"
351 }
352
353 #############################################################################
354 # install a module from unpacked sources
355
356 instsrc() {
357 [ $NOCHECK_INSTALL ] || install
358
359 verblock <<EOF
360 installing modules from source
361 $@
362 EOF
363
364 for mod in "$@"; do
365 echo
366 echo $mod
367 (
368 rcd $mod
369 make -f Makefile.aperl map_clean >/dev/null 2>&1
370 make distclean >/dev/null 2>&1
371 "$PERL_PREFIX"/bin/perl Makefile.PL || fatal "$mod: error running Makefile.PL"
372 make || fatal "$mod: error building module"
373 "$PERL_PREFIX"/bin/cpan-make-install || fatal "$mod: error installing module"
374 make distclean >/dev/null 2>&1
375 exit 0
376 ) || exit $?
377 done
378 }
379
380 #############################################################################
381 # main
382
383 podusage() {
384 echo
385
386 if [ -e "$PERL_PREFIX/bin/perl" ]; then
387 "$PERL_PREFIX/bin/perl" -MPod::Usage -e \
388 'pod2usage -input => *STDIN, -output => *STDOUT, -verbose => '$1', -exitval => 0, -noperldoc => 1' <"$0" \
389 2>/dev/null && exit
390 fi
391
392 # try whatever perl we can find
393 perl -MPod::Usage -e \
394 'pod2usage -input => *STDIN, -output => *STDOUT, -verbose => '$1', -exitval => 0, -noperldoc => 1' <"$0" \
395 2>/dev/null && exit
396
397 fatal "displaying documentation requires a working perl - try '$0 install' to build one in a safe location"
398 }
399
400 usage() {
401 podusage 0
402 }
403
404 catmkbundle() {
405 {
406 read dummy
407 echo "#!$PERL_PREFIX/bin/perl"
408 cat
409 } <<'MKBUNDLE'
410 #CAT mkbundle
411 MKBUNDLE
412 }
413
414 bundle() {
415 catmkbundle >"$MKBUNDLE~" || fatal "$MKBUNDLE~: cannot create"
416 chmod 755 "$MKBUNDLE~" && mv "$MKBUNDLE~" "$MKBUNDLE"
417 CACHE="$STATICPERL/cache"
418 mkdir -p "$CACHE"
419 "$PERL_PREFIX/bin/perl" -- "$MKBUNDLE" --cache "$CACHE" "$@"
420 }
421
422 if [ $# -gt 0 ]; then
423 while [ $# -gt 0 ]; do
424 mkdir -p "$STATICPERL" || fatal "$STATICPERL: cannot create"
425 mkdir -p "$PERL_PREFIX" || fatal "$PERL_PREFIX: cannot create"
426
427 command="${1#--}"; shift
428 case "$command" in
429 version )
430 echo "staticperl version $VERSION"
431 ;;
432 fetch | configure | build | install | clean | distclean)
433 ( "$command" )
434 ;;
435 instsrc )
436 ( instsrc "$@" )
437 exit
438 ;;
439 instcpan )
440 ( instcpan "$@" )
441 exit
442 ;;
443 cpan )
444 ( install )
445 "$PERL_PREFIX/bin/cpan" "$@"
446 exit
447 ;;
448 mkbundle )
449 ( install )
450 bundle "$@"
451 exit
452 ;;
453 mkperl )
454 ( install )
455 bundle --perl "$@"
456 exit
457 ;;
458 mkapp )
459 ( install )
460 bundle --app "$@"
461 exit
462 ;;
463 help )
464 podusage 2
465 ;;
466 * )
467 exec 1>&2
468 echo
469 echo "Unknown command: $command"
470 podusage 0
471 ;;
472 esac
473 done
474 else
475 usage
476 fi
477
478 exit 0
479
480 #CAT staticperl.pod
481