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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines