forked from bmx-ng/bmk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbmk_modutil.bmx
261 lines (222 loc) · 5.42 KB
/
bmk_modutil.bmx
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
Strict
Import BRL.MaxUtil
Import BRL.TextStream
Import "bmk_util.bmx"
Const SOURCE_UNKNOWN:Int = 0
Const SOURCE_BMX:Int = $01
Const SOURCE_IFACE:Int = $02
Const SOURCE_C:Int = $04
Const SOURCE_HEADER:Int = $08
Const SOURCE_ASM:Int = $10
'Const SOURCE_PYTHON:Int = $20
'Const SOURCE_PERL:Int = $40
'Const SOURCE_RUBY:Int = $80
' etc ?
Type TSourceFile
Field ext$ 'one of: "bmx", "i", "c", "cpp", "m", "s", "h"
Field path$
Field modid$
Field framewk$
Field info:TList=New TList
Field modimports:TList=New TList
Field imports:TList=New TList
Field includes:TList=New TList
Field incbins:TList=New TList
Field declids:TList=New TList
Field pragmas:TList = New TList
End Type
Function ValidSourceExt( ext:Int )
If ext & $FFFF Then
Return True
End If
Return False
End Function
Function ParseSourceFile:TSourceFile( path$ )
If FileType(path)<>FILETYPE_FILE Return
Local ext$=ExtractExt( path ).ToLower()
Local exti:Int = String(RunCommand("source_type", [ext])).ToInt()
If Not ValidSourceExt( exti ) Return
Local file:TSourceFile=New TSourceFile
file.ext=ext
file.path=path
Local str$=LoadText( path )
Local pos,in_rem,cc=True
While pos<Len(str)
Local eol=str.Find( "~n",pos )
If eol=-1 eol=Len(str)
Local line$=str[pos..eol].Trim()
pos=eol+1
Local pragmaLine:String
Local n:Int = line.Find("@")
If n <> -1 And line[n+1..n+4] = "bmk" Then
pragmaLine = line[n+4..]
End If
Select exti
Case SOURCE_BMX, SOURCE_IFACE
n=line.Find( "'" )
If n<>-1 line=line[..n]
If Not line And Not pragmaLine Continue
Local lline$=line.Tolower()
If in_rem
If lline[..6]="endrem" Or lline[..7]="end rem"
in_rem=False
EndIf
Continue
Else If lline[..3]="rem"
in_rem=True
Continue
EndIf
If lline[..1]="?"
Local t$=lline[1..].Trim()
Local cNot
If t.StartsWith( "not " )
cNot=True
t=t[4..].Trim()
EndIf
t = t.toLower()
Select t
Case ""
cc=True
Case "debug"
cc=opt_debug
Case "threaded"
cc=opt_threaded
'?x86
Case "x86" cc=processor.CPU()="x86"
'?ppc
Case "ppc" cc=processor.CPU()="ppc"
Case "x64" cc=processor.CPU()="x64"
Case "arm" cc=processor.CPU()="arm"
'?
Case "win32"
cc=False
If processor.Platform() = "win32"
cc=True
End If
Case "win32x86"
cc=False
If processor.Platform() = "win32"
cc=opt_arch="x86"
End If
Case "win32ppc"
cc=False
If processor.Platform() = "win32"
cc=opt_arch="ppc"
End If
Case "win32x64"
cc=False
If processor.Platform() = "win32"
cc=opt_arch="x64"
End If
Case "linux"
cc=False
If processor.Platform() = "linux"
cc=True
End If
Case "linuxx86"
cc=False
If processor.Platform() = "linux"
cc=opt_arch="x86"
End If
Case "linuxppc"
cc=False
If processor.Platform() = "linux"
cc=opt_arch="ppc"
End If
Case "linuxx64"
cc=False
If processor.Platform() = "linux"
cc=opt_arch="x64"
End If
Case "linuxarm"
cc=False
If processor.Platform() = "linux"
cc=opt_arch="arm"
End If
Case "macos"
cc=False
If processor.Platform() = "macos"
cc=True
End If
Case "macosx86"
cc=False
If processor.Platform() = "macos"
cc=processor.CPU()="x86"
End If
Case "macosppc"
cc=False
If processor.Platform() = "macos"
cc=processor.CPU()="ppc"
End If
Case "macosx64"
cc=False
If processor.Platform() = "macos"
cc=processor.CPU()="x64"
End If
Default
cc=False
End Select
If cNot cc=Not cc
Continue
EndIf
If Not cc Continue
Local i:Int
' new pragma stuff
If pragmaLine Then
Local lpragma:String = pragmaLine.ToLower()
i = 0
While i<lpragma.length And Not (CharIsAlpha(lpragma[i]) Or CharIsDigit(lpragma[i]) Or lpragma[i] = Asc("@"))
i:+1
Wend
file.pragmas.AddLast pragmaLine[i..]
End If
If lline.length And Not CharIsAlpha( lline[0] ) Continue
i=1
While i<lline.length And (CharIsAlpha(lline[i]) Or CharIsDigit(lline[i]))
i:+1
Wend
If i=lline.length Continue
Local key$=lline[..i]
Local val$=line[i..].Trim(),qval$,qext$
If val.length>1 And val[0]=34 And val[val.length-1]=34
qval=val[1..val.length-1]
EndIf
Select key
Case "module"
file.modid=val.ToLower()
Case "framework"
file.framewk=val.ToLower()
Case "import"
If qval
file.imports.AddLast qval
Else
file.modimports.AddLast val.ToLower()
EndIf
Case "incbin"
If qval
file.incbins.AddLast qval
EndIf
Case "include"
If qval
file.includes.AddLast qval
EndIf
Case "moduleinfo"
If qval
file.info.AddLast qval
If mod_opts mod_opts.addOption(qval) ' BaH
EndIf
End Select
Case SOURCE_C, SOURCE_HEADER '"c","m","h","cpp","cxx","hpp","hxx"
If line[..8]="#include"
Local val$=line[8..].Trim(),qval$,qext$
If val.length>1 And val[0]=34 And val[val.length-1]=34
qval=val[1..val.length-1]
EndIf
If qval
file.includes.AddLast qval
EndIf
EndIf
End Select
Wend
Return file
End Function