#  Copyright (c) 1997-2010
#  Ewgenij Gawrilow, Michael Joswig (Technische Universitaet Darmstadt, Germany)
#  http://www.polymake.de
#
#  This program is free software; you can redistribute it and/or modify it
#  under the terms of the GNU General Public License as published by the
#  Free Software Foundation; either version 2, or (at your option) any
#  later version: http://www.gnu.org/licenses/gpl.txt.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#-------------------------------------------------------------------------------
#  $Project: polymake $$Id: createBootstrap.pl 9991 2010-12-12 23:36:28Z gawrilow $

use strict;

@ARGV or die "usage: perl $0 FILE.c ... >FILE.h\n";

my $proto="XS(boot_DynaLoader);\n";
my $bind=<<'.';
   newXS("DynaLoader::boot_DynaLoader", boot_DynaLoader, __FILE__);
.

foreach my $file (@ARGV) {
   open my $C, $file or die "can't read $file: $!\n";
   my $ugly_cast= $] <= 5.008 && "(char*)";
   while (<$C>) {
      if (/^XS\((boot_(\w+))\);/) {
         $proto .= "$&\n";
         my $func=$1;
         (my $pkg=$2) =~ s/_/:/g;
         $bind .= qq{   newXS("$pkg\::bootstrap", $func, $ugly_cast"$file");\n};
      }
   }
}

print <<".";
/* CAUTION: this file is created automatically.
   Please make all changes in $0, not here.

   This header collects all the package bootstrap functions which must be called
   during the initial loading of the callable library.
*/

#ifndef _POLYMAKE_XS_EXT_BOOTSTRAP_H
#define _POLYMAKE_XS_EXT_BOOTSTRAP_H

$proto
static void xs_init(pTHX)
{
$bind
}

#endif // _POLYMAKE_XS_EXT_BOOTSTRAP_H
.

# Local Variables:
# mode: perl
# cperl-indent-level:3
# indent-tabs-mode:nil
# End:
