ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/App-Staticperl/staticperl.sh
Revision: 1.7
Committed: Tue Dec 7 13:23:07 2010 UTC (13 years, 6 months ago) by root
Content type: application/x-sh
Branch: MAIN
Changes since 1.6: +4 -4 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     STATICPERL=~/.staticperl
7     CPAN=http://mirror.netcologne.de/cpan/ # which mirror to use
8     EMAIL="read the documentation <rtfm@example.org>"
9    
10     MKBUNDLE="$STATICPERL/mkbundle"
11    
12     # perl build variables
13 root 1.6 PERL_PREFIX="$STATICPERL/perl" # where the perl gets installed
14     PERL_VERSION=5.12.2 # 5.8.9 is also a good choice
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 root 1.7 preconfigure() { : ; }
52 root 1.1 postconfigure() { : ; }
53     postbuild() { : ; }
54     postinstall() { : ; }
55    
56     # now source user config, if any
57     [ -r /etc/staticperlrc ] && . /etc/staticperlrc
58     [ -r ~/.staticperlrc ] && . ~/.staticperlrc
59     [ -r "$STATICPERL/rc" ] && . "$STATICPERL/rc"
60    
61     #############################################################################
62     # support
63    
64     # set version in a way that Makefile.PL can extract
65     VERSION=VERSION; eval \
66     $VERSION=0.1
67    
68     BZ2=bz2
69     BZIP2=bzip2
70    
71     fatal() {
72     printf -- "\nFATAL: %s\n\n" "$*" >&2
73     exit 1
74     }
75    
76     verbose() {
77     printf -- "%s\n" "$*"
78     }
79    
80     verblock() {
81     verbose
82     verbose "***"
83     while read line; do
84     verbose "*** $line"
85     done
86     verbose "***"
87     verbose
88     }
89    
90     rcd() {
91     cd "$1" || fatal "$1: cannot enter"
92     }
93    
94     trace() {
95     prefix="$1"; shift
96     # "$@" 2>&1 | while read line; do
97     # echo "$prefix: $line"
98     # done
99     "$@"
100     }
101    
102     trap wait 0
103    
104     #############################################################################
105     # clean
106    
107     distclean() {
108     verblock <<EOF
109     deleting everything installed by this script
110     EOF
111    
112     rm -rf "$STATICPERL"
113     }
114    
115     #############################################################################
116     # download/configure/compile/install perl
117    
118     clean() {
119 root 1.7 rm -rf "$STATICPERL/src/perl-$PERL_VERSION"
120 root 1.1 }
121    
122     fetch() {
123     rcd "$STATICPERL"
124    
125     mkdir -p src
126     rcd src
127    
128 root 1.6 if ! [ -d "perl-$PERL_VERSION" ]; then
129     if ! [ -e "perl-$PERL_VERSION.tar.$BZ2" ]; then
130 root 1.1
131 root 1.6 URL="$CPAN/src/5.0/perl-$PERL_VERSION.tar.$BZ2"
132 root 1.1
133     verblock <<EOF
134     downloading perl
135     to manually download perl yourself, place
136 root 1.6 perl-$PERL_VERSION.tar.$BZ2 in $STATICPERL
137 root 1.1 trying $URL
138     EOF
139    
140 root 1.6 rm -f perl-$PERL_VERSION.tar.$BZ2~ # just to be on the safe side
141     wget -O perl-$PERL_VERSION.tar.$BZ2~ "$URL" \
142     || curl >perl-$PERL_VERSION.tar.$BZ2~ "$URL" \
143 root 1.5 || fatal "$URL: unable to download"
144 root 1.6 mv perl-$PERL_VERSION.tar.$BZ2~ perl-$PERL_VERSION.tar.$BZ2
145 root 1.1 fi
146    
147     verblock <<EOF
148     unpacking perl
149     EOF
150    
151     mkdir -p unpack
152 root 1.6 $BZIP2 -d <perl-$PERL_VERSION.tar.bz2 | tar xpC unpack \
153     || fatal "perl-$PERL_VERSION.tar.bz2: error during unpacking"
154     mv unpack/perl-$PERL_VERSION perl-$PERL_VERSION
155 root 1.1 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 root 1.6 rcd "$STATICPERL/src/perl-$PERL_VERSION"
169 root 1.1
170     [ -e staticstamp.configure ] && return
171    
172     verblock <<EOF
173 root 1.6 configuring $STATICPERL/src/perl-$PERL_VERSION
174 root 1.1 EOF
175    
176     clean
177    
178 root 1.6 rm -f "$PERL_PREFIX/staticstamp.install"
179 root 1.1
180     # I hate them
181     grep -q -- -fstack-protector Configure && \
182     sedreplace 's/-fstack-protector/-fno-stack-protector/g' Configure
183    
184 root 1.7 preconfigure
185    
186 root 1.1 # trace configure \
187     sh Configure -Duselargefiles \
188     -Uuse64bitint \
189     -Dusemymalloc=n \
190     -Uusedl \
191     -Uusethreads \
192     -Uuseithreads \
193     -Uusemultiplicity \
194     -Duseperlio \
195     -Uusesfio \
196     -Uuseshrplib \
197     -Dcppflags="$PERL_CPPFLAGS" \
198     -Dccflags="-g2 -fno-strict-aliasing" \
199     -Doptimize="$PERL_OPTIMIZE" \
200     -Dldflags="$PERL_LDFLAGS" \
201     -Dlibs="$PERL_LIBS" \
202 root 1.6 -Dprefix="$PERL_PREFIX" \
203     -Dbin="$PERL_PREFIX/bin" \
204     -Dprivlib="$PERL_PREFIX/lib" \
205     -Darchlib="$PERL_PREFIX/lib" \
206 root 1.1 -Uusevendorprefix \
207 root 1.6 -Dsitelib="$PERL_PREFIX/lib" \
208     -Dsitearch="$PERL_PREFIX/lib" \
209 root 1.1 -Usitelibexp \
210     -Uman1dir \
211     -Uman3dir \
212     -Usiteman1dir \
213     -Usiteman3dir \
214     -Dpager=/usr/bin/less \
215     -Demail="$EMAIL" \
216     -Dcf_email="$EMAIL" \
217     -Dcf_by="$EMAIL" \
218 root 1.4 $PERL_CONFIGURE \
219 root 1.1 -dE || fatal "Configure failed"
220    
221     sedreplace '
222     s/-Wl,--no-gc-sections/-Wl,--gc-sections/g
223     s/ *-fno-stack-protector */ /g
224     ' config.sh
225    
226     sh Configure -S || fatal "Configure -S failed"
227    
228     postconfigure || fatal "postconfigure hook failed"
229    
230     touch staticstamp.configure
231     }
232    
233     build() {
234     configure
235    
236 root 1.6 rcd "$STATICPERL/src/perl-$PERL_VERSION"
237 root 1.1
238     verblock <<EOF
239 root 1.6 building $STATICPERL/src/perl-$PERL_VERSION
240 root 1.1 EOF
241    
242 root 1.6 rm -f "$PERL_PREFIX/staticstamp.install"
243 root 1.1
244     make || fatal "make: error while building perl"
245    
246     postbuild || fatal "postbuild hook failed"
247     }
248    
249     install() {
250 root 1.6 [ -e "$PERL_PREFIX/staticstamp.install" ] && return
251 root 1.1
252     build
253    
254     verblock <<EOF
255 root 1.6 installing $STATICPERL/src/perl-$PERL_VERSION
256     to $PERL_PREFIX
257 root 1.1 EOF
258    
259 root 1.6 rm -rf "$PERL_PREFIX"
260 root 1.1
261     make install || fatal "make install: error while installing"
262    
263 root 1.6 rcd "$PERL_PREFIX"
264 root 1.2
265 root 1.1 # create a "make install" replacement for CPAN
266 root 1.6 cat >"$PERL_PREFIX"/bin/cpan-make-install <<EOF
267 root 1.1 make install UNINST=1
268     if find blib/arch/auto -type f | grep -q -v .exists; then
269     echo Probably an XS module, rebuilding perl
270     make perl
271 root 1.6 rm -f "$PERL_PREFIX"/bin/perl
272 root 1.1 make -f Makefile.aperl inst_perl
273     make -f Makefile.aperl map_clean
274     fi
275     EOF
276 root 1.6 chmod 755 "$PERL_PREFIX"/bin/cpan-make-install
277 root 1.1
278 root 1.3 # trick CPAN into avoiding ~/.cpan completely
279 root 1.6 echo 1 >"$PERL_PREFIX/lib/CPAN/MyConfig.pm"
280 root 1.2
281 root 1.6 "$PERL_PREFIX"/bin/perl -MCPAN -e '
282 root 1.1 CPAN::Shell->o (conf => urllist => push => "'"$CPAN"'");
283 root 1.2 CPAN::Shell->o (conf => q<cpan_home>, "'"$STATICPERL"'/cpan");
284 root 1.1 CPAN::Shell->o (conf => q<init>);
285     CPAN::Shell->o (conf => q<cpan_home>, "'"$STATICPERL"'/cpan");
286     CPAN::Shell->o (conf => q<build_dir>, "'"$STATICPERL"'/cpan/build");
287     CPAN::Shell->o (conf => q<prefs_dir>, "'"$STATICPERL"'/cpan/prefs");
288     CPAN::Shell->o (conf => q<histfile> , "'"$STATICPERL"'/cpan/histfile");
289     CPAN::Shell->o (conf => q<keep_source_where>, "'"$STATICPERL"'/cpan/sources");
290 root 1.6 CPAN::Shell->o (conf => q<make_install_make_command>, "'"$PERL_PREFIX"'/bin/cpan-make-install");
291 root 1.1 CPAN::Shell->o (conf => q<prerequisites_policy>, q<follow>);
292     CPAN::Shell->o (conf => q<build_requires_install_policy>, q<no>);
293     CPAN::Shell->o (conf => q<commit>);
294     ' || fatal "error while initialising CPAN"
295    
296     NOCHECK_INSTALL=+
297 root 1.2 instcpan $STATICPERL_MODULES
298     [ $EXTRA_MODULES ] && instcpan $EXTRA_MODULES
299 root 1.1
300     postinstall || fatal "postinstall hook failed"
301    
302 root 1.6 touch "$PERL_PREFIX/staticstamp.install"
303 root 1.1 }
304    
305     #############################################################################
306     # install a module from CPAN
307    
308     instcpan() {
309     [ $NOCHECK_INSTALL ] || install
310    
311     verblock <<EOF
312     installing modules from CPAN
313     $@
314     EOF
315    
316     for mod in "$@"; do
317 root 1.6 "$PERL_PREFIX"/bin/perl -MCPAN -e 'notest install => "'"$mod"'"' \
318 root 1.1 || fatal "$mod: unable to install from CPAN"
319     done
320     rm -rf "$STATICPERL/build"
321     }
322    
323     #############################################################################
324     # install a module from unpacked sources
325    
326     instsrc() {
327     [ $NOCHECK_INSTALL ] || install
328    
329     verblock <<EOF
330     installing modules from source
331     $@
332     EOF
333    
334     for mod in "$@"; do
335     echo
336     echo $mod
337     (
338     rcd $mod
339     make -f Makefile.aperl map_clean >/dev/null 2>&1
340     make distclean >/dev/null 2>&1
341 root 1.6 "$PERL_PREFIX"/bin/perl Makefile.PL || fatal "$mod: error running Makefile.PL"
342 root 1.1 make || fatal "$mod: error building module"
343 root 1.6 "$PERL_PREFIX"/bin/cpan-make-install || fatal "$mod: error installing module"
344 root 1.1 make distclean >/dev/null 2>&1
345     exit 0
346     ) || exit $?
347     done
348     }
349    
350     #############################################################################
351     # main
352    
353     podusage() {
354     echo
355 root 1.6 if [ -e "$PERL_PREFIX/bin/perl" ]; then
356     "$PERL_PREFIX/bin/perl" -MPod::Usage -e \
357 root 1.1 'pod2usage -input => *STDIN, -output => *STDOUT, -verbose => '$1', -exitval => 0, -noperldoc => 1' <"$0" \
358     2>/dev/null && exit
359     fi
360     # try whatever perl we can find
361     perl -MPod::Usage -e \
362     'pod2usage -input => *STDIN, -output => *STDOUT, -verbose => '$1', -exitval => 0, -noperldoc => 1' <"$0" \
363     2>/dev/null && exit
364    
365     fatal "displaying documentation requires a working perl - try '$0 install' first"
366     }
367    
368     usage() {
369     podusage 0
370     }
371    
372     catmkbundle() {
373     {
374     read dummy
375 root 1.6 echo "#!$PERL_PREFIX/bin/perl"
376 root 1.1 cat
377     } <<'MKBUNDLE'
378     #CAT mkbundle
379     MKBUNDLE
380     }
381    
382     bundle() {
383     catmkbundle >"$MKBUNDLE~" || fatal "$MKBUNDLE~: cannot create"
384     chmod 755 "$MKBUNDLE~" && mv "$MKBUNDLE~" "$MKBUNDLE"
385 root 1.6 "$PERL_PREFIX/bin/perl" -- "$MKBUNDLE" "$@"
386 root 1.1 }
387    
388     if [ $# -gt 0 ]; then
389     while [ $# -gt 0 ]; do
390     mkdir -p "$STATICPERL" || fatal "$STATICPERL: cannot create"
391 root 1.6 mkdir -p "$PERL_PREFIX" || fatal "$PERL_PREFIX: cannot create"
392 root 1.1
393     command="${1#--}"; shift
394     case "$command" in
395     fetch | configure | build | install | clean | distclean)
396     verblock <<EOF
397     $command
398     EOF
399 root 1.6 ( "$command" )
400 root 1.1 ;;
401     instsrc )
402 root 1.6 ( instsrc "$@" )
403 root 1.1 exit
404     ;;
405     instcpan )
406 root 1.6 ( instcpan "$@" )
407 root 1.1 exit
408     ;;
409     cpan )
410 root 1.6 ( install )
411     "$PERL_PREFIX/bin/cpan" "$@"
412 root 1.1 exit
413     ;;
414     mkbundle )
415 root 1.6 ( install )
416 root 1.1 bundle "$@"
417     exit
418     ;;
419     mkperl )
420 root 1.6 ( install )
421 root 1.1 bundle --perl "$@"
422     exit
423     ;;
424     help )
425     podusage 2
426     ;;
427     * )
428     exec 1>&2
429     echo
430     echo "Unknown command: $command"
431     podusage 0
432     ;;
433     esac
434     done
435     else
436     usage
437     fi
438    
439     exit 0
440    
441     #CAT staticperl.pod
442