summaryrefslogtreecommitdiffstats
path: root/aports/abuild.lua
blob: 01d94f8d5fa3816220da866a490c5b0c7d09a62c (plain) (blame)
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
52
53
54
55
56
57
58
59
60

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)
	-- check cache
	if abuild_conf[var] 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

	-- execute functions.sh
	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