1#  Copyright (c) 1997-2021
2#  Ewgenij Gawrilow, Michael Joswig, and the polymake team
3#  Technische Universität Berlin, Germany
4#  https://polymake.org
5#
6#  This program is free software; you can redistribute it and/or modify it
7#  under the terms of the GNU General Public License as published by the
8#  Free Software Foundation; either version 2, or (at your option) any
9#  later version: http://www.gnu.org/licenses/gpl.txt.
10#
11#  This program is distributed in the hope that it will be useful,
12#  but WITHOUT ANY WARRANTY; without even the implied warranty of
13#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14#  GNU General Public License for more details.
15#-------------------------------------------------------------------------------
16
17use strict;
18
19@ARGV or die "usage: perl $0 FILE.c ... >FILE.h\n";
20
21my $proto="XS(boot_DynaLoader);\n";
22my $bind=<<'.';
23   newXS("DynaLoader::boot_DynaLoader", boot_DynaLoader, "Main.cc");
24.
25
26foreach my $file (@ARGV) {
27   open my $C, $file or die "can't read $file: $!\n";
28   my ($filename)= $file =~ m{(?:^|/)([^/]+)$};
29   while (<$C>) {
30      if (/^XS(?:_EXTERNAL)?\((boot_(\w+))\);/) {
31         $proto .= "$&\n";
32         my $func=$1;
33         (my $pkg=$2) =~ s/_/:/g;
34         $bind .= qq{   newXS("$pkg\::bootstrap", $func, "$filename");\n};
35      }
36   }
37}
38
39print <<".";
40/* CAUTION: this file is created automatically.
41   Please make all changes in $0, not here.
42
43   This header collects all the package bootstrap functions which must be called
44   during the initial loading of the callable library.
45*/
46
47#ifndef POLYMAKE_XS_EXT_BOOTSTRAP_H
48#define POLYMAKE_XS_EXT_BOOTSTRAP_H
49
50#ifndef XS_EXTERNAL
51#define XS_EXTERNAL(name) XS(name)
52#endif
53
54$proto
55static void xs_init(pTHX)
56{
57$bind
58}
59
60#endif // POLYMAKE_XS_EXT_BOOTSTRAP_H
61.
62
63# Local Variables:
64# mode: perl
65# cperl-indent-level:3
66# indent-tabs-mode:nil
67# End:
68