forked from pool/lua-macros
121 lines
3.7 KiB
Lua
121 lines
3.7 KiB
Lua
# RPM macros for Lua
|
|
|
|
# The major.minor version of Lua
|
|
%lua_version %{lua:
|
|
local f = io.popen("lua -e 'print(_VERSION)'")
|
|
local output = f:read("*a")
|
|
f:close()
|
|
local ver = output:match("Lua (%d%.%d)")
|
|
print(ver:gsub("^%s*(.-)%s*$", "%1"))
|
|
}
|
|
%lua_version_nodots %{lua:
|
|
local ver = rpm.expand("%{lua_version}")
|
|
local nodots = ver:gsub("%.", "")
|
|
print(nodots:gsub("^%s*(.-)%s*$", "%1"))
|
|
}
|
|
# compiled modules should go here
|
|
%lua_archdir %{lua:
|
|
local handle = io.popen("pkgconf --variable=INSTALL_CMOD lua 2>/dev/null")
|
|
local result = handle:read("*a")
|
|
handle:close()
|
|
result = result:gsub("^%s*(.-)%s*$", "%1")
|
|
print(result)
|
|
}
|
|
# pure Lua modules should go here
|
|
%lua_noarchdir %{lua:
|
|
local output = ""
|
|
local f = io.popen("pkgconf --variable=INSTALL_LMOD lua 2>/dev/null")
|
|
if f ~= nil then
|
|
output = f:read("*a"):gsub("^%s*(.-)%s*$", "%1")
|
|
f:close()
|
|
end
|
|
if output:len() > 0 then
|
|
print(output)
|
|
return
|
|
end
|
|
print(rpm.expand("%{_datadir}/lua/%{lua_version}"))
|
|
}
|
|
# lua includes folder
|
|
%lua_incdir %{lua:
|
|
local handle = io.popen("pkgconf --variable=includedir lua 2>/dev/null")
|
|
local result = handle:read("*a")
|
|
handle:close()
|
|
result = result:gsub("^%s*(.-)%s*$", "%1")
|
|
print(result)
|
|
}
|
|
%lua_version_default %{lua:
|
|
local result = 5.4
|
|
local ver = rpm.expand("%{?suse_version}")
|
|
if #ver > 0 then
|
|
ver = tonumber(ver)
|
|
if ver < 1500 then
|
|
result = 5.1
|
|
elseif ver < 1600 then
|
|
result = 5.3
|
|
end
|
|
end
|
|
print(result)
|
|
}
|
|
# Define a conditional that evaluates true when building for the default Lua version
|
|
%lua_version_default_nodots %{lua:
|
|
local ver = rpm.expand("%{lua_version_default}")
|
|
local nodots = ver:gsub("%.", "")
|
|
print(nodots)
|
|
}
|
|
# Lua default version
|
|
# This REQUIRES macro %{mod_name} to be defined.
|
|
# Optionally you can define macro `lua_provides_type`, which can
|
|
# have two different values:
|
|
# 'exclude-prefix' which excludes lua prefix, or
|
|
# anything else which is used as the provided symbol
|
|
%lua_provides %{lua:
|
|
local mod_name = rpm.expand("%{?mod_name}")
|
|
if mod_name == "" then
|
|
print("-- Error: %{mod_name} is not defined!")
|
|
return
|
|
end
|
|
|
|
local current_ver = rpm.expand("%{lua_version_nodots}"):gsub("^%s*(.-)%s*$", "%1")
|
|
local default_ver = rpm.expand("%{lua_version_default_nodots}"):gsub("^%s*(.-)%s*$", "%1")
|
|
|
|
local output = ""
|
|
|
|
-- Check if we are building for the default Lua version
|
|
if current_ver == default_ver then
|
|
|
|
local package_type = rpm.expand("%{?lua_provides_type}"):gsub("^%s*(.-)%s*$", "%1")
|
|
local package_name = mod_name
|
|
|
|
-- Check for type defined externally (e.g., via --define 'lua_provides_type package-name')
|
|
if package_type == "exclude-prefix" then
|
|
-- Use name without "lua-" prefix
|
|
package_name = mod_name
|
|
elseif package_type ~= "" then
|
|
-- Use custom name defined by package_type
|
|
package_name = package_type
|
|
else
|
|
-- Default: Use 'lua-' prefix
|
|
package_name = "lua-" .. mod_name
|
|
end
|
|
|
|
local version = rpm.expand("%{version}")
|
|
local release = rpm.expand("%{release}")
|
|
|
|
output = "Provides: " .. package_name .. " = " .. version .. "-" .. release .. " Obsoletes: " .. package_name .. " < " .. version .. "-" .. release
|
|
end
|
|
|
|
print(output)
|
|
}
|
|
|
|
# LuaRocks
|
|
%luarocks_build \
|
|
luarocks --lua-version "%{lua_version}" make --deps-mode none --pack-binary-rock
|
|
|
|
%luarocks_treedir %{_prefix}/lib/luarocks/rocks-%{lua_version}
|
|
|
|
%luarocks_install \
|
|
/bin/sh -c 'luarocks --lua-version="%{lua_version}" --tree="%{buildroot}%{_prefix}" install --deps-mode=none --no-manifest "$@" && \
|
|
source_dir="%{buildroot}%{luarocks_treedir}/%{mod_name}/%{rock_version}" && \
|
|
[ -d "${source_dir}" ] && [ "$(ls -A "${source_dir}" | wc -l)" -gt 0 ] && \
|
|
mv -v "${source_dir}" __rocktree' --
|