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.4 by root, Tue Dec 7 09:27:54 2010 UTC vs.
Revision 1.14 by root, Fri Dec 10 20:29:17 2010 UTC

1#!/bin/sh 1#!/bin/sh
2 2
3############################################################################# 3#############################################################################
4# configuration to fill in 4# configuration to fill in
5 5
6PERLVER=5.12.2 # 5.8.9 is also a good choice
7STATICPERL=~/.staticperl 6STATICPERL=~/.staticperl
8CPAN=http://mirror.netcologne.de/cpan/ # which mirror to use 7CPAN=http://mirror.netcologne.de/cpan # which mirror to use
9EMAIL="read the documentation <rtfm@example.org>" 8EMAIL="read the documentation <rtfm@example.org>"
10 9
11MKBUNDLE="$STATICPERL/mkbundle"
12 10
13# perl build variables 11# perl build variables
14PREFIX="$STATICPERL/perl" # where the perl gets installed 12PERL_VERSION=5.12.2 # 5.8.9 is also a good choice
15PERL_CONFIGURE="" # additional Configure arguments 13PERL_CONFIGURE="" # additional Configure arguments
16PERL_CPPFLAGS="-DPERL_DISABLE_PMC -DPERL_ARENA_SIZE=65536 -D_GNU_SOURCE -DNDEBUG -USITELIB_EXP -USITEARCHEXP -UARCHLIB_EXP" 14PERL_CPPFLAGS="-DPERL_DISABLE_PMC -DPERL_ARENA_SIZE=65536 -D_GNU_SOURCE -DNDEBUG -USITELIB_EXP -USITEARCHEXP -UARCHLIB_EXP"
17PERL_OPTIMIZE="-Os -ffunction-sections -fdata-sections -finline-limit=8 -ffast-math" 15PERL_OPTIMIZE="-Os -ffunction-sections -fdata-sections -finline-limit=8 -ffast-math"
18 16
19ARCH="$(uname -m)" 17ARCH="$(uname -m)"
46 44
47# which extra modules you might want to install 45# which extra modules you might want to install
48EXTRA_MODULES="" 46EXTRA_MODULES=""
49 47
50# overridable functions 48# overridable functions
49preconfigure() { : ; }
51postconfigure() { : ; } 50postconfigure() { : ; }
52postbuild() { : ; } 51postbuild() { : ; }
53postinstall() { : ; } 52postinstall() { : ; }
54 53
55# now source user config, if any 54# now source user config, if any
55if [ "$STATICPERLRC" ]; then
56 . "$STATICPERLRC"
57else
56[ -r /etc/staticperlrc ] && . /etc/staticperlrc 58 [ -r /etc/staticperlrc ] && . /etc/staticperlrc
57[ -r ~/.staticperlrc ] && . ~/.staticperlrc 59 [ -r ~/.staticperlrc ] && . ~/.staticperlrc
58[ -r "$STATICPERL/rc" ] && . "$STATICPERL/rc" 60 [ -r "$STATICPERL/rc" ] && . "$STATICPERL/rc"
61fi
59 62
60############################################################################# 63#############################################################################
61# support 64# support
65
66MKBUNDLE="${MKBUNDLE:=$STATICPERL/mkbundle}"
67PERL_PREFIX="${PERL_PREFIX:=$STATICPERL/perl}" # where the perl gets installed
68
69unset PERL5OPT PERL5LIB PERLLIB PERL_UNICODE PERLIO_DEBUG
70export LC_ALL=C # just to be on the safe side
62 71
63# set version in a way that Makefile.PL can extract 72# set version in a way that Makefile.PL can extract
64VERSION=VERSION; eval \ 73VERSION=VERSION; eval \
65$VERSION=0.1 74$VERSION=0.9
66 75
67BZ2=bz2 76BZ2=bz2
68BZIP2=bzip2 77BZIP2=bzip2
69 78
70fatal() { 79fatal() {
103############################################################################# 112#############################################################################
104# clean 113# clean
105 114
106distclean() { 115distclean() {
107 verblock <<EOF 116 verblock <<EOF
108deleting everything installed by this script 117 deleting everything installed by this script (rm -rf $STATICPERL)
109EOF 118EOF
110 119
111 rm -rf "$STATICPERL" 120 rm -rf "$STATICPERL"
112} 121}
113 122
114############################################################################# 123#############################################################################
115# download/configure/compile/install perl 124# download/configure/compile/install perl
116 125
117clean() { 126clean() {
118 cd "$STATICPERL/src/perl-$PERLVER" 2>/dev/null || return 127 rm -rf "$STATICPERL/src/perl-$PERL_VERSION"
119
120 rm -f staticstamp.configure
121 make distclean >/dev/null 2>&1
122} 128}
123 129
124fetch() { 130fetch() {
125 rcd "$STATICPERL" 131 rcd "$STATICPERL"
126 132
127 mkdir -p src 133 mkdir -p src
128 rcd src 134 rcd src
129 135
130 if ! [ -d "perl-$PERLVER" ]; then 136 if ! [ -d "perl-$PERL_VERSION" ]; then
131 if ! [ -e "perl-$PERLVER.tar.$BZ2" ]; then 137 if ! [ -e "perl-$PERL_VERSION.tar.$BZ2" ]; then
132 138
133 URL="$CPAN/src/5.0/perl-$PERLVER.tar.$BZ2" 139 URL="$CPAN/src/5.0/perl-$PERL_VERSION.tar.$BZ2"
134 140
135 verblock <<EOF 141 verblock <<EOF
136downloading perl 142downloading perl
137to manually download perl yourself, place 143to manually download perl yourself, place
138perl-$PERLVER.tar.$BZ2 in $STATICPERL 144perl-$PERL_VERSION.tar.$BZ2 in $STATICPERL
139trying $URL 145trying $URL
140EOF 146EOF
141 147
142 curl >perl-$PERLVER.tar.$BZ2~ "$URL" \ 148 rm -f perl-$PERL_VERSION.tar.$BZ2~ # just to be on the safe side
143 || wget -O perl-$PERLVER.tar.$BZ2~ "$URL" \ 149 wget -O perl-$PERL_VERSION.tar.$BZ2~ "$URL" \
150 || curl >perl-$PERL_VERSION.tar.$BZ2~ "$URL" \
144 || fatal "$URL: error during downloading" 151 || fatal "$URL: unable to download"
145 mv perl-$PERLVER.tar.$BZ2~ perl-$PERLVER.tar.$BZ2 152 mv perl-$PERL_VERSION.tar.$BZ2~ perl-$PERL_VERSION.tar.$BZ2
146 fi 153 fi
147 154
148 verblock <<EOF 155 verblock <<EOF
149unpacking perl 156unpacking perl
150EOF 157EOF
151 158
152 mkdir -p unpack 159 mkdir -p unpack
153 $BZIP2 -d <perl-$PERLVER.tar.bz2 | tar xpC unpack \ 160 $BZIP2 -d <perl-$PERL_VERSION.tar.bz2 | tar xfC - unpack \
154 || fatal "perl-$PERLVER.tar.bz2: error during unpacking" 161 || fatal "perl-$PERL_VERSION.tar.bz2: error during unpacking"
162 chmod -R u+w unpack/perl-$PERL_VERSION
155 mv unpack/perl-$PERLVER perl-$PERLVER 163 mv unpack/perl-$PERL_VERSION perl-$PERL_VERSION
156 rmdir -p unpack 164 rmdir -p unpack
157 fi 165 fi
158} 166}
159 167
160# similar to GNU-sed -i or perl -pi 168# similar to GNU-sed -i or perl -pi
164} 172}
165 173
166configure() { 174configure() {
167 fetch 175 fetch
168 176
169 rcd "$STATICPERL/src/perl-$PERLVER" 177 rcd "$STATICPERL/src/perl-$PERL_VERSION"
170 178
171 [ -e staticstamp.configure ] && return 179 [ -e staticstamp.configure ] && return
172 180
173 verblock <<EOF 181 verblock <<EOF
174configuring $STATICPERL/src/perl-$PERLVER 182configuring $STATICPERL/src/perl-$PERL_VERSION
175EOF 183EOF
176 184
177 clean
178
179 rm -f "$PREFIX/staticstamp.install" 185 rm -f "$PERL_PREFIX/staticstamp.install"
186
187 make distclean >/dev/null 2>&1
180 188
181 # I hate them 189 # I hate them
182 grep -q -- -fstack-protector Configure && \ 190 grep -q -- -fstack-protector Configure && \
183 sedreplace 's/-fstack-protector/-fno-stack-protector/g' Configure 191 sedreplace 's/-fstack-protector/-fno-stack-protector/g' Configure
192
193 preconfigure
184 194
185# trace configure \ 195# trace configure \
186 sh Configure -Duselargefiles \ 196 sh Configure -Duselargefiles \
187 -Uuse64bitint \ 197 -Uuse64bitint \
188 -Dusemymalloc=n \ 198 -Dusemymalloc=n \
196 -Dcppflags="$PERL_CPPFLAGS" \ 206 -Dcppflags="$PERL_CPPFLAGS" \
197 -Dccflags="-g2 -fno-strict-aliasing" \ 207 -Dccflags="-g2 -fno-strict-aliasing" \
198 -Doptimize="$PERL_OPTIMIZE" \ 208 -Doptimize="$PERL_OPTIMIZE" \
199 -Dldflags="$PERL_LDFLAGS" \ 209 -Dldflags="$PERL_LDFLAGS" \
200 -Dlibs="$PERL_LIBS" \ 210 -Dlibs="$PERL_LIBS" \
201 -Dprefix="$PREFIX" \ 211 -Dprefix="$PERL_PREFIX" \
202 -Dbin="$PREFIX/bin" \ 212 -Dbin="$PERL_PREFIX/bin" \
203 -Dprivlib="$PREFIX/lib" \ 213 -Dprivlib="$PERL_PREFIX/lib" \
204 -Darchlib="$PREFIX/lib" \ 214 -Darchlib="$PERL_PREFIX/lib" \
205 -Uusevendorprefix \ 215 -Uusevendorprefix \
206 -Dsitelib="$PREFIX/lib" \ 216 -Dsitelib="$PERL_PREFIX/lib" \
207 -Dsitearch="$PREFIX/lib" \ 217 -Dsitearch="$PERL_PREFIX/lib" \
208 -Usitelibexp \ 218 -Usitelibexp \
209 -Uman1dir \ 219 -Uman1dir \
210 -Uman3dir \ 220 -Uman3dir \
211 -Usiteman1dir \ 221 -Usiteman1dir \
212 -Usiteman3dir \ 222 -Usiteman3dir \
230} 240}
231 241
232build() { 242build() {
233 configure 243 configure
234 244
235 rcd "$STATICPERL/src/perl-$PERLVER" 245 rcd "$STATICPERL/src/perl-$PERL_VERSION"
236 246
237 verblock <<EOF 247 verblock <<EOF
238building $STATICPERL/src/perl-$PERLVER 248building $STATICPERL/src/perl-$PERL_VERSION
239EOF 249EOF
240 250
241 rm -f "$PREFIX/staticstamp.install" 251 rm -f "$PERL_PREFIX/staticstamp.install"
242 252
243 make || fatal "make: error while building perl" 253 make || fatal "make: error while building perl"
244 254
245 postbuild || fatal "postbuild hook failed" 255 postbuild || fatal "postbuild hook failed"
246} 256}
247 257
248install() { 258install() {
249 [ -e "$PREFIX/staticstamp.install" ] && return 259 if ! [ -e "$PERL_PREFIX/staticstamp.install" ]; then
250
251 build 260 build
252 261
253 verblock <<EOF 262 verblock <<EOF
254installing $STATICPERL/src/perl-$PERLVER 263installing $STATICPERL/src/perl-$PERL_VERSION
255to $PREFIX 264to $PERL_PREFIX
256EOF 265EOF
257 266
258 rm -rf "$PREFIX" 267 ln -sf "perl/bin/" "$STATICPERL/bin"
259 268 ln -sf "perl/lib/" "$STATICPERL/lib"
269
270 ln -sf "$PERL_PREFIX" "$STATICPERL/perl" # might get overwritten
271 rm -rf "$PERL_PREFIX" # by this rm -rf
272
260 make install || fatal "make install: error while installing" 273 make install || fatal "make install: error while installing"
261 274
262 rcd "$PREFIX" 275 rcd "$PERL_PREFIX"
263 276
264 # create a "make install" replacement for CPAN 277 # create a "make install" replacement for CPAN
265 cat >"$PREFIX"/bin/cpan-make-install <<EOF 278 cat >"$PERL_PREFIX"/bin/cpan-make-install <<EOF
266make install UNINST=1 279make || exit
280
267if find blib/arch/auto -type f | grep -q -v .exists; then 281if find blib/arch/auto -type f | grep -q -v .exists; then
268 echo Probably an XS module, rebuilding perl 282 echo Probably an XS module, rebuilding perl
269 make perl 283 if make perl; then
270 rm -f "$PREFIX"/bin/perl 284 mv perl "$PERL_PREFIX"/bin/perl
271 make -f Makefile.aperl inst_perl
272 make -f Makefile.aperl map_clean 285 make -f Makefile.aperl map_clean
286 else
287 make -f Makefile.aperl map_clean
288 exit 1
289 fi
273fi 290fi
291
292make install UNINST=1
274EOF 293EOF
275 chmod 755 "$PREFIX"/bin/cpan-make-install 294 chmod 755 "$PERL_PREFIX"/bin/cpan-make-install
276 295
277 # trick CPAN into avoiding ~/.cpan completely 296 # trick CPAN into avoiding ~/.cpan completely
278 echo 1 >"$PREFIX/lib/CPAN/MyConfig.pm" 297 echo 1 >"$PERL_PREFIX/lib/CPAN/MyConfig.pm"
279 298
280 "$PREFIX"/bin/perl -MCPAN -e ' 299 "$PERL_PREFIX"/bin/perl -MCPAN -e '
281 CPAN::Shell->o (conf => urllist => push => "'"$CPAN"'"); 300 CPAN::Shell->o (conf => urllist => push => "'"$CPAN"'");
282 CPAN::Shell->o (conf => q<cpan_home>, "'"$STATICPERL"'/cpan"); 301 CPAN::Shell->o (conf => q<cpan_home>, "'"$STATICPERL"'/cpan");
283 CPAN::Shell->o (conf => q<init>); 302 CPAN::Shell->o (conf => q<init>);
284 CPAN::Shell->o (conf => q<cpan_home>, "'"$STATICPERL"'/cpan"); 303 CPAN::Shell->o (conf => q<cpan_home>, "'"$STATICPERL"'/cpan");
285 CPAN::Shell->o (conf => q<build_dir>, "'"$STATICPERL"'/cpan/build"); 304 CPAN::Shell->o (conf => q<build_dir>, "'"$STATICPERL"'/cpan/build");
286 CPAN::Shell->o (conf => q<prefs_dir>, "'"$STATICPERL"'/cpan/prefs"); 305 CPAN::Shell->o (conf => q<prefs_dir>, "'"$STATICPERL"'/cpan/prefs");
287 CPAN::Shell->o (conf => q<histfile> , "'"$STATICPERL"'/cpan/histfile"); 306 CPAN::Shell->o (conf => q<histfile> , "'"$STATICPERL"'/cpan/histfile");
288 CPAN::Shell->o (conf => q<keep_source_where>, "'"$STATICPERL"'/cpan/sources"); 307 CPAN::Shell->o (conf => q<keep_source_where>, "'"$STATICPERL"'/cpan/sources");
289 CPAN::Shell->o (conf => q<make_install_make_command>, "'"$PREFIX"'/bin/cpan-make-install"); 308 CPAN::Shell->o (conf => q<make_install_make_command>, "'"$PERL_PREFIX"'/bin/cpan-make-install");
290 CPAN::Shell->o (conf => q<prerequisites_policy>, q<follow>); 309 CPAN::Shell->o (conf => q<prerequisites_policy>, q<follow>);
291 CPAN::Shell->o (conf => q<build_requires_install_policy>, q<no>); 310 CPAN::Shell->o (conf => q<build_requires_install_policy>, q<no>);
292 CPAN::Shell->o (conf => q<commit>); 311 CPAN::Shell->o (conf => q<commit>);
293 ' || fatal "error while initialising CPAN" 312 ' || fatal "error while initialising CPAN"
294 313
314 touch "$PERL_PREFIX/staticstamp.install"
315 fi
316
317 if ! [ -e "$PERL_PREFIX/staticstamp.postinstall" ]; then
295 NOCHECK_INSTALL=+ 318 NOCHECK_INSTALL=+
296 instcpan $STATICPERL_MODULES 319 instcpan $STATICPERL_MODULES
297 [ $EXTRA_MODULES ] && instcpan $EXTRA_MODULES 320 [ $EXTRA_MODULES ] && instcpan $EXTRA_MODULES
298 321
299 postinstall || fatal "postinstall hook failed" 322 postinstall || fatal "postinstall hook failed"
300 323
301 touch "$PREFIX/staticstamp.install" 324 touch "$PERL_PREFIX/staticstamp.postinstall"
325 fi
302} 326}
303 327
304############################################################################# 328#############################################################################
305# install a module from CPAN 329# install a module from CPAN
306 330
311installing modules from CPAN 335installing modules from CPAN
312$@ 336$@
313EOF 337EOF
314 338
315 for mod in "$@"; do 339 for mod in "$@"; do
316 "$PREFIX"/bin/perl -MCPAN -e 'notest install => "'"$mod"'"' \ 340 "$PERL_PREFIX"/bin/perl -MCPAN -e 'notest install => "'"$mod"'"' \
317 || fatal "$mod: unable to install from CPAN" 341 || fatal "$mod: unable to install from CPAN"
318 done 342 done
319 rm -rf "$STATICPERL/build" 343 rm -rf "$STATICPERL/build"
320} 344}
321 345
335 echo $mod 359 echo $mod
336 ( 360 (
337 rcd $mod 361 rcd $mod
338 make -f Makefile.aperl map_clean >/dev/null 2>&1 362 make -f Makefile.aperl map_clean >/dev/null 2>&1
339 make distclean >/dev/null 2>&1 363 make distclean >/dev/null 2>&1
340 "$PREFIX"/bin/perl Makefile.PL || fatal "$mod: error running Makefile.PL" 364 "$PERL_PREFIX"/bin/perl Makefile.PL || fatal "$mod: error running Makefile.PL"
341 make || fatal "$mod: error building module" 365 make || fatal "$mod: error building module"
342 "$PREFIX"/bin/cpan-make-install || fatal "$mod: error installing module" 366 "$PERL_PREFIX"/bin/cpan-make-install || fatal "$mod: error installing module"
343 make distclean >/dev/null 2>&1 367 make distclean >/dev/null 2>&1
344 exit 0 368 exit 0
345 ) || exit $? 369 ) || exit $?
346 done 370 done
347} 371}
348 372
349############################################################################# 373#############################################################################
350# do schmorpy stuff
351
352MODSRCDIR=~/src
353
354instmodsrc() {
355 for mod in "$@"; do
356 instmod_src "$MODSRCDIR/$mod"
357 done
358}
359
360install_schmorp() {
361 install
362
363 instcpan Data::Dump Term::ReadLine::Perl Term::ANSIColor Term::ReadKey
364 instcpan Digest::SHA Digest::MD6 Digest::SHA256 Digest::MD4 Digest::HMAC_MD5 Digest::HMAC_MD6 Digest::FNV
365 #instcpan Net::SSLeay # requires static -ldl
366
367 instmodsrc common-sense Crypt-Twofish2 Array-Heap Convert-Scalar Compress-LZF JSON-XS
368 instmodsrc EV Guard Async-Interrupt IO-AIO
369 instmodsrc AnyEvent AnyEvent-AIO Coro AnyEvent-HTTP
370 instmodsrc Linux-Inotify2 EV-Loop-Async
371
372 instcpan AnyEvent::HTTPD
373}
374
375#############################################################################
376# main 374# main
377 375
378podusage() { 376podusage() {
379 echo 377 echo
380 if [ -e "$PREFIX/bin/perl" ]; then 378 if [ -e "$PERL_PREFIX/bin/perl" ]; then
381 "$PREFIX/bin/perl" -MPod::Usage -e \ 379 "$PERL_PREFIX/bin/perl" -MPod::Usage -e \
382 'pod2usage -input => *STDIN, -output => *STDOUT, -verbose => '$1', -exitval => 0, -noperldoc => 1' <"$0" \ 380 'pod2usage -input => *STDIN, -output => *STDOUT, -verbose => '$1', -exitval => 0, -noperldoc => 1' <"$0" \
383 2>/dev/null && exit 381 2>/dev/null && exit
384 fi 382 fi
385 # try whatever perl we can find 383 # try whatever perl we can find
386 perl -MPod::Usage -e \ 384 perl -MPod::Usage -e \
395} 393}
396 394
397catmkbundle() { 395catmkbundle() {
398 { 396 {
399 read dummy 397 read dummy
400 echo "#!$PREFIX/bin/perl" 398 echo "#!$PERL_PREFIX/bin/perl"
401 cat 399 cat
402 } <<'MKBUNDLE' 400 } <<'MKBUNDLE'
403#CAT mkbundle 401#CAT mkbundle
404MKBUNDLE 402MKBUNDLE
405} 403}
406 404
407bundle() { 405bundle() {
408 catmkbundle >"$MKBUNDLE~" || fatal "$MKBUNDLE~: cannot create" 406 catmkbundle >"$MKBUNDLE~" || fatal "$MKBUNDLE~: cannot create"
409 chmod 755 "$MKBUNDLE~" && mv "$MKBUNDLE~" "$MKBUNDLE" 407 chmod 755 "$MKBUNDLE~" && mv "$MKBUNDLE~" "$MKBUNDLE"
408 CACHE="$STATICPERL/cache"
409 mkdir -p "$CACHE"
410 "$PREFIX/bin/perl" -- "$MKBUNDLE" "$@" 410 "$PERL_PREFIX/bin/perl" -- "$MKBUNDLE" --cache "$CACHE" "$@"
411} 411}
412 412
413if [ $# -gt 0 ]; then 413if [ $# -gt 0 ]; then
414 while [ $# -gt 0 ]; do 414 while [ $# -gt 0 ]; do
415 mkdir -p "$STATICPERL" || fatal "$STATICPERL: cannot create" 415 mkdir -p "$STATICPERL" || fatal "$STATICPERL: cannot create"
416 mkdir -p "$PREFIX" || fatal "$PREFIX: cannot create" 416 mkdir -p "$PERL_PREFIX" || fatal "$PERL_PREFIX: cannot create"
417 417
418 command="${1#--}"; shift 418 command="${1#--}"; shift
419 case "$command" in 419 case "$command" in
420 version )
421 echo "staticperl version $VERSION"
422 ;;
420 fetch | configure | build | install | clean | distclean) 423 fetch | configure | build | install | clean | distclean)
421 verblock <<EOF
422$command
423EOF
424 "$command" 424 ( "$command" )
425 ;; 425 ;;
426 instsrc ) 426 instsrc )
427 instsrc "$@" 427 ( instsrc "$@" )
428 exit 428 exit
429 ;; 429 ;;
430 instcpan ) 430 instcpan )
431 instcpan "$@" 431 ( instcpan "$@" )
432 exit
433 ;; 432 exit
434 instschmorp )
435 install_schmorp
436 ;; 433 ;;
437 cpan ) 434 cpan )
438 install 435 ( install )
439 "$PREFIX/bin/cpan" "$@" 436 "$PERL_PREFIX/bin/cpan" "$@"
440 exit 437 exit
441 ;; 438 ;;
442 mkbundle ) 439 mkbundle )
443 install 440 ( install )
444 bundle "$@" 441 bundle "$@"
445 exit 442 exit
446 ;; 443 ;;
447 mkperl ) 444 mkperl )
448 install 445 ( install )
449 bundle --perl "$@" 446 bundle --perl "$@"
447 exit
448 ;;
449 mkapp )
450 ( install )
451 bundle --app "$@"
450 exit 452 exit
451 ;; 453 ;;
452 help ) 454 help )
453 podusage 2 455 podusage 2
454 ;; 456 ;;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines