ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/App-Staticperl/staticperl.sh
Revision: 1.15
Committed: Fri Dec 10 21:15:06 2010 UTC (13 years, 6 months ago) by root
Content type: application/x-sh
Branch: MAIN
CVS Tags: rel-0_91
Changes since 1.14: +1 -1 lines
Log Message:
0.91

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