ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/App-Staticperl/staticperl.sh
Revision: 1.8
Committed: Tue Dec 7 19:55:56 2010 UTC (13 years, 7 months ago) by root
Content type: application/x-sh
Branch: MAIN
Changes since 1.7: +4 -3 lines
Log Message:
*** empty log message ***

File Contents

# Content
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 PERL_PREFIX="$STATICPERL/perl" # where the perl gets installed
14 PERL_VERSION=5.12.2 # 5.8.9 is also a good choice
15 PERL_CONFIGURE="" # additional Configure arguments
16 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 STATICPERL_MODULES="common::sense Pod::Strip PPI::XS Pod::Usage"
46
47 # which extra modules you might want to install
48 EXTRA_MODULES=""
49
50 # overridable functions
51 preconfigure() { : ; }
52 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 rm -rf "$STATICPERL/src/perl-$PERL_VERSION"
120 }
121
122 fetch() {
123 rcd "$STATICPERL"
124
125 mkdir -p src
126 rcd src
127
128 if ! [ -d "perl-$PERL_VERSION" ]; then
129 if ! [ -e "perl-$PERL_VERSION.tar.$BZ2" ]; then
130
131 URL="$CPAN/src/5.0/perl-$PERL_VERSION.tar.$BZ2"
132
133 verblock <<EOF
134 downloading perl
135 to manually download perl yourself, place
136 perl-$PERL_VERSION.tar.$BZ2 in $STATICPERL
137 trying $URL
138 EOF
139
140 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 || fatal "$URL: unable to download"
144 mv perl-$PERL_VERSION.tar.$BZ2~ perl-$PERL_VERSION.tar.$BZ2
145 fi
146
147 verblock <<EOF
148 unpacking perl
149 EOF
150
151 mkdir -p unpack
152 $BZIP2 -d <perl-$PERL_VERSION.tar.bz2 | tar xC unpack \
153 || fatal "perl-$PERL_VERSION.tar.bz2: error during unpacking"
154 chmod -R u+w unpack/perl-$PERL_VERSION
155 mv unpack/perl-$PERL_VERSION perl-$PERL_VERSION
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-$PERL_VERSION"
170
171 [ -e staticstamp.configure ] && return
172
173 verblock <<EOF
174 configuring $STATICPERL/src/perl-$PERL_VERSION
175 EOF
176
177 rm -f "$PERL_PREFIX/staticstamp.install"
178
179 make distclean >/dev/null 2>&1
180
181 # I hate them
182 grep -q -- -fstack-protector Configure && \
183 sedreplace 's/-fstack-protector/-fno-stack-protector/g' Configure
184
185 preconfigure
186
187 # 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 -Dprefix="$PERL_PREFIX" \
204 -Dbin="$PERL_PREFIX/bin" \
205 -Dprivlib="$PERL_PREFIX/lib" \
206 -Darchlib="$PERL_PREFIX/lib" \
207 -Uusevendorprefix \
208 -Dsitelib="$PERL_PREFIX/lib" \
209 -Dsitearch="$PERL_PREFIX/lib" \
210 -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 $PERL_CONFIGURE \
220 -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 rcd "$STATICPERL/src/perl-$PERL_VERSION"
238
239 verblock <<EOF
240 building $STATICPERL/src/perl-$PERL_VERSION
241 EOF
242
243 rm -f "$PERL_PREFIX/staticstamp.install"
244
245 make || fatal "make: error while building perl"
246
247 postbuild || fatal "postbuild hook failed"
248 }
249
250 install() {
251 [ -e "$PERL_PREFIX/staticstamp.install" ] && return
252
253 build
254
255 verblock <<EOF
256 installing $STATICPERL/src/perl-$PERL_VERSION
257 to $PERL_PREFIX
258 EOF
259
260 rm -rf "$PERL_PREFIX"
261
262 make install || fatal "make install: error while installing"
263
264 rcd "$PERL_PREFIX"
265
266 # create a "make install" replacement for CPAN
267 cat >"$PERL_PREFIX"/bin/cpan-make-install <<EOF
268 make install UNINST=1
269 if find blib/arch/auto -type f | grep -q -v .exists; then
270 echo Probably an XS module, rebuilding perl
271 make perl
272 rm -f "$PERL_PREFIX"/bin/perl
273 make -f Makefile.aperl inst_perl
274 make -f Makefile.aperl map_clean
275 fi
276 EOF
277 chmod 755 "$PERL_PREFIX"/bin/cpan-make-install
278
279 # trick CPAN into avoiding ~/.cpan completely
280 echo 1 >"$PERL_PREFIX/lib/CPAN/MyConfig.pm"
281
282 "$PERL_PREFIX"/bin/perl -MCPAN -e '
283 CPAN::Shell->o (conf => urllist => push => "'"$CPAN"'");
284 CPAN::Shell->o (conf => q<cpan_home>, "'"$STATICPERL"'/cpan");
285 CPAN::Shell->o (conf => q<init>);
286 CPAN::Shell->o (conf => q<cpan_home>, "'"$STATICPERL"'/cpan");
287 CPAN::Shell->o (conf => q<build_dir>, "'"$STATICPERL"'/cpan/build");
288 CPAN::Shell->o (conf => q<prefs_dir>, "'"$STATICPERL"'/cpan/prefs");
289 CPAN::Shell->o (conf => q<histfile> , "'"$STATICPERL"'/cpan/histfile");
290 CPAN::Shell->o (conf => q<keep_source_where>, "'"$STATICPERL"'/cpan/sources");
291 CPAN::Shell->o (conf => q<make_install_make_command>, "'"$PERL_PREFIX"'/bin/cpan-make-install");
292 CPAN::Shell->o (conf => q<prerequisites_policy>, q<follow>);
293 CPAN::Shell->o (conf => q<build_requires_install_policy>, q<no>);
294 CPAN::Shell->o (conf => q<commit>);
295 ' || fatal "error while initialising CPAN"
296
297 NOCHECK_INSTALL=+
298 instcpan $STATICPERL_MODULES
299 [ $EXTRA_MODULES ] && instcpan $EXTRA_MODULES
300
301 postinstall || fatal "postinstall hook failed"
302
303 touch "$PERL_PREFIX/staticstamp.install"
304 }
305
306 #############################################################################
307 # install a module from CPAN
308
309 instcpan() {
310 [ $NOCHECK_INSTALL ] || install
311
312 verblock <<EOF
313 installing modules from CPAN
314 $@
315 EOF
316
317 for mod in "$@"; do
318 "$PERL_PREFIX"/bin/perl -MCPAN -e 'notest install => "'"$mod"'"' \
319 || fatal "$mod: unable to install from CPAN"
320 done
321 rm -rf "$STATICPERL/build"
322 }
323
324 #############################################################################
325 # install a module from unpacked sources
326
327 instsrc() {
328 [ $NOCHECK_INSTALL ] || install
329
330 verblock <<EOF
331 installing modules from source
332 $@
333 EOF
334
335 for mod in "$@"; do
336 echo
337 echo $mod
338 (
339 rcd $mod
340 make -f Makefile.aperl map_clean >/dev/null 2>&1
341 make distclean >/dev/null 2>&1
342 "$PERL_PREFIX"/bin/perl Makefile.PL || fatal "$mod: error running Makefile.PL"
343 make || fatal "$mod: error building module"
344 "$PERL_PREFIX"/bin/cpan-make-install || fatal "$mod: error installing module"
345 make distclean >/dev/null 2>&1
346 exit 0
347 ) || exit $?
348 done
349 }
350
351 #############################################################################
352 # main
353
354 podusage() {
355 echo
356 if [ -e "$PERL_PREFIX/bin/perl" ]; then
357 "$PERL_PREFIX/bin/perl" -MPod::Usage -e \
358 'pod2usage -input => *STDIN, -output => *STDOUT, -verbose => '$1', -exitval => 0, -noperldoc => 1' <"$0" \
359 2>/dev/null && exit
360 fi
361 # try whatever perl we can find
362 perl -MPod::Usage -e \
363 'pod2usage -input => *STDIN, -output => *STDOUT, -verbose => '$1', -exitval => 0, -noperldoc => 1' <"$0" \
364 2>/dev/null && exit
365
366 fatal "displaying documentation requires a working perl - try '$0 install' first"
367 }
368
369 usage() {
370 podusage 0
371 }
372
373 catmkbundle() {
374 {
375 read dummy
376 echo "#!$PERL_PREFIX/bin/perl"
377 cat
378 } <<'MKBUNDLE'
379 #CAT mkbundle
380 MKBUNDLE
381 }
382
383 bundle() {
384 catmkbundle >"$MKBUNDLE~" || fatal "$MKBUNDLE~: cannot create"
385 chmod 755 "$MKBUNDLE~" && mv "$MKBUNDLE~" "$MKBUNDLE"
386 "$PERL_PREFIX/bin/perl" -- "$MKBUNDLE" "$@"
387 }
388
389 if [ $# -gt 0 ]; then
390 while [ $# -gt 0 ]; do
391 mkdir -p "$STATICPERL" || fatal "$STATICPERL: cannot create"
392 mkdir -p "$PERL_PREFIX" || fatal "$PERL_PREFIX: cannot create"
393
394 command="${1#--}"; shift
395 case "$command" in
396 fetch | configure | build | install | clean | distclean)
397 verblock <<EOF
398 $command
399 EOF
400 ( "$command" )
401 ;;
402 instsrc )
403 ( instsrc "$@" )
404 exit
405 ;;
406 instcpan )
407 ( instcpan "$@" )
408 exit
409 ;;
410 cpan )
411 ( install )
412 "$PERL_PREFIX/bin/cpan" "$@"
413 exit
414 ;;
415 mkbundle )
416 ( install )
417 bundle "$@"
418 exit
419 ;;
420 mkperl )
421 ( install )
422 bundle --perl "$@"
423 exit
424 ;;
425 help )
426 podusage 2
427 ;;
428 * )
429 exec 1>&2
430 echo
431 echo "Unknown command: $command"
432 podusage 0
433 ;;
434 esac
435 done
436 else
437 usage
438 fi
439
440 exit 0
441
442 #CAT staticperl.pod
443