Skip to content

Instantly share code, notes, and snippets.

@nsf
Created October 11, 2013 12:40
Show Gist options
  • Save nsf/6933957 to your computer and use it in GitHub Desktop.
Save nsf/6933957 to your computer and use it in GitHub Desktop.
3rd party libs bootstrap script
#!/usr/bin/env lua
local function sh(fmt, ...)
local cmd = string.format(fmt, ...)
return os.execute(cmd)
end
local function sh_or_err(fmt, ...)
local cmd = string.format(fmt, ...)
if not os.execute(cmd) then
errorf("command failed: %s", cmd)
end
end
local function errorf(fmt, ...)
error(string.format(fmt, ...), 2)
end
local function printf(fmt, ...)
print(string.format(fmt, ...))
end
local function remove_project(proj)
sh_or_err("rm -rf %s", proj.name)
end
local function packkeys(...)
local t = table.pack(...)
if #t == 0 then
return nil
end
local out = {}
for _, v in ipairs(t) do
out[v] = true
end
return out
end
local function unpack_project(proj)
local sc = proj.strip_components or 1
sh_or_err("mkdir -p %s", proj.name)
sh_or_err("tar -xf %s -C %s --strip-components %s", proj.file, proj.name, sc)
end
local function install_project(proj, destdir)
if not proj.install then
printf("install instructions for %s weren't found, skipping...", proj.name)
return
end
local cmd = proj.install:gsub("$destdir", destdir)
if not os.execute(cmd) then
errorf("failed installing: %s", proj.name)
end
end
dofile("config.lua")
local destdir = config.destdir
if not destdir:match("^/") then
destdir = os.getenv("PWD") .. "/" .. destdir
end
local action = arg[1] or "all"
if action == "all" then
for _, proj in ipairs(config) do
if sh("[ -d %s ]", proj.name) then
printf("%s dir found, assuming it was already installed", proj.name)
goto continue
end
printf("%s not found, installing...", proj.name)
unpack_project(proj)
install_project(proj, destdir)
::continue::
end
elseif action == "reinstall" then
local targets = packkeys(select(2, ...))
if not targets then
error("please specify project(s) to reinstall")
end
local projs = {}
if targets.all then
projs = config
else
for _, p in ipairs(config) do
if targets[p.name] then
projs[#projs+1] = p
end
end
end
if #projs == 0 then
errorf("none of the targets were found in config.lua")
end
for _, proj in ipairs(projs) do
printf("reinstalling %s...", proj.name)
remove_project(proj)
unpack_project(proj)
install_project(proj, destdir)
end
end
config = {
{
name = "cosmo",
file = "packages/cosmo-74fc80b.tar.gz",
install = [=====[
cd cosmo
mkdir -p $destdir/share/lua/5.2/cosmo
cp src/cosmo.lua $destdir/share/lua/5.2/
cp src/cosmo/grammar.lua $destdir/share/lua/5.2/cosmo
cp src/cosmo/fill.lua $destdir/share/lua/5.2/cosmo
]=====],
},
{
name = "lpeg",
file = "packages/lpeg-0.12p.tar.gz",
install = [=====[
cd lpeg
make linux
install -Dm755 lpeg.so $destdir/lib/lua/5.2/lpeg.so
]=====],
},
{
name = "sdl2",
file = "packages/SDL2-2.0.0.tar.gz",
install = [=====[
cd sdl2
mkdir build && cd build
cmake -DRPATH=OFF -DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX="" -DSDL_SHARED=OFF ..
make -j4
DESTDIR="$destdir" make install
]=====],
},
{
name = "lua",
file = "packages/lua-5.2.2.tar.gz",
install = [=====[
cd lua
make linux
make install INSTALL_TOP="$destdir"
]=====],
},
destdir = "local",
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment