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.9 by root, Tue Dec 7 20:03:15 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
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 install UNINST=1
265if find blib/arch/auto -type f | grep -q -v .exists; then 268if find blib/arch/auto -type f | grep -q -v .exists; then
266 echo Probably an XS module, rebuilding perl 269 echo Probably an XS module, rebuilding perl
267 make perl 270 make perl
268 rm -f "$PREFIX"/bin/perl 271 rm -f "$PERL_PREFIX"/bin/perl
269 make -f Makefile.aperl inst_perl 272 make -f Makefile.aperl inst_perl
270 make -f Makefile.aperl map_clean 273 make -f Makefile.aperl map_clean
271fi 274fi
272EOF 275EOF
273 chmod 755 "$PREFIX"/bin/cpan-make-install 276 chmod 755 "$PERL_PREFIX"/bin/cpan-make-install
274 277
275 # trick CPAN into avoiding ~/.cpan completely 278 # trick CPAN into avoiding ~/.cpan completely
276 echo 1 >"$PREFIX/lib/CPAN/MyConfig.pm" 279 echo 1 >"$PERL_PREFIX/lib/CPAN/MyConfig.pm"
277 280
278 "$PREFIX"/bin/perl -MCPAN -e ' 281 "$PERL_PREFIX"/bin/perl -MCPAN -e '
279 CPAN::Shell->o (conf => urllist => push => "'"$CPAN"'"); 282 CPAN::Shell->o (conf => urllist => push => "'"$CPAN"'");
280 CPAN::Shell->o (conf => q<cpan_home>, "'"$STATICPERL"'/cpan"); 283 CPAN::Shell->o (conf => q<cpan_home>, "'"$STATICPERL"'/cpan");
281 CPAN::Shell->o (conf => q<init>); 284 CPAN::Shell->o (conf => q<init>);
282 CPAN::Shell->o (conf => q<cpan_home>, "'"$STATICPERL"'/cpan"); 285 CPAN::Shell->o (conf => q<cpan_home>, "'"$STATICPERL"'/cpan");
283 CPAN::Shell->o (conf => q<build_dir>, "'"$STATICPERL"'/cpan/build"); 286 CPAN::Shell->o (conf => q<build_dir>, "'"$STATICPERL"'/cpan/build");
284 CPAN::Shell->o (conf => q<prefs_dir>, "'"$STATICPERL"'/cpan/prefs"); 287 CPAN::Shell->o (conf => q<prefs_dir>, "'"$STATICPERL"'/cpan/prefs");
285 CPAN::Shell->o (conf => q<histfile> , "'"$STATICPERL"'/cpan/histfile"); 288 CPAN::Shell->o (conf => q<histfile> , "'"$STATICPERL"'/cpan/histfile");
286 CPAN::Shell->o (conf => q<keep_source_where>, "'"$STATICPERL"'/cpan/sources"); 289 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"); 290 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>); 291 CPAN::Shell->o (conf => q<prerequisites_policy>, q<follow>);
289 CPAN::Shell->o (conf => q<build_requires_install_policy>, q<no>); 292 CPAN::Shell->o (conf => q<build_requires_install_policy>, q<no>);
290 CPAN::Shell->o (conf => q<commit>); 293 CPAN::Shell->o (conf => q<commit>);
291 ' || fatal "error while initialising CPAN" 294 ' || fatal "error while initialising CPAN"
292 295
296 touch "$PERL_PREFIX/staticstamp.install"
297 fi
298
299 if ! [ -e "$PERL_PREFIX/staticstamp.postinstall"; then
293 NOCHECK_INSTALL=+ 300 NOCHECK_INSTALL=+
294 instcpan $STATICPERL_MODULES 301 instcpan $STATICPERL_MODULES
295 [ $EXTRA_MODULES ] && instcpan $EXTRA_MODULES 302 [ $EXTRA_MODULES ] && instcpan $EXTRA_MODULES
296 303
297 postinstall || fatal "postinstall hook failed" 304 postinstall || fatal "postinstall hook failed"
298 305
299 touch "$PREFIX/staticstamp.install" 306 touch "$PERL_PREFIX/staticstamp.postinstall"
307 fi
300} 308}
301 309
302############################################################################# 310#############################################################################
303# install a module from CPAN 311# install a module from CPAN
304 312
309installing modules from CPAN 317installing modules from CPAN
310$@ 318$@
311EOF 319EOF
312 320
313 for mod in "$@"; do 321 for mod in "$@"; do
314 "$PREFIX"/bin/perl -MCPAN -e 'notest install => "'"$mod"'"' \ 322 "$PERL_PREFIX"/bin/perl -MCPAN -e 'notest install => "'"$mod"'"' \
315 || fatal "$mod: unable to install from CPAN" 323 || fatal "$mod: unable to install from CPAN"
316 done 324 done
317 rm -rf "$STATICPERL/build" 325 rm -rf "$STATICPERL/build"
318} 326}
319 327
333 echo $mod 341 echo $mod
334 ( 342 (
335 rcd $mod 343 rcd $mod
336 make -f Makefile.aperl map_clean >/dev/null 2>&1 344 make -f Makefile.aperl map_clean >/dev/null 2>&1
337 make distclean >/dev/null 2>&1 345 make distclean >/dev/null 2>&1
338 "$PREFIX"/bin/perl Makefile.PL || fatal "$mod: error running Makefile.PL" 346 "$PERL_PREFIX"/bin/perl Makefile.PL || fatal "$mod: error running Makefile.PL"
339 make || fatal "$mod: error building module" 347 make || fatal "$mod: error building module"
340 "$PREFIX"/bin/cpan-make-install || fatal "$mod: error installing module" 348 "$PERL_PREFIX"/bin/cpan-make-install || fatal "$mod: error installing module"
341 make distclean >/dev/null 2>&1 349 make distclean >/dev/null 2>&1
342 exit 0 350 exit 0
343 ) || exit $? 351 ) || exit $?
344 done 352 done
345} 353}
346 354
347############################################################################# 355#############################################################################
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 356# main
375 357
376podusage() { 358podusage() {
377 echo 359 echo
378 if [ -e "$PREFIX/bin/perl" ]; then 360 if [ -e "$PERL_PREFIX/bin/perl" ]; then
379 "$PREFIX/bin/perl" -MPod::Usage -e \ 361 "$PERL_PREFIX/bin/perl" -MPod::Usage -e \
380 'pod2usage -input => *STDIN, -output => *STDOUT, -verbose => '$1', -exitval => 0, -noperldoc => 1' <"$0" \ 362 'pod2usage -input => *STDIN, -output => *STDOUT, -verbose => '$1', -exitval => 0, -noperldoc => 1' <"$0" \
381 2>/dev/null && exit 363 2>/dev/null && exit
382 fi 364 fi
383 # try whatever perl we can find 365 # try whatever perl we can find
384 perl -MPod::Usage -e \ 366 perl -MPod::Usage -e \
393} 375}
394 376
395catmkbundle() { 377catmkbundle() {
396 { 378 {
397 read dummy 379 read dummy
398 echo "#!$PREFIX/bin/perl" 380 echo "#!$PERL_PREFIX/bin/perl"
399 cat 381 cat
400 } <<'MKBUNDLE' 382 } <<'MKBUNDLE'
401#CAT mkbundle 383#CAT mkbundle
402MKBUNDLE 384MKBUNDLE
403} 385}
404 386
405bundle() { 387bundle() {
406 catmkbundle >"$MKBUNDLE~" || fatal "$MKBUNDLE~: cannot create" 388 catmkbundle >"$MKBUNDLE~" || fatal "$MKBUNDLE~: cannot create"
407 chmod 755 "$MKBUNDLE~" && mv "$MKBUNDLE~" "$MKBUNDLE" 389 chmod 755 "$MKBUNDLE~" && mv "$MKBUNDLE~" "$MKBUNDLE"
408 "$PREFIX/bin/perl" -- "$MKBUNDLE" "$@" 390 "$PERL_PREFIX/bin/perl" -- "$MKBUNDLE" "$@"
409} 391}
410 392
411if [ $# -gt 0 ]; then 393if [ $# -gt 0 ]; then
412 while [ $# -gt 0 ]; do 394 while [ $# -gt 0 ]; do
413 mkdir -p "$STATICPERL" || fatal "$STATICPERL: cannot create" 395 mkdir -p "$STATICPERL" || fatal "$STATICPERL: cannot create"
414 mkdir -p "$PREFIX" || fatal "$PREFIX: cannot create" 396 mkdir -p "$PERL_PREFIX" || fatal "$PERL_PREFIX: cannot create"
415 397
416 command="${1#--}"; shift 398 command="${1#--}"; shift
417 case "$command" in 399 case "$command" in
418 fetch | configure | build | install | clean | distclean) 400 fetch | configure | build | install | clean | distclean)
419 verblock <<EOF 401 verblock <<EOF
420$command 402$command
421EOF 403EOF
422 "$command" 404 ( "$command" )
423 ;; 405 ;;
424 instsrc ) 406 instsrc )
425 instsrc "$@" 407 ( instsrc "$@" )
426 exit 408 exit
427 ;; 409 ;;
428 instcpan ) 410 instcpan )
429 instcpan "$@" 411 ( instcpan "$@" )
430 exit 412 exit
431 ;; 413 ;;
432 instschmorp )
433 install_schmorp
434 ;;
435 cpan ) 414 cpan )
436 install 415 ( install )
437 "$PREFIX/bin/cpan" "$@" 416 "$PERL_PREFIX/bin/cpan" "$@"
438 exit 417 exit
439 ;; 418 ;;
440 mkbundle ) 419 mkbundle )
441 install 420 ( install )
442 bundle "$@" 421 bundle "$@"
443 exit 422 exit
444 ;; 423 ;;
445 mkperl ) 424 mkperl )
446 install 425 ( install )
447 bundle --perl "$@" 426 bundle --perl "$@"
448 exit 427 exit
449 ;; 428 ;;
450 help ) 429 help )
451 podusage 2 430 podusage 2

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines