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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines