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