#!@PERL@ -w

my ${prefix}="@prefix@";

my ${exec_prefix}="@exec_prefix@";

my ${datarootdir}="@datarootdir@";

my ${datadir}="@datadir@";

my $PERL="@PERL@";
my $PERL_LIB_PATH="@PERL_LIB_PATH@";
if( $PERL_LIB_PATH ne "no" ){
    $PERL_LIB_PATH_CODE = "use lib '".$PERL_LIB_PATH."';";
}else{
    $PERL_LIB_PATH = "";
    $PERL_LIB_PATH_CODE = "";
}
my $SHELL="@SHELL@";
my $STRIP="@STRIP@";
my $INSTALL="@INSTALL@";
if($INSTALL =~ /^\.\//){
    $INSTALL =~ s/^\.\//\.\.\//;
}
my $INSTALL_OPTS="@INSTALL_OPTS@";
my $DEBUG="@DEBUG@";
my $PERFDATA_DIR="@PERFDATA_DIR@";
my $PERFDATA_LOG="@PERFDATA_LOG@";
my $PERFDATA_SPOOL_DIR="@PERFDATA_SPOOL_DIR@";
my $RRDTOOL="@RRDTOOL@";
my $RRDS="@RRDS@";
my $XML_STRUCTURE_VERSION="@XML_STRUCTURE_VERSION@";
my $PKG_REL_DATE="@PKG_REL_DATE@";
my $PKG_VERSION="@PKG_VERSION@";
my $PKG_NAME="@PKG_NAME@";
my $BASE_URL="@BASE_URL@";
my $HTTPD_CONF="@HTTPD_CONF@";
my $init_dir="@init_dir@";
my $npcd_name="@npcd_name@";
my $pp_pl_name="@pp_pl_name@";
my $nagios_user="@nagios_user@";
my $nagios_grp="@nagios_grp@";
my $libexecdir="@libexecdir@"; # put all --with-vars before directories
my $localstatedir="@localstatedir@";
my $KOHANA="@KOHANA@";
my $KOHANA_SYSTEM="@KOHANA_SYSTEM@";
my $libdir="@libdir@";
my $sysconfdir="@sysconfdir@";
my $host_os="@host_os@";
my $ac_configure_args="@ac_configure_args@";

my $sbindir="@sbindir@";
my $bindir="@bindir@";
my $srcdir="@srcdir@";

my $CC="@CC@";
my $CFLAGS="@CFLAGS@";
my $DEFS="@DEFS@";
my $LDFLAGS="@LDFLAGS@";
my $LIBS="@LIBS@";
my $MOD_CFLAGS="@MOD_CFLAGS@";
my $MOD_LDFLAGS="@MOD_LDFLAGS@";

my $CP="@CP@";


while ($f = shift @ARGV) {

	if (-x "/bin/mktemp") { 
		$TEMP = `/bin/mktemp $f.$$.XXXXXX`;
		die 'Cannot make temporary file $TEMP' if($?);
		chomp $TEMP;
	} else {
		$XXXXXX = rand;
		$TEMP = "$f.$$.$XXXXXX";
	}

	open(IN,"<$f.in");
	open(OUT,">$TEMP") || die 'Cannot make temporary file $TEMP';

	while (<IN>) {
		s|\@PERL\@|$PERL|g;
		s|\@PERL_LIB_PATH\@|$PERL_LIB_PATH|g;
		s|\@PERL_LIB_PATH_CODE\@|$PERL_LIB_PATH_CODE|g;
		s|\@SHELL\@|$SHELL|g;
		s|\@STRIP\@|$STRIP|g;
		s|\@INSTALL\@|$INSTALL|g;
		s|\@INSTALL_OPTS\@|$INSTALL_OPTS|g;
		s|\@DEBUG\@|$DEBUG|g;
		s|\@PERFDATA_DIR\@|$PERFDATA_DIR|g;
		s|\@PERFDATA_LOG\@|$PERFDATA_LOG|g;
		s|\@PERFDATA_SPOOL_DIR\@|$PERFDATA_SPOOL_DIR|g;
		s|\@RRDTOOL\@|$RRDTOOL|g;
		s|\@RRDS\@|$RRDS|g;
		s|\@XML_STRUCTURE_VERSION\@|$XML_STRUCTURE_VERSION|g;
		s|\@PKG_REL_DATE\@|$PKG_REL_DATE|g;
		s|\@PKG_VERSION\@|$PKG_VERSION|g;
		s|\@PKG_NAME\@|$PKG_NAME|g;
		s|\@BASE_URL\@|$BASE_URL|g;
		s|\@HTTPD_CONF\@|$HTTPD_CONF|g;
		s|\@npcd_name\@|$npcd_name|g;
		s|\@pp_pl_name\@|$pp_pl_name|g;
		s|\@nagios_user\@|$nagios_user|g;
		s|\@nagios_grp\@|$nagios_grp|g;
		s|\@libexecdir\@|$libexecdir|g; # put all --with-vars before directories
		s|\@localstatedir\@|$localstatedir|g;
		s|\@KOHANA\@|$KOHANA|g;
		s|\@KOHANA_SYSTEM\@|$KOHANA_SYSTEM|g;
		s|\@libdir\@|$libdir|g;
		s|\@init_dir\@|$init_dir|g;
		s|\@sysconfdir\@|$sysconfdir|g;
		s|\@datarootdir\@|$datarootdir|g;
		s|\@datadir\@|$datadir|g;
		s|\@sbindir\@|$sbindir|g;
		s|\@bindir\@|$bindir|g;
		s|\@srcdir\@|$srcdir|g;
		s|\@CC\@|$CC|g;
		s|\@CFLAGS\@|$CFLAGS|g;
		s|\@DEFS\@|$DEFS|g;
		s|\@LDFLAGS\@|$LDFLAGS|g;
		s|\@MOD_LDFLAGS\@|$MOD_LDFLAGS|g;
		s|\@MOD_CFLAGS\@|$MOD_CFLAGS|g;
		s|\@LIBS\@|$LIBS|g;
		s|\@CP\@|$CP|g;
		s|\@prefix\@|$prefix|g;
		s|\@host_os\@|$host_os|g;
		s|\@ac_configure_args\@|$ac_configure_args|g;
		s|\$\{exec_prefix\}|$exec_prefix|g; # must be next to last
		s|\$\{prefix\}|$prefix|g; # must be last
		print OUT $_;
	}

	close IN;
	close OUT;

	if ((! -e $f) || (`diff $f $TEMP`)) {
		`mv $TEMP $f`;
	} else {
	         unlink $TEMP;
	}

}
