#! /usr/bin/perl -w
#
# Creates the $GENIE/src/Conventions/GBuild.h header file
#
# C.Andreopoulos <costas.andreopoulos \at stfc.ac.uk>, Rutherford Lab.
#

$GENIE = $ENV{'GENIE'};
die ("Not even the GENIE environmental variable is defined!") unless defined $GENIE;

# Read version info
$REL_INFO_FILE = "$GENIE/VERSION";
open(REL_INFO, "<$REL_INFO_FILE") or die("Can not read the GENIE release information!");
@rel_info=<REL_INFO>;
close(REL_INFO);
chomp($release = $rel_info[0]);

# ($major, $minor, $rev) = split('.', $release);
# note: split() doesn't split on dots...
$release=~m/(\d+).(\d+).(\d+)/;
$major = $1;
$minor = $2;
$revis = $3;

# Open header file
$GVRS_FILE = "$GENIE/src/Conventions/GVersion.h";
open(GVRS, ">$GVRS_FILE") or die("Can not write out the GVersion.h file!");

# Write header file
print GVRS "#ifndef _GVERSION_H_ \n";
print GVRS "#define _GVERSION_H_ \n";
print GVRS "/* \n";
print GVRS " * Version information automatically generated by the GENIE installer \n";
print GVRS " * \n";
print GVRS " * These macros can be used in the following way (as the ones at ROOT's RVersion.h): \n";
print GVRS " * #if __GENIE_RELEASE_CODE__ >= GRELCODE(2,4,11) \n";
print GVRS " * #include <newheader.h>\n";
print GVRS " * #else\n";
print GVRS " * #include <oldheader.h>\n";
print GVRS " * #endif\n";
print GVRS "*/ \n\n";
print GVRS "#define GRELCODE(a,b,c) (((a) << 16) + ((b) << 8) + (c)) \n\n";
print GVRS "#define __GENIE_RELEASE__      \"$release\"\n";
print GVRS "#define __GENIE_RELEASE_CODE__ GRELCODE($major,$minor,$revis) \n";
print GVRS "\n#endif\n\n";

# Close header file
close(GVRS);


