1 |
#!/bin/sh |
2 |
|
3 |
############################################################################# |
4 |
# configuration to fill in |
5 |
|
6 |
PERLVER=5.12.2 # 5.8.9 is also a good choice |
7 |
STATICPERL=~/.staticperl |
8 |
CPAN=http://mirror.netcologne.de/cpan/ # which mirror to use |
9 |
EMAIL="read the documentation <rtfm@example.org>" |
10 |
|
11 |
MKBUNDLE="$STATICPERL/mkbundle" |
12 |
|
13 |
# perl build variables |
14 |
PREFIX="$STATICPERL/perl" # where the perl gets installed |
15 |
PERL_CPPFLAGS="-DPERL_DISABLE_PMC -DPERL_ARENA_SIZE=65536 -D_GNU_SOURCE -DNDEBUG -USITELIB_EXP -USITEARCHEXP -UARCHLIB_EXP" |
16 |
PERL_OPTIMIZE="-Os -ffunction-sections -fdata-sections -finline-limit=8 -ffast-math" |
17 |
|
18 |
ARCH="$(uname -m)" |
19 |
|
20 |
case "$ARCH" in |
21 |
i*86 | x86_64 | amd64 ) |
22 |
PERL_OPTIMIZE="$PERL_OPTIMIZE -mpush-args -mno-inline-stringops-dynamically -mno-align-stringops -mno-ieee-fp" # 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 |
# -z muldefs is to work around uclibc's pthread static linking bug |
34 |
PERL_LDFLAGS="-Wl,--no-gc-sections -z muldefs" |
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 |
EXTRA_MODULES="common::sense Pod::Strip PPI::XS Pod::Usage" |
45 |
|
46 |
# overridable functions |
47 |
postconfigure() { : ; } |
48 |
postbuild() { : ; } |
49 |
postinstall() { : ; } |
50 |
|
51 |
# now source user config, if any |
52 |
[ -r /etc/staticperlrc ] && . /etc/staticperlrc |
53 |
[ -r ~/.staticperlrc ] && . ~/.staticperlrc |
54 |
[ -r "$STATICPERL/rc" ] && . "$STATICPERL/rc" |
55 |
|
56 |
############################################################################# |
57 |
# support |
58 |
|
59 |
# set version in a way that Makefile.PL can extract |
60 |
VERSION=VERSION; eval \ |
61 |
$VERSION=0.1 |
62 |
|
63 |
BZ2=bz2 |
64 |
BZIP2=bzip2 |
65 |
|
66 |
fatal() { |
67 |
printf -- "\nFATAL: %s\n\n" "$*" >&2 |
68 |
exit 1 |
69 |
} |
70 |
|
71 |
verbose() { |
72 |
printf -- "%s\n" "$*" |
73 |
} |
74 |
|
75 |
verblock() { |
76 |
verbose |
77 |
verbose "***" |
78 |
while read line; do |
79 |
verbose "*** $line" |
80 |
done |
81 |
verbose "***" |
82 |
verbose |
83 |
} |
84 |
|
85 |
rcd() { |
86 |
cd "$1" || fatal "$1: cannot enter" |
87 |
} |
88 |
|
89 |
trace() { |
90 |
prefix="$1"; shift |
91 |
# "$@" 2>&1 | while read line; do |
92 |
# echo "$prefix: $line" |
93 |
# done |
94 |
"$@" |
95 |
} |
96 |
|
97 |
trap wait 0 |
98 |
|
99 |
############################################################################# |
100 |
# clean |
101 |
|
102 |
distclean() { |
103 |
verblock <<EOF |
104 |
deleting everything installed by this script |
105 |
EOF |
106 |
|
107 |
rm -rf "$STATICPERL" |
108 |
} |
109 |
|
110 |
############################################################################# |
111 |
# download/configure/compile/install perl |
112 |
|
113 |
clean() { |
114 |
cd "$STATICPERL/src/perl-$PERLVER" 2>/dev/null || return |
115 |
|
116 |
rm -f staticstamp.configure |
117 |
make distclean >/dev/null 2>&1 |
118 |
} |
119 |
|
120 |
fetch() { |
121 |
rcd "$STATICPERL" |
122 |
|
123 |
mkdir -p src |
124 |
rcd src |
125 |
|
126 |
if ! [ -d "perl-$PERLVER" ]; then |
127 |
if ! [ -e "perl-$PERLVER.tar.$BZ2" ]; then |
128 |
|
129 |
URL="$CPAN/src/5.0/perl-$PERLVER.tar.$BZ2" |
130 |
|
131 |
verblock <<EOF |
132 |
downloading perl |
133 |
to manually download perl yourself, place |
134 |
perl-$PERLVER.tar.$BZ2 in $STATICPERL |
135 |
trying $URL |
136 |
EOF |
137 |
|
138 |
curl >perl-$PERLVER.tar.$BZ2~ "$URL" \ |
139 |
|| wget -O perl-$PERLVER.tar.$BZ2~ "$URL" \ |
140 |
|| fatal "$URL: error during downloading" |
141 |
mv perl-$PERLVER.tar.$BZ2~ perl-$PERLVER.tar.$BZ2 |
142 |
fi |
143 |
|
144 |
verblock <<EOF |
145 |
unpacking perl |
146 |
EOF |
147 |
|
148 |
mkdir -p unpack |
149 |
$BZIP2 -d <perl-$PERLVER.tar.bz2 | tar xpC unpack \ |
150 |
|| fatal "perl-$PERLVER.tar.bz2: error during unpacking" |
151 |
mv unpack/perl-$PERLVER perl-$PERLVER |
152 |
rmdir -p unpack |
153 |
fi |
154 |
} |
155 |
|
156 |
# similar to GNU-sed -i or perl -pi |
157 |
sedreplace() { |
158 |
sed -e "$1" <"$2" > "$2~" || fatal "error while running sed" |
159 |
mv "$2~" "$2" |
160 |
} |
161 |
|
162 |
configure() { |
163 |
fetch |
164 |
|
165 |
rcd "$STATICPERL/src/perl-$PERLVER" |
166 |
|
167 |
[ -e staticstamp.configure ] && return |
168 |
|
169 |
verblock <<EOF |
170 |
configuring $STATICPERL/src/perl-$PERLVER |
171 |
EOF |
172 |
|
173 |
clean |
174 |
|
175 |
rm -f "$PREFIX/staticstamp.install" |
176 |
|
177 |
# I hate them |
178 |
grep -q -- -fstack-protector Configure && \ |
179 |
sedreplace 's/-fstack-protector/-fno-stack-protector/g' Configure |
180 |
|
181 |
# trace configure \ |
182 |
sh Configure -Duselargefiles \ |
183 |
-Uuse64bitint \ |
184 |
-Dusemymalloc=n \ |
185 |
-Uusedl \ |
186 |
-Uusethreads \ |
187 |
-Uuseithreads \ |
188 |
-Uusemultiplicity \ |
189 |
-Duseperlio \ |
190 |
-Uusesfio \ |
191 |
-Uuseshrplib \ |
192 |
-Dcppflags="$PERL_CPPFLAGS" \ |
193 |
-Dccflags="-g2 -fno-strict-aliasing" \ |
194 |
-Doptimize="$PERL_OPTIMIZE" \ |
195 |
-Dldflags="$PERL_LDFLAGS" \ |
196 |
-Dlibs="$PERL_LIBS" \ |
197 |
-Dprefix="$PREFIX" \ |
198 |
-Dbin="$PREFIX/bin" \ |
199 |
-Dprivlib="$PREFIX/plib" \ |
200 |
-Darchlib="$PREFIX/plib" \ |
201 |
-Uusevendorprefix \ |
202 |
-Dsitelib="$PREFIX/plib" \ |
203 |
-Dsitearch="$PREFIX/plib" \ |
204 |
-Usitelibexp \ |
205 |
-Uman1dir \ |
206 |
-Uman3dir \ |
207 |
-Usiteman1dir \ |
208 |
-Usiteman3dir \ |
209 |
-Dpager=/usr/bin/less \ |
210 |
-Demail="$EMAIL" \ |
211 |
-Dcf_email="$EMAIL" \ |
212 |
-Dcf_by="$EMAIL" \ |
213 |
-dE || fatal "Configure failed" |
214 |
|
215 |
sedreplace ' |
216 |
s/-Wl,--no-gc-sections/-Wl,--gc-sections/g |
217 |
s/ *-fno-stack-protector */ /g |
218 |
' config.sh |
219 |
|
220 |
sh Configure -S || fatal "Configure -S failed" |
221 |
|
222 |
postconfigure || fatal "postconfigure hook failed" |
223 |
|
224 |
touch staticstamp.configure |
225 |
} |
226 |
|
227 |
build() { |
228 |
configure |
229 |
|
230 |
rcd "$STATICPERL/src/perl-$PERLVER" |
231 |
|
232 |
verblock <<EOF |
233 |
building $STATICPERL/src/perl-$PERLVER |
234 |
EOF |
235 |
|
236 |
rm -f "$PREFIX/staticstamp.install" |
237 |
|
238 |
make || fatal "make: error while building perl" |
239 |
|
240 |
postbuild || fatal "postbuild hook failed" |
241 |
} |
242 |
|
243 |
install() { |
244 |
[ -e "$PREFIX/staticstamp.install" ] && return |
245 |
|
246 |
build |
247 |
|
248 |
verblock <<EOF |
249 |
installing $STATICPERL/src/perl-$PERLVER |
250 |
to $PREFIX |
251 |
EOF |
252 |
|
253 |
rm -rf "$PREFIX" |
254 |
|
255 |
make install || fatal "make install: error while installing" |
256 |
|
257 |
# create a "make install" replacement for CPAN |
258 |
cat >"$PREFIX"/bin/cpan-make-install <<EOF |
259 |
make install UNINST=1 |
260 |
if find blib/arch/auto -type f | grep -q -v .exists; then |
261 |
echo Probably an XS module, rebuilding perl |
262 |
make perl |
263 |
rm -f "$PREFIX"/bin/perl |
264 |
make -f Makefile.aperl inst_perl |
265 |
make -f Makefile.aperl map_clean |
266 |
fi |
267 |
EOF |
268 |
chmod 755 "$PREFIX"/bin/cpan-make-install |
269 |
|
270 |
"$PREFIX"/bin/perl -MCPAN -e ' |
271 |
CPAN::Shell->o (conf => urllist => push => "'"$CPAN"'"); |
272 |
CPAN::Shell->o (conf => q<init>); |
273 |
CPAN::Shell->o (conf => q<cpan_home>, "'"$STATICPERL"'/cpan"); |
274 |
CPAN::Shell->o (conf => q<build_dir>, "'"$STATICPERL"'/cpan/build"); |
275 |
CPAN::Shell->o (conf => q<prefs_dir>, "'"$STATICPERL"'/cpan/prefs"); |
276 |
CPAN::Shell->o (conf => q<histfile> , "'"$STATICPERL"'/cpan/histfile"); |
277 |
CPAN::Shell->o (conf => q<keep_source_where>, "'"$STATICPERL"'/cpan/sources"); |
278 |
CPAN::Shell->o (conf => q<make_install_make_command>, "'"$PREFIX"'/bin/cpan-make-install"); |
279 |
CPAN::Shell->o (conf => q<prerequisites_policy>, q<follow>); |
280 |
CPAN::Shell->o (conf => q<build_requires_install_policy>, q<no>); |
281 |
CPAN::Shell->o (conf => q<commit>); |
282 |
' || fatal "error while initialising CPAN" |
283 |
|
284 |
NOCHECK_INSTALL=+ |
285 |
instcpan $EXTRA_MODULES |
286 |
|
287 |
postinstall || fatal "postinstall hook failed" |
288 |
|
289 |
touch "$PREFIX/staticstamp.install" |
290 |
} |
291 |
|
292 |
############################################################################# |
293 |
# install a module from CPAN |
294 |
|
295 |
instcpan() { |
296 |
[ $NOCHECK_INSTALL ] || install |
297 |
|
298 |
verblock <<EOF |
299 |
installing modules from CPAN |
300 |
$@ |
301 |
EOF |
302 |
|
303 |
for mod in "$@"; do |
304 |
"$PREFIX"/bin/perl -MCPAN -e 'notest install => "'"$mod"'"' \ |
305 |
|| fatal "$mod: unable to install from CPAN" |
306 |
done |
307 |
rm -rf "$STATICPERL/build" |
308 |
} |
309 |
|
310 |
############################################################################# |
311 |
# install a module from unpacked sources |
312 |
|
313 |
instsrc() { |
314 |
[ $NOCHECK_INSTALL ] || install |
315 |
|
316 |
verblock <<EOF |
317 |
installing modules from source |
318 |
$@ |
319 |
EOF |
320 |
|
321 |
for mod in "$@"; do |
322 |
echo |
323 |
echo $mod |
324 |
( |
325 |
rcd $mod |
326 |
make -f Makefile.aperl map_clean >/dev/null 2>&1 |
327 |
make distclean >/dev/null 2>&1 |
328 |
"$PREFIX"/bin/perl Makefile.PL || fatal "$mod: error running Makefile.PL" |
329 |
make || fatal "$mod: error building module" |
330 |
"$PREFIX"/bin/cpan-make-install || fatal "$mod: error installing module" |
331 |
make distclean >/dev/null 2>&1 |
332 |
exit 0 |
333 |
) || exit $? |
334 |
done |
335 |
} |
336 |
|
337 |
############################################################################# |
338 |
# do schmorpy stuff |
339 |
|
340 |
MODSRCDIR=~/src |
341 |
|
342 |
instmodsrc() { |
343 |
for mod in "$@"; do |
344 |
instmod_src "$MODSRCDIR/$mod" |
345 |
done |
346 |
} |
347 |
|
348 |
install_schmorp() { |
349 |
install |
350 |
|
351 |
instcpan Data::Dump Term::ReadLine::Perl Term::ANSIColor Term::ReadKey |
352 |
instcpan Digest::SHA Digest::MD6 Digest::SHA256 Digest::MD4 Digest::HMAC_MD5 Digest::HMAC_MD6 Digest::FNV |
353 |
#instcpan Net::SSLeay # requires static -ldl |
354 |
|
355 |
instmodsrc common-sense Crypt-Twofish2 Array-Heap Convert-Scalar Compress-LZF JSON-XS |
356 |
instmodsrc EV Guard Async-Interrupt IO-AIO |
357 |
instmodsrc AnyEvent AnyEvent-AIO Coro AnyEvent-HTTP |
358 |
instmodsrc Linux-Inotify2 EV-Loop-Async |
359 |
|
360 |
instcpan AnyEvent::HTTPD |
361 |
} |
362 |
|
363 |
############################################################################# |
364 |
# main |
365 |
|
366 |
podusage() { |
367 |
echo |
368 |
if [ -e "$PREFIX/bin/perl" ]; then |
369 |
"$PREFIX/bin/perl" -MPod::Usage -e \ |
370 |
'pod2usage -input => *STDIN, -output => *STDOUT, -verbose => '$1', -exitval => 0, -noperldoc => 1' <"$0" \ |
371 |
2>/dev/null && exit |
372 |
fi |
373 |
# try whatever perl we can find |
374 |
perl -MPod::Usage -e \ |
375 |
'pod2usage -input => *STDIN, -output => *STDOUT, -verbose => '$1', -exitval => 0, -noperldoc => 1' <"$0" \ |
376 |
2>/dev/null && exit |
377 |
|
378 |
fatal "displaying documentation requires a working perl - try '$0 install' first" |
379 |
} |
380 |
|
381 |
usage() { |
382 |
podusage 0 |
383 |
} |
384 |
|
385 |
catmkbundle() { |
386 |
{ |
387 |
read dummy |
388 |
echo "#!$PREFIX/bin/perl" |
389 |
cat |
390 |
} <<'MKBUNDLE' |
391 |
#CAT mkbundle |
392 |
MKBUNDLE |
393 |
} |
394 |
|
395 |
bundle() { |
396 |
catmkbundle >"$MKBUNDLE~" || fatal "$MKBUNDLE~: cannot create" |
397 |
chmod 755 "$MKBUNDLE~" && mv "$MKBUNDLE~" "$MKBUNDLE" |
398 |
"$PREFIX/bin/perl" -- "$MKBUNDLE" "$@" |
399 |
} |
400 |
|
401 |
if [ $# -gt 0 ]; then |
402 |
while [ $# -gt 0 ]; do |
403 |
mkdir -p "$STATICPERL" || fatal "$STATICPERL: cannot create" |
404 |
mkdir -p "$PREFIX" || fatal "$PREFIX: cannot create" |
405 |
|
406 |
command="${1#--}"; shift |
407 |
case "$command" in |
408 |
fetch | configure | build | install | clean | distclean) |
409 |
verblock <<EOF |
410 |
$command |
411 |
EOF |
412 |
"$command" |
413 |
;; |
414 |
instsrc ) |
415 |
instsrc "$@" |
416 |
exit |
417 |
;; |
418 |
instcpan ) |
419 |
instcpan "$@" |
420 |
exit |
421 |
;; |
422 |
instschmorp ) |
423 |
install_schmorp |
424 |
;; |
425 |
cpan ) |
426 |
install |
427 |
"$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 |
help ) |
441 |
podusage 2 |
442 |
;; |
443 |
* ) |
444 |
exec 1>&2 |
445 |
echo |
446 |
echo "Unknown command: $command" |
447 |
podusage 0 |
448 |
;; |
449 |
esac |
450 |
done |
451 |
else |
452 |
usage |
453 |
fi |
454 |
|
455 |
exit 0 |
456 |
|
457 |
#CAT staticperl.pod |
458 |
|