aboutsummaryrefslogtreecommitdiff
path: root/harness/tools/genbuild.pl
blob: 1acabc055682ee00ffcbea5808ae30ae7b33aa28 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env perl

$comment="";

print "#include <stdio.h>\n";
print "#include <dlfcn.h>\n";
print "#include <pthread.h>\n";
print "#include <string.h>\n";
print "#include \"plugin.h\"\n\n";

print "int load_plugin_from_dl_(dlhandle_t dl, plugin_t* plug)\n";
print "{\n";
print "  void* ptr;\n";
print "  int ret = 0;\n";
print "\n";
print "  const char** name = dlsym(dl, \"plugin_name\");\n";
print "  memset(plug, 0, sizeof(*plug));\n";
print "  if (name) {\n";
print "    plug->plugin_name = *name;\n";
print "  } else {\n";
print "    plug->plugin_name = NULL;\n";
print "  }\n";
print "  plug->state = NULL;\n";
print "  plug->library_handle = dl;\n";
print "\n";
while (<>) {
  if (/^\s*EXPORT/) {
    my $line = "$_";
    while (not ($line =~ /;$/)) {
      my $nextline = <STDIN>;
      last unless defined $nextline;

      $line="$line$nextline";
    }
    if ($line =~ /^\s*EXPORT\(\s*((?:\w|\s*\*\s*)+)\s*\(\*(\w+)\)\s*\((.*)\)\);/s) {
      print "\n";
      print "  ptr = dlsym(dl, \"$2\");\n";
      print "  if (!ptr) {\n";
      print "    fprintf(stderr, \"Plugin missing %s\\n\", \"$2\");\n";
      print "    ret |= 1;\n";
      print "  }\n";
      print "  plug->$2 = ptr;\n";
      $comment="";
    }
  }
}
print "\n  return ret;\n";
print "}\n";