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.15 by root, Fri Dec 10 21:15:06 2010 UTC vs.
Revision 1.23 by root, Sat Dec 18 13:58:12 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"
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.91 75$VERSION=0.912
75 76
76BZ2=bz2 77BZ2=bz2
77BZIP2=bzip2 78BZIP2=bzip2
78 79
79fatal() { 80fatal() {
125 126
126clean() { 127clean() {
127 rm -rf "$STATICPERL/src/perl-$PERL_VERSION" 128 rm -rf "$STATICPERL/src/perl-$PERL_VERSION"
128} 129}
129 130
131realclean() {
132 rm -f "$PERL_PREFIX/staticstamp.postinstall"
133 rm -f "$PERL_PREFIX/staticstamp.install"
134 rm -f "$STATICPERL/src/perl-"*"/staticstamp.configure"
135}
136
130fetch() { 137fetch() {
131 rcd "$STATICPERL" 138 rcd "$STATICPERL"
132 139
133 mkdir -p src 140 mkdir -p src
134 rcd src 141 rcd src
147 154
148 rm -f perl-$PERL_VERSION.tar.$BZ2~ # just to be on the safe side 155 rm -f perl-$PERL_VERSION.tar.$BZ2~ # just to be on the safe side
149 wget -O perl-$PERL_VERSION.tar.$BZ2~ "$URL" \ 156 wget -O perl-$PERL_VERSION.tar.$BZ2~ "$URL" \
150 || curl >perl-$PERL_VERSION.tar.$BZ2~ "$URL" \ 157 || curl >perl-$PERL_VERSION.tar.$BZ2~ "$URL" \
151 || fatal "$URL: unable to download" 158 || fatal "$URL: unable to download"
159 rm -f perl-$PERL_VERSION.tar.$BZ2
152 mv perl-$PERL_VERSION.tar.$BZ2~ perl-$PERL_VERSION.tar.$BZ2 160 mv perl-$PERL_VERSION.tar.$BZ2~ perl-$PERL_VERSION.tar.$BZ2
153 fi 161 fi
154 162
155 verblock <<EOF 163 verblock <<EOF
156unpacking perl 164unpacking perl
157EOF 165EOF
158 166
159 mkdir -p unpack 167 mkdir -p unpack
168 rm -rf unpack/perl-$PERL_VERSION
160 $BZIP2 -d <perl-$PERL_VERSION.tar.bz2 | tar xfC - unpack \ 169 $BZIP2 -d <perl-$PERL_VERSION.tar.bz2 | tar xfC - unpack \
161 || fatal "perl-$PERL_VERSION.tar.bz2: error during unpacking" 170 || fatal "perl-$PERL_VERSION.tar.bz2: error during unpacking"
162 chmod -R u+w unpack/perl-$PERL_VERSION 171 chmod -R u+w unpack/perl-$PERL_VERSION
163 mv unpack/perl-$PERL_VERSION perl-$PERL_VERSION 172 mv unpack/perl-$PERL_VERSION perl-$PERL_VERSION
164 rmdir -p unpack 173 rmdir -p unpack
166} 175}
167 176
168# similar to GNU-sed -i or perl -pi 177# similar to GNU-sed -i or perl -pi
169sedreplace() { 178sedreplace() {
170 sed -e "$1" <"$2" > "$2~" || fatal "error while running sed" 179 sed -e "$1" <"$2" > "$2~" || fatal "error while running sed"
180 rm -f "$2"
171 mv "$2~" "$2" 181 mv "$2~" "$2"
182}
183
184configure_failure() {
185 cat <<EOF
186
187
188***
189*** Configure failed - see above for the exact error message(s).
190***
191*** Most commonly, this is because the default PERL_CCFLAGS or PERL_OPTIMIZE
192*** flags are not supported by your compiler. Less often, this is because
193*** PERL_LIBS either contains a library not available on your system (such as
194*** -lcrypt), or because it lacks a required library (e.g. -lsocket or -lnsl).
195***
196*** You can provide your own flags by creating a ~/.staticperlrc file with
197*** variable assignments. For example (these are the actual values used):
198***
199
200PERL_CC="$PERL_CC"
201PERL_CCFLAGS="$PERL_CCFLAGS"
202PERL_OPTIMIZE="$PERL_OPTIMIZE"
203PERL_LDFLAGS="$PERL_LDFLAGS"
204PERL_LIBS="$PERL_LIBS"
205
206EOF
207 exit 1
172} 208}
173 209
174configure() { 210configure() {
175 fetch 211 fetch
176 212
182configuring $STATICPERL/src/perl-$PERL_VERSION 218configuring $STATICPERL/src/perl-$PERL_VERSION
183EOF 219EOF
184 220
185 rm -f "$PERL_PREFIX/staticstamp.install" 221 rm -f "$PERL_PREFIX/staticstamp.install"
186 222
187 make distclean >/dev/null 2>&1 223 "$MAKE" distclean >/dev/null 2>&1
188 224
225 sedreplace '/^#define SITELIB/d' config_h.SH
226
189 # I hate them 227 # I hate them for this
190 grep -q -- -fstack-protector Configure && \ 228 grep -q -- -fstack-protector Configure && \
191 sedreplace 's/-fstack-protector/-fno-stack-protector/g' Configure 229 sedreplace 's/-fstack-protector/-fno-stack-protector/g' Configure
192 230
193 preconfigure 231 preconfigure
194 232
198 -Dusemymalloc=n \ 236 -Dusemymalloc=n \
199 -Uusedl \ 237 -Uusedl \
200 -Uusethreads \ 238 -Uusethreads \
201 -Uuseithreads \ 239 -Uuseithreads \
202 -Uusemultiplicity \ 240 -Uusemultiplicity \
203 -Duseperlio \
204 -Uusesfio \ 241 -Uusesfio \
205 -Uuseshrplib \ 242 -Uuseshrplib \
206 -Dcppflags="$PERL_CPPFLAGS" \ 243 -A ccflags=" $PERL_CCFLAGS" \
207 -Dccflags="-g2 -fno-strict-aliasing" \ 244 -Dcc="$PERL_CC" \
208 -Doptimize="$PERL_OPTIMIZE" \ 245 -Doptimize="$PERL_OPTIMIZE" \
209 -Dldflags="$PERL_LDFLAGS" \ 246 -Dldflags="$PERL_LDFLAGS" \
210 -Dlibs="$PERL_LIBS" \ 247 -Dlibs="$PERL_LIBS" \
211 -Dprefix="$PERL_PREFIX" \ 248 -Dprefix="$PERL_PREFIX" \
212 -Dbin="$PERL_PREFIX/bin" \ 249 -Dbin="$PERL_PREFIX/bin" \
213 -Dprivlib="$PERL_PREFIX/lib" \ 250 -Dprivlib="$PERL_PREFIX/lib" \
214 -Darchlib="$PERL_PREFIX/lib" \ 251 -Darchlib="$PERL_PREFIX/lib" \
215 -Uusevendorprefix \ 252 -Uusevendorprefix \
216 -Dsitelib="$PERL_PREFIX/lib" \ 253 -Dsitelib="$PERL_PREFIX/lib" \
217 -Dsitearch="$PERL_PREFIX/lib" \ 254 -Dsitearch="$PERL_PREFIX/lib" \
218 -Usitelibexp \
219 -Uman1dir \ 255 -Uman1dir \
220 -Uman3dir \ 256 -Uman3dir \
221 -Usiteman1dir \ 257 -Usiteman1dir \
222 -Usiteman3dir \ 258 -Usiteman3dir \
223 -Dpager=/usr/bin/less \ 259 -Dpager=/usr/bin/less \
224 -Demail="$EMAIL" \ 260 -Demail="$EMAIL" \
225 -Dcf_email="$EMAIL" \ 261 -Dcf_email="$EMAIL" \
226 -Dcf_by="$EMAIL" \ 262 -Dcf_by="$EMAIL" \
227 $PERL_CONFIGURE \ 263 $PERL_CONFIGURE \
264 -Duseperlio \
228 -dE || fatal "Configure failed" 265 -dE || configure_failure
229 266
230 sedreplace ' 267 sedreplace '
231 s/-Wl,--no-gc-sections/-Wl,--gc-sections/g 268 s/-Wl,--no-gc-sections/-Wl,--gc-sections/g
232 s/ *-fno-stack-protector */ /g 269 s/ *-fno-stack-protector */ /g
233 ' config.sh 270 ' config.sh
248building $STATICPERL/src/perl-$PERL_VERSION 285building $STATICPERL/src/perl-$PERL_VERSION
249EOF 286EOF
250 287
251 rm -f "$PERL_PREFIX/staticstamp.install" 288 rm -f "$PERL_PREFIX/staticstamp.install"
252 289
253 make || fatal "make: error while building perl" 290 "$MAKE" || fatal "make: error while building perl"
254 291
255 postbuild || fatal "postbuild hook failed" 292 postbuild || fatal "postbuild hook failed"
256} 293}
257 294
258install() { 295install() {
268 ln -sf "perl/lib/" "$STATICPERL/lib" 305 ln -sf "perl/lib/" "$STATICPERL/lib"
269 306
270 ln -sf "$PERL_PREFIX" "$STATICPERL/perl" # might get overwritten 307 ln -sf "$PERL_PREFIX" "$STATICPERL/perl" # might get overwritten
271 rm -rf "$PERL_PREFIX" # by this rm -rf 308 rm -rf "$PERL_PREFIX" # by this rm -rf
272 309
273 make install || fatal "make install: error while installing" 310 "$MAKE" install || fatal "make install: error while installing"
274 311
275 rcd "$PERL_PREFIX" 312 rcd "$PERL_PREFIX"
276 313
277 # create a "make install" replacement for CPAN 314 # create a "make install" replacement for CPAN
278 cat >"$PERL_PREFIX"/bin/cpan-make-install <<EOF 315 cat >"$PERL_PREFIX"/bin/cpan-make-install <<EOF
279make || exit 316"$MAKE" || exit
280 317
281if find blib/arch/auto -type f | grep -q -v .exists; then 318if find blib/arch/auto -type f | grep -q -v .exists; then
282 echo Probably an XS module, rebuilding perl 319 echo Probably an XS module, rebuilding perl
283 if make perl; then 320 if "$MAKE" perl; then
284 mv perl "$PERL_PREFIX"/bin/perl 321 mv perl "$PERL_PREFIX"/bin/perl~ \
322 && rm -f "$PERL_PREFIX"/bin/perl \
323 && mv "$PERL_PREFIX"/bin/perl~ "$PERL_PREFIX"/bin/perl
285 make -f Makefile.aperl map_clean 324 "$MAKE" -f Makefile.aperl map_clean
286 else 325 else
287 make -f Makefile.aperl map_clean 326 "$MAKE" -f Makefile.aperl map_clean
288 exit 1 327 exit 1
289 fi 328 fi
290fi 329fi
291 330
292make install UNINST=1 331"$MAKE" install UNINST=1
293EOF 332EOF
294 chmod 755 "$PERL_PREFIX"/bin/cpan-make-install 333 chmod 755 "$PERL_PREFIX"/bin/cpan-make-install
295 334
296 # trick CPAN into avoiding ~/.cpan completely 335 # trick CPAN into avoiding ~/.cpan completely
297 echo 1 >"$PERL_PREFIX/lib/CPAN/MyConfig.pm" 336 echo 1 >"$PERL_PREFIX/lib/CPAN/MyConfig.pm"
357 for mod in "$@"; do 396 for mod in "$@"; do
358 echo 397 echo
359 echo $mod 398 echo $mod
360 ( 399 (
361 rcd $mod 400 rcd $mod
362 make -f Makefile.aperl map_clean >/dev/null 2>&1 401 "$MAKE" -f Makefile.aperl map_clean >/dev/null 2>&1
363 make distclean >/dev/null 2>&1 402 "$MAKE" distclean >/dev/null 2>&1
364 "$PERL_PREFIX"/bin/perl Makefile.PL || fatal "$mod: error running Makefile.PL" 403 "$PERL_PREFIX"/bin/perl Makefile.PL || fatal "$mod: error running Makefile.PL"
365 make || fatal "$mod: error building module" 404 "$MAKE" || fatal "$mod: error building module"
366 "$PERL_PREFIX"/bin/cpan-make-install || fatal "$mod: error installing module" 405 "$PERL_PREFIX"/bin/cpan-make-install || fatal "$mod: error installing module"
367 make distclean >/dev/null 2>&1 406 "$MAKE" distclean >/dev/null 2>&1
368 exit 0 407 exit 0
369 ) || exit $? 408 ) || exit $?
370 done 409 done
371} 410}
372 411
373############################################################################# 412#############################################################################
374# main 413# main
375 414
376podusage() { 415podusage() {
377 echo 416 echo
417
378 if [ -e "$PERL_PREFIX/bin/perl" ]; then 418 if [ -e "$PERL_PREFIX/bin/perl" ]; then
379 "$PERL_PREFIX/bin/perl" -MPod::Usage -e \ 419 "$PERL_PREFIX/bin/perl" -MPod::Usage -e \
380 'pod2usage -input => *STDIN, -output => *STDOUT, -verbose => '$1', -exitval => 0, -noperldoc => 1' <"$0" \ 420 'pod2usage -input => *STDIN, -output => *STDOUT, -verbose => '$1', -exitval => 0, -noperldoc => 1' <"$0" \
381 2>/dev/null && exit 421 2>/dev/null && exit
382 fi 422 fi
423
383 # try whatever perl we can find 424 # try whatever perl we can find
384 perl -MPod::Usage -e \ 425 perl -MPod::Usage -e \
385 'pod2usage -input => *STDIN, -output => *STDOUT, -verbose => '$1', -exitval => 0, -noperldoc => 1' <"$0" \ 426 'pod2usage -input => *STDIN, -output => *STDOUT, -verbose => '$1', -exitval => 0, -noperldoc => 1' <"$0" \
386 2>/dev/null && exit 427 2>/dev/null && exit
387 428
388 fatal "displaying documentation requires a working perl - try '$0 install' first" 429 fatal "displaying documentation requires a working perl - try '$0 install' to build one in a safe location"
389} 430}
390 431
391usage() { 432usage() {
392 podusage 0 433 podusage 0
393} 434}
418 command="${1#--}"; shift 459 command="${1#--}"; shift
419 case "$command" in 460 case "$command" in
420 version ) 461 version )
421 echo "staticperl version $VERSION" 462 echo "staticperl version $VERSION"
422 ;; 463 ;;
423 fetch | configure | build | install | clean | distclean) 464 fetch | configure | build | install | clean | realclean | distclean)
424 ( "$command" ) 465 ( "$command" ) || exit
425 ;; 466 ;;
426 instsrc ) 467 instsrc )
427 ( instsrc "$@" ) 468 ( instsrc "$@" ) || exit
428 exit 469 exit
429 ;; 470 ;;
430 instcpan ) 471 instcpan )
431 ( instcpan "$@" ) 472 ( instcpan "$@" ) || exit
432 exit 473 exit
433 ;; 474 ;;
434 cpan ) 475 cpan )
435 ( install ) 476 ( install ) || exit
436 "$PERL_PREFIX/bin/cpan" "$@" 477 "$PERL_PREFIX/bin/cpan" "$@"
437 exit 478 exit
438 ;; 479 ;;
439 mkbundle ) 480 mkbundle )
440 ( install ) 481 ( install ) || exit
441 bundle "$@" 482 bundle "$@"
442 exit 483 exit
443 ;; 484 ;;
444 mkperl ) 485 mkperl )
445 ( install ) 486 ( install ) || exit
446 bundle --perl "$@" 487 bundle --perl "$@"
447 exit 488 exit
448 ;; 489 ;;
449 mkapp ) 490 mkapp )
450 ( install ) 491 ( install ) || exit
451 bundle --app "$@" 492 bundle --app "$@"
452 exit 493 exit
453 ;; 494 ;;
454 help ) 495 help )
455 podusage 2 496 podusage 2

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines