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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines