Skip to content

Instantly share code, notes, and snippets.

@dgl
Created January 23, 2011 16:52
Show Gist options
  • Save dgl/792206 to your computer and use it in GitHub Desktop.
Save dgl/792206 to your computer and use it in GitHub Desktop.
An install script that installs a development version of perl (from git) and keeps a particular set of modules installed. Sort of perlbrew for blead, but not quite.
#!/bin/sh
# installblead: An install script that installs a development version of perl
# (from git) and keeps a particular set of modules installed. Sort of perlbrew
# for blead, but not quite.
# Usage:
# wget -O ~/bin/installblead https://gist.github.com/raw/792206/installblead
# chmod +x ~/bin/installblead
#
# git clone git://perl5.git.perl.org/perl # or git pull, whatever
#
# cd perl
# installblead
#
# Optionally you may provide an argument to specify the type of perl to build:
# - threads (-Dusethreads)
# - multi (-Dusemultiplicity)
# This is added to the name (bleadperlthreads for example)
# When *run in a git checkout of perl* does the following:
# - Build checked out version of perl, put it in ~/perls/blead-$(git describe)
# - Setup symlink to ~/perls/blead/ and make "bleadperl" and "bleadcpanm" on
# path work.
# - Then grab list of modules from previous blead install (if present)
# and install them on the new install with bleadcpanm.
# Optional settings:
# What options to give cpanm (None if not set)
#CPANM_OPT="--mirror-only --mirror /Mirror/CPAN"
# Extra options to pass to ./Configure
# (Note -Doptimize=-ggdb3 is passed below by default, before 356123f14 this
# means Configure decides this will be a debugging Perl, in that case you may
# wish to add -UDEBUGGING and maybe a better optimize level here to avoid the
# performance hit of a debugging build but keep symbols.)
#CONF_OPTS=
# Where?
PERLS=$HOME/perls
# Ensure we don't pick up any local::lib or other confusion
export PERL5LIB=
set -e
case "$1" in
'') ;;
'threads')
CONF_OPTS="$CONF_OPTS -Dusethreads"
name=threads
;;
'multi')
CONF_OPTS="$CONF_OPTS -Dusemultiplicity"
name=multi
;;
esac
cleaned=0
ok=0
while [ $cleaned -ne 1 ]; do
echo "I'm going to run git clean, is that okay? [Yn?]"
read response
case "$response" in
'') ok=1 ;;
[Yy]) ok=1 ;;
n*) exit 1 ;;
\?) git clean -dXn ;;
esac
if [ $ok -eq 1 ]; then
git clean -dXf
cleaned=1
fi
done
set -x
# Is ccache around?
if which ccache 2>/dev/null; then
CC='ccache cc'
else
CC='cc'
fi
V=blead-$(git describe)
if [ -n "$name" ]; then
V="$V-$name"
fi
nprocs=$(getconf _NPROCESSORS_ONLN)
if [ -z "$nprocs" ]; then
nprocs=2
else
nprocs=$(($nprocs + 1))
fi
if which dtrace 2>/dev/null; then
CONF_OPTS="$CONF_OPTS -Dusedtrace"
fi
./Configure -Dusedevel -Dprefix=$PERLS/$V -Dcc="$CC" -Dld=cc -Doptimize=-ggdb3 $CONF_OPTS -de
make -j$nprocs
HARNESS_OPTIONS=j$(($nprocs * 2)):c make -j$nprocs test_harness
make install
# Find set of modules previously installed
bleadperl$name -MConfig -le'for(grep /site/, @INC) { for my $f(`find $_ -name "*.pm"`) { $f =~ s{\Q$_\E/}{}; $f =~ /$Config{archname}/ || print $f } }' > /tmp/blead-modlist || echo First time install
blead=$PERLS/blead$name
# Now we've used the old blead, setup new symlinks
rm -f $blead
ln -sf $PERLS/$V $blead
ln -sf $blead/bin/perl5.* $HOME/bin/bleadperl$name
# Grab and setup cpanm
wget --no-check-certificate cpanmin.us -O $blead/bin/cpanm
ln -sf $blead/bin/cpanm $HOME/bin/bleadcpanm$name
perl -pi -e'$. == 1 && s{^#!.*}{#!'$HOME/bin/bleadperl$name'}' $HOME/bin/bleadcpanm$name
chmod +x $HOME/bin/bleadcpanm$name
# Finally use cpanm to install modules, if needed
if [ -s /tmp/blead-modlist ]; then
xargs bleadcpanm$name $CPANM_OPTS < /tmp/blead-modlist
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment