#!/usr/bin/perl
# Dockerfile.in -> Dockerfile
# currently just resolve .include ..

use strict;
use warnings;
use Cwd qw(abs_path);
use File::Basename qw(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";
}
continue {
    print if defined;
}
