1 | #!/bin/sh |
1 | #!/bin/sh |
2 | |
2 | |
3 | ############################################################################# |
3 | ############################################################################# |
4 | # configuration to fill in |
4 | # configuration to fill in |
5 | |
5 | |
6 | PERLVER=5.12.2 # 5.8.9 is also a good choice |
|
|
7 | STATICPERL=~/.staticperl |
6 | STATICPERL=~/.staticperl |
8 | CPAN=http://mirror.netcologne.de/cpan/ # which mirror to use |
7 | CPAN=http://mirror.netcologne.de/cpan/ # which mirror to use |
9 | EMAIL="read the documentation <rtfm@example.org>" |
8 | EMAIL="read the documentation <rtfm@example.org>" |
10 | |
9 | |
11 | MKBUNDLE="$STATICPERL/mkbundle" |
10 | MKBUNDLE="$STATICPERL/mkbundle" |
12 | |
11 | |
13 | # perl build variables |
12 | # perl build variables |
14 | PREFIX="$STATICPERL/perl" # where the perl gets installed |
13 | PERL_PREFIX="$STATICPERL/perl" # where the perl gets installed |
|
|
14 | PERL_VERSION=5.12.2 # 5.8.9 is also a good choice |
15 | PERL_CONFIGURE="" # additional Configure arguments |
15 | PERL_CONFIGURE="" # additional Configure arguments |
16 | PERL_CPPFLAGS="-DPERL_DISABLE_PMC -DPERL_ARENA_SIZE=65536 -D_GNU_SOURCE -DNDEBUG -USITELIB_EXP -USITEARCHEXP -UARCHLIB_EXP" |
16 | PERL_CPPFLAGS="-DPERL_DISABLE_PMC -DPERL_ARENA_SIZE=65536 -D_GNU_SOURCE -DNDEBUG -USITELIB_EXP -USITEARCHEXP -UARCHLIB_EXP" |
17 | PERL_OPTIMIZE="-Os -ffunction-sections -fdata-sections -finline-limit=8 -ffast-math" |
17 | PERL_OPTIMIZE="-Os -ffunction-sections -fdata-sections -finline-limit=8 -ffast-math" |
18 | |
18 | |
19 | ARCH="$(uname -m)" |
19 | ARCH="$(uname -m)" |
… | |
… | |
113 | |
113 | |
114 | ############################################################################# |
114 | ############################################################################# |
115 | # download/configure/compile/install perl |
115 | # download/configure/compile/install perl |
116 | |
116 | |
117 | clean() { |
117 | clean() { |
118 | cd "$STATICPERL/src/perl-$PERLVER" 2>/dev/null || return |
118 | cd "$STATICPERL/src/perl-$PERL_VERSION" 2>/dev/null || return |
119 | |
119 | |
120 | rm -f staticstamp.configure |
120 | rm -f staticstamp.configure |
121 | make distclean >/dev/null 2>&1 |
121 | make distclean >/dev/null 2>&1 |
122 | } |
122 | } |
123 | |
123 | |
… | |
… | |
125 | rcd "$STATICPERL" |
125 | rcd "$STATICPERL" |
126 | |
126 | |
127 | mkdir -p src |
127 | mkdir -p src |
128 | rcd src |
128 | rcd src |
129 | |
129 | |
130 | if ! [ -d "perl-$PERLVER" ]; then |
130 | if ! [ -d "perl-$PERL_VERSION" ]; then |
131 | if ! [ -e "perl-$PERLVER.tar.$BZ2" ]; then |
131 | if ! [ -e "perl-$PERL_VERSION.tar.$BZ2" ]; then |
132 | |
132 | |
133 | URL="$CPAN/src/5.0/perl-$PERLVER.tar.$BZ2" |
133 | URL="$CPAN/src/5.0/perl-$PERL_VERSION.tar.$BZ2" |
134 | |
134 | |
135 | verblock <<EOF |
135 | verblock <<EOF |
136 | downloading perl |
136 | downloading perl |
137 | to manually download perl yourself, place |
137 | to manually download perl yourself, place |
138 | perl-$PERLVER.tar.$BZ2 in $STATICPERL |
138 | perl-$PERL_VERSION.tar.$BZ2 in $STATICPERL |
139 | trying $URL |
139 | trying $URL |
140 | EOF |
140 | EOF |
141 | |
141 | |
142 | curl >perl-$PERLVER.tar.$BZ2~ "$URL" \ |
142 | rm -f perl-$PERL_VERSION.tar.$BZ2~ # just to be on the safe side |
143 | || wget -O perl-$PERLVER.tar.$BZ2~ "$URL" \ |
143 | wget -O perl-$PERL_VERSION.tar.$BZ2~ "$URL" \ |
|
|
144 | || curl >perl-$PERL_VERSION.tar.$BZ2~ "$URL" \ |
144 | || fatal "$URL: unable to download" |
145 | || fatal "$URL: unable to download" |
145 | mv perl-$PERLVER.tar.$BZ2~ perl-$PERLVER.tar.$BZ2 |
146 | mv perl-$PERL_VERSION.tar.$BZ2~ perl-$PERL_VERSION.tar.$BZ2 |
146 | fi |
147 | fi |
147 | |
148 | |
148 | verblock <<EOF |
149 | verblock <<EOF |
149 | unpacking perl |
150 | unpacking perl |
150 | EOF |
151 | EOF |
151 | |
152 | |
152 | mkdir -p unpack |
153 | mkdir -p unpack |
153 | $BZIP2 -d <perl-$PERLVER.tar.bz2 | tar xpC unpack \ |
154 | $BZIP2 -d <perl-$PERL_VERSION.tar.bz2 | tar xpC unpack \ |
154 | || fatal "perl-$PERLVER.tar.bz2: error during unpacking" |
155 | || fatal "perl-$PERL_VERSION.tar.bz2: error during unpacking" |
155 | mv unpack/perl-$PERLVER perl-$PERLVER |
156 | mv unpack/perl-$PERL_VERSION perl-$PERL_VERSION |
156 | rmdir -p unpack |
157 | rmdir -p unpack |
157 | fi |
158 | fi |
158 | } |
159 | } |
159 | |
160 | |
160 | # similar to GNU-sed -i or perl -pi |
161 | # similar to GNU-sed -i or perl -pi |
… | |
… | |
164 | } |
165 | } |
165 | |
166 | |
166 | configure() { |
167 | configure() { |
167 | fetch |
168 | fetch |
168 | |
169 | |
169 | rcd "$STATICPERL/src/perl-$PERLVER" |
170 | rcd "$STATICPERL/src/perl-$PERL_VERSION" |
170 | |
171 | |
171 | [ -e staticstamp.configure ] && return |
172 | [ -e staticstamp.configure ] && return |
172 | |
173 | |
173 | verblock <<EOF |
174 | verblock <<EOF |
174 | configuring $STATICPERL/src/perl-$PERLVER |
175 | configuring $STATICPERL/src/perl-$PERL_VERSION |
175 | EOF |
176 | EOF |
176 | |
177 | |
177 | clean |
178 | clean |
178 | |
179 | |
179 | rm -f "$PREFIX/staticstamp.install" |
180 | rm -f "$PERL_PREFIX/staticstamp.install" |
180 | |
181 | |
181 | # I hate them |
182 | # I hate them |
182 | grep -q -- -fstack-protector Configure && \ |
183 | grep -q -- -fstack-protector Configure && \ |
183 | sedreplace 's/-fstack-protector/-fno-stack-protector/g' Configure |
184 | sedreplace 's/-fstack-protector/-fno-stack-protector/g' Configure |
184 | |
185 | |
… | |
… | |
196 | -Dcppflags="$PERL_CPPFLAGS" \ |
197 | -Dcppflags="$PERL_CPPFLAGS" \ |
197 | -Dccflags="-g2 -fno-strict-aliasing" \ |
198 | -Dccflags="-g2 -fno-strict-aliasing" \ |
198 | -Doptimize="$PERL_OPTIMIZE" \ |
199 | -Doptimize="$PERL_OPTIMIZE" \ |
199 | -Dldflags="$PERL_LDFLAGS" \ |
200 | -Dldflags="$PERL_LDFLAGS" \ |
200 | -Dlibs="$PERL_LIBS" \ |
201 | -Dlibs="$PERL_LIBS" \ |
201 | -Dprefix="$PREFIX" \ |
202 | -Dprefix="$PERL_PREFIX" \ |
202 | -Dbin="$PREFIX/bin" \ |
203 | -Dbin="$PERL_PREFIX/bin" \ |
203 | -Dprivlib="$PREFIX/lib" \ |
204 | -Dprivlib="$PERL_PREFIX/lib" \ |
204 | -Darchlib="$PREFIX/lib" \ |
205 | -Darchlib="$PERL_PREFIX/lib" \ |
205 | -Uusevendorprefix \ |
206 | -Uusevendorprefix \ |
206 | -Dsitelib="$PREFIX/lib" \ |
207 | -Dsitelib="$PERL_PREFIX/lib" \ |
207 | -Dsitearch="$PREFIX/lib" \ |
208 | -Dsitearch="$PERL_PREFIX/lib" \ |
208 | -Usitelibexp \ |
209 | -Usitelibexp \ |
209 | -Uman1dir \ |
210 | -Uman1dir \ |
210 | -Uman3dir \ |
211 | -Uman3dir \ |
211 | -Usiteman1dir \ |
212 | -Usiteman1dir \ |
212 | -Usiteman3dir \ |
213 | -Usiteman3dir \ |
… | |
… | |
230 | } |
231 | } |
231 | |
232 | |
232 | build() { |
233 | build() { |
233 | configure |
234 | configure |
234 | |
235 | |
235 | rcd "$STATICPERL/src/perl-$PERLVER" |
236 | rcd "$STATICPERL/src/perl-$PERL_VERSION" |
236 | |
237 | |
237 | verblock <<EOF |
238 | verblock <<EOF |
238 | building $STATICPERL/src/perl-$PERLVER |
239 | building $STATICPERL/src/perl-$PERL_VERSION |
239 | EOF |
240 | EOF |
240 | |
241 | |
241 | rm -f "$PREFIX/staticstamp.install" |
242 | rm -f "$PERL_PREFIX/staticstamp.install" |
242 | |
243 | |
243 | make || fatal "make: error while building perl" |
244 | make || fatal "make: error while building perl" |
244 | |
245 | |
245 | postbuild || fatal "postbuild hook failed" |
246 | postbuild || fatal "postbuild hook failed" |
246 | } |
247 | } |
247 | |
248 | |
248 | install() { |
249 | install() { |
249 | [ -e "$PREFIX/staticstamp.install" ] && return |
250 | [ -e "$PERL_PREFIX/staticstamp.install" ] && return |
250 | |
251 | |
251 | build |
252 | build |
252 | |
253 | |
253 | verblock <<EOF |
254 | verblock <<EOF |
254 | installing $STATICPERL/src/perl-$PERLVER |
255 | installing $STATICPERL/src/perl-$PERL_VERSION |
255 | to $PREFIX |
256 | to $PERL_PREFIX |
256 | EOF |
257 | EOF |
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 |
266 | make install UNINST=1 |
267 | make install UNINST=1 |
267 | if find blib/arch/auto -type f | grep -q -v .exists; then |
268 | if find blib/arch/auto -type f | grep -q -v .exists; then |
268 | echo Probably an XS module, rebuilding perl |
269 | echo Probably an XS module, rebuilding perl |
269 | make perl |
270 | make perl |
270 | rm -f "$PREFIX"/bin/perl |
271 | rm -f "$PERL_PREFIX"/bin/perl |
271 | make -f Makefile.aperl inst_perl |
272 | make -f Makefile.aperl inst_perl |
272 | make -f Makefile.aperl map_clean |
273 | make -f Makefile.aperl map_clean |
273 | fi |
274 | fi |
274 | EOF |
275 | EOF |
275 | chmod 755 "$PREFIX"/bin/cpan-make-install |
276 | chmod 755 "$PERL_PREFIX"/bin/cpan-make-install |
276 | |
277 | |
277 | # trick CPAN into avoiding ~/.cpan completely |
278 | # trick CPAN into avoiding ~/.cpan completely |
278 | echo 1 >"$PREFIX/lib/CPAN/MyConfig.pm" |
279 | echo 1 >"$PERL_PREFIX/lib/CPAN/MyConfig.pm" |
279 | |
280 | |
280 | "$PREFIX"/bin/perl -MCPAN -e ' |
281 | "$PERL_PREFIX"/bin/perl -MCPAN -e ' |
281 | CPAN::Shell->o (conf => urllist => push => "'"$CPAN"'"); |
282 | CPAN::Shell->o (conf => urllist => push => "'"$CPAN"'"); |
282 | CPAN::Shell->o (conf => q<cpan_home>, "'"$STATICPERL"'/cpan"); |
283 | CPAN::Shell->o (conf => q<cpan_home>, "'"$STATICPERL"'/cpan"); |
283 | CPAN::Shell->o (conf => q<init>); |
284 | CPAN::Shell->o (conf => q<init>); |
284 | CPAN::Shell->o (conf => q<cpan_home>, "'"$STATICPERL"'/cpan"); |
285 | CPAN::Shell->o (conf => q<cpan_home>, "'"$STATICPERL"'/cpan"); |
285 | CPAN::Shell->o (conf => q<build_dir>, "'"$STATICPERL"'/cpan/build"); |
286 | CPAN::Shell->o (conf => q<build_dir>, "'"$STATICPERL"'/cpan/build"); |
286 | CPAN::Shell->o (conf => q<prefs_dir>, "'"$STATICPERL"'/cpan/prefs"); |
287 | CPAN::Shell->o (conf => q<prefs_dir>, "'"$STATICPERL"'/cpan/prefs"); |
287 | CPAN::Shell->o (conf => q<histfile> , "'"$STATICPERL"'/cpan/histfile"); |
288 | CPAN::Shell->o (conf => q<histfile> , "'"$STATICPERL"'/cpan/histfile"); |
288 | CPAN::Shell->o (conf => q<keep_source_where>, "'"$STATICPERL"'/cpan/sources"); |
289 | 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"); |
290 | 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>); |
291 | CPAN::Shell->o (conf => q<prerequisites_policy>, q<follow>); |
291 | CPAN::Shell->o (conf => q<build_requires_install_policy>, q<no>); |
292 | CPAN::Shell->o (conf => q<build_requires_install_policy>, q<no>); |
292 | CPAN::Shell->o (conf => q<commit>); |
293 | CPAN::Shell->o (conf => q<commit>); |
293 | ' || fatal "error while initialising CPAN" |
294 | ' || fatal "error while initialising CPAN" |
294 | |
295 | |
… | |
… | |
296 | instcpan $STATICPERL_MODULES |
297 | instcpan $STATICPERL_MODULES |
297 | [ $EXTRA_MODULES ] && instcpan $EXTRA_MODULES |
298 | [ $EXTRA_MODULES ] && instcpan $EXTRA_MODULES |
298 | |
299 | |
299 | postinstall || fatal "postinstall hook failed" |
300 | postinstall || fatal "postinstall hook failed" |
300 | |
301 | |
301 | touch "$PREFIX/staticstamp.install" |
302 | touch "$PERL_PREFIX/staticstamp.install" |
302 | } |
303 | } |
303 | |
304 | |
304 | ############################################################################# |
305 | ############################################################################# |
305 | # install a module from CPAN |
306 | # install a module from CPAN |
306 | |
307 | |
… | |
… | |
311 | installing modules from CPAN |
312 | installing modules from CPAN |
312 | $@ |
313 | $@ |
313 | EOF |
314 | EOF |
314 | |
315 | |
315 | for mod in "$@"; do |
316 | for mod in "$@"; do |
316 | "$PREFIX"/bin/perl -MCPAN -e 'notest install => "'"$mod"'"' \ |
317 | "$PERL_PREFIX"/bin/perl -MCPAN -e 'notest install => "'"$mod"'"' \ |
317 | || fatal "$mod: unable to install from CPAN" |
318 | || fatal "$mod: unable to install from CPAN" |
318 | done |
319 | done |
319 | rm -rf "$STATICPERL/build" |
320 | rm -rf "$STATICPERL/build" |
320 | } |
321 | } |
321 | |
322 | |
… | |
… | |
335 | echo $mod |
336 | echo $mod |
336 | ( |
337 | ( |
337 | rcd $mod |
338 | rcd $mod |
338 | make -f Makefile.aperl map_clean >/dev/null 2>&1 |
339 | make -f Makefile.aperl map_clean >/dev/null 2>&1 |
339 | make distclean >/dev/null 2>&1 |
340 | make distclean >/dev/null 2>&1 |
340 | "$PREFIX"/bin/perl Makefile.PL || fatal "$mod: error running Makefile.PL" |
341 | "$PERL_PREFIX"/bin/perl Makefile.PL || fatal "$mod: error running Makefile.PL" |
341 | make || fatal "$mod: error building module" |
342 | make || fatal "$mod: error building module" |
342 | "$PREFIX"/bin/cpan-make-install || fatal "$mod: error installing module" |
343 | "$PERL_PREFIX"/bin/cpan-make-install || fatal "$mod: error installing module" |
343 | make distclean >/dev/null 2>&1 |
344 | make distclean >/dev/null 2>&1 |
344 | exit 0 |
345 | exit 0 |
345 | ) || exit $? |
346 | ) || exit $? |
346 | done |
347 | done |
347 | } |
348 | } |
… | |
… | |
349 | ############################################################################# |
350 | ############################################################################# |
350 | # main |
351 | # main |
351 | |
352 | |
352 | podusage() { |
353 | podusage() { |
353 | echo |
354 | echo |
354 | if [ -e "$PREFIX/bin/perl" ]; then |
355 | if [ -e "$PERL_PREFIX/bin/perl" ]; then |
355 | "$PREFIX/bin/perl" -MPod::Usage -e \ |
356 | "$PERL_PREFIX/bin/perl" -MPod::Usage -e \ |
356 | 'pod2usage -input => *STDIN, -output => *STDOUT, -verbose => '$1', -exitval => 0, -noperldoc => 1' <"$0" \ |
357 | 'pod2usage -input => *STDIN, -output => *STDOUT, -verbose => '$1', -exitval => 0, -noperldoc => 1' <"$0" \ |
357 | 2>/dev/null && exit |
358 | 2>/dev/null && exit |
358 | fi |
359 | fi |
359 | # try whatever perl we can find |
360 | # try whatever perl we can find |
360 | perl -MPod::Usage -e \ |
361 | perl -MPod::Usage -e \ |
… | |
… | |
369 | } |
370 | } |
370 | |
371 | |
371 | catmkbundle() { |
372 | catmkbundle() { |
372 | { |
373 | { |
373 | read dummy |
374 | read dummy |
374 | echo "#!$PREFIX/bin/perl" |
375 | echo "#!$PERL_PREFIX/bin/perl" |
375 | cat |
376 | cat |
376 | } <<'MKBUNDLE' |
377 | } <<'MKBUNDLE' |
377 | #CAT mkbundle |
378 | #CAT mkbundle |
378 | MKBUNDLE |
379 | MKBUNDLE |
379 | } |
380 | } |
380 | |
381 | |
381 | bundle() { |
382 | bundle() { |
382 | catmkbundle >"$MKBUNDLE~" || fatal "$MKBUNDLE~: cannot create" |
383 | catmkbundle >"$MKBUNDLE~" || fatal "$MKBUNDLE~: cannot create" |
383 | chmod 755 "$MKBUNDLE~" && mv "$MKBUNDLE~" "$MKBUNDLE" |
384 | chmod 755 "$MKBUNDLE~" && mv "$MKBUNDLE~" "$MKBUNDLE" |
384 | "$PREFIX/bin/perl" -- "$MKBUNDLE" "$@" |
385 | "$PERL_PREFIX/bin/perl" -- "$MKBUNDLE" "$@" |
385 | } |
386 | } |
386 | |
387 | |
387 | if [ $# -gt 0 ]; then |
388 | if [ $# -gt 0 ]; then |
388 | while [ $# -gt 0 ]; do |
389 | while [ $# -gt 0 ]; do |
389 | mkdir -p "$STATICPERL" || fatal "$STATICPERL: cannot create" |
390 | mkdir -p "$STATICPERL" || fatal "$STATICPERL: cannot create" |
390 | mkdir -p "$PREFIX" || fatal "$PREFIX: cannot create" |
391 | mkdir -p "$PERL_PREFIX" || fatal "$PERL_PREFIX: cannot create" |
391 | |
392 | |
392 | command="${1#--}"; shift |
393 | command="${1#--}"; shift |
393 | case "$command" in |
394 | case "$command" in |
394 | fetch | configure | build | install | clean | distclean) |
395 | fetch | configure | build | install | clean | distclean) |
395 | verblock <<EOF |
396 | verblock <<EOF |
396 | $command |
397 | $command |
397 | EOF |
398 | EOF |
398 | "$command" |
399 | ( "$command" ) |
399 | ;; |
400 | ;; |
400 | instsrc ) |
401 | instsrc ) |
401 | instsrc "$@" |
402 | ( instsrc "$@" ) |
402 | exit |
403 | exit |
403 | ;; |
404 | ;; |
404 | instcpan ) |
405 | instcpan ) |
405 | instcpan "$@" |
406 | ( instcpan "$@" ) |
406 | exit |
407 | exit |
407 | ;; |
408 | ;; |
408 | cpan ) |
409 | cpan ) |
409 | install |
410 | ( install ) |
410 | "$PREFIX/bin/cpan" "$@" |
411 | "$PERL_PREFIX/bin/cpan" "$@" |
411 | exit |
412 | exit |
412 | ;; |
413 | ;; |
413 | mkbundle ) |
414 | mkbundle ) |
414 | install |
415 | ( install ) |
415 | bundle "$@" |
416 | bundle "$@" |
416 | exit |
417 | exit |
417 | ;; |
418 | ;; |
418 | mkperl ) |
419 | mkperl ) |
419 | install |
420 | ( install ) |
420 | bundle --perl "$@" |
421 | bundle --perl "$@" |
421 | exit |
422 | exit |
422 | ;; |
423 | ;; |
423 | help ) |
424 | help ) |
424 | podusage 2 |
425 | podusage 2 |