1 |
#!/bin/sh |
2 |
|
3 |
############################################################################# |
4 |
# configuration to fill in |
5 |
|
6 |
STATICPERL=~/.staticperl |
7 |
CPAN=http://mirror.netcologne.de/cpan # which mirror to use |
8 |
EMAIL="read the documentation <rtfm@example.org>" |
9 |
|
10 |
# perl build variables |
11 |
PERL_VERSION=5.12.2 # 5.8.9 is also a good choice |
12 |
PERL_CC=cc |
13 |
PERL_CONFIGURE="" # additional Configure arguments |
14 |
PERL_CPPFLAGS="-DPERL_DISABLE_PMC -DPERL_ARENA_SIZE=65536 -D_GNU_SOURCE -DNDEBUG -USITELIB_EXP -USITEARCHEXP -UARCHLIB_EXP" |
15 |
PERL_OPTIMIZE="-Os -ffunction-sections -fdata-sections -finline-limit=8 -ffast-math" |
16 |
|
17 |
ARCH="$(uname -m)" |
18 |
|
19 |
case "$ARCH" in |
20 |
i*86 | x86_64 | amd64 ) |
21 |
#PERL_OPTIMIZE="$PERL_OPTIMIZE -mpush-args -mno-inline-stringops-dynamically -mno-align-stringops -mno-ieee-fp" # x86/amd64 |
22 |
PERL_OPTIMIZE="$PERL_OPTIMIZE" # x86/amd64 |
23 |
case "$ARCH" in |
24 |
i*86 ) |
25 |
PERL_OPTIMIZE="$PERL_OPTIMIZE -fomit-frame-pointer -march=pentium3 -mtune=i386" # x86 only |
26 |
;; |
27 |
esac |
28 |
;; |
29 |
esac |
30 |
|
31 |
# -Wl,--gc-sections makes it impossible to check for undefined references |
32 |
# for some reason so we need to patch away the "-no" after Configure and before make :/ |
33 |
# --allow-multiple-definition exists to work around uclibc's pthread static linking bug |
34 |
PERL_LDFLAGS="-Wl,--no-gc-sections -Wl,--allow-multiple-definition" |
35 |
PERL_LIBS="-lm -lcrypt" # perl loves to add lotsa crap itself |
36 |
|
37 |
# some configuration options for modules |
38 |
export PERL_MM_USE_DEFAULT=1 |
39 |
#export CORO_INTERFACE=p # needed without nptl on x86, due to bugs in linuxthreads - very slow |
40 |
export 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 |
# which extra modules to install by default from CPAN that are |
43 |
# required by mkbundle |
44 |
STATICPERL_MODULES="common::sense Pod::Strip PPI::XS Pod::Usage" |
45 |
|
46 |
# which extra modules you might want to install |
47 |
EXTRA_MODULES="" |
48 |
|
49 |
# overridable functions |
50 |
preconfigure() { : ; } |
51 |
postconfigure() { : ; } |
52 |
postbuild() { : ; } |
53 |
postinstall() { : ; } |
54 |
|
55 |
# now source user config, if any |
56 |
if [ "$STATICPERLRC" ]; then |
57 |
. "$STATICPERLRC" |
58 |
else |
59 |
[ -r /etc/staticperlrc ] && . /etc/staticperlrc |
60 |
[ -r ~/.staticperlrc ] && . ~/.staticperlrc |
61 |
[ -r "$STATICPERL/rc" ] && . "$STATICPERL/rc" |
62 |
fi |
63 |
|
64 |
############################################################################# |
65 |
# support |
66 |
|
67 |
MKBUNDLE="${MKBUNDLE:=$STATICPERL/mkbundle}" |
68 |
PERL_PREFIX="${PERL_PREFIX:=$STATICPERL/perl}" # where the perl gets installed |
69 |
|
70 |
unset PERL5OPT PERL5LIB PERLLIB PERL_UNICODE PERLIO_DEBUG |
71 |
export LC_ALL=C # just to be on the safe side |
72 |
|
73 |
# set version in a way that Makefile.PL can extract |
74 |
VERSION=VERSION; eval \ |
75 |
$VERSION=0.911 |
76 |
|
77 |
BZ2=bz2 |
78 |
BZIP2=bzip2 |
79 |
|
80 |
fatal() { |
81 |
printf -- "\nFATAL: %s\n\n" "$*" >&2 |
82 |
exit 1 |
83 |
} |
84 |
|
85 |
verbose() { |
86 |
printf -- "%s\n" "$*" |
87 |
} |
88 |
|
89 |
verblock() { |
90 |
verbose |
91 |
verbose "***" |
92 |
while read line; do |
93 |
verbose "*** $line" |
94 |
done |
95 |
verbose "***" |
96 |
verbose |
97 |
} |
98 |
|
99 |
rcd() { |
100 |
cd "$1" || fatal "$1: cannot enter" |
101 |
} |
102 |
|
103 |
trace() { |
104 |
prefix="$1"; shift |
105 |
# "$@" 2>&1 | while read line; do |
106 |
# echo "$prefix: $line" |
107 |
# done |
108 |
"$@" |
109 |
} |
110 |
|
111 |
trap wait 0 |
112 |
|
113 |
############################################################################# |
114 |
# clean |
115 |
|
116 |
distclean() { |
117 |
verblock <<EOF |
118 |
deleting everything installed by this script (rm -rf $STATICPERL) |
119 |
EOF |
120 |
|
121 |
rm -rf "$STATICPERL" |
122 |
} |
123 |
|
124 |
############################################################################# |
125 |
# download/configure/compile/install perl |
126 |
|
127 |
clean() { |
128 |
rm -rf "$STATICPERL/src/perl-$PERL_VERSION" |
129 |
} |
130 |
|
131 |
fetch() { |
132 |
rcd "$STATICPERL" |
133 |
|
134 |
mkdir -p src |
135 |
rcd src |
136 |
|
137 |
if ! [ -d "perl-$PERL_VERSION" ]; then |
138 |
if ! [ -e "perl-$PERL_VERSION.tar.$BZ2" ]; then |
139 |
|
140 |
URL="$CPAN/src/5.0/perl-$PERL_VERSION.tar.$BZ2" |
141 |
|
142 |
verblock <<EOF |
143 |
downloading perl |
144 |
to manually download perl yourself, place |
145 |
perl-$PERL_VERSION.tar.$BZ2 in $STATICPERL |
146 |
trying $URL |
147 |
EOF |
148 |
|
149 |
rm -f perl-$PERL_VERSION.tar.$BZ2~ # just to be on the safe side |
150 |
wget -O perl-$PERL_VERSION.tar.$BZ2~ "$URL" \ |
151 |
|| curl >perl-$PERL_VERSION.tar.$BZ2~ "$URL" \ |
152 |
|| fatal "$URL: unable to download" |
153 |
mv perl-$PERL_VERSION.tar.$BZ2~ perl-$PERL_VERSION.tar.$BZ2 |
154 |
fi |
155 |
|
156 |
verblock <<EOF |
157 |
unpacking perl |
158 |
EOF |
159 |
|
160 |
mkdir -p unpack |
161 |
$BZIP2 -d <perl-$PERL_VERSION.tar.bz2 | tar xfC - unpack \ |
162 |
|| fatal "perl-$PERL_VERSION.tar.bz2: error during unpacking" |
163 |
chmod -R u+w unpack/perl-$PERL_VERSION |
164 |
mv unpack/perl-$PERL_VERSION perl-$PERL_VERSION |
165 |
rmdir -p unpack |
166 |
fi |
167 |
} |
168 |
|
169 |
# similar to GNU-sed -i or perl -pi |
170 |
sedreplace() { |
171 |
sed -e "$1" <"$2" > "$2~" || fatal "error while running sed" |
172 |
mv "$2~" "$2" |
173 |
} |
174 |
|
175 |
configure() { |
176 |
fetch |
177 |
|
178 |
rcd "$STATICPERL/src/perl-$PERL_VERSION" |
179 |
|
180 |
[ -e staticstamp.configure ] && return |
181 |
|
182 |
verblock <<EOF |
183 |
configuring $STATICPERL/src/perl-$PERL_VERSION |
184 |
EOF |
185 |
|
186 |
rm -f "$PERL_PREFIX/staticstamp.install" |
187 |
|
188 |
make distclean >/dev/null 2>&1 |
189 |
|
190 |
# I hate them |
191 |
grep -q -- -fstack-protector Configure && \ |
192 |
sedreplace 's/-fstack-protector/-fno-stack-protector/g' Configure |
193 |
|
194 |
preconfigure |
195 |
|
196 |
# trace configure \ |
197 |
sh Configure -Duselargefiles \ |
198 |
-Uuse64bitint \ |
199 |
-Dusemymalloc=n \ |
200 |
-Uusedl \ |
201 |
-Uusethreads \ |
202 |
-Uuseithreads \ |
203 |
-Uusemultiplicity \ |
204 |
-Uusesfio \ |
205 |
-Uuseshrplib \ |
206 |
-Dcc="$PERL_CC" \ |
207 |
-Dcppflags="$PERL_CPPFLAGS" \ |
208 |
-Dccflags="-g2 -fno-strict-aliasing" \ |
209 |
-Doptimize="$PERL_OPTIMIZE" \ |
210 |
-Dldflags="$PERL_LDFLAGS" \ |
211 |
-Dlibs="$PERL_LIBS" \ |
212 |
-Dprefix="$PERL_PREFIX" \ |
213 |
-Dbin="$PERL_PREFIX/bin" \ |
214 |
-Dprivlib="$PERL_PREFIX/lib" \ |
215 |
-Darchlib="$PERL_PREFIX/lib" \ |
216 |
-Uusevendorprefix \ |
217 |
-Dsitelib="$PERL_PREFIX/lib" \ |
218 |
-Dsitearch="$PERL_PREFIX/lib" \ |
219 |
-Usitelibexp \ |
220 |
-Uman1dir \ |
221 |
-Uman3dir \ |
222 |
-Usiteman1dir \ |
223 |
-Usiteman3dir \ |
224 |
-Dpager=/usr/bin/less \ |
225 |
-Demail="$EMAIL" \ |
226 |
-Dcf_email="$EMAIL" \ |
227 |
-Dcf_by="$EMAIL" \ |
228 |
$PERL_CONFIGURE \ |
229 |
-Duseperlio \ |
230 |
-dE || fatal "Configure failed" |
231 |
|
232 |
sedreplace ' |
233 |
s/-Wl,--no-gc-sections/-Wl,--gc-sections/g |
234 |
s/ *-fno-stack-protector */ /g |
235 |
' config.sh |
236 |
|
237 |
sh Configure -S || fatal "Configure -S failed" |
238 |
|
239 |
postconfigure || fatal "postconfigure hook failed" |
240 |
|
241 |
touch staticstamp.configure |
242 |
} |
243 |
|
244 |
build() { |
245 |
configure |
246 |
|
247 |
rcd "$STATICPERL/src/perl-$PERL_VERSION" |
248 |
|
249 |
verblock <<EOF |
250 |
building $STATICPERL/src/perl-$PERL_VERSION |
251 |
EOF |
252 |
|
253 |
rm -f "$PERL_PREFIX/staticstamp.install" |
254 |
|
255 |
make || fatal "make: error while building perl" |
256 |
|
257 |
postbuild || fatal "postbuild hook failed" |
258 |
} |
259 |
|
260 |
install() { |
261 |
if ! [ -e "$PERL_PREFIX/staticstamp.install" ]; then |
262 |
build |
263 |
|
264 |
verblock <<EOF |
265 |
installing $STATICPERL/src/perl-$PERL_VERSION |
266 |
to $PERL_PREFIX |
267 |
EOF |
268 |
|
269 |
ln -sf "perl/bin/" "$STATICPERL/bin" |
270 |
ln -sf "perl/lib/" "$STATICPERL/lib" |
271 |
|
272 |
ln -sf "$PERL_PREFIX" "$STATICPERL/perl" # might get overwritten |
273 |
rm -rf "$PERL_PREFIX" # by this rm -rf |
274 |
|
275 |
make install || fatal "make install: error while installing" |
276 |
|
277 |
rcd "$PERL_PREFIX" |
278 |
|
279 |
# create a "make install" replacement for CPAN |
280 |
cat >"$PERL_PREFIX"/bin/cpan-make-install <<EOF |
281 |
make || exit |
282 |
|
283 |
if find blib/arch/auto -type f | grep -q -v .exists; then |
284 |
echo Probably an XS module, rebuilding perl |
285 |
if make perl; then |
286 |
mv perl "$PERL_PREFIX"/bin/perl |
287 |
make -f Makefile.aperl map_clean |
288 |
else |
289 |
make -f Makefile.aperl map_clean |
290 |
exit 1 |
291 |
fi |
292 |
fi |
293 |
|
294 |
make install UNINST=1 |
295 |
EOF |
296 |
chmod 755 "$PERL_PREFIX"/bin/cpan-make-install |
297 |
|
298 |
# trick CPAN into avoiding ~/.cpan completely |
299 |
echo 1 >"$PERL_PREFIX/lib/CPAN/MyConfig.pm" |
300 |
|
301 |
"$PERL_PREFIX"/bin/perl -MCPAN -e ' |
302 |
CPAN::Shell->o (conf => urllist => push => "'"$CPAN"'"); |
303 |
CPAN::Shell->o (conf => q<cpan_home>, "'"$STATICPERL"'/cpan"); |
304 |
CPAN::Shell->o (conf => q<init>); |
305 |
CPAN::Shell->o (conf => q<cpan_home>, "'"$STATICPERL"'/cpan"); |
306 |
CPAN::Shell->o (conf => q<build_dir>, "'"$STATICPERL"'/cpan/build"); |
307 |
CPAN::Shell->o (conf => q<prefs_dir>, "'"$STATICPERL"'/cpan/prefs"); |
308 |
CPAN::Shell->o (conf => q<histfile> , "'"$STATICPERL"'/cpan/histfile"); |
309 |
CPAN::Shell->o (conf => q<keep_source_where>, "'"$STATICPERL"'/cpan/sources"); |
310 |
CPAN::Shell->o (conf => q<make_install_make_command>, "'"$PERL_PREFIX"'/bin/cpan-make-install"); |
311 |
CPAN::Shell->o (conf => q<prerequisites_policy>, q<follow>); |
312 |
CPAN::Shell->o (conf => q<build_requires_install_policy>, q<no>); |
313 |
CPAN::Shell->o (conf => q<commit>); |
314 |
' || fatal "error while initialising CPAN" |
315 |
|
316 |
touch "$PERL_PREFIX/staticstamp.install" |
317 |
fi |
318 |
|
319 |
if ! [ -e "$PERL_PREFIX/staticstamp.postinstall" ]; then |
320 |
NOCHECK_INSTALL=+ |
321 |
instcpan $STATICPERL_MODULES |
322 |
[ $EXTRA_MODULES ] && instcpan $EXTRA_MODULES |
323 |
|
324 |
postinstall || fatal "postinstall hook failed" |
325 |
|
326 |
touch "$PERL_PREFIX/staticstamp.postinstall" |
327 |
fi |
328 |
} |
329 |
|
330 |
############################################################################# |
331 |
# install a module from CPAN |
332 |
|
333 |
instcpan() { |
334 |
[ $NOCHECK_INSTALL ] || install |
335 |
|
336 |
verblock <<EOF |
337 |
installing modules from CPAN |
338 |
$@ |
339 |
EOF |
340 |
|
341 |
for mod in "$@"; do |
342 |
"$PERL_PREFIX"/bin/perl -MCPAN -e 'notest install => "'"$mod"'"' \ |
343 |
|| fatal "$mod: unable to install from CPAN" |
344 |
done |
345 |
rm -rf "$STATICPERL/build" |
346 |
} |
347 |
|
348 |
############################################################################# |
349 |
# install a module from unpacked sources |
350 |
|
351 |
instsrc() { |
352 |
[ $NOCHECK_INSTALL ] || install |
353 |
|
354 |
verblock <<EOF |
355 |
installing modules from source |
356 |
$@ |
357 |
EOF |
358 |
|
359 |
for mod in "$@"; do |
360 |
echo |
361 |
echo $mod |
362 |
( |
363 |
rcd $mod |
364 |
make -f Makefile.aperl map_clean >/dev/null 2>&1 |
365 |
make distclean >/dev/null 2>&1 |
366 |
"$PERL_PREFIX"/bin/perl Makefile.PL || fatal "$mod: error running Makefile.PL" |
367 |
make || fatal "$mod: error building module" |
368 |
"$PERL_PREFIX"/bin/cpan-make-install || fatal "$mod: error installing module" |
369 |
make distclean >/dev/null 2>&1 |
370 |
exit 0 |
371 |
) || exit $? |
372 |
done |
373 |
} |
374 |
|
375 |
############################################################################# |
376 |
# main |
377 |
|
378 |
podusage() { |
379 |
echo |
380 |
|
381 |
if [ -e "$PERL_PREFIX/bin/perl" ]; then |
382 |
"$PERL_PREFIX/bin/perl" -MPod::Usage -e \ |
383 |
'pod2usage -input => *STDIN, -output => *STDOUT, -verbose => '$1', -exitval => 0, -noperldoc => 1' <"$0" \ |
384 |
2>/dev/null && exit |
385 |
fi |
386 |
|
387 |
# try whatever perl we can find |
388 |
perl -MPod::Usage -e \ |
389 |
'pod2usage -input => *STDIN, -output => *STDOUT, -verbose => '$1', -exitval => 0, -noperldoc => 1' <"$0" \ |
390 |
2>/dev/null && exit |
391 |
|
392 |
fatal "displaying documentation requires a working perl - try '$0 install' to build one in a safe location" |
393 |
} |
394 |
|
395 |
usage() { |
396 |
podusage 0 |
397 |
} |
398 |
|
399 |
catmkbundle() { |
400 |
{ |
401 |
read dummy |
402 |
echo "#!$PERL_PREFIX/bin/perl" |
403 |
cat |
404 |
} <<'MKBUNDLE' |
405 |
#CAT mkbundle |
406 |
MKBUNDLE |
407 |
} |
408 |
|
409 |
bundle() { |
410 |
catmkbundle >"$MKBUNDLE~" || fatal "$MKBUNDLE~: cannot create" |
411 |
chmod 755 "$MKBUNDLE~" && mv "$MKBUNDLE~" "$MKBUNDLE" |
412 |
CACHE="$STATICPERL/cache" |
413 |
mkdir -p "$CACHE" |
414 |
"$PERL_PREFIX/bin/perl" -- "$MKBUNDLE" --cache "$CACHE" "$@" |
415 |
} |
416 |
|
417 |
if [ $# -gt 0 ]; then |
418 |
while [ $# -gt 0 ]; do |
419 |
mkdir -p "$STATICPERL" || fatal "$STATICPERL: cannot create" |
420 |
mkdir -p "$PERL_PREFIX" || fatal "$PERL_PREFIX: cannot create" |
421 |
|
422 |
command="${1#--}"; shift |
423 |
case "$command" in |
424 |
version ) |
425 |
echo "staticperl version $VERSION" |
426 |
;; |
427 |
fetch | configure | build | install | clean | distclean) |
428 |
( "$command" ) |
429 |
;; |
430 |
instsrc ) |
431 |
( instsrc "$@" ) |
432 |
exit |
433 |
;; |
434 |
instcpan ) |
435 |
( instcpan "$@" ) |
436 |
exit |
437 |
;; |
438 |
cpan ) |
439 |
( install ) |
440 |
"$PERL_PREFIX/bin/cpan" "$@" |
441 |
exit |
442 |
;; |
443 |
mkbundle ) |
444 |
( install ) |
445 |
bundle "$@" |
446 |
exit |
447 |
;; |
448 |
mkperl ) |
449 |
( install ) |
450 |
bundle --perl "$@" |
451 |
exit |
452 |
;; |
453 |
mkapp ) |
454 |
( install ) |
455 |
bundle --app "$@" |
456 |
exit |
457 |
;; |
458 |
help ) |
459 |
podusage 2 |
460 |
;; |
461 |
* ) |
462 |
exec 1>&2 |
463 |
echo |
464 |
echo "Unknown command: $command" |
465 |
podusage 0 |
466 |
;; |
467 |
esac |
468 |
done |
469 |
else |
470 |
usage |
471 |
fi |
472 |
|
473 |
exit 0 |
474 |
|
475 |
#CAT staticperl.pod |
476 |
|