File maint-sync-luke-with-upstream.patch of Package lua-luaposix

From: Gary V. Vaughan <gary@gnu.org>
Date: Sun May 14 21:10:22 2017 -0700
Subject: maint: sync luke with upstream
Patch-mainline: Upstream
Git-repo: https://github.com/luaposix/luaposix
Git-commit: b13a9e68103ca2c868f63cdb00c7c18bdd9c11c7
References: 

Closes #278.
* build-aux/luke: fixes for greedy option '=', and concat nil value
error, among others.

Signed-off-by: Gary V. Vaughan <gary@gnu.org>
Signed-off-by: Egbert Eich <eich@suse.de>
---
 build-aux/luke | 47 ++++++++++++++++++++---------------------------
 1 file changed, 20 insertions(+), 27 deletions(-)
diff --git a/build-aux/luke b/build-aux/luke
index fc9f258..4c7a702 100755
--- a/build-aux/luke
+++ b/build-aux/luke
@@ -44,12 +44,12 @@ stderr:write('luke: error: '..msg..'\n')stderr:write("luke: try '"..arg[0].." --
 local function display(...)return stdout:write(concat{...})end
 local function dump(...)return stderr:write('   DEBUG: "'..concat(map(list(...),str))..'"\n')end
 local function interpolate_to_substitute(s)return(gsub(s,'%$([%w_]+)','@%1@'))end
-return{parse_arguments=function(args)local clidefs,fname,targets,install={},'lukefile',{},{}local verbose,write,debug=nop,display,nop
-map(args,function(opt)case(opt,{['--debug']=function()debug=dump
+return{parse_arguments=function(args)local clidefs,fname,targets,install={},'lukefile',{},{}local verbose,write,log=nop,display,nop
+map(args,function(opt)case(opt,{['--debug']=function()log=dump
 end,['--file=(.+)']=function(optarg)fname=optarg
 end,['--quiet']=function()write=nop
 end,['--verbose']=function()verbose=display
-end,['--help']=help,['--version']=version,['(.+)=(.+)']=function(name,value)clidefs[name]=value
+end,['--help']=help,['--version']=version,['([^=]+)=(.+)']=function(name,value)clidefs[name]=value
 end,function(opt)if match(opt,'^-')~=nil then
 opterr(format("unrecognized option '%s'",opt))end
 append(targets,opt)end,})end)local luke,err=loadluke(fname)if luke==nil then
@@ -69,7 +69,7 @@ luke.modules=build
 if isempty(luke.modules)then
 luke.external_dependencies=nil
 end
-luke.substitute=merge(luke.substitute or{},{package=interpolate_to_substitute(luke.package),version=interpolate_to_substitute(luke.version),})luke.variables=merge(luke.variables or{},collect_variables(luke),{LUA_DIR='/usr',LUA_BINDIR='$LUA_DIR/bin',LUA_INCDIR='$LUA_DIR/include/lua$LUAVERSION',LUA_LIBDIR='$LUA_DIR/lib',objdir=platforms[1],package=luke.package,version=luke.version,})return{clidefs=clidefs,install=install,debug=debug,luke=luke,verbose=verbose,write=write,}end,}
+luke.substitute=merge(luke.substitute or{},{package=interpolate_to_substitute(luke.package),version=interpolate_to_substitute(luke.version),})luke.variables=merge(luke.variables or{},collect_variables(luke),{LUA_DIR='/usr',LUA_BINDIR='$LUA_DIR/bin',LUA_INCDIR='$LUA_DIR/include/lua$LUAVERSION',LUA_LIBDIR='$LUA_DIR/lib',objdir=platforms[1],package=luke.package,version=luke.version,})return{clidefs=clidefs,install=install,log=log,luke=luke,verbose=verbose,write=write,}end,}
 end
 package.preload['luke.compile']=function()
 local _ENV=require'std.normalize'{'luke._base','luke.environment','std.functional','type.context-manager',SHELLMETACHARS='[%s%$"]',}local function spawn(env,...)local command=interpolate(env,concat({...},' '))return with(TmpFile(),TmpFile(),function(out,err)local pipe=concat{command,' >',out.filename,' 2>',err.filename,'; printf $?'}return int(slurp(Pipe(pipe))),slurp(File(err.filename)),slurp(File(out.filename))end)end
@@ -102,7 +102,11 @@ return status
 end)end,libdirs=libdirs,run_command=run,spawn=spawn,}
 end
 package.preload['luke.configure']=function()
-local _ENV=require'std.normalize'{'luke._base','luke.compile','luke.environment','std.functional','type.context-manager','type.dict',CCPROGS={'cc','gcc','clang'},}local function checking(L,...)L.verbose('checking ',concat({...},' '),'... ')end
+local _ENV=require'std.normalize'{'luke._base','luke.compile','luke.environment','std.functional','type.context-manager','type.dict',CCPROGS={'cc','gcc','clang'},}local function logspawn(L,env,...)local status,err=spawn(env,...)if status~=0 and err~=''then
+L.log(err)end
+return status
+end
+local function checking(L,...)L.verbose('checking ',concat({...},' '),'... ')end
 local function found_library(L,x)if x==nil or x==''then
 L.verbose'none required'else
 L.verbose(x)end
@@ -110,19 +114,16 @@ L.verbose'\n'return x
 end
 local function found_prog(L,x)L.verbose(x and'yes\n'or'no\n')return x
 end
-local function found_result(L,x)L.verbose(x==1 and'yes\n'or'no\n')return x
+local function found_result(L,x)L.verbose(x==0 and'yes\n'or'no\n')return x~=0 and 0 or 1
 end
 local function bindirs(...)return map(flatten(...),function(v)return v..':'end)end
-local function compile_command(L,env,config,filename)local command=flatten('$CC','-c','$CFLAGS',incdirs(config.incdir),'$CPPFLAGS',filename)L.debug(interpolate(env,concat(command,' ')))return unpack(command)end
-local function link_command(L,env,config,a_out,source,lib)local command=flatten('$CC','$CFLAGS',incdirs(config.incdir),'$CPPFLAGS','-o',a_out,source,libdirs(config.libdir),'$LDFLAGS','$libs',CONFIGENV.libs,lib)L.debug(interpolate(env,concat(command,' ')))return unpack(command)end
+local function compile_command(L,env,config,filename)local command=flatten('$CC','-c','$CFLAGS',incdirs(config.incdir),'$CPPFLAGS',filename)L.log(interpolate(env,concat(command,' ')))return unpack(command)end
+local function link_command(L,env,config,a_out,source,lib)local command=flatten('$CC','$CFLAGS',incdirs(config.incdir),'$CPPFLAGS','-o',a_out,source,libdirs(config.libdir),'$LDFLAGS','$libs',CONFIGENV.libs,lib)L.log(interpolate(env,concat(command,' ')))return unpack(command)end
 local function check_executable_in_path(L,env,config,prog)local PATH=concat(bindirs(config.bindir))..getenv('PATH')local found=dropuntil(gmatch(PATH,'[^:]+'),function(path)local progpath=path..'/'..prog
 return with(File(progpath,'r'),function(h)return isfile(h.context)and progpath or nil
-end)end)L.debug('found '..found)return found~=nil
+end)end)L.log(found and'found '..found or prog..' not found')return found~=nil
 end
