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