diff options
-rw-r--r-- | Makefile | 1 | ||||
-rw-r--r-- | build/skel-template.pl | 58 | ||||
-rw-r--r-- | template-skel/Configure.pl (renamed from skel/Configure.pl) | 18 |
3 files changed, 74 insertions, 3 deletions
@@ -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..0e355fe --- /dev/null +++ b/build/skel-template.pl @@ -0,0 +1,58 @@ +# grabs some variables (containing versions) from Makefile, +# and then copies files from template-skel over to the +# dist folder, replacing occurrences of those variables +# in the process. + +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); |