Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Initial check-in

  • Loading branch information...
commit c6d270eb680724da70d637c79f8791efc8012477 0 parents
Ray Miller authored July 21, 2011

Showing 2 changed files with 161 additions and 0 deletions. Show diff stats Hide diff stats

  1. 88  bin/dt
  2. 73  build.pl
88  bin/dt
... ...
@@ -0,0 +1,88 @@
  1
+#!/usr/bin/env perl
  2
+
  3
+use strict;
  4
+use warnings FATAL => 'all';
  5
+
  6
+use Getopt::Long;
  7
+
  8
+sub LOG {
  9
+    my ( $level, $mesg ) = @_;
  10
+    printf STDERR "%s [%s] %s\n", scalar localtime, $level, $mesg;
  11
+}
  12
+
  13
+sub WARN { LOG 'WARN', @_ }
  14
+
  15
+sub INFO { LOG 'INFO', @_ }
  16
+
  17
+sub ERROR { LOG 'ERROR', @_ };
  18
+
  19
+sub LOGDIE { ERROR @_; exit 2 };
  20
+
  21
+{
  22
+    my %tasks;
  23
+
  24
+    sub deftask ($&) {
  25
+        my ( $task, $thunk ) = @_;
  26
+        LOGDIE "Invalid task name '$task' (may only contain alphanumeric, '_', '-', and '.')"
  27
+          unless $task =~ m/^[\w\-.]+$/;
  28
+        $tasks{$task}{thunk} = $thunk;
  29
+    }
  30
+
  31
+    sub tasks {
  32
+        sort keys %tasks;
  33
+    }
  34
+
  35
+    sub runtask {
  36
+        my $task = shift;
  37
+        LOGDIE "No such task '$task'" unless exists $tasks{$task};
  38
+        unless ( $tasks{$task}{has_run} ) {
  39
+            INFO  "Running $task";
  40
+            $tasks{$task}{thunk}->();
  41
+            $tasks{$task}{has_run} = 1;
  42
+        }
  43
+    }
  44
+
  45
+    sub depends {
  46
+        my @dependencies = map { split ',' } @_;
  47
+        runtask($_) for @dependencies;
  48
+    }
  49
+}
  50
+
  51
+sub shell {
  52
+    my $script = shift;
  53
+    open( my $pipe, '|bash -e -x' );
  54
+    print $pipe $script;
  55
+    close $pipe;
  56
+    my $exit_code = $? >> 8;
  57
+    LOGDIE "Shell script exited $exit_code"
  58
+      if $exit_code != 0;
  59
+}
  60
+
  61
+{
  62
+    my $build_file = 'build.pl';
  63
+    our $BASEDIR = '/tmp/foo';
  64
+
  65
+    GetOptions(
  66
+               'build-file=s' => \$build_file,
  67
+               'base-dir=s'   => \$BASEDIR,
  68
+              );
  69
+
  70
+    LOGDIE "$BASEDIR is not writable"
  71
+      unless -w $BASEDIR;
  72
+
  73
+    $build_file = 'build.pl' unless defined $build_file;
  74
+
  75
+    {
  76
+        my $rc = do $build_file;
  77
+        LOGDIE "Couldn't parse $build_file"  if $@;
  78
+        LOGDIE "Couldn't do $build_file: $!" unless defined $rc;
  79
+        LOGDIE "Couldn't run $build_file"    unless $rc;
  80
+    }
  81
+
  82
+    if ( @ARGV ) {
  83
+        runtask $_ for @ARGV;
  84
+    }
  85
+    else {
  86
+        print "Available tasks: \n", map( "  $_\n", tasks() );
  87
+    }
  88
+}
73  build.pl
... ...
@@ -0,0 +1,73 @@
  1
+my $CPANM_URL = 'http://cpanmin.us';
  2
+
  3
+my $GIT_VERSION = '1.7.6';
  4
+my $GIT_URL     = "http://kernel.org/pub/software/scm/git/git-${GIT_VERSION}.tar.bz2";
  5
+
  6
+my $ZLIB_VERSION = '1.2.5';
  7
+my $ZLIB_URL     = "http://prdownloads.sourceforge.net/libpng/zlib-${ZLIB_VERSION}.tar.bz2?download";
  8
+
  9
+deftask 'base-dirs' => sub {
  10
+    shell "mkdir -p $BASEDIR/{bin,lib,man,share,src}"
  11
+};
  12
+
  13
+sub append_path {
  14
+    my ( $var_name, $value ) = @_;
  15
+    if ( $ENV{$var_name} ) {
  16
+        $ENV{$var_name} = $value . ':' . $ENV{$var_name};
  17
+    }
  18
+    else {
  19
+        $ENV{$var_name} = $value;
  20
+    }
  21
+}
  22
+
  23
+deftask 'setenv' => sub {
  24
+    append_path PATH            => "$BASEDIR/bin";
  25
+    append_path LD_LIBRARY_PATH => "$BASEDIR/lib";
  26
+    append_path MANPATH         => "$BASEDIR/man";
  27
+};
  28
+
  29
+deftask 'env' => sub {
  30
+    depends "setenv";
  31
+    shell 'env';
  32
+};
  33
+
  34
+deftask 'cpanm' => sub {
  35
+    depends "base-dirs,setenv";
  36
+    my $cpanm = "$BASEDIR/bin/cpanm";
  37
+    shell "wget -O $cpanm $CPANM_URL" unless -e $cpanm;
  38
+    chmod 0755, "$cpanm" unless -x $cpanm;
  39
+};
  40
+
  41
+deftask 'local-lib' => sub {
  42
+    depends "cpanm";
  43
+    shell "cpanm -l $BASEDIR local::lib";
  44
+};
  45
+
  46
+deftask 'zlib' => sub {
  47
+    depends "base-dirs,setenv";
  48
+    my $tarball = "zlib-${ZLIB_VERSION}.tar.bz2";
  49
+    shell <<"EOT";
  50
+cd $BASEDIR/src
  51
+test -e $tarball || wget -v $ZLIB_URL -O $tarball
  52
+test -d zlib-${ZLIB_VERSION} || tar xf $tarball
  53
+cd zlib-${ZLIB_VERSION}
  54
+./configure --prefix=$BASEDIR
  55
+make
  56
+make install
  57
+EOT
  58
+};
  59
+
  60
+deftask 'git' => sub {
  61
+    depends "base-dirs,setenv,zlib";
  62
+    shell <<"EOT";
  63
+cd $BASEDIR/src
  64
+wget -N -v $GIT_URL
  65
+tar xf git-${GIT_VERSION}.tar.bz2
  66
+cd git-$GIT_VERSION
  67
+./configure --prefix=$BASEDIR --with-zlib=$BASEDIR
  68
+make
  69
+make install
  70
+EOT
  71
+};
  72
+
  73
+1;

0 notes on commit c6d270e

Please sign in to comment.
Something went wrong with that request. Please try again.