aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMoritz Lenz <moritz@faui2k3.org>2012-05-28 14:09:59 +0200
committerMoritz Lenz <moritz@faui2k3.org>2012-05-28 14:09:59 +0200
commitf4632b9b729b4f2df4b2af111e2583feac178dd5 (patch)
treefdcf65bfa3b9464ec2f812ff200f7fbeba6cf2a9
parent7d37beba5508bd14c3fa7996c626103921d0b6fc (diff)
[build] add a basic template mechanism
this grabs the {parrot,rakudo,nqp} revisions and fudges them into Configure.pl, so at least it is one less location to update
-rw-r--r--Makefile1
-rw-r--r--build/skel-template.pl53
-rw-r--r--template-skel/Configure.pl (renamed from skel/Configure.pl)18
3 files changed, 69 insertions, 3 deletions
diff --git a/Makefile b/Makefile
index f51e854..aead8c9 100644
--- a/Makefile
+++ b/Makefile
@@ -66,6 +66,7 @@ always:
$(DISTDIR): always
mkdir -p $(DISTDIR)
cp -av skel/. $(DISTDIR)
+ perl build/skel-template.pl $(DISTDIR)
$(PARROT_DIR): $(PARROT_TGZ)
tar -C $(DISTDIR) -xvzf $(PARROT_TGZ)
diff --git a/build/skel-template.pl b/build/skel-template.pl
new file mode 100644
index 0000000..8940d33
--- /dev/null
+++ b/build/skel-template.pl
@@ -0,0 +1,53 @@
+use strict;
+use warnings;
+
+my $destination = shift(@ARGV) || die "Usage: $0 <destination>";
+unless (-d $destination) {
+ die "Destination '$destination' should be a directory, but is not";
+}
+
+my %look_for = (PARROT_VER => 1, RAKUDO_VER => 1, NQP_VER => 1);
+my %vars;
+
+open my $fh, '<', 'Makefile'
+ or die "Cannot open Makefile for reading: $!";
+
+while (<$fh>) {
+ chomp;
+ if (/^(\w+)\s*=\s*(\S*)/ && $look_for{$1}) {
+ delete $look_for{$1};
+ $vars{$1} = $2;
+ last unless %look_for;
+ }
+}
+close $fh;
+if (%look_for) {
+ die "Couldn't find a definition for the following variable(s) in Makfile\n"
+ . join(', ', keys %look_for) . "\n";
+}
+
+my $subst_re = join '|', map quotemeta, keys %vars;
+$subst_re = qr{\<($subst_re)\>};
+
+# XXX recursive traversal + templating NYI, one level is enough for a start
+
+for my $file (glob 'template-skel/*') {
+ my $dest = $file;
+ $dest =~ s{^template-skel/}{$destination/};
+ process_file($file, $dest);
+}
+
+sub process_file {
+ my ($source, $dest) = @_;
+ print "Processing '$source' into '$dest'\n";
+ open my $in, '<', $source
+ or die "Cannot open '$source' for reading: $!";
+ open my $out, '>', $dest
+ or die "Cannot open '$dest' for writing: $!";
+ while (<$in>) {
+ s/$subst_re/$vars{$1}/g;
+ print { $out } $_ or die "Cannot write to '$dest': $!";
+ }
+ close $in;
+ close $out or die "Cannot close '$dest': $!";
+}
diff --git a/skel/Configure.pl b/template-skel/Configure.pl
index 90cac74..02aaf31 100644
--- a/skel/Configure.pl
+++ b/template-skel/Configure.pl
@@ -13,6 +13,18 @@ use NQP::Configure qw(sorry slurp cmp_rev gen_nqp read_config
system_or_die verify_install);
my $lang = 'Rakudo';
+my $parrot_ver = '<PARROT_VER>';
+my $nqp_ver = '<NQP_VER>';
+my $rakudo_ver = '<RAKUDO_VER>';
+
+for ($parrot_ver, $nqp_ver, $rakudo_ver) {
+ if (/^<\w+_VER>/) {
+ die "You are running the original version of Configure.pl,\n"
+ . "but you should only run a version which has been processed by\n"
+ . "build/skel-template.pl\n";
+ }
+}
+
my $lclang = lc $lang;
my $uclang = uc $lang;
@@ -43,7 +55,7 @@ MAIN: {
my $prefix = $options{'prefix'} || cwd().'/install';
my $with_parrot = $options{'with-parrot'};
- $options{'gen-parrot'} ||= 'parrot-4.4.0' if defined $options{'gen-parrot'};
+ $options{'gen-parrot'} ||= "parrot-$parrot_ver" if defined $options{'gen-parrot'};
my $gen_parrot = $options{'gen-parrot'};
# Save options in config.status
@@ -59,12 +71,12 @@ MAIN: {
$options{'gen-nqp'} ||= '';
}
- $options{'gen-nqp'} ||= 'nqp-2012.05' if defined $options{'gen-nqp'};
+ $options{'gen-nqp'} ||= "nqp-$nqp_ver" if defined $options{'gen-nqp'};
my $with_nqp = $options{'with-nqp'};
my $gen_nqp = $options{'gen-nqp'};
# determine the version of NQP we want
- my ($nqp_want) = split(' ', slurp('rakudo-2012.05/tools/build/NQP_REVISION'));
+ my ($nqp_want) = split(' ', slurp("rakudo-$rakudo_ver/tools/build/NQP_REVISION"));
if (defined $gen_nqp) {
$with_nqp = gen_nqp($nqp_want, %options);