aboutsummaryrefslogtreecommitdiff
path: root/build/skel-template.pl
diff options
context:
space:
mode:
authorMoritz Lenz <moritz@faui2k3.org>2012-05-28 20:14:31 +0200
committerMoritz Lenz <moritz@faui2k3.org>2012-05-28 20:14:31 +0200
commitc27e2ab3d7f4e6e554ac244521bef4039f9730ad (patch)
tree2022ecb899c7d63280fa2cfd26fa2238d7345040 /build/skel-template.pl
parent7d37beba5508bd14c3fa7996c626103921d0b6fc (diff)
parent2663a4881dd24a7d42007adbf870302e73cbf779 (diff)
Merge branch 'template'
Diffstat (limited to 'build/skel-template.pl')
-rw-r--r--build/skel-template.pl58
1 files changed, 58 insertions, 0 deletions
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': $!";
+}