ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/App-Staticperl/staticperl.sh
Revision: 1.10
Committed: Tue Dec 7 21:22:12 2010 UTC (13 years, 6 months ago) by root
Content type: application/x-sh
Branch: MAIN
CVS Tags: rel-0_2
Changes since 1.9: +13 -7 lines
Log Message:
rel-0.2

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 root 1.10 $VERSION=0.2
67 root 1.1
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.8 $BZIP2 -d <perl-$PERL_VERSION.tar.bz2 | tar xC unpack \
153 root 1.6 || fatal "perl-$PERL_VERSION.tar.bz2: error during unpacking"
154 root 1.8 chmod -R u+w unpack/perl-$PERL_VERSION
155 root 1.6 mv unpack/perl-$PERL_VERSION perl-$PERL_VERSION
156 root 1.1 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 root 1.6 rcd "$STATICPERL/src/perl-$PERL_VERSION"
170 root 1.1
171     [ -e staticstamp.configure ] && return
172    
173     verblock <<EOF
174 root 1.6 configuring $STATICPERL/src/perl-$PERL_VERSION
175 root 1.1 EOF
176    
177 root 1.8 rm -f "$PERL_PREFIX/staticstamp.install"
178 root 1.1
179 root 1.8 make distclean >/dev/null 2>&1
180 root 1.1
181     # I hate them
182     grep -q -- -fstack-protector Configure && \
183     sedreplace 's/-fstack-protector/-fno-stack-protector/g' Configure
184    
185 root 1.7 preconfigure
186    
187 root 1.1 # trace configure \
188     sh Configure -Duselargefiles \
189     -Uuse64bitint \
190     -Dusemymalloc=n \
191     -Uusedl \
192     -Uusethreads \
193     -Uuseithreads \
194     -Uusemultiplicity \
195     -Duseperlio \
196     -Uusesfio \
197     -Uuseshrplib \
198     -Dcppflags="$PERL_CPPFLAGS" \
199     -Dccflags="-g2 -fno-strict-aliasing" \
200     -Doptimize="$PERL_OPTIMIZE" \
201     -Dldflags="$PERL_LDFLAGS" \
202     -Dlibs="$PERL_LIBS" \
203 root 1.6 -Dprefix="$PERL_PREFIX" \
204     -Dbin="$PERL_PREFIX/bin" \
205     -Dprivlib="$PERL_PREFIX/lib" \
206     -Darchlib="$PERL_PREFIX/lib" \
207 root 1.1 -Uusevendorprefix \
208 root 1.6 -Dsitelib="$PERL_PREFIX/lib" \
209     -Dsitearch="$PERL_PREFIX/lib" \
210 root 1.1 -Usitelibexp \
211     -Uman1dir \
212     -Uman3dir \
213     -Usiteman1dir \
214     -Usiteman3dir \
215     -Dpager=/usr/bin/less \
216     -Demail="$EMAIL" \
217     -Dcf_email="$EMAIL" \
218     -Dcf_by="$EMAIL" \
219 root 1.4 $PERL_CONFIGURE \
220 root 1.1 -dE || fatal "Configure failed"
221    
222     sedreplace '
223     s/-Wl,--no-gc-sections/-Wl,--gc-sections/g
224     s/ *-fno-stack-protector */ /g
225     ' config.sh
226    
227     sh Configure -S || fatal "Configure -S failed"
228    
229     postconfigure || fatal "postconfigure hook failed"
230    
231     touch staticstamp.configure
232     }
233    
234     build() {
235     configure
236    
237 root 1.6 rcd "$STATICPERL/src/perl-$PERL_VERSION"
238 root 1.1
239     verblock <<EOF
240 root 1.6 building $STATICPERL/src/perl-$PERL_VERSION
241 root 1.1 EOF
242    
243 root 1.6 rm -f "$PERL_PREFIX/staticstamp.install"
244 root 1.1
245     make || fatal "make: error while building perl"
246    
247     postbuild || fatal "postbuild hook failed"
248     }
249    
250     install() {
251 root 1.9 if ! [ -e "$PERL_PREFIX/staticstamp.install" ]; then
252     build
253 root 1.1
254 root 1.9 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.9 rm -rf "$PERL_PREFIX"
260    
261     make install || fatal "make install: error while installing"
262 root 1.1
263 root 1.9 rcd "$PERL_PREFIX"
264 root 1.2
265 root 1.9 # create a "make install" replacement for CPAN
266     cat >"$PERL_PREFIX"/bin/cpan-make-install <<EOF
267 root 1.10 make || exit
268    
269 root 1.1 if find blib/arch/auto -type f | grep -q -v .exists; then
270     echo Probably an XS module, rebuilding perl
271 root 1.10 if make perl; then
272     mv perl "$PERL_PREFIX"/bin/perl
273     make -f Makefile.aperl map_clean
274     else
275     make -f Makefile.aperl map_clean
276     exit 1
277     fi
278 root 1.1 fi
279 root 1.10
280     make install UNINST=1
281 root 1.1 EOF
282 root 1.9 chmod 755 "$PERL_PREFIX"/bin/cpan-make-install
283    
284     # trick CPAN into avoiding ~/.cpan completely
285     echo 1 >"$PERL_PREFIX/lib/CPAN/MyConfig.pm"
286 root 1.1
287 root 1.9 "$PERL_PREFIX"/bin/perl -MCPAN -e '
288     CPAN::Shell->o (conf => urllist => push => "'"$CPAN"'");
289     CPAN::Shell->o (conf => q<cpan_home>, "'"$STATICPERL"'/cpan");
290     CPAN::Shell->o (conf => q<init>);
291     CPAN::Shell->o (conf => q<cpan_home>, "'"$STATICPERL"'/cpan");
292     CPAN::Shell->o (conf => q<build_dir>, "'"$STATICPERL"'/cpan/build");
293     CPAN::Shell->o (conf => q<prefs_dir>, "'"$STATICPERL"'/cpan/prefs");
294     CPAN::Shell->o (conf => q<histfile> , "'"$STATICPERL"'/cpan/histfile");
295     CPAN::Shell->o (conf => q<keep_source_where>, "'"$STATICPERL"'/cpan/sources");
296     CPAN::Shell->o (conf => q<make_install_make_command>, "'"$PERL_PREFIX"'/bin/cpan-make-install");
297     CPAN::Shell->o (conf => q<prerequisites_policy>, q<follow>);
298     CPAN::Shell->o (conf => q<build_requires_install_policy>, q<no>);
299     CPAN::Shell->o (conf => q<commit>);
300     ' || fatal "error while initialising CPAN"
301 root 1.2
302 root 1.9 touch "$PERL_PREFIX/staticstamp.install"
303     fi
304    
305 root 1.10 if ! [ -e "$PERL_PREFIX/staticstamp.postinstall" ]; then
306 root 1.9 NOCHECK_INSTALL=+
307     instcpan $STATICPERL_MODULES
308     [ $EXTRA_MODULES ] && instcpan $EXTRA_MODULES
309 root 1.1
310 root 1.9 postinstall || fatal "postinstall hook failed"
311 root 1.1
312 root 1.9 touch "$PERL_PREFIX/staticstamp.postinstall"
313     fi
314 root 1.1 }
315    
316     #############################################################################
317     # install a module from CPAN
318    
319     instcpan() {
320     [ $NOCHECK_INSTALL ] || install
321    
322     verblock <<EOF
323     installing modules from CPAN
324     $@
325     EOF
326    
327     for mod in "$@"; do
328 root 1.6 "$PERL_PREFIX"/bin/perl -MCPAN -e 'notest install => "'"$mod"'"' \
329 root 1.1 || fatal "$mod: unable to install from CPAN"
330     done
331     rm -rf "$STATICPERL/build"
332     }
333    
334     #############################################################################
335     # install a module from unpacked sources
336    
337     instsrc() {
338     [ $NOCHECK_INSTALL ] || install
339    
340     verblock <<EOF
341     installing modules from source
342     $@
343     EOF
344    
345     for mod in "$@"; do
346     echo
347     echo $mod
348     (
349     rcd $mod
350     make -f Makefile.aperl map_clean >/dev/null 2>&1
351     make distclean >/dev/null 2>&1
352 root 1.6 "$PERL_PREFIX"/bin/perl Makefile.PL || fatal "$mod: error running Makefile.PL"
353 root 1.1 make || fatal "$mod: error building module"
354 root 1.6 "$PERL_PREFIX"/bin/cpan-make-install || fatal "$mod: error installing module"
355 root 1.1 make distclean >/dev/null 2>&1
356     exit 0
357     ) || exit $?
358     done
359     }
360    
361     #############################################################################
362     # main
363    
364     podusage() {
365     echo
366 root 1.6 if [ -e "$PERL_PREFIX/bin/perl" ]; then
367     "$PERL_PREFIX/bin/perl" -MPod::Usage -e \
368 root 1.1 'pod2usage -input => *STDIN, -output => *STDOUT, -verbose => '$1', -exitval => 0, -noperldoc => 1' <"$0" \
369     2>/dev/null && exit
370     fi
371     # try whatever perl we can find
372     perl -MPod::Usage -e \
373     'pod2usage -input => *STDIN, -output => *STDOUT, -verbose => '$1', -exitval => 0, -noperldoc => 1' <"$0" \
374     2>/dev/null && exit
375    
376     fatal "displaying documentation requires a working perl - try '$0 install' first"
377     }
378    
379     usage() {
380     podusage 0
381     }
382    
383     catmkbundle() {
384     {
385     read dummy
386 root 1.6 echo "#!$PERL_PREFIX/bin/perl"
387 root 1.1 cat
388     } <<'MKBUNDLE'
389     #CAT mkbundle
390     MKBUNDLE
391     }
392    
393     bundle() {
394     catmkbundle >"$MKBUNDLE~" || fatal "$MKBUNDLE~: cannot create"
395     chmod 755 "$MKBUNDLE~" && mv "$MKBUNDLE~" "$MKBUNDLE"
396 root 1.6 "$PERL_PREFIX/bin/perl" -- "$MKBUNDLE" "$@"
397 root 1.1 }
398    
399     if [ $# -gt 0 ]; then
400     while [ $# -gt 0 ]; do
401     mkdir -p "$STATICPERL" || fatal "$STATICPERL: cannot create"
402 root 1.6 mkdir -p "$PERL_PREFIX" || fatal "$PERL_PREFIX: cannot create"
403 root 1.1
404     command="${1#--}"; shift
405     case "$command" in
406     fetch | configure | build | install | clean | distclean)
407     verblock <<EOF
408     $command
409     EOF
410 root 1.6 ( "$command" )
411 root 1.1 ;;
412     instsrc )
413 root 1.6 ( instsrc "$@" )
414 root 1.1 exit
415     ;;
416     instcpan )
417 root 1.6 ( instcpan "$@" )
418 root 1.1 exit
419     ;;
420     cpan )
421 root 1.6 ( install )
422     "$PERL_PREFIX/bin/cpan" "$@"
423 root 1.1 exit
424     ;;
425     mkbundle )
426 root 1.6 ( install )
427 root 1.1 bundle "$@"
428     exit
429     ;;
430     mkperl )
431 root 1.6 ( install )
432 root 1.1 bundle --perl "$@"
433     exit
434     ;;
435     help )
436     podusage 2
437     ;;
438     * )
439     exec 1>&2
440     echo
441     echo "Unknown command: $command"
442     podusage 0
443     ;;
444     esac
445     done
446     else
447     usage
448     fi
449    
450     exit 0
451    
452     #CAT staticperl.pod
453