diff -r 06b955c7b673 -r 0d1bd8c1cf85 scripts/din2d --- a/scripts/din2d Mon Aug 24 21:41:18 2015 +0200 +++ b/scripts/din2d Tue Aug 25 15:30:13 2015 +0200 @@ -1,22 +1,49 @@ #!/usr/bin/perl # Dockerfile.in -> Dockerfile # currently just resolve .include_if_exists .. +# .include +# .platform +# use strict; use warnings; +use 5.14.0; use Cwd qw(abs_path); -use File::Basename qw(dirname); +use File::Basename qw(basename dirname); use Getopt::Long; while (<>) { - /^\.include_if_exists\s+(.+?)\s*$/ or next; - $_ = "# from $1 {{\n" . do { - my $file = abs_path(dirname($ARGV) . "/$1"); - open(my $in, '<', $file) or die "Can't open $file: $!\n"; - local $/ = undef; - <$in>; - } - . "# }}\n"; + state $platform; + + if (/^.platform\s+(\S+)\s*/) { + $platform = $1; + $_ = "# platform is $1\n"; + next; + } + + if (/^(?.include(?_if_exists)?)\s+(?.+?)\s*$/) { + $_ = "# $+{cmd} from $+{file} {{\n" . join('' => do { + my @yield; + my @files = glob abs_path(dirname($ARGV)) . "/$+{file}"; + foreach my $file (@files) { + push @yield, "# from $file\n"; + if (open(my $in, '<', $file)) { + local $/ = undef; + push @yield, <$in>; + } + else { + die "$file: $!\n" if not $+{try}; + } + } + @yield; + }) . "# }}\n"; + } + + if (//) { + die "$0:$ARGV platform not known yet!\n" + if not defined $platform; + s//$platform/g; + } } continue { print if defined;