Skip to content

Commit

Permalink
maint: sync with upstream luke
Browse files Browse the repository at this point in the history
* build-aux/luke: Update.

Signed-off-by: Gary V. Vaughan <gary@gnu.org>
  • Loading branch information
gvvaughan committed Apr 26, 2017
1 parent eaecdd2 commit 763e7e1
Showing 1 changed file with 25 additions and 23 deletions.
48 changes: 25 additions & 23 deletions build-aux/luke
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ abspath=abspath..'.lua'return src,(gsub(abspath,'/[^/]+%.lua$',''))end
local function module_to_path(module,sources,objdir)return dropuntil(sources,function(source)return case(source,{['.*%.[ch]']=bind(c_source,{module,objdir}),['(.*%.[ch])%.in']=bind(c_source,{module,objdir}),['.*%.lua']=bind(lua_source,{module}),['(.*%.lua)%.in']=bind(lua_source,{module}),function(src)fatal("unsupported source type '%s'",src)end,})end)end
return{build_c_module=function(L,env,luke,name)local rules=luke.modules[name]local c_module=c_module_path(luke.variables.objdir,name)local command={'$MAKEDIRS',(gsub(c_module,'/[^/]*$',''))}local status,err,out=spawn(env,unpack(command))if status~=0 then
stdout:write(concat(command,' ')..'\n')stderr:write(err..'\n')exit(status)end
return run(L,env,flatten('$COMPILE',defines(env,except(pack(rules.defines,luke.defines),nil)),incdirs(rules.incdirs,luke.incdirs),rules.sources,'-o',c_module,libdirs(rules.libdirs,luke.libdirs),'$LIBS',rules.libraries,luke.libraries))end,c_modules=function(modules)return filter(keys(modules),function(name)return dropuntil(modules[name].sources,bind(match,{[2]='%.[ch]$'}))end)end,incdirs=incdirs,install_modules=function(L,env,luke,modules)return reduce(keys(modules),0,function(status,name)if status==0 then
return run(L,env,flatten('$COMPILE',defines(env,except(list(rules.defines,luke.defines),nil)),incdirs(rules.incdirs,luke.incdirs),rules.sources,'-o',c_module,libdirs(rules.libdirs,luke.libdirs),'$LIBS',rules.libraries,luke.libraries))end,c_modules=function(modules)return filter(keys(modules),function(name)return dropuntil(modules[name].sources,bind(match,{[2]='%.[ch]$'}))end)end,incdirs=incdirs,install_modules=function(L,env,luke,modules)return reduce(keys(modules),0,function(status,name)if status==0 then
local src,dir=module_to_path(name,modules[name].sources,luke.variables.objdir)if open(interpolate(env,dir))==nil then
status=run(L,env,{'$MAKEDIRS',dir})end
if status==0 then
Expand Down Expand Up @@ -233,7 +233,7 @@ return r
end
local function isenv(t)return getmetatable(t)==env_mt
end
return{CONFIGENV={compile='$CC -c $CFLAGS $CPPFLAGS',libs='',link='$CC $CFLAGS $CPPFLAGS $LDFLAGS',},DEFAULTENV=filter_platforms{LUAVERSION=LUAVERSION,PREFIX='/usr/local',INST_LIBDIR='$PREFIX/lib/lua/$LUAVERSION',INST_LUADIR='$PREFIX/share/lua/$LUAVERSION',LUA_INCDIR='/usr/include/lua$LUAVERSION',LIB_EXTENSION='so',OBJ_EXTENSION='o',INSTALL='cp',MAKEDIRS='mkdir -p',COMPILE='$CC $CFLAGS $LIBFLAGS $PKGFLAGS $CPPFLAGS',CFLAGS='-O2',platforms={macosx={LIBFLAGS='-fPIC -bundle -undefined dynamic_lookup -all_load',},LIBFLAGS='-shared -fPIC',},},SHELLENV=setmetatable({},{__index=function(_,v)return getenv(v)end,}),expand=bind(interpolate_with,{'@([^@]+)@'}),interpolate=bind(interpolate_with,{'%$([%w_]+)'}),makeenv=function(...)local env=reduce(except(pack(...),nil),function(r,t)if isenv(t)then
return{CONFIGENV={compile='$CC -c $CFLAGS $CPPFLAGS',libs='',link='$CC $CFLAGS $CPPFLAGS $LDFLAGS',},DEFAULTENV=filter_platforms{LUAVERSION=LUAVERSION,PREFIX='/usr/local',INST_LIBDIR='$PREFIX/lib/lua/$LUAVERSION',INST_LUADIR='$PREFIX/share/lua/$LUAVERSION',LUA_INCDIR='/usr/include/lua$LUAVERSION',LIB_EXTENSION='so',OBJ_EXTENSION='o',INSTALL='cp',MAKEDIRS='mkdir -p',COMPILE='$CC $CFLAGS $LIBFLAGS $PKGFLAGS $CPPFLAGS',CFLAGS='-O2',platforms={macosx={LIBFLAGS='-fPIC -bundle -undefined dynamic_lookup -all_load',},LIBFLAGS='-shared -fPIC',},},SHELLENV=setmetatable({},{__index=function(_,v)return getenv(v)end,}),expand=bind(interpolate_with,{'@([^@]+)@'}),interpolate=bind(interpolate_with,{'%$([%w_]+)'}),makeenv=function(...)local env=reduce(except(list(...),nil),function(r,t)if isenv(t)then
map(t,bind(append,{r}))else
append(r,t)end
end)return setmetatable(env,env_mt)end,}
Expand Down Expand Up @@ -325,20 +325,22 @@ return r
end,}
end
package.preload['luke.platforms']=function()
local _ENV=require'std.normalize'{'std.functional',CANON={['AIX']={'aix','unix'},['FreeBSD']={'freebsd','bsd','unix'},['OpenBSD']={'openbsd','bsd','unix'},['NetBSD']={'netbsd','bsd','unix'},['Darwin']={'macosx','bsd','unix'},['Linux']={'linux','unix'},['SunOS']={'solaris','unix'},['^CYGWIN']={'cygwin','unix'},['^MSYS']={'msys','cygwin','unix'},['^Windows']={'win32','windows'},['^MINGW']={'mingw32','win32','windows'},['^procnto']={'qnx'},['QNX']={'qnx'},['Haiku']={'haiku','unix'},},}local UNAME=popen('uname -s'):read'*l'local LITERALS,PATTERNS=partition(keys(CANON),function(k)return sub(k,1,1)~='^'end)local function match_uname(x)return match(UNAME,x)and CANON[x]end
local platforms=LITERALS[UNAME]or dropuntil(map(PATTERNS,match_uname))or{'unix'}local allplatforms=reduce(values(CANON),function(acc,platforms)map(platforms,function(v)acc[v]=true
end)end)local function isplatform(x)return allplatforms[x]~=nil
local _ENV=require'std.normalize'{'std.functional',}local CANON={['AIX']=list('aix','unix'),['FreeBSD']=list('freebsd','bsd','unix'),['OpenBSD']=list('openbsd','bsd','unix'),['NetBSD']=list('netbsd','bsd','unix'),['Darwin']=list('macosx','bsd','unix'),['Linux']=list('linux','unix'),['SunOS']=list('solaris','unix'),['^CYGWIN']=list('cygwin','unix'),['^MSYS']=list('msys','cygwin','unix'),['^Windows']=list('win32','windows'),['^MINGW']=list('mingw32','win32','windows'),['^procnto']=list('qnx'),['QNX']=list('qnx'),['Haiku']=list('haiku','unix'),}local ALLPLATFORMS=reduce(values(CANON),function(acc,platforms)map(platforms,function(v)acc[v]=true
end)end)local function match_uname(lookup,uname,x)return match(uname,x)and lookup[x]end
local function toplatforms(lookup,uname)local literalkeys,patternkeys=partition(keys(lookup),function(k)return sub(k,1,1)~='^'end)return(pluck(literalkeys,lookup)or{})[uname]or dropuntil(map(patternkeys,bind(match_uname,{lookup,uname})))or list('unix')end
local function isplatform(x)return ALLPLATFORMS[x]~=nil
end
local function filter_platforms(t)local r={}for k,v in next,t do
local platforms=toplatforms(CANON,popen('uname -s'):read'*l')local function filter_platforms(t,using,predicate)local r,platforms,isplatform={},using or platforms,predicate or isplatform
for k,v in next,t do
if k=='platforms'then
local branches,defaults=partition(keys(v),isplatform)local matches=filter(branches,bind(contains,{platforms}))merge(r,hoist(matches,v)or pluck(defaults,v))elseif istable(v)then
r[k]=filter_platforms(v)else
r[k]=filter_platforms(v,using)else
r[k]=r[k]or v
end
end
return r
end
return{filter_platforms=filter_platforms,platforms=platforms,}
return{filter_platforms=filter_platforms,platforms=platforms,toplatforms=toplatforms,}
end
package.preload['std.functional']=function()
local _ENV=require'std.normalize'{destructure=next,isfile=function(x)return io.type(x)=='file'end,wrap=coroutine.wrap,yield=coroutine.yield,}local function apply(fn,argu)assert(fn~=nil,'cannot apply nil-valued function')if iscallable(fn)then
Expand All @@ -349,7 +351,7 @@ local function call(fn,...)assert(fn~=nil,'cannot call nil-valued function')if i
return fn(...)end
return fn
end
local function wrapnonnil(iterator)return function(...)local r=pack(iterator(...))if r[1]~=nil then
local function wrapnonnil(iterator)return function(...)local r=list(iterator(...))if r[1]~=nil then
return r
end
end
Expand All @@ -358,7 +360,7 @@ local function each(seq)if type(seq)=='function'then
return wrapnonnil(seq)end
local i,n=0,int(seq.n)or len(seq)return function()if i<n then
i=i+1
return pack(seq[i])end
return list(seq[i])end
end
end
local function eq(x)return function(y)return x==y
Expand All @@ -379,7 +381,7 @@ visit(unpack(valu))end
else
yield(x)end
end
local function flatten(...)local r={}for v in wrap(visit),except(pack(...),nil)do
local function flatten(...)local r={}for v in wrap(visit),except(list(...),nil)do
r[#r+1]=v
end
return r
Expand All @@ -390,7 +392,7 @@ return true
end
end
return false
end,apply=apply,bind=function(fn,bound)local n=bound.n or maxn(bound)return function(...)local argu,unbound=copy(bound),pack(...)local i=1
end,apply=apply,bind=function(fn,bound)local n=bound.n or maxn(bound)return function(...)local argu,unbound=copy(bound),list(...)local i=1
for j=1,unbound.n do
while argu[i]~=nil do
i=i+1
Expand All @@ -404,14 +406,14 @@ return call(branches[s],s)end
local DEFAULT=1
for pattern,fn in next,branches do
if pattern~=DEFAULT then
local argu=pack(match(s,'^'..pattern..'$'))if argu[1]~=nil then
local argu=list(match(s,'^'..pattern..'$'))if argu[1]~=nil then
return apply(fn,argu)end
end
end
local default=branches[DEFAULT]if iscallable(default)then
return call(default,s)end
return default
end,cond=function(...)for clauseu in each(pack(...))do
end,cond=function(...)for clauseu in each(list(...))do
local expr,consequence=destructure(unpack(clauseu))if expr then
return call(consequence,expr)end
end
Expand All @@ -427,7 +429,7 @@ predicate,block=isnonnil,predicate
end
if block~=nil then
for valu in each(seq)do
local r=pack(block(unpack(valu)))if predicate(unpack(r))then
local r=list(block(unpack(valu)))if predicate(unpack(r))then
return unpack(r)end
end
else
Expand All @@ -453,17 +455,17 @@ merge(r,dict[unpack(keyu)])end
return next(r)and r or nil
end,id=function(...)return...end,isempty=function(x)return type(x)=='table'and not next(x)end,isfile=isfile,isfunction=function(x)return type(x)=='function'end,isnil=function(x)return x==nil
end,isstring=function(x)return type(x)=='string'end,istable=function(x)return type(x)=='table'end,isnonzero=function(x)return x~=0
end,keys=function(iterable)local r=pack()for k in next,iterable or{}do
end,keys=function(iterable)local r=list()for k in next,iterable or{}do
append(r,k)end
return r
end,map=function(seq,block)local r=pack()for valu in each(seq)do
end,map=function(seq,block)local r=list()for valu in each(seq)do
append(r,block(unpack(valu)))end
return r
end,mapvalues=function(iterable,block)local r={}for k,v in next,iterable or{}do
r[k]=block(v)or v
end
return r
end,nop=function()end,partition=function(seq,block)local r,s=pack(),pack()for valu in each(seq)do
end,nop=function()end,partition=function(seq,block)local r,s=list(),list()for valu in each(seq)do
append(block(unpack(valu))and r or s,unpack(valu))end
return r,s
end,pluck=function(keylist,dict)local r={}for keyu in each(keylist)do
Expand All @@ -476,10 +478,10 @@ for valu in each(seq)do
acc=block(acc,unpack(valu))or acc
end
return acc
end,values=function(iterable)local r=pack()for _,v in next,iterable or{}do
end,values=function(iterable)local r=list()for _,v in next,iterable or{}do
append(r,v)end
return r
end,zip_with=function(iterable,block)local r=pack()for k,v in next,iterable or{}do
end,zip_with=function(iterable,block)local r=list()for k,v in next,iterable or{}do
append(r,block(k,v))end
return r
end,}
Expand Down Expand Up @@ -557,7 +559,7 @@ end
return setmetatable({append=function(seq,v)local n=(int(seq.n)or len(seq))+1
seq.n,seq[n]=n,v
return seq
end,arg=arg,assert=assert,char=string.char,close=io.close,concat=concat,copy=copy,exit=os.exit,float=tonumber,format=string.format,getenv=os.getenv,getmetatable=getmetatable,getmetamethod=getmetamethod,gmatch=string.gmatch,gsub=string.gsub,int=int,iscallable=iscallable,len=len,lines=io.lines,loadstring=loadstring,match=string.match,maxn=function(iterable)local n=0
end,arg=arg,assert=assert,char=string.char,close=io.close,concat=concat,copy=copy,exit=os.exit,float=tonumber,format=string.format,getenv=os.getenv,getmetatable=getmetatable,getmetamethod=getmetamethod,gmatch=string.gmatch,gsub=string.gsub,int=int,iscallable=iscallable,len=len,lines=io.lines,list=pack,loadstring=loadstring,match=string.match,maxn=function(iterable)local n=0
for k,v in next,iterable or{}do
local i=int(k)if i and i>n then
n=i
Expand Down Expand Up @@ -597,7 +599,7 @@ setmetatable(cm,contextmanager_mt)end
return cm
end
local function context_close(cm)return isfile(cm.context)and close(cm.context)end
local function with(...)local argu=pack(...)local block=pop(argu)local r=pack(apply(block,argu))map(argu,function(cm)cm:release()end)return unpack(r)end
local function with(...)local argu=list(...)local block=pop(argu)local r=list(apply(block,argu))map(argu,function(cm)cm:release()end)return unpack(r)end
return{CTest=function()local conftest=tmpname()return ContextManager(function(cm)rm(conftest)rm(gsub(conftest,'^.*/','')..'.o')if context_close(cm)then
return rm(cm.filename)end
return false
Expand All @@ -607,7 +609,7 @@ return false
end,open,fname or tmpname(),mode or'w')end,slurp=function(cm)return with(cm,function(h)return h:read'*a'end)end,with=with,}
end
package.preload['type.dict']=function()
local _ENV=require'std.normalize'{destructure=next,}return{OrderedDict=function(...)local r,argu={},pack(...)for i=1,argu.n do
local _ENV=require'std.normalize'{destructure=next,}return{OrderedDict=function(...)local r,argu={},list(...)for i=1,argu.n do
local k,v=destructure(argu[i])append(r,k)r[k]=v
end
return r
Expand Down

0 comments on commit 763e7e1

Please sign in to comment.