-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathAutoOpen.pl
92 lines (81 loc) · 3.04 KB
/
AutoOpen.pl
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
### Class AutoOpen: Create a proto file #######################################
BEGIN {
package AutoOpen;
sub new {
my $proto = shift;
my %params = @_;
my $class = ref($proto) || $proto;
my $self = {};
$self->{SFD} = $params{'sfd'};
bless ($self, $class);
return $self;
}
sub header {
my $self = shift;
my $sfd = $self->{SFD};
print "/* Automatically generated header (sfdc SFDC_VERSION)! Do not edit! */\n";
print "\n";
if ($sfd->{base} ne '') {
print "#ifdef __cplusplus\n";
print "extern \"C\" {\n";
print "#endif /* __cplusplus */\n";
print "\n";
print "#if defined (__libnix__)\n";
print "\n";
print "#include <stabs.h>\n";
print "void* $sfd->{base}" . "[2] = { 0, \"$sfd->{libname}\" };\n";
print "ADD2LIB($sfd->{base});\n";
print "\n";
print "#elif defined (__AMIGAOS4__)\n";
print "\n";
print "#undef __USE_INLINE__\n";
print "#define _NO_INLINE\n";
foreach my $inc (@{$$sfd{'includes'}}) {
print "#include $inc\n";
}
foreach my $td (@{$$sfd{'typedefs'}}) {
print "typedef $td;\n";
}
print "\n";
print "#include <interfaces/$sfd->{basename}.h>\n";
print "#include <proto/exec.h>\n";
print "#include <assert.h>\n";
print "\n";
print "__attribute__((weak)) $sfd->{basetype} $sfd->{base} = NULL;\n";
print "__attribute__((weak)) struct $sfd->{BaseName}IFace* I$sfd->{BaseName} = NULL;\n";
print "\n";
print "void __init_$sfd->{BaseName}(void) __attribute__((constructor));\n";
print "void __exit_$sfd->{BaseName}(void) __attribute__((destructor));\n";
print "\n";
print "void __init_$sfd->{BaseName}(void) {\n";
print " if ($sfd->{base} == NULL) {\n";
print " $sfd->{base} = ($sfd->{basetype}) IExec->OpenLibrary(\"$sfd->{libname}\", 0);\n";
print " assert($sfd->{base} != NULL);\n";
print " }\n";
print " if (I$sfd->{BaseName} == NULL) {\n";
print " I$sfd->{BaseName} = (struct $sfd->{BaseName}IFace*) IExec->GetInterface(";
print "(struct Library*) $sfd->{base}, \"main\", 1, NULL);\n";
print " assert(I$sfd->{BaseName} != NULL);\n";
print " }\n";
print "}\n";
print "\n";
print "void __exit_$sfd->{BaseName}(void) {\n";
print " IExec->DropInterface((struct Interface*) I$sfd->{BaseName});\n";
print " IExec->CloseLibrary((struct Library*) $sfd->{base});\n";
print "}\n";
print "\n";
print "\n";
print "#endif\n";
}
print "\n";
print "#ifdef __cplusplus\n";
print "}\n";
print "#endif /* __cplusplus */\n";
}
sub function {
# Nothing to do here ...
}
sub footer {
# Nothing to do here ...
}
}