-local function check_header_compile(L,env,config,header,extra_hdrs)return with(CTest(),function(conftest)conftest:write(format('%s\n#include "%s"\n',extra_hdrs,header))local status,err=spawn(env,compile_command(L,env,config,conftest.filename))if status~=0 and err~=''then
-L.debug(err)end
-return 0==status and 1 or 0
-end)end
+local function check_header_compile(L,env,config,header,extra_hdrs)return with(CTest(),function(conftest)conftest:write(format('%s\n#include "%s"\n',extra_hdrs,header))return logspawn(L,env,compile_command(L,env,config,conftest.filename))end)end
 local function try_link(L,env,config,lib,symbol)return with(CTest(),TmpFile(),function(conftest,a_out)conftest:write(format([[
 /* Override any GCC internal prototype to avoid an error.
  Use char because int might match the return type of a GCC
@@ -131,10 +132,7 @@ char %s ();
 int main () {
 return %s ();
 }
-]],symbol,symbol))local status,err=spawn(env,link_command(L,env,config,a_out.filename,conftest.filename,lib))if status~=0 and err~=''then
-L.debug(err)end
-return status
-end)end
+]],symbol,symbol))return logspawn(L,env,link_command(L,env,config,a_out.filename,conftest.filename,lib))end)end
 local function check_func_decl(L,env,config,fname,extra_hdrs)return with(CTest(),function(conftest)conftest:write(format([[
 %s
 int
@@ -145,10 +143,7 @@ main()
 #endif
 return 0;
 }
-]],extra_hdrs,fname,fname))local status,err=spawn(env,compile_command(L,env,config,conftest.filename))if status~=0 and err~=''then
-L.debug(err)end
-return 0==status and 1 or 0
-end)end
+]],extra_hdrs,fname,fname))return logspawn(L,env,compile_command(L,env,config,conftest.filename))end)end
 local function check_func_link(L,env,config,fname)return with(CTest(),TmpFile(),function(conftest,a_out)conftest:write(format([[
 /* Define to an innocous variant, in case <limits.h> declares it.
  For example, HP-UX 11i <limits,h> declares gettimeofday.   */
@@ -182,10 +177,7 @@ choke me
 int main () {
 return %s ();
 }
-]],fname,fname,fname,fname,fname,fname,fname))local status,err=spawn(env,link_command(L,env,config,a_out.filename,conftest.filename))if status~=0 and err~=''then
-L.debug(err)end
-return 0==status and 1 or 0
-end)end
+]],fname,fname,fname,fname,fname,fname,fname))return logspawn(L,env,link_command(L,env,config,a_out.filename,conftest.filename))end)end
 local function add_external_deps(env,config,prefix)if prefix~=nil then
 for k,v in next,{bindir='$%s_BINDIR',incdir='$%s_INCDIR',libdir='$%s_LIBDIR'}do
 local envvar=interpolate(env,format(v,prefix))if envvar~=''then
@@ -194,10 +186,11 @@ end
 end
 end
 end
+local function format_includes(includes)return map(includes or{},function(include)return format('#include "%s"',include)end)end
 local configure=setmetatable(OrderedDict({checkprog=function(L,env,config)return dropuntil(config.progs,function(prog)checking(L,'for',prog)if found_prog(L,check_executable_in_path(L,env,config,prog))then
 return prog
 end
-end)or fatal('cannot find '..config.checkprog)end},{checkheader=function(L,env,config)checking(L,'for',config.checkheader)local extra_hdrs=map(config.includes or{},function(include)return format('#include "%s"',include)end)return found_result(L,check_header_compile(L,env,config,config.checkheader,concat(extra_hdrs,'\n')))end},{checkdecl=function(L,env,config)checking(L,'whether',config.checkdecl,'is declared')local extra_hdrs=map(config.includes or{},function(include)return format('#include "%s"',include)end)return found_result(L,check_func_decl(L,env,config,config.checkdecl,concat(extra_hdrs,'\n')))end},{checksymbol=function(L,env,config)checking(L,'for library containing',config.checksymbol)local libraries,symbol=config.libraries,config.checksymbol
+end)or fatal('cannot find '..config.checkprog)end},{checkheader=function(L,env,config)checking(L,'for',config.checkheader)local extra_hdrs=concat(format_includes(config.includes),'\n')return found_result(L,check_header_compile(L,env,config,config.checkheader,extra_hdrs))end},{checkdecl=function(L,env,config)checking(L,'whether',config.checkdecl,'is declared')local extra_hdrs=concat(format_includes(config.includes),'\n')return found_result(L,check_func_decl(L,env,config,config.checkdecl,extra_hdrs))end},{checksymbol=function(L,env,config)checking(L,'for library containing',config.checksymbol)local libraries,symbol=config.libraries,config.checksymbol
 local trylibs=reduce(libraries,{''},function(r,lib)append(r,'-l'..lib)end)local lib=dropuntil(trylibs,function(lib)if try_link(L,env,config,lib,symbol)==0 then
 if lib~=''then
 if CONFIGENV.libs~=''then
@@ -208,7 +201,7 @@ end
 return found_library(L,lib)end
 end)or call(function()L.verbose'\n'fatal("required symbol '%s' not found in any of libc, lib%s",symbol,concat(libraries,', lib'))end)return{library=gsub(lib,'^-l','')}end},{checkfunc=function(L,env,config)checking(L,'for',config.checkfunc)return found_result(L,check_func_link(L,env,config,config.checkfunc))end}),{__call=function(self,L,env,config,prefix)return case(type(config),{['number']=function()return str(config)end,['string']=function()return config
 end,['table']=function()return dropuntil(self,function(fname)if config[fname]~=nil then
-add_external_deps(env,config,prefix)return apply(self[fname],{L,env,config})end
+add_external_deps(env,config,prefix)return apply(self[fname],list(L,env,config))end
 end)or fatal("unable to configure with keys '%s'",concat(keys(config),"', '"))end,function(type)fatal("unsupported configure type '%s'",type)end,})end,})return{config_compiler=function(L,env)local CC=env.CC
 if CC==nil then
 CC=configure(L,env,{checkprog='C compiler',progs=CCPROGS})env=makeenv(env,{CC=CC})end