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