ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/App-Staticperl/staticperl.sh
Revision: 1.3
Committed: Mon Dec 6 21:10:41 2010 UTC (13 years, 7 months ago) by root
Content type: application/x-sh
Branch: MAIN
Changes since 1.2: +1 -1 lines
Log Message:
*** empty log message ***

File Contents

# Content
1 #!/bin/sh
2
3 #############################################################################
4 # configuration to fill in
5
6 PERLVER=5.12.2 # 5.8.9 is also a good choice
7 STATICPERL=~/.staticperl
8 CPAN=http://mirror.netcologne.de/cpan/ # which mirror to use
9 EMAIL="read the documentation <rtfm@example.org>"
10
11 MKBUNDLE="$STATICPERL/mkbundle"
12
13 # perl build variables
14 PREFIX="$STATICPERL/perl" # where the perl gets installed
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 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 # -z muldefs is to work around uclibc's pthread static linking bug
34 PERL_LDFLAGS="-Wl,--no-gc-sections -z muldefs"
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 postconfigure() { : ; }
51 postbuild() { : ; }
52 postinstall() { : ; }
53
54 # now source user config, if any
55 [ -r /etc/staticperlrc ] && . /etc/staticperlrc
56 [ -r ~/.staticperlrc ] && . ~/.staticperlrc
57 [ -r "$STATICPERL/rc" ] && . "$STATICPERL/rc"
58
59 #############################################################################
60 # support
61
62 # set version in a way that Makefile.PL can extract
63 VERSION=VERSION; eval \
64 $VERSION=0.1
65
66 BZ2=bz2
67 BZIP2=bzip2
68
69 fatal() {
70 printf -- "\nFATAL: %s\n\n" "$*" >&2
71 exit 1
72 }
73
74 verbose() {
75 printf -- "%s\n" "$*"
76 }
77
78 verblock() {
79 verbose
80 verbose "***"
81 while read line; do
82 verbose "*** $line"
83 done
84 verbose "***"
85 verbose
86 }
87
88 rcd() {
89 cd "$1" || fatal "$1: cannot enter"
90 }
91
92 trace() {
93 prefix="$1"; shift
94 # "$@" 2>&1 | while read line; do
95 # echo "$prefix: $line"
96 # done
97 "$@"
98 }
99
100 trap wait 0
101
102 #############################################################################
103 # clean
104
105 distclean() {
106 verblock <<EOF
107 deleting everything installed by this script
108 EOF
109
110 rm -rf "$STATICPERL"
111 }
112
113 #############################################################################
114 # download/configure/compile/install perl
115
116 clean() {
117 cd "$STATICPERL/src/perl-$PERLVER" 2>/dev/null || return
118
119 rm -f staticstamp.configure
120 make distclean >/dev/null 2>&1
121 }
122
123 fetch() {
124 rcd "$STATICPERL"
125
126 mkdir -p src
127 rcd src
128
129 if ! [ -d "perl-$PERLVER" ]; then
130 if ! [ -e "perl-$PERLVER.tar.$BZ2" ]; then
131
132 URL="$CPAN/src/5.0/perl-$PERLVER.tar.$BZ2"
133
134 verblock <<EOF
135 downloading perl
136 to manually download perl yourself, place
137 perl-$PERLVER.tar.$BZ2 in $STATICPERL
138 trying $URL
139 EOF
140
141 curl >perl-$PERLVER.tar.$BZ2~ "$URL" \
142 || wget -O perl-$PERLVER.tar.$BZ2~ "$URL" \
143 || fatal "$URL: error during downloading"
144 mv perl-$PERLVER.tar.$BZ2~ perl-$PERLVER.tar.$BZ2
145 fi
146
147 verblock <<EOF
148 unpacking perl
149 EOF
150
151 mkdir -p unpack
152 $BZIP2 -d <perl-$PERLVER.tar.bz2 | tar xpC unpack \
153 || fatal "perl-$PERLVER.tar.bz2: error during unpacking"
154 mv unpack/perl-$PERLVER perl-$PERLVER
155 rmdir -p unpack
156 fi
157 }
158
159 # similar to GNU-sed -i or perl -pi
160 sedreplace() {
161 sed -e "$1" <"$2" > "$2~" || fatal "error while running sed"
162 mv "$2~" "$2"
163 }
164
165 configure() {
166 fetch
167
168 rcd "$STATICPERL/src/perl-$PERLVER"
169
170 [ -e staticstamp.configure ] && return
171
172 verblock <<EOF
173 configuring $STATICPERL/src/perl-$PERLVER
174 EOF
175
176 clean
177
178 rm -f "$PREFIX/staticstamp.install"
179
180 # I hate them
181 grep -q -- -fstack-protector Configure && \
182 sedreplace 's/-fstack-protector/-fno-stack-protector/g' Configure
183
184 # trace configure \
185 sh Configure -Duselargefiles \
186 -Uuse64bitint \
187 -Dusemymalloc=n \
188 -Uusedl \
189 -Uusethreads \
190 -Uuseithreads \
191 -Uusemultiplicity \
192 -Duseperlio \
193 -Uusesfio \
194 -Uuseshrplib \
195 -Dcppflags="$PERL_CPPFLAGS" \
196 -Dccflags="-g2 -fno-strict-aliasing" \
197 -Doptimize="$PERL_OPTIMIZE" \
198 -Dldflags="$PERL_LDFLAGS" \
199 -Dlibs="$PERL_LIBS" \
200 -Dprefix="$PREFIX" \
201 -Dbin="$PREFIX/bin" \
202 -Dprivlib="$PREFIX/lib" \
203 -Darchlib="$PREFIX/lib" \
204 -Uusevendorprefix \
205 -Dsitelib="$PREFIX/lib" \
206 -Dsitearch="$PREFIX/lib" \
207 -Usitelibexp \
208 -Uman1dir \
209 -Uman3dir \
210 -Usiteman1dir \
211 -Usiteman3dir \
212 -Dpager=/usr/bin/less \
213 -Demail="$EMAIL" \
214 -Dcf_email="$EMAIL" \
215 -Dcf_by="$EMAIL" \
216 -dE || fatal "Configure failed"
217
218 sedreplace '
219 s/-Wl,--no-gc-sections/-Wl,--gc-sections/g
220 s/ *-fno-stack-protector */ /g
221 ' config.sh
222
223 sh Configure -S || fatal "Configure -S failed"
224
225 postconfigure || fatal "postconfigure hook failed"
226
227 touch staticstamp.configure
228 }
229
230 build() {
231 configure
232
233 rcd "$STATICPERL/src/perl-$PERLVER"
234
235 verblock <<EOF
236 building $STATICPERL/src/perl-$PERLVER
237 EOF
238
239 rm -f "$PREFIX/staticstamp.install"
240
241 make || fatal "make: error while building perl"
242
243 postbuild || fatal "postbuild hook failed"
244 }
245
246 install() {
247 [ -e "$PREFIX/staticstamp.install" ] && return
248
249 build
250
251 verblock <<EOF
252 installing $STATICPERL/src/perl-$PERLVER
253 to $PREFIX
254 EOF
255
256 rm -rf "$PREFIX"
257
258 make install || fatal "make install: error while installing"
259
260 rcd "$PREFIX"
261
262 # create a "make install" replacement for CPAN
263 cat >"$PREFIX"/bin/cpan-make-install <<EOF
264 make install UNINST=1
265 if find blib/arch/auto -type f | grep -q -v .exists; then
266 echo Probably an XS module, rebuilding perl
267 make perl
268 rm -f "$PREFIX"/bin/perl
269 make -f Makefile.aperl inst_perl
270 make -f Makefile.aperl map_clean
271 fi
272 EOF
273 chmod 755 "$PREFIX"/bin/cpan-make-install
274
275 # trick CPAN into avoiding ~/.cpan completely
276 echo 1 >"$PREFIX/lib/CPAN/MyConfig.pm"
277
278 "$PREFIX"/bin/perl -MCPAN -e '
279 CPAN::Shell->o (conf => urllist => push => "'"$CPAN"'");
280 CPAN::Shell->o (conf => q<cpan_home>, "'"$STATICPERL"'/cpan");
281 CPAN::Shell->o (conf => q<init>);
282 CPAN::Shell->o (conf => q<cpan_home>, "'"$STATICPERL"'/cpan");
283 CPAN::Shell->o (conf => q<build_dir>, "'"$STATICPERL"'/cpan/build");
284 CPAN::Shell->o (conf => q<prefs_dir>, "'"$STATICPERL"'/cpan/prefs");
285 CPAN::Shell->o (conf => q<histfile> , "'"$STATICPERL"'/cpan/histfile");
286 CPAN::Shell->o (conf => q<keep_source_where>, "'"$STATICPERL"'/cpan/sources");
287 CPAN::Shell->o (conf => q<make_install_make_command>, "'"$PREFIX"'/bin/cpan-make-install");
288 CPAN::Shell->o (conf => q<prerequisites_policy>, q<follow>);
289 CPAN::Shell->o (conf => q<build_requires_install_policy>, q<no>);
290 CPAN::Shell->o (conf => q<commit>);
291 ' || fatal "error while initialising CPAN"
292
293 NOCHECK_INSTALL=+
294 instcpan $STATICPERL_MODULES
295 [ $EXTRA_MODULES ] && instcpan $EXTRA_MODULES
296
297 postinstall || fatal "postinstall hook failed"
298
299 touch "$PREFIX/staticstamp.install"
300 }
301
302 #############################################################################
303 # install a module from CPAN
304
305 instcpan() {
306 [ $NOCHECK_INSTALL ] || install
307
308 verblock <<EOF
309 installing modules from CPAN
310 $@
311 EOF
312
313 for mod in "$@"; do
314 "$PREFIX"/bin/perl -MCPAN -e 'notest install => "'"$mod"'"' \
315 || fatal "$mod: unable to install from CPAN"
316 done
317 rm -rf "$STATICPERL/build"
318 }
319
320 #############################################################################
321 # install a module from unpacked sources
322
323 instsrc() {
324 [ $NOCHECK_INSTALL ] || install
325
326 verblock <<EOF
327 installing modules from source
328 $@
329 EOF
330
331 for mod in "$@"; do
332 echo
333 echo $mod
334 (
335 rcd $mod
336 make -f Makefile.aperl map_clean >/dev/null 2>&1
337 make distclean >/dev/null 2>&1
338 "$PREFIX"/bin/perl Makefile.PL || fatal "$mod: error running Makefile.PL"
339 make || fatal "$mod: error building module"
340 "$PREFIX"/bin/cpan-make-install || fatal "$mod: error installing module"
341 make distclean >/dev/null 2>&1
342 exit 0
343 ) || exit $?
344 done
345 }
346
347 #############################################################################
348 # do schmorpy stuff
349
350 MODSRCDIR=~/src
351
352 instmodsrc() {
353 for mod in "$@"; do
354 instmod_src "$MODSRCDIR/$mod"
355 done
356 }
357
358 install_schmorp() {
359 install
360
361 instcpan Data::Dump Term::ReadLine::Perl Term::ANSIColor Term::ReadKey
362 instcpan Digest::SHA Digest::MD6 Digest::SHA256 Digest::MD4 Digest::HMAC_MD5 Digest::HMAC_MD6 Digest::FNV
363 #instcpan Net::SSLeay # requires static -ldl
364
365 instmodsrc common-sense Crypt-Twofish2 Array-Heap Convert-Scalar Compress-LZF JSON-XS
366 instmodsrc EV Guard Async-Interrupt IO-AIO
367 instmodsrc AnyEvent AnyEvent-AIO Coro AnyEvent-HTTP
368 instmodsrc Linux-Inotify2 EV-Loop-Async
369
370 instcpan AnyEvent::HTTPD
371 }
372
373 #############################################################################
374 # main
375
376 podusage() {
377 echo
378 if [ -e "$PREFIX/bin/perl" ]; then
379 "$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 "#!$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 "$PREFIX/bin/perl" -- "$MKBUNDLE" "$@"
409 }
410
411 if [ $# -gt 0 ]; then
412 while [ $# -gt 0 ]; do
413 mkdir -p "$STATICPERL" || fatal "$STATICPERL: cannot create"
414 mkdir -p "$PREFIX" || fatal "$PREFIX: cannot create"
415
416 command="${1#--}"; shift
417 case "$command" in
418 fetch | configure | build | install | clean | distclean)
419 verblock <<EOF
420 $command
421 EOF
422 "$command"
423 ;;
424 instsrc )
425 instsrc "$@"
426 exit
427 ;;
428 instcpan )
429 instcpan "$@"
430 exit
431 ;;
432 instschmorp )
433 install_schmorp
434 ;;
435 cpan )
436 install
437 "$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 help )
451 podusage 2
452 ;;
453 * )
454 exec 1>&2
455 echo
456 echo "Unknown command: $command"
457 podusage 0
458 ;;
459 esac
460 done
461 else
462 usage
463 fi
464
465 exit 0
466
467 #CAT staticperl.pod
468