summaryrefslogtreecommitdiffstats
path: root/aports/abuild.lua
blob: 805bdb982ec3a5ef935856ccaa3287725f66f159 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51

local M = {}
local abuild_conf = {}
M.conf_file = "/etc/abuild.conf"
M.functions = "/usr/share/abuild/functions.sh"

function M.get_conf(var)
	-- check cache
	if abuild_conf[var] ~= nil then
		return abuild_conf[var]
	end

	-- use os env var
	abuild_conf[var] = os.getenv(var)
	if abuild_conf[var] ~= nil then
		return abuild_conf[var]
	end

	-- parse config file
	local f = io.popen(" . "..M.conf_file..' ; echo -n "$'..var..'"')
	abuild_conf[var] = f:read("*all")
	f:close()
	return abuild_conf[var]
end

local function get_cached_var(var)
	if abuild_conf[var] then
		return abuild_conf[var]
	end
	local f = io.popen((' . %s ; echo -n "$%s"'):format(M.functions, var))
	abuild_conf[var] = f:read("*all")
	f:close()
	return abuild_conf[var]
end

function M.get_arch()
	return get_cached_var("CARCH")
end

function M.get_libc()
	return get_cached_var("CLIBC")
end

M.arch = M.get_arch()
M.libc = M.get_libc()
M.repodest = M.get_conf("REPODEST")
M.pkgdest = M.get_conf("PKGDEST")
M.chost = M.get_conf("CHOST")


return M