ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/App-Staticperl/staticperl.sh
(Generate patch)

Comparing App-Staticperl/staticperl.sh (file contents):
Revision 1.14 by root, Fri Dec 10 20:29:17 2010 UTC vs.
Revision 1.22 by root, Wed Dec 15 00:17:48 2010 UTC

5 5
6STATICPERL=~/.staticperl 6STATICPERL=~/.staticperl
7CPAN=http://mirror.netcologne.de/cpan # which mirror to use 7CPAN=http://mirror.netcologne.de/cpan # which mirror to use
8EMAIL="read the documentation <rtfm@example.org>" 8EMAIL="read the documentation <rtfm@example.org>"
9 9
10
11# perl build variables 10# perl build variables
11MAKE=make
12PERL_VERSION=5.12.2 # 5.8.9 is also a good choice 12PERL_VERSION=5.12.2 # 5.8.9 is also a good choice
13PERL_CC=cc
13PERL_CONFIGURE="" # additional Configure arguments 14PERL_CONFIGURE="" # additional Configure arguments
14PERL_CPPFLAGS="-DPERL_DISABLE_PMC -DPERL_ARENA_SIZE=65536 -D_GNU_SOURCE -DNDEBUG -USITELIB_EXP -USITEARCHEXP -UARCHLIB_EXP" 15PERL_CCFLAGS="-DPERL_DISABLE_PMC -DPERL_ARENA_SIZE=65536 -D_GNU_SOURCE -DNDEBUG -USITELIB_EXP -USITEARCHEXP -UARCHLIB_EXP"
15PERL_OPTIMIZE="-Os -ffunction-sections -fdata-sections -finline-limit=8 -ffast-math" 16PERL_OPTIMIZE="-Os -ffunction-sections -fdata-sections -finline-limit=8 -ffast-math"
16 17
17ARCH="$(uname -m)" 18ARCH="$(uname -m)"
18 19
19case "$ARCH" in 20case "$ARCH" in
27 ;; 28 ;;
28esac 29esac
29 30
30# -Wl,--gc-sections makes it impossible to check for undefined references 31# -Wl,--gc-sections makes it impossible to check for undefined references
31# for some reason so we need to patch away the "-no" after Configure and before make :/ 32# for some reason so we need to patch away the "-no" after Configure and before make :/
32# -z muldefs is to work around uclibc's pthread static linking bug 33# --allow-multiple-definition exists to work around uclibc's pthread static linking bug
33PERL_LDFLAGS="-Wl,--no-gc-sections -z muldefs" 34PERL_LDFLAGS="-Wl,--no-gc-sections -Wl,--allow-multiple-definition"
34PERL_LIBS="-lm -lcrypt" # perl loves to add lotsa crap itself 35PERL_LIBS="-lm -lcrypt" # perl loves to add lotsa crap itself
35 36
36# some configuration options for modules 37# some configuration options for modules
37export PERL_MM_USE_DEFAULT=1 38export PERL_MM_USE_DEFAULT=1
38#export CORO_INTERFACE=p # needed without nptl on x86, due to bugs in linuxthreads - very slow 39#export CORO_INTERFACE=p # needed without nptl on x86, due to bugs in linuxthreads - very slow
69unset PERL5OPT PERL5LIB PERLLIB PERL_UNICODE PERLIO_DEBUG 70unset PERL5OPT PERL5LIB PERLLIB PERL_UNICODE PERLIO_DEBUG
70export LC_ALL=C # just to be on the safe side 71export LC_ALL=C # just to be on the safe side
71 72
72# set version in a way that Makefile.PL can extract 73# set version in a way that Makefile.PL can extract
73VERSION=VERSION; eval \ 74VERSION=VERSION; eval \
74$VERSION=0.9 75$VERSION=0.912
75 76
76BZ2=bz2 77BZ2=bz2
77BZIP2=bzip2 78BZIP2=bzip2
78 79
79fatal() { 80fatal() {
147 148
148 rm -f perl-$PERL_VERSION.tar.$BZ2~ # just to be on the safe side 149 rm -f perl-$PERL_VERSION.tar.$BZ2~ # just to be on the safe side
149 wget -O perl-$PERL_VERSION.tar.$BZ2~ "$URL" \ 150 wget -O perl-$PERL_VERSION.tar.$BZ2~ "$URL" \
150 || curl >perl-$PERL_VERSION.tar.$BZ2~ "$URL" \ 151 || curl >perl-$PERL_VERSION.tar.$BZ2~ "$URL" \
151 || fatal "$URL: unable to download" 152 || fatal "$URL: unable to download"
153 rm -f perl-$PERL_VERSION.tar.$BZ2
152 mv perl-$PERL_VERSION.tar.$BZ2~ perl-$PERL_VERSION.tar.$BZ2 154 mv perl-$PERL_VERSION.tar.$BZ2~ perl-$PERL_VERSION.tar.$BZ2
153 fi 155 fi
154 156
155 verblock <<EOF 157 verblock <<EOF
156unpacking perl 158unpacking perl
157EOF 159EOF
158 160
159 mkdir -p unpack 161 mkdir -p unpack
162 rm -rf unpack/perl-$PERL_VERSION
160 $BZIP2 -d <perl-$PERL_VERSION.tar.bz2 | tar xfC - unpack \ 163 $BZIP2 -d <perl-$PERL_VERSION.tar.bz2 | tar xfC - unpack \
161 || fatal "perl-$PERL_VERSION.tar.bz2: error during unpacking" 164 || fatal "perl-$PERL_VERSION.tar.bz2: error during unpacking"
162 chmod -R u+w unpack/perl-$PERL_VERSION 165 chmod -R u+w unpack/perl-$PERL_VERSION
163 mv unpack/perl-$PERL_VERSION perl-$PERL_VERSION 166 mv unpack/perl-$PERL_VERSION perl-$PERL_VERSION
164 rmdir -p unpack 167 rmdir -p unpack
166} 169}
167 170
168# similar to GNU-sed -i or perl -pi 171# similar to GNU-sed -i or perl -pi
169sedreplace() { 172sedreplace() {
170 sed -e "$1" <"$2" > "$2~" || fatal "error while running sed" 173 sed -e "$1" <"$2" > "$2~" || fatal "error while running sed"
174 rm -f "$2"
171 mv "$2~" "$2" 175 mv "$2~" "$2"
176}
177
178configure_failure() {
179 cat <<EOF
180
181
182***
183*** Configure failed - see above for the exact error message(s).
184***
185*** Most commonly, this is because the default PERL_CCFLAGS or PERL_OPTIMIZE
186*** flags are not supported by your compiler. Less often, this is because
187*** PERL_LIBS either contains a library not available on your system (such as
188*** -lcrypt), or because it lacks a required library (e.g. -lsocket or -lnsl).
189***
190*** You can provide your own flags by creating a ~/.staticperlrc file with
191*** variable assignments. For example (these are the actual values used):
192***
193
194PERL_CC="$PERL_CC"
195PERL_CCFLAGS="$PERL_CCFLAGS"
196PERL_OPTIMIZE="$PERL_OPTIMIZE"
197PERL_LDFLAGS="$PERL_LDFLAGS"
198PERL_LIBS="$PERL_LIBS"
199
200EOF
201 exit 1
172} 202}
173 203
174configure() { 204configure() {
175 fetch 205 fetch
176 206
182configuring $STATICPERL/src/perl-$PERL_VERSION 212configuring $STATICPERL/src/perl-$PERL_VERSION
183EOF 213EOF
184 214
185 rm -f "$PERL_PREFIX/staticstamp.install" 215 rm -f "$PERL_PREFIX/staticstamp.install"
186 216
187 make distclean >/dev/null 2>&1 217 "$MAKE" distclean >/dev/null 2>&1
188 218
189 # I hate them 219 # I hate them
190 grep -q -- -fstack-protector Configure && \ 220 grep -q -- -fstack-protector Configure && \
191 sedreplace 's/-fstack-protector/-fno-stack-protector/g' Configure 221 sedreplace 's/-fstack-protector/-fno-stack-protector/g' Configure
192 222
198 -Dusemymalloc=n \ 228 -Dusemymalloc=n \
199 -Uusedl \ 229 -Uusedl \
200 -Uusethreads \ 230 -Uusethreads \
201 -Uuseithreads \ 231 -Uuseithreads \
202 -Uusemultiplicity \ 232 -Uusemultiplicity \
203 -Duseperlio \
204 -Uusesfio \ 233 -Uusesfio \
205 -Uuseshrplib \ 234 -Uuseshrplib \
206 -Dcppflags="$PERL_CPPFLAGS" \ 235 -A ccflags=" $PERL_CCFLAGS" \
207 -Dccflags="-g2 -fno-strict-aliasing" \ 236 -Dcc="$PERL_CC" \
208 -Doptimize="$PERL_OPTIMIZE" \ 237 -Doptimize="$PERL_OPTIMIZE" \
209 -Dldflags="$PERL_LDFLAGS" \ 238 -Dldflags="$PERL_LDFLAGS" \
210 -Dlibs="$PERL_LIBS" \ 239 -Dlibs="$PERL_LIBS" \
211 -Dprefix="$PERL_PREFIX" \ 240 -Dprefix="$PERL_PREFIX" \
212 -Dbin="$PERL_PREFIX/bin" \ 241 -Dbin="$PERL_PREFIX/bin" \
223 -Dpager=/usr/bin/less \ 252 -Dpager=/usr/bin/less \
224 -Demail="$EMAIL" \ 253 -Demail="$EMAIL" \
225 -Dcf_email="$EMAIL" \ 254 -Dcf_email="$EMAIL" \
226 -Dcf_by="$EMAIL" \ 255 -Dcf_by="$EMAIL" \
227 $PERL_CONFIGURE \ 256 $PERL_CONFIGURE \
257 -Duseperlio \
228 -dE || fatal "Configure failed" 258 -dE || configure_failure
229 259
230 sedreplace ' 260 sedreplace '
231 s/-Wl,--no-gc-sections/-Wl,--gc-sections/g 261 s/-Wl,--no-gc-sections/-Wl,--gc-sections/g
232 s/ *-fno-stack-protector */ /g 262 s/ *-fno-stack-protector */ /g
233 ' config.sh 263 ' config.sh
248building $STATICPERL/src/perl-$PERL_VERSION 278building $STATICPERL/src/perl-$PERL_VERSION
249EOF 279EOF
250 280
251 rm -f "$PERL_PREFIX/staticstamp.install" 281 rm -f "$PERL_PREFIX/staticstamp.install"
252 282
253 make || fatal "make: error while building perl" 283 "$MAKE" || fatal "make: error while building perl"
254 284
255 postbuild || fatal "postbuild hook failed" 285 postbuild || fatal "postbuild hook failed"
256} 286}
257 287
258install() { 288install() {
268 ln -sf "perl/lib/" "$STATICPERL/lib" 298 ln -sf "perl/lib/" "$STATICPERL/lib"
269 299
270 ln -sf "$PERL_PREFIX" "$STATICPERL/perl" # might get overwritten 300 ln -sf "$PERL_PREFIX" "$STATICPERL/perl" # might get overwritten
271 rm -rf "$PERL_PREFIX" # by this rm -rf 301 rm -rf "$PERL_PREFIX" # by this rm -rf
272 302
273 make install || fatal "make install: error while installing" 303 "$MAKE" install || fatal "make install: error while installing"
274 304
275 rcd "$PERL_PREFIX" 305 rcd "$PERL_PREFIX"
276 306
277 # create a "make install" replacement for CPAN 307 # create a "make install" replacement for CPAN
278 cat >"$PERL_PREFIX"/bin/cpan-make-install <<EOF 308 cat >"$PERL_PREFIX"/bin/cpan-make-install <<EOF
279make || exit 309"$MAKE" || exit
280 310
281if find blib/arch/auto -type f | grep -q -v .exists; then 311if find blib/arch/auto -type f | grep -q -v .exists; then
282 echo Probably an XS module, rebuilding perl 312 echo Probably an XS module, rebuilding perl
283 if make perl; then 313 if "$MAKE" perl; then
284 mv perl "$PERL_PREFIX"/bin/perl 314 mv perl "$PERL_PREFIX"/bin/perl~ \
315 && rm -f "$PERL_PREFIX"/bin/perl \
316 && mv "$PERL_PREFIX"/bin/perl~ "$PERL_PREFIX"/bin/perl
285 make -f Makefile.aperl map_clean 317 "$MAKE" -f Makefile.aperl map_clean
286 else 318 else
287 make -f Makefile.aperl map_clean 319 "$MAKE" -f Makefile.aperl map_clean
288 exit 1 320 exit 1
289 fi 321 fi
290fi 322fi
291 323
292make install UNINST=1 324"$MAKE" install UNINST=1
293EOF 325EOF
294 chmod 755 "$PERL_PREFIX"/bin/cpan-make-install 326 chmod 755 "$PERL_PREFIX"/bin/cpan-make-install
295 327
296 # trick CPAN into avoiding ~/.cpan completely 328 # trick CPAN into avoiding ~/.cpan completely
297 echo 1 >"$PERL_PREFIX/lib/CPAN/MyConfig.pm" 329 echo 1 >"$PERL_PREFIX/lib/CPAN/MyConfig.pm"
357 for mod in "$@"; do 389 for mod in "$@"; do
358 echo 390 echo
359 echo $mod 391 echo $mod
360 ( 392 (
361 rcd $mod 393 rcd $mod
362 make -f Makefile.aperl map_clean >/dev/null 2>&1 394 "$MAKE" -f Makefile.aperl map_clean >/dev/null 2>&1
363 make distclean >/dev/null 2>&1 395 "$MAKE" distclean >/dev/null 2>&1
364 "$PERL_PREFIX"/bin/perl Makefile.PL || fatal "$mod: error running Makefile.PL" 396 "$PERL_PREFIX"/bin/perl Makefile.PL || fatal "$mod: error running Makefile.PL"
365 make || fatal "$mod: error building module" 397 "$MAKE" || fatal "$mod: error building module"
366 "$PERL_PREFIX"/bin/cpan-make-install || fatal "$mod: error installing module" 398 "$PERL_PREFIX"/bin/cpan-make-install || fatal "$mod: error installing module"
367 make distclean >/dev/null 2>&1 399 "$MAKE" distclean >/dev/null 2>&1
368 exit 0 400 exit 0
369 ) || exit $? 401 ) || exit $?
370 done 402 done
371} 403}
372 404
373############################################################################# 405#############################################################################
374# main 406# main
375 407
376podusage() { 408podusage() {
377 echo 409 echo
410
378 if [ -e "$PERL_PREFIX/bin/perl" ]; then 411 if [ -e "$PERL_PREFIX/bin/perl" ]; then
379 "$PERL_PREFIX/bin/perl" -MPod::Usage -e \ 412 "$PERL_PREFIX/bin/perl" -MPod::Usage -e \
380 'pod2usage -input => *STDIN, -output => *STDOUT, -verbose => '$1', -exitval => 0, -noperldoc => 1' <"$0" \ 413 'pod2usage -input => *STDIN, -output => *STDOUT, -verbose => '$1', -exitval => 0, -noperldoc => 1' <"$0" \
381 2>/dev/null && exit 414 2>/dev/null && exit
382 fi 415 fi
416
383 # try whatever perl we can find 417 # try whatever perl we can find
384 perl -MPod::Usage -e \ 418 perl -MPod::Usage -e \
385 'pod2usage -input => *STDIN, -output => *STDOUT, -verbose => '$1', -exitval => 0, -noperldoc => 1' <"$0" \ 419 'pod2usage -input => *STDIN, -output => *STDOUT, -verbose => '$1', -exitval => 0, -noperldoc => 1' <"$0" \
386 2>/dev/null && exit 420 2>/dev/null && exit
387 421
388 fatal "displaying documentation requires a working perl - try '$0 install' first" 422 fatal "displaying documentation requires a working perl - try '$0 install' to build one in a safe location"
389} 423}
390 424
391usage() { 425usage() {
392 podusage 0 426 podusage 0
393} 427}
419 case "$command" in 453 case "$command" in
420 version ) 454 version )
421 echo "staticperl version $VERSION" 455 echo "staticperl version $VERSION"
422 ;; 456 ;;
423 fetch | configure | build | install | clean | distclean) 457 fetch | configure | build | install | clean | distclean)
424 ( "$command" ) 458 ( "$command" ) || exit
425 ;; 459 ;;
426 instsrc ) 460 instsrc )
427 ( instsrc "$@" ) 461 ( instsrc "$@" ) || exit
428 exit 462 exit
429 ;; 463 ;;
430 instcpan ) 464 instcpan )
431 ( instcpan "$@" ) 465 ( instcpan "$@" ) || exit
432 exit 466 exit
433 ;; 467 ;;
434 cpan ) 468 cpan )
435 ( install ) 469 ( install ) || exit
436 "$PERL_PREFIX/bin/cpan" "$@" 470 "$PERL_PREFIX/bin/cpan" "$@"
437 exit 471 exit
438 ;; 472 ;;
439 mkbundle ) 473 mkbundle )
440 ( install ) 474 ( install ) || exit
441 bundle "$@" 475 bundle "$@"
442 exit 476 exit
443 ;; 477 ;;
444 mkperl ) 478 mkperl )
445 ( install ) 479 ( install ) || exit
446 bundle --perl "$@" 480 bundle --perl "$@"
447 exit 481 exit
448 ;; 482 ;;
449 mkapp ) 483 mkapp )
450 ( install ) 484 ( install ) || exit
451 bundle --app "$@" 485 bundle --app "$@"
452 exit 486 exit
453 ;; 487 ;;
454 help ) 488 help )
455 podusage 2 489 podusage 2

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines