Created
September 25, 2013 16:57
-
-
Save hishamhm/6702614 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env lua | |
local arg = { ... } | |
local function read_file(filename) | |
local result = {} | |
local chunk, err | |
if setfenv then -- Lua 5.1 | |
chunk, err = loadfile(filename) | |
if chunk then | |
setfenv(chunk, result) | |
ran, err = pcall(chunk) | |
end | |
else -- Lua 5.2 | |
chunk, err = loadfile(filename, "t", result) | |
if chunk then | |
ran, err = pcall(chunk) | |
end | |
end | |
return result | |
end | |
local rs = read_file(arg[1]) | |
local vars = { | |
PREFIX = "where you want to install "..rs.package, | |
LIBDIR = "where you want to install "..rs.package.."'s C modules", | |
LUADIR = "where you want to install "..rs.package.."'s Lua modules", | |
LUA = "your Lua interpreter", | |
LUA_INCDIR = "where your Lua headers live", | |
LUA_LIBDIR = "where your Lua libraries live", | |
} | |
local function explain_variables(cmd) | |
print("where") | |
for var, expl in pairs(vars) do | |
if cmd:match("%$%("..var.."%)") then | |
print(" * $("..var..") is "..expl) | |
end | |
end | |
end | |
print("Announcing "..rs.package.." version "..rs.version:gsub("-[0-9]+$","").." - "..rs.description.summary) | |
print() | |
print(rs.description.detailed) | |
print() | |
if rs.dependencies and next(rs.dependencies) then | |
print(rs.package.." depends on the following Lua packages:") | |
for _, dep in ipairs(rs.dependencies) do | |
print("* "..dep) | |
end | |
print() | |
end | |
if rs.description.homepage then | |
print("More information at the website: ") | |
print(rs.description.homepage) | |
print() | |
end | |
print("The license of "..rs.package.." is "..rs.description.license..".") | |
print() | |
if rs.source.url:match("^http") then | |
print("You can download the sources at the following URL:") | |
print(rs.source.url) | |
if rs.source.md5 then | |
print("MD5: "..rs.source.md5) | |
end | |
print() | |
end | |
print(rs.package.." can be installed using LuaRocks:") | |
print() | |
print(" luarocks install "..rs.package:lower()) | |
print() | |
if rs.build.type == "command" then | |
print("Alternatively, you can build and install it using the following commands:") | |
print() | |
print("To build:") | |
print(" "..rs.build.build_command) | |
explain_variables(rs.build.build_command) | |
print() | |
print("To install:") | |
print(" "..rs.build.install_command) | |
explain_variables(rs.build.install_command) | |
print() | |
elseif rs.build.type == "make" then | |
print("Alternatively, you can build and install it using make:") | |
print() | |
print("To build:") | |
print(" make "..table.concat(rs.build.build_variables or {}, " ")) | |
print() | |
print("To install:") | |
print(" make "..(rs.build.install_target or "install")..table.concat(rs.build.install_variables or {}, " ")) | |
print() | |
elseif rs.build.type == "builtin" then | |
print("Alternatively, you can install by hand the following modules") | |
print("to their proper places:") | |
print() | |
for mod, data in pairs(rs.build.modules) do | |
if type(data) == "string" then | |
print("* install "..data.." as the module `"..mod.."`") | |
elseif type(data) == "table" then | |
if type(data.sources) == "string" then | |
print("* install "..data.sources.." as the module `"..mod.."`") | |
elseif type(data.sources) == "table" then | |
print("* compile "..table.concat(data.sources, ", ").." to the module `"..mod.."`") | |
end | |
end | |
end | |
elseif rs.build.type == "none" then | |
print("Alternatively, you can install by hand the following files") | |
print("to their proper places:") | |
print() | |
if rs.build.install.lua then | |
for name, file in pairs(rs.build.install.lua) do | |
print("* install "..file.." as the module `"..name.."`") | |
end | |
end | |
if rs.build.install.bin then | |
for name, file in pairs(rs.build.install.bin) do | |
print("* install "..file.." as the script `"..name.."`") | |
end | |
end | |
print() | |
end | |
if rs.build.copy_directories and next(rs.build.copy_directories) then | |
print("Also, copy the following directories from the source package") | |
print("to the appropriate places in your system:") | |
for _, dir in ipairs(rs.build.copy_directories) do | |
print(" "..dir) | |
end | |
end | |
print() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment