ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/App-Staticperl/staticperl.sh
Revision: 1.4
Committed: Tue Dec 7 09:27:54 2010 UTC (13 years, 7 months ago) by root
Content type: application/x-sh
Branch: MAIN
Changes since 1.3: +2 -0 lines
Log Message:
*** empty log message ***

File Contents

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