#! /usr/bin/env perl

my $header = <<ENDHEADER;
##**************************************************************
##
## Copyright (C) 1990-2008, Condor Team, Computer Sciences Department,
## University of Wisconsin-Madison, WI.
## 
## Licensed under the Apache License, Version 2.0 (the "License"); you
## may not use this file except in compliance with the License.  You may
## obtain a copy of the License at
## 
##    http://www.apache.org/licenses/LICENSE-2.0
## 
## Unless required by applicable law or agreed to in writing, software
## distributed under the License is distributed on an "AS IS" BASIS,
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
## See the License for the specific language governing permissions and
## limitations under the License.
##
##**************************************************************
ENDHEADER

use strict;
use warnings;

if ( $#ARGV != 1 )
{
    die "usage: $0 </path/to/config.h> <outfile|->";
}

my $configfile = shift(@ARGV);
my $outfile    = shift(@ARGV);
my $wrapname   = "_CONDOR_USER_LOG_CONFIG_H_";

open( IN, $configfile ) or die "Can't read $configfile";

if ( $outfile eq "-" )
{
    open( OUT, ">&STDOUT" ) or die "Can't clone STDOUT";
}
else
{
    open( OUT, ">$outfile" ) or die "Can't write to $outfile";
}

$header =~ s/\#\#/\*\*/g;
chomp $header;

print OUT "/" . $header . "/\n";
print OUT "\n";
print OUT "#ifndef $wrapname\n";
print OUT "#define $wrapname\n";
print OUT "\n";

my @WANT = ( "HAVE_SYS_TYPES_H",
	     "HAVE_INTTYPES_H",
	     "HAVE_INT64_T",
	     "HAVE___INT64",
	     "HAVE_LONG_LONG",
	     );
my $wantre = "(".join("|",@WANT).")";
my $pline = "";
while( <IN> )
{
    chomp;
    if (  /$wantre/ )
    {
	print OUT "$pline\n";
	print OUT "$_\n";
	print OUT "\n";
    }

    $pline = $_;
}

print OUT "#endif /* $wrapname */\n";
