ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/App-Staticperl/staticperl.sh
Revision: 1.9
Committed: Tue Dec 7 20:03:15 2010 UTC (13 years, 7 months ago) by root
Content type: application/x-sh
Branch: MAIN
Changes since 1.8: +37 -33 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.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.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.9 chmod 755 "$PERL_PREFIX"/bin/cpan-make-install
277    
278     # trick CPAN into avoiding ~/.cpan completely
279     echo 1 >"$PERL_PREFIX/lib/CPAN/MyConfig.pm"
280 root 1.1
281 root 1.9 "$PERL_PREFIX"/bin/perl -MCPAN -e '
282     CPAN::Shell->o (conf => urllist => push => "'"$CPAN"'");
283     CPAN::Shell->o (conf => q<cpan_home>, "'"$STATICPERL"'/cpan");
284     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     CPAN::Shell->o (conf => q<make_install_make_command>, "'"$PERL_PREFIX"'/bin/cpan-make-install");
291     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 root 1.2
296 root 1.9 touch "$PERL_PREFIX/staticstamp.install"
297     fi
298    
299     if ! [ -e "$PERL_PREFIX/staticstamp.postinstall"; then
300     NOCHECK_INSTALL=+
301     instcpan $STATICPERL_MODULES
302     [ $EXTRA_MODULES ] && instcpan $EXTRA_MODULES
303 root 1.1
304 root 1.9 postinstall || fatal "postinstall hook failed"
305 root 1.1
306 root 1.9 touch "$PERL_PREFIX/staticstamp.postinstall"
307     fi
308 root 1.1 }
309    
310     #############################################################################
311     # install a module from CPAN
312    
313     instcpan() {
314     [ $NOCHECK_INSTALL ] || install
315    
316     verblock <<EOF
317     installing modules from CPAN
318     $@
319     EOF
320    
321     for mod in "$@"; do
322 root 1.6 "$PERL_PREFIX"/bin/perl -MCPAN -e 'notest install => "'"$mod"'"' \
323 root 1.1 || fatal "$mod: unable to install from CPAN"
324     done
325     rm -rf "$STATICPERL/build"
326     }
327    
328     #############################################################################
329     # install a module from unpacked sources
330    
331     instsrc() {
332     [ $NOCHECK_INSTALL ] || install
333    
334     verblock <<EOF
335     installing modules from source
336     $@
337     EOF
338    
339     for mod in "$@"; do
340     echo
341     echo $mod
342     (
343     rcd $mod
344     make -f Makefile.aperl map_clean >/dev/null 2>&1
345     make distclean >/dev/null 2>&1
346 root 1.6 "$PERL_PREFIX"/bin/perl Makefile.PL || fatal "$mod: error running Makefile.PL"
347 root 1.1 make || fatal "$mod: error building module"
348 root 1.6 "$PERL_PREFIX"/bin/cpan-make-install || fatal "$mod: error installing module"
349 root 1.1 make distclean >/dev/null 2>&1
350     exit 0
351     ) || exit $?
352     done
353     }
354    
355     #############################################################################
356     # main
357    
358     podusage() {
359     echo
360 root 1.6 if [ -e "$PERL_PREFIX/bin/perl" ]; then
361     "$PERL_PREFIX/bin/perl" -MPod::Usage -e \
362 root 1.1 'pod2usage -input => *STDIN, -output => *STDOUT, -verbose => '$1', -exitval => 0, -noperldoc => 1' <"$0" \
363     2>/dev/null && exit
364     fi
365     # try whatever perl we can find
366     perl -MPod::Usage -e \
367     'pod2usage -input => *STDIN, -output => *STDOUT, -verbose => '$1', -exitval => 0, -noperldoc => 1' <"$0" \
368     2>/dev/null && exit
369    
370     fatal "displaying documentation requires a working perl - try '$0 install' first"
371     }
372    
373     usage() {
374     podusage 0
375     }
376    
377     catmkbundle() {
378     {
379     read dummy
380 root 1.6 echo "#!$PERL_PREFIX/bin/perl"
381 root 1.1 cat
382     } <<'MKBUNDLE'
383     #CAT mkbundle
384     MKBUNDLE
385     }
386    
387     bundle() {
388     catmkbundle >"$MKBUNDLE~" || fatal "$MKBUNDLE~: cannot create"
389     chmod 755 "$MKBUNDLE~" && mv "$MKBUNDLE~" "$MKBUNDLE"
390 root 1.6 "$PERL_PREFIX/bin/perl" -- "$MKBUNDLE" "$@"
391 root 1.1 }
392    
393     if [ $# -gt 0 ]; then
394     while [ $# -gt 0 ]; do
395     mkdir -p "$STATICPERL" || fatal "$STATICPERL: cannot create"
396 root 1.6 mkdir -p "$PERL_PREFIX" || fatal "$PERL_PREFIX: cannot create"
397 root 1.1
398     command="${1#--}"; shift
399     case "$command" in
400     fetch | configure | build | install | clean | distclean)
401     verblock <<EOF
402     $command
403     EOF
404 root 1.6 ( "$command" )
405 root 1.1 ;;
406     instsrc )
407 root 1.6 ( instsrc "$@" )
408 root 1.1 exit
409     ;;
410     instcpan )
411 root 1.6 ( instcpan "$@" )
412 root 1.1 exit
413     ;;
414     cpan )
415 root 1.6 ( install )
416     "$PERL_PREFIX/bin/cpan" "$@"
417 root 1.1 exit
418     ;;
419     mkbundle )
420 root 1.6 ( install )
421 root 1.1 bundle "$@"
422     exit
423     ;;
424     mkperl )
425 root 1.6 ( install )
426 root 1.1 bundle --perl "$@"
427     exit
428     ;;
429     help )
430     podusage 2
431     ;;
432     * )
433     exec 1>&2
434     echo
435     echo "Unknown command: $command"
436     podusage 0
437     ;;
438     esac
439     done
440     else
441     usage
442     fi
443    
444     exit 0
445    
446     #CAT staticperl.pod
447