This repository was archived by the owner on Aug 31, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 226
Expand file tree
/
Copy pathbuild_libinfo.lc
More file actions
75 lines (59 loc) · 1.88 KB
/
build_libinfo.lc
File metadata and controls
75 lines (59 loc) · 1.88 KB
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
#! /usr/bin/revolution -ui
local sOutput
on startup
local tSpec
put url("file:" & $2) into tSpec
local tName
put $1 into tName
put $3 into sOutput
open file sOutput for binary write
local tSymbolExterns, tSymbolEntries
repeat for each line tLine in tSpec
if word 1 to -1 of tLine is empty then
next repeat
end if
if char 1 of word 1 of tLine is "#" then
next repeat
end if
if char 1 of tLine is not tab then
next repeat
end if
if word 1 to -1 of (char 2 to -1 of tLine) is empty then
next repeat
end if
local tEntry
put word 1 to -1 of (char 2 to -1 of tLine) into tEntry
local tSymbol
if word 1 of tEntry is "?" then
put word 2 of tEntry into tSymbol
else
put word 1 of tEntry into tSymbol
end if
if char -1 of tSymbol is ":" then
delete char -1 of tSymbol
end if
put format("extern \"C\" void *%s;", tSymbol) & return after tSymbolExterns
put format(" { \"%s\", &%s },", tSymbol, tSymbol) & return after tSymbolEntries
end repeat
write tSymbolExterns to file sOutput
output "extern" && quote & "C" & quote && "{"
output "struct LibExport { const char *name; void *address; };"
output "struct LibInfo { const char **name; struct LibExport *exports; };"
output "static const char *__libexternalname =" && quote & tName & quote & ";"
output "static struct LibExport __libexports[] ="
output "{"
write tSymbolEntries to file sOutput
output " { 0, 0 }"
output "};"
output "static struct LibInfo __libinfo="
output "{"
output " &__libexternalname,"
output " __libexports"
output "};"
output "__attribute((section(" & quote & "__DATA,__libs" & quote & "))) volatile struct LibInfo *__libinfoptr_" & tName & " = &__libinfo;"
output "};"
close file sOutput
end startup
on output pLine
write pLine & return to file sOutput
end output