mirror of
https://github.com/natnat-mc/moonbuild
synced 2026-05-28 18:49:40 +02:00
depend on amalg.lua to produce a single binary, fix #10
This commit is contained in:
@@ -1,155 +0,0 @@
|
||||
local dir, attributes
|
||||
do
|
||||
local _obj_0 = require('lfs')
|
||||
dir, attributes = _obj_0.dir, _obj_0.attributes
|
||||
end
|
||||
local gmatch, match, gsub, sub
|
||||
do
|
||||
local _obj_0 = string
|
||||
gmatch, match, gsub, sub = _obj_0.gmatch, _obj_0.match, _obj_0.gsub, _obj_0.sub
|
||||
end
|
||||
local insert, concat
|
||||
do
|
||||
local _obj_0 = table
|
||||
insert, concat = _obj_0.insert, _obj_0.concat
|
||||
end
|
||||
local ls
|
||||
ls = function(d)
|
||||
local _accum_0 = { }
|
||||
local _len_0 = 1
|
||||
for f in dir(d) do
|
||||
if f ~= '.' and f ~= '..' then
|
||||
_accum_0[_len_0] = f
|
||||
_len_0 = _len_0 + 1
|
||||
end
|
||||
end
|
||||
return _accum_0
|
||||
end
|
||||
local lswithpath
|
||||
lswithpath = function(d)
|
||||
if d == '' then
|
||||
return ls('.')
|
||||
end
|
||||
local _accum_0 = { }
|
||||
local _len_0 = 1
|
||||
for f in dir(d) do
|
||||
if f ~= '.' and f ~= '..' then
|
||||
_accum_0[_len_0] = d .. '/' .. f
|
||||
_len_0 = _len_0 + 1
|
||||
end
|
||||
end
|
||||
return _accum_0
|
||||
end
|
||||
local exists
|
||||
exists = function(f)
|
||||
return (attributes(f)) ~= nil
|
||||
end
|
||||
local isdir
|
||||
isdir = function(f)
|
||||
local a = attributes(f)
|
||||
return a and a.mode == 'directory' or false
|
||||
end
|
||||
local mtime
|
||||
mtime = function(f)
|
||||
local a = attributes(f)
|
||||
return a and a.modification
|
||||
end
|
||||
local matchglob
|
||||
matchglob = function(str, glob)
|
||||
local patt = '^' .. (gsub((gsub(glob, '%*%*', '.*')), '%*', '[^/]*')) .. '$'
|
||||
local rst
|
||||
if (type(str)) == 'table' then
|
||||
local results, i = { }, 1
|
||||
for _index_0 = 1, #str do
|
||||
local s = str[_index_0]
|
||||
rst = (match(s, patt)) and s
|
||||
if rst then
|
||||
results[i], i = rst, i + 1
|
||||
end
|
||||
end
|
||||
rst = results
|
||||
else
|
||||
rst = (match(str, patt)) and str
|
||||
end
|
||||
return rst
|
||||
end
|
||||
local wildcard
|
||||
wildcard = function(glob)
|
||||
local parts
|
||||
do
|
||||
local _accum_0 = { }
|
||||
local _len_0 = 1
|
||||
for part in gmatch(glob, '[^/]+') do
|
||||
_accum_0[_len_0] = part
|
||||
_len_0 = _len_0 + 1
|
||||
end
|
||||
parts = _accum_0
|
||||
end
|
||||
local absolute = (sub(glob, 1, 1)) == '/'
|
||||
for i, part in ipairs(parts) do
|
||||
local prevpath = (absolute and '/' or '') .. concat(parts, '/', 1, i - 1)
|
||||
local currpath = prevpath .. '/' .. part
|
||||
if match(part, '%*%*.*%*%*') then
|
||||
error("Two '**' in the same path component in a wildcard")
|
||||
end
|
||||
if match(part, '%*%*') then
|
||||
local prefix = match(currpath, '^(.*)%*%*')
|
||||
local suffix = (match(part, '%*%*(.*)$')) .. (i == #parts and '' or ('/' .. concat(parts, '/', i + 1, #parts)))
|
||||
local files = lswithpath(prevpath)
|
||||
local results = { }
|
||||
for _index_0 = 1, #files do
|
||||
local file = files[_index_0]
|
||||
if matchglob(file, currpath) then
|
||||
if i == #parts then
|
||||
insert(results, file)
|
||||
elseif isdir(file) then
|
||||
local _list_0 = wildcard(file .. '/' .. concat(parts, '/', i + 1, #parts))
|
||||
for _index_1 = 1, #_list_0 do
|
||||
local result = _list_0[_index_1]
|
||||
insert(results, result)
|
||||
end
|
||||
end
|
||||
end
|
||||
if (matchglob(file, prefix .. '**')) and isdir(file) then
|
||||
local _list_0 = wildcard(file .. '/**' .. suffix)
|
||||
for _index_1 = 1, #_list_0 do
|
||||
local result = _list_0[_index_1]
|
||||
insert(results, result)
|
||||
end
|
||||
end
|
||||
end
|
||||
return results
|
||||
end
|
||||
if match(part, '%*') then
|
||||
local files = lswithpath(prevpath)
|
||||
if i == #parts then
|
||||
return matchglob(files, glob)
|
||||
end
|
||||
local results = { }
|
||||
for _index_0 = 1, #files do
|
||||
local file = files[_index_0]
|
||||
if (matchglob(file, currpath)) and isdir(file) then
|
||||
local _list_0 = wildcard(file .. '/' .. concat(parts, '/', i + 1, #parts))
|
||||
for _index_1 = 1, #_list_0 do
|
||||
local result = _list_0[_index_1]
|
||||
insert(results, result)
|
||||
end
|
||||
end
|
||||
end
|
||||
return results
|
||||
end
|
||||
end
|
||||
if exists(glob) then
|
||||
return {
|
||||
glob
|
||||
}
|
||||
else
|
||||
return { }
|
||||
end
|
||||
end
|
||||
return {
|
||||
wildcard = wildcard,
|
||||
exists = exists,
|
||||
isdir = isdir,
|
||||
mtime = mtime
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
local match, gmatch, sub
|
||||
do
|
||||
local _obj_0 = string
|
||||
match, gmatch, sub = _obj_0.match, _obj_0.gmatch, _obj_0.sub
|
||||
end
|
||||
local upper, lower
|
||||
do
|
||||
local _obj_0 = string
|
||||
upper, lower = _obj_0.upper, _obj_0.lower
|
||||
end
|
||||
local GLOB_PATT = '^([^%%]*)%%([^%%]*)$'
|
||||
local patsubst
|
||||
patsubst = function(str, pattern, replacement)
|
||||
if (type(str)) == 'table' then
|
||||
local _accum_0 = { }
|
||||
local _len_0 = 1
|
||||
for _index_0 = 1, #str do
|
||||
local s = str[_index_0]
|
||||
_accum_0[_len_0] = patsubst(s, pattern, replacement)
|
||||
_len_0 = _len_0 + 1
|
||||
end
|
||||
return _accum_0
|
||||
end
|
||||
local prefix, suffix = match(pattern, GLOB_PATT)
|
||||
if not (prefix) then
|
||||
return str
|
||||
end
|
||||
local reprefix, resuffix = match(replacement, GLOB_PATT)
|
||||
if not (reprefix) then
|
||||
return replacement
|
||||
end
|
||||
if (sub(str, 1, #prefix)) == prefix and (sub(str, -#suffix)) == suffix then
|
||||
return reprefix .. (sub(str, #prefix + 1, -#suffix - 1)) .. resuffix
|
||||
end
|
||||
return str
|
||||
end
|
||||
local splitsp
|
||||
splitsp = function(str)
|
||||
local _accum_0 = { }
|
||||
local _len_0 = 1
|
||||
for elem in gmatch(str, '%S+') do
|
||||
_accum_0[_len_0] = elem
|
||||
_len_0 = _len_0 + 1
|
||||
end
|
||||
return _accum_0
|
||||
end
|
||||
return {
|
||||
patsubst = patsubst,
|
||||
splitsp = splitsp,
|
||||
upper = upper,
|
||||
lower = lower
|
||||
}
|
||||
@@ -1,132 +0,0 @@
|
||||
local insert, remove, concat, sort
|
||||
do
|
||||
local _obj_0 = table
|
||||
insert, remove, concat, sort = _obj_0.insert, _obj_0.remove, _obj_0.concat, _obj_0.sort
|
||||
end
|
||||
local unpack = unpack or table.unpack
|
||||
local sortedpairs
|
||||
sortedpairs = function(table, cmp)
|
||||
local keys
|
||||
do
|
||||
local _accum_0 = { }
|
||||
local _len_0 = 1
|
||||
for k in pairs(table) do
|
||||
_accum_0[_len_0] = k
|
||||
_len_0 = _len_0 + 1
|
||||
end
|
||||
keys = _accum_0
|
||||
end
|
||||
sort(keys, cmp)
|
||||
return coroutine.wrap(function()
|
||||
for _index_0 = 1, #keys do
|
||||
local key = keys[_index_0]
|
||||
coroutine.yield(key, table[key])
|
||||
end
|
||||
end)
|
||||
end
|
||||
local min
|
||||
min = function(table, cmp)
|
||||
if cmp == nil then
|
||||
cmp = function(a, b)
|
||||
return a < b
|
||||
end
|
||||
end
|
||||
local val = table[1]
|
||||
for i = 2, #table do
|
||||
local elem = table[i]
|
||||
if cmp(val, elem) then
|
||||
val = elem
|
||||
end
|
||||
end
|
||||
return val
|
||||
end
|
||||
local max
|
||||
max = function(table, cmp)
|
||||
if cmp == nil then
|
||||
cmp = function(a, b)
|
||||
return a < b
|
||||
end
|
||||
end
|
||||
local val = table[1]
|
||||
for i = 2, #table do
|
||||
local elem = table[i]
|
||||
if not cmp(val, elem) then
|
||||
val = elem
|
||||
end
|
||||
end
|
||||
return val
|
||||
end
|
||||
local foreach
|
||||
foreach = function(tab, fn)
|
||||
local _accum_0 = { }
|
||||
local _len_0 = 1
|
||||
for _index_0 = 1, #tab do
|
||||
local e = tab[_index_0]
|
||||
_accum_0[_len_0] = fn(e)
|
||||
_len_0 = _len_0 + 1
|
||||
end
|
||||
return _accum_0
|
||||
end
|
||||
local first
|
||||
first = function(tab, fn)
|
||||
for _index_0 = 1, #tab do
|
||||
local e = tab[_index_0]
|
||||
if fn(e) then
|
||||
return e
|
||||
end
|
||||
end
|
||||
end
|
||||
local exclude
|
||||
exclude = function(tab, ...)
|
||||
local i = 1
|
||||
while i <= #tab do
|
||||
local removed = false
|
||||
for j = 1, select('#', ...) do
|
||||
if tab[i] == select(j, ...) then
|
||||
remove(tab, i)
|
||||
removed = true
|
||||
break
|
||||
end
|
||||
end
|
||||
if not (removed) then
|
||||
i = i + 1
|
||||
end
|
||||
end
|
||||
return tab
|
||||
end
|
||||
local flatten
|
||||
flatten = function(tab)
|
||||
if (type(tab)) ~= 'table' then
|
||||
return {
|
||||
tab
|
||||
}
|
||||
end
|
||||
local out = { }
|
||||
for _index_0 = 1, #tab do
|
||||
local e = tab[_index_0]
|
||||
if (type(e)) == 'table' then
|
||||
local _list_0 = flatten(e)
|
||||
for _index_1 = 1, #_list_0 do
|
||||
local v = _list_0[_index_1]
|
||||
insert(out, v)
|
||||
end
|
||||
else
|
||||
insert(out, e)
|
||||
end
|
||||
end
|
||||
return out
|
||||
end
|
||||
return {
|
||||
min = min,
|
||||
max = max,
|
||||
foreach = foreach,
|
||||
first = first,
|
||||
exclude = exclude,
|
||||
flatten = flatten,
|
||||
sortedpairs = sortedpairs,
|
||||
insert = insert,
|
||||
remove = remove,
|
||||
concat = concat,
|
||||
sort = sort,
|
||||
unpack = unpack
|
||||
}
|
||||
@@ -1,189 +0,0 @@
|
||||
local wildcard, exists, isdir, mtime
|
||||
do
|
||||
local _obj_0 = require('moonbuild.fsutil')
|
||||
wildcard, exists, isdir, mtime = _obj_0.wildcard, _obj_0.exists, _obj_0.isdir, _obj_0.mtime
|
||||
end
|
||||
local foreach, first, flatten, exclude, sortedpairs, min, max
|
||||
do
|
||||
local _obj_0 = require('moonbuild.tableutil')
|
||||
foreach, first, flatten, exclude, sortedpairs, min, max = _obj_0.foreach, _obj_0.first, _obj_0.flatten, _obj_0.exclude, _obj_0.sortedpairs, _obj_0.min, _obj_0.max
|
||||
end
|
||||
local patsubst, splitsp
|
||||
do
|
||||
local _obj_0 = require('moonbuild.stringutil')
|
||||
patsubst, splitsp = _obj_0.patsubst, _obj_0.splitsp
|
||||
end
|
||||
local insert, concat, sort, pairs
|
||||
do
|
||||
local _obj_0 = require('moonbuild.tableutil')
|
||||
insert, concat, sort, pairs = _obj_0.insert, _obj_0.concat, _obj_0.sort, _obj_0.pairs
|
||||
end
|
||||
local upper, lower
|
||||
do
|
||||
local _obj_0 = require('moonbuild.stringutil')
|
||||
upper, lower = _obj_0.upper, _obj_0.lower
|
||||
end
|
||||
local GLOB_PATT = '^([^%%]*)%%([^%%]*)$'
|
||||
local escapecmdpart
|
||||
escapecmdpart = function(p)
|
||||
if (type(p)) == 'table' then
|
||||
if p.raw then
|
||||
return p.raw
|
||||
end
|
||||
return concat((function()
|
||||
local _accum_0 = { }
|
||||
local _len_0 = 1
|
||||
for _index_0 = 1, #p do
|
||||
local part = p[_index_0]
|
||||
_accum_0[_len_0] = escapecmdpart(part)
|
||||
_len_0 = _len_0 + 1
|
||||
end
|
||||
return _accum_0
|
||||
end)(), ' ')
|
||||
end
|
||||
if p:match('^[a-zA-Z0-9_./-]+$') then
|
||||
return p
|
||||
end
|
||||
return '"' .. p:gsub('\\', '\\\\'):gsub('"', '\\"') .. '"'
|
||||
end
|
||||
local escapecmd
|
||||
escapecmd = function(c, args)
|
||||
if args == nil then
|
||||
args = { }
|
||||
end
|
||||
c = escapecmdpart(c)
|
||||
local _list_0 = flatten(args)
|
||||
for _index_0 = 1, #_list_0 do
|
||||
local a = _list_0[_index_0]
|
||||
if a then
|
||||
c = c .. (' ' .. escapecmdpart(a))
|
||||
end
|
||||
end
|
||||
return c
|
||||
end
|
||||
local run
|
||||
run = function(c, args, params)
|
||||
if params == nil then
|
||||
params = { }
|
||||
end
|
||||
local escaped = escapecmd(c, args)
|
||||
if params.print then
|
||||
print(escaped)
|
||||
end
|
||||
local ret, _, code = os.execute(escaped)
|
||||
if (type(ret)) == 'number' then
|
||||
ret, code = ret == 0, ret
|
||||
end
|
||||
if params.error and not ret then
|
||||
error(tostring(c) .. " failed with code " .. tostring(code))
|
||||
end
|
||||
return ret, code
|
||||
end
|
||||
local popen
|
||||
popen = function(c, args, mode, params)
|
||||
if mode == nil then
|
||||
mode = 'r'
|
||||
end
|
||||
if params == nil then
|
||||
params = { }
|
||||
end
|
||||
local escaped = escapecmd(c, args)
|
||||
if params.print then
|
||||
print(escaped)
|
||||
end
|
||||
return io.popen(escaped, mode)
|
||||
end
|
||||
local calccdeps
|
||||
calccdeps = function(infile, includesys)
|
||||
if includesys == nil then
|
||||
includesys = false
|
||||
end
|
||||
local data = (popen('cc', {
|
||||
includesys and '-M' or '-MM',
|
||||
infile
|
||||
})):read('*a')
|
||||
local rawdeps = data:gsub('\\\n', ''):match(':(.+)')
|
||||
local _accum_0 = { }
|
||||
local _len_0 = 1
|
||||
for dep in rawdeps:gmatch('%S+') do
|
||||
if dep ~= infile then
|
||||
_accum_0[_len_0] = dep
|
||||
_len_0 = _len_0 + 1
|
||||
end
|
||||
end
|
||||
return _accum_0
|
||||
end
|
||||
local findclib
|
||||
findclib = function(name, mode)
|
||||
if mode == nil then
|
||||
mode = 'all'
|
||||
end
|
||||
local args = {
|
||||
name
|
||||
}
|
||||
if mode == 'all' or mode == 'cc' then
|
||||
insert(args, '--cflags')
|
||||
end
|
||||
if mode == 'all' or mode == 'ld' then
|
||||
insert(args, '--libs')
|
||||
end
|
||||
local _accum_0 = { }
|
||||
local _len_0 = 1
|
||||
for arg in (popen('pkg-config', args)):read('*a'):gmatch('%S+') do
|
||||
_accum_0[_len_0] = arg
|
||||
_len_0 = _len_0 + 1
|
||||
end
|
||||
return _accum_0
|
||||
end
|
||||
local match
|
||||
match = function(str, glob)
|
||||
local prefix, suffix = glob:match(GLOB_PATT)
|
||||
if not (prefix) then
|
||||
return str == glob
|
||||
end
|
||||
if (str:sub(1, #prefix)) == prefix and (str:sub(-#suffix)) == suffix then
|
||||
return str:sub(#prefix + 1, -#suffix - 1)
|
||||
end
|
||||
return false
|
||||
end
|
||||
local isglob
|
||||
isglob = function(glob)
|
||||
if glob:match(GLOB_PATT) then
|
||||
return true
|
||||
else
|
||||
return false
|
||||
end
|
||||
end
|
||||
local env
|
||||
env = function(key, def)
|
||||
return (os.getenv(key)) or def
|
||||
end
|
||||
return {
|
||||
min = min,
|
||||
max = max,
|
||||
foreach = foreach,
|
||||
first = first,
|
||||
exclude = exclude,
|
||||
flatten = flatten,
|
||||
sortedpairs = sortedpairs,
|
||||
insert = insert,
|
||||
remove = remove,
|
||||
concat = concat,
|
||||
sort = sort,
|
||||
unpack = unpack,
|
||||
wildcard = wildcard,
|
||||
mtime = mtime,
|
||||
exists = exists,
|
||||
isdir = isdir,
|
||||
run = run,
|
||||
popen = popen,
|
||||
calccdeps = calccdeps,
|
||||
findclib = findclib,
|
||||
patsubst = patsubst,
|
||||
splitsp = splitsp,
|
||||
upper = upper,
|
||||
lower = lower,
|
||||
match = match,
|
||||
isglob = isglob,
|
||||
env = env
|
||||
}
|
||||
Reference in New Issue
Block a user