ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/App-Staticperl/staticperl.sh
Revision: 1.11
Committed: Wed Dec 8 22:27:35 2010 UTC (13 years, 5 months ago) by root
Content type: application/x-sh
Branch: MAIN
CVS Tags: rel-0_9
Changes since 1.10: +6 -1 lines
Log Message:
0.9

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.9
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 if ! [ -e "$PERL_PREFIX/staticstamp.install" ]; then
252 build
253
254 verblock <<EOF
255 installing $STATICPERL/src/perl-$PERL_VERSION
256 to $PERL_PREFIX
257 EOF
258
259 rm -rf "$PERL_PREFIX"
260
261 make install || fatal "make install: error while installing"
262
263 rcd "$PERL_PREFIX"
264
265 # create a "make install" replacement for CPAN
266 cat >"$PERL_PREFIX"/bin/cpan-make-install <<EOF
267 make || exit
268
269 if find blib/arch/auto -type f | grep -q -v .exists; then
270 echo Probably an XS module, rebuilding perl
271 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 fi
279
280 make install UNINST=1
281 EOF
282 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
287 "$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
302 touch "$PERL_PREFIX/staticstamp.install"
303 fi
304
305 if ! [ -e "$PERL_PREFIX/staticstamp.postinstall" ]; then
306 NOCHECK_INSTALL=+
307 instcpan $STATICPERL_MODULES
308 [ $EXTRA_MODULES ] && instcpan $EXTRA_MODULES
309
310 postinstall || fatal "postinstall hook failed"
311
312 touch "$PERL_PREFIX/staticstamp.postinstall"
313 fi
314 }
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 "$PERL_PREFIX"/bin/perl -MCPAN -e 'notest install => "'"$mod"'"' \
329 || 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 "$PERL_PREFIX"/bin/perl Makefile.PL || fatal "$mod: error running Makefile.PL"
353 make || fatal "$mod: error building module"
354 "$PERL_PREFIX"/bin/cpan-make-install || fatal "$mod: error installing module"
355 make distclean >/dev/null 2>&1
356 exit 0
357 ) || exit $?
358 done
359 }
360
361 #############################################################################
362 # main
363
364 podusage() {
365 echo
366 if [ -e "$PERL_PREFIX/bin/perl" ]; then
367 "$PERL_PREFIX/bin/perl" -MPod::Usage -e \
368 '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 echo "#!$PERL_PREFIX/bin/perl"
387 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 "$PERL_PREFIX/bin/perl" -- "$MKBUNDLE" "$@"
397 }
398
399 if [ $# -gt 0 ]; then
400 while [ $# -gt 0 ]; do
401 mkdir -p "$STATICPERL" || fatal "$STATICPERL: cannot create"
402 mkdir -p "$PERL_PREFIX" || fatal "$PERL_PREFIX: cannot create"
403
404 command="${1#--}"; shift
405 case "$command" in
406 fetch | configure | build | install | clean | distclean)
407 verblock <<EOF
408 $command
409 EOF
410 ( "$command" )
411 ;;
412 instsrc )
413 ( instsrc "$@" )
414 exit
415 ;;
416 instcpan )
417 ( instcpan "$@" )
418 exit
419 ;;
420 cpan )
421 ( install )
422 "$PERL_PREFIX/bin/cpan" "$@"
423 exit
424 ;;
425 mkbundle )
426 ( install )
427 bundle "$@"
428 exit
429 ;;
430 mkperl )
431 ( install )
432 bundle --perl "$@"
433 exit
434 ;;
435 mkapp )
436 ( install )
437 bundle --app "$@"
438 exit
439 ;;
440 help )
441 podusage 2
442 ;;
443 * )
444 exec 1>&2
445 echo
446 echo "Unknown command: $command"
447 podusage 0
448 ;;
449 esac
450 done
451 else
452 usage
453 fi
454
455 exit 0
456
457 #CAT staticperl.pod
458