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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines