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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
...
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
|
local u = dofile('common.lua')
local default = function(var,def)
local v = os.getenv(var)
if v then return v else return def end
end
local posixes = {
linux = true; osx = true;
android = true; haiku = true;
}
local conf = {
pkg = {};
os = default('parsav_target_os', 'linux');
dist = default('parsav_dist', os.getenv('NIX_PATH') and 'nixos');
tgttrip = default('parsav_arch_triple'); -- target triple, used in xcomp
tgtcpu = default('parsav_arch_cpu'); -- target cpu, used in xcomp
tgthf = u.tobool(default('parsav_arch_armhf',true));
}
conf.posix = posixes[conf.os]
conf.exe = u.tobool(default('parsav_link',not conf.tgttrip)); -- turn off for partial builds
local fallback = dofile('pkgdata.lua')
local libfind do local mkf = function(p)
return function(l) return string.format(p,l) end
end
local unx = function(p)
return function(l)
if string.sub(l,1,3) == 'lib'
................................................................................
then return string.format('%s.%s',l,p)
else return string.format('lib%s.%s',l,p)
end
end
end
libfind = {
linux = {
static = unx 'a';
dynamic = unx 'so';
};
osx = { dynamic = mkf '%s.dylib'; };
win = { dynamic = mkf '%s.dll'; };
}
end
local pkg = function(name)
local fbo = fallback[name] and fallback[name].osvars
and fallback[name].osvars[conf.os .. '_' .. conf.dist]
local fbv = fallback[name] and fallback[name].vars
local pkgenv = function(e)
return os.getenv(string.format('parsav_pkg_%s_%s',name,e))
end
name = pkgenv('override') or name
local nul = function() end
local pkc, pkv = nul, nul
local cnfvar = function(v,e)
local eval = function(e)
if type(e) == 'function'
then return e(conf)
else return e
end
end
return pkgenv(v) or pkv(e or v) or (fbo and eval(fbo[v])) or (fbv and eval(fbv[v]))
end
if conf.posix then
pkc = function(...) return u.exec { 'pkg-config'; name; ... } end
local pkcv = function(...) return u.exec({ 'pkg-config'; name; ... }, true) end
if pkcv('--exists') == 0 then
pkv = function(v)
return pkc('--variable', v)
end
else pkc = nul end
else
print '(warn) configuring on non-POSIX OS, all relevant paths must be specified manually in environment variables or build will fail!'
end
local locdep = u.ping('./lib/' .. name)
local prefix
if locdep then
prefix = './lib/' .. name
end
prefix = prefix or cnfvar('prefix')
local libdir = cnfvar('libdir')
if not libdir then
if locdep
then libdir = prefix .. (cnfvar('builddir') or cnfvar('libbuilddir')) or ''
else libdir = prefix .. '/lib'
end
end
local incdir = cnfvar('incdir','includedir') or (prefix .. '/include')
local libstr = pkc '--libs-only-l' -- (--static is not reliable)
local libs = fallback[name] and fallback[name].libs or {}
local linkstatic = locdep
if (not locdep) and libstr then
libs = {}
for m in string.gmatch(libstr, '-l(%g+)') do
libs[#libs + 1] = m
end
else
................................................................................
local ldf = {}
for _,v in pairs(me.statlibs) do
local fl = libdir .. '/' .. v
if u.ping(fl) then ldf[#ldf+1] = fl end
end
me.linkargs = ldf
else
local arg = name
if string.sub(arg,1,3) == 'lib' then arg = string.sub(arg,4) end
local linkline = libstr or string.format('-l%s', arg)
me.linkargs = {
string.format('-L%s', me.libdir);
}
for m in string.gmatch(linkline, '(%g+)') do
me.linkargs[#me.linkargs+1] = m
end
-- siiiiigh
for _,l in pairs(libs) do
local sw = string.format('-l%s', l)
local found = false
for _,a in pairs(me.linkargs) do
if a == sw then found = true break end
end
if not found then
me.linkargs[#me.linkargs+1] = sw
end
end
end
end
pkg('mbedtls')
pkg('libhttp')
pkg('json-c')
return conf
|
>
>
>
>
>
>
>
|
|
>
>
>
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
<
<
|
<
|
|
|
|
>
>
>
<
>
>
>
>
|
>
>
>
>
|
|
|
>
|
|
|
>
>
|
|
<
<
|
<
|
<
>
|
>
|
|
|
>
|
>
|
|
>
>
|
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
..
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
...
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
|
local u = dofile('common.lua')
local default = function(var,def)
local v = os.getenv(var)
if v then return v else return def end
end
local function coalesce(x,...)
if x ~= nil then return x else
if select('#',...) == 0 then return nil end
return coalesce(...)
end
end
local posixes = {
linux = true; osx = true;
android = true; haiku = true;
}
local default_os = 'linux'
local conf = {
pkg = {};
dist = default('parsav_dist', coalesce(
os.getenv('NIX_PATH') and 'nixos',
os.getenv('NIX_STORE') and 'nixos',
''));
tgttrip = default('parsav_arch_triple'); -- target triple, used in xcomp
tgtcpu = default('parsav_arch_cpu'); -- target cpu, used in xcomp
tgthf = u.tobool(default('parsav_arch_armhf',true));
build = {
id = u.rndstr(6);
release = u.ingest('release');
when = os.date();
};
feat = {};
}
if u.ping '.fslckout' or u.ping '_FOSSIL_' then
if u.ping '_FOSSIL_' then default_os = 'windows' end
conf.build.branch = u.exec { 'fossil', 'branch', 'current' }
conf.build.checkout = (u.exec { 'fossil', 'sql',
[[select value from localdb.vvar where name = 'checkout-hash']]
}):gsub("^'(.*)'$", '%1')
end
conf.os = default('parsav_host_os', default_os);
conf.tgtos = default('parsav_target_os', default_os);
conf.posix = posixes[conf.os]
conf.exe = u.tobool(default('parsav_link',not conf.tgttrip)); -- turn off for partial builds
conf.build.origin = coalesce(
os.getenv('parsav_builder'),
string.format('%s@%s', coalesce (
os.getenv('USER'),
u.exec{'whoami'}
), u.exec{'hostname'}) -- whoami and hostname are present on both windows & unix
)
if conf.build.release then
local v = conf.build.release
conf.build.str = string.format('release %s', conf.build.release)
else
conf.build.str = string.format('build %s-%s', conf.build.id, conf.build.origin)
if conf.build.branch then
conf.build.str = conf.build.str .. string.format(':%s(%s)',
conf.build.branch, string.sub(conf.build.checkout,1,10))
end
end
if conf.tgtos == 'linux' then
conf.feat.randomizer = default('parsav_feat_randomizer', 'kern')
else
conf.feat.randomizer = default('parsav_feat_randomizer', 'libc')
end
local choplib = function(l)
if string.sub(l,1,3) == 'lib' then return string.sub(l,4) end
return l
end
local fallback = dofile('pkgdata.lua')
local libfind do local mkf = function(p)
return function(l) return string.format(p,l) end
end
local unx = function(p)
return function(l)
if string.sub(l,1,3) == 'lib'
................................................................................
then return string.format('%s.%s',l,p)
else return string.format('lib%s.%s',l,p)
end
end
end
libfind = {
linux = { static = unx 'a', dynamic = unx 'so'; };
osx = { dynamic = mkf '%s.dylib'; };
win = { dynamic = mkf '%s.dll'; };
}
end
local pkg = function(name)
local fbo = fallback[name] and fallback[name].osvars and coalesce(
fallback[name].osvars[conf.os .. '_' .. conf.dist],
fallback[name].osvars[conf.os]
)
local fbv = fallback[name] and fallback[name].vars
local fb = fallback[name]
local pkgenv = function(e)
return os.getenv(string.format('parsav_pkg_%s_%s',name,e))
end
local nul = function() end
local pkc, pkv = nul, nul
local locdep = false
local cnfvar = function(v,e)
local eval = function(e)
if type(e) == 'function'
then return e(conf)
else return e
end
end
return coalesce(
pkgenv(v),
pkv(e or v),
(fbo and eval(fbo[v])),
(fbv and eval(fbv[v])))
end
local name = cnfvar('override') or name
local pcname = coalesce(cnfvar('pcname'), name)
if conf.posix then
pkc = function(...) if locdep then return nil end
return u.exec { 'pkg-config'; pcname; ... } end
local pkcv = function(...) return u.exec({ 'pkg-config'; pcname; ... }, true) end
if pkcv('--exists') == 0 then
pkv = function(v)
if locdep then return nil end
return pkc('--variable', v)
end
else pkc = nul end
else
print '(warn) configuring on non-POSIX OS, all relevant paths must be specified manually in environment variables or build will fail!'
end
locdep = u.ping('./lib/' .. name)
local incdir, libdir, prefix
if locdep then
prefix = './lib/' .. name
libdir = prefix .. coalesce(cnfvar('libbuilddir'),cnfvar('builddir'),'')
incdir = prefix .. coalesce(cnfvar('srcincdir'),cnfvar('builddir'),'/include')
else
prefix = coalesce(cnfvar('prefix'), '/usr')
libdir = cnfvar('libdir')
incdir = cnfvar('incdir','includedir')
end
libdir = libdir or prefix .. '/lib'
incdir = incdir or prefix .. '/include'
local libstr = pkc '--libs-only-l' -- (--static is not reliable)
local libs = fb and fb.libs or {}
local linkstatic = locdep
if (not locdep) and libstr then
libs = {}
for m in string.gmatch(libstr, '-l(%g+)') do
libs[#libs + 1] = m
end
else
................................................................................
local ldf = {}
for _,v in pairs(me.statlibs) do
local fl = libdir .. '/' .. v
if u.ping(fl) then ldf[#ldf+1] = fl end
end
me.linkargs = ldf
else
local arg = choplib(name)
local linkline = libstr
if not linkline and #libs == 0 then
linkline = string.format('-l%s', arg)
elseif not linkline then linkline = '' end
me.linkargs = {
string.format('-L%s', me.libdir);
}
for m in string.gmatch(linkline, '(%g+)') do
me.linkargs[#me.linkargs+1] = m
end
-- siiiiigh
for _,l in pairs(libs) do
local sw = string.format('-l%s', choplib(l))
local found = false
for _,a in pairs(me.linkargs) do
if a == sw then found = true break end
end
if not found then
me.linkargs[#me.linkargs+1] = sw
end
end
end
end
pkg('mbedtls')
pkg('mongoose')
pkg('json-c')
pkg('libc')
pkg('libpq')
return conf
|