-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmake.lua
More file actions
executable file
·66 lines (60 loc) · 2.23 KB
/
make.lua
File metadata and controls
executable file
·66 lines (60 loc) · 2.23 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
#!/usr/bin/env luajit
local ffi = require 'ffi'
local path = require 'ext.path'
local table = require 'ext.table'
local os = require 'ext.os'
local includeList = table(require 'include.include-list')
local req = assert(..., "`make.lua all` for all, or `make.lua <sourceIncludeFile.h>`")
local start = req:match'^start=(.*)$'
if start then
for i=assert(includeList:find(nil, function(inc) return inc.inc == start end), "couldn't find starting point: "..start)-1,1,-1 do
includeList:remove(i)
end
else
local stop = req:match'^stop=(.*)$'
if stop then
for i=assert(includeList:find(nil, function(inc) return inc.inc == stop end), "couldn't find starting point: "..stop)+1,#includeList do
includeList[i] = nil
end
elseif req ~= 'all' then
-- TODO seems using <> or "" now is essential for excluding recursive require's
if req:sub(1,1) ~= '<' and req:sub(1,1) ~= '"' then
error('must be system (<...>) or user ("...") include space')
end
print('searching for '..req)
includeList = includeList:filter(function(inc) return inc.inc == req end)
if #includeList == 0 then
error("couldn't find "..req)
end
end
end
local outdirbase = path'results' -- also in generate.lua
for _,inc in ipairs(includeList) do
if not inc.dontGen then
local outpath = outdirbase/'ffi'/inc.out
outpath:getdir():mkdir(true)
if inc.forcecode then
-- just write it , proly a split between dif os versions
outpath:write(inc.forcecode)
else
outpath:write(require 'generate'(inc))
end
if ffi.os == 'Windows' then
-- in windows, the linux code writes \n's, but the windows >> writes \r\n's,
-- so unify them all here, pick whichever format you want
outpath:write((
outpath:read()
:gsub('\r\n', '\n')
))
end
-- verify it works
-- can't use -lext because that will load ffi/c stuff which could cause clashes in cdefs
-- luajit has loadfile, nice.
--[=[ use loadfile ... and all the old/original ffi locations
assert(os.exec([[luajit -e "assert(loadfile(']]..outpath..[['))()"]]))
--]=]
-- [=[ use require, and base it in the output folder
assert(os.exec([[luajit -e "package.path=']]..outdirbase..[[/?.lua;'..package.path require 'ffi.req' ']]..assert((inc.out:match'(.*)%.lua')):gsub('/', '.')..[['"]]))
--]=]
end
end