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