forked from livecode/livecode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild_libinfo.lc
More file actions
69 lines (56 loc) · 1.78 KB
/
build_libinfo.lc
File metadata and controls
69 lines (56 loc) · 1.78 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
#! /usr/bin/revolution -ui
on startup
local tSpec
read from stdin until eof
put it into tSpec
local tName
put $1 into tName
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 stdout
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 stdout
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 "};"
end startup
on output pLine
write pLine & return to stdout
end output