2020-05-26 21:30:05 +00:00
|
|
|
local lib = dofile('scripts/target_lib.lua')
|
2020-05-31 11:04:10 +00:00
|
|
|
local feature_lib = dofile('scripts/feature_lib.lua')
|
2020-05-26 21:30:05 +00:00
|
|
|
local env = lib.env
|
|
|
|
|
|
|
|
local target = env.GLUON_TARGET
|
|
|
|
|
|
|
|
assert(target)
|
|
|
|
assert(env.BOARD)
|
|
|
|
assert(env.SUBTARGET)
|
|
|
|
|
|
|
|
local openwrt_config_target
|
|
|
|
if env.SUBTARGET ~= '' then
|
|
|
|
openwrt_config_target = env.BOARD .. '_' .. env.SUBTARGET
|
|
|
|
else
|
|
|
|
openwrt_config_target = env.BOARD
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2020-05-03 19:35:01 +00:00
|
|
|
-- Split a string into words
|
|
|
|
local function split(s)
|
|
|
|
local ret = {}
|
|
|
|
for w in string.gmatch(s, '%S+') do
|
|
|
|
table.insert(ret, w)
|
|
|
|
end
|
|
|
|
return ret
|
|
|
|
end
|
|
|
|
|
2020-05-31 11:04:10 +00:00
|
|
|
local feeds = split(lib.exec_capture_raw('. scripts/modules.sh; echo "$FEEDS"'))
|
|
|
|
|
2020-05-03 19:35:01 +00:00
|
|
|
-- Strip leading '-' character
|
|
|
|
local function strip_neg(s)
|
|
|
|
if string.sub(s, 1, 1) == '-' then
|
|
|
|
return string.sub(s, 2)
|
|
|
|
else
|
|
|
|
return s
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Add an element to a list, removing duplicate entries and handling negative
|
|
|
|
-- elements prefixed with a '-'
|
|
|
|
local function append_to_list(list, item, keep_neg)
|
|
|
|
local match = strip_neg(item)
|
|
|
|
local ret = {}
|
|
|
|
for _, el in ipairs(list) do
|
|
|
|
if strip_neg(el) ~= match then
|
|
|
|
table.insert(ret, el)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if keep_neg ~= false or string.sub(item, 1, 1) ~= '-' then
|
|
|
|
table.insert(ret, item)
|
|
|
|
end
|
|
|
|
return ret
|
|
|
|
end
|
|
|
|
|
2020-05-31 10:47:10 +00:00
|
|
|
local function concat_list(a, b, keep_neg)
|
|
|
|
local ret = a
|
|
|
|
for _, el in ipairs(b) do
|
2020-05-03 19:35:01 +00:00
|
|
|
ret = append_to_list(ret, el, keep_neg)
|
|
|
|
end
|
|
|
|
return ret
|
|
|
|
end
|
|
|
|
|
2020-05-31 10:47:10 +00:00
|
|
|
local function compact_list(list, keep_neg)
|
|
|
|
return concat_list({}, list, keep_neg)
|
|
|
|
end
|
2019-06-17 23:33:12 +00:00
|
|
|
|
2020-05-31 11:04:10 +00:00
|
|
|
local function file_exists(file)
|
|
|
|
local f = io.open(file)
|
|
|
|
if not f then
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
f:close()
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2020-05-26 21:30:05 +00:00
|
|
|
local function site_vars(var)
|
|
|
|
return lib.exec_capture_raw(string.format(
|
|
|
|
[[
|
|
|
|
MAKEFLAGS= make print _GLUON_SITE_VARS_=%s --no-print-directory -s -f - <<'END_MAKE'
|
2019-06-17 23:33:12 +00:00
|
|
|
include $(GLUON_SITEDIR)/site.mk
|
|
|
|
|
|
|
|
print:
|
2020-05-03 15:13:42 +00:00
|
|
|
echo -n '$(_GLUON_SITE_VARS_)'
|
2019-06-17 23:33:12 +00:00
|
|
|
END_MAKE
|
2020-05-26 21:30:05 +00:00
|
|
|
]],
|
|
|
|
lib.escape(var)))
|
|
|
|
end
|
2020-05-03 15:13:42 +00:00
|
|
|
|
2020-05-26 21:30:05 +00:00
|
|
|
local function site_packages(image)
|
|
|
|
return split(site_vars(string.format('$(GLUON_%s_SITE_PACKAGES)', image)))
|
|
|
|
end
|
2020-05-03 19:35:01 +00:00
|
|
|
|
2020-05-26 21:30:05 +00:00
|
|
|
local function feature_packages(features)
|
2020-08-28 20:20:13 +00:00
|
|
|
local files = {'package/features'}
|
2020-05-31 11:04:10 +00:00
|
|
|
for _, feed in ipairs(feeds) do
|
|
|
|
local path = string.format('packages/%s/features', feed)
|
|
|
|
if file_exists(path) then
|
2020-08-28 20:20:13 +00:00
|
|
|
table.insert(files, path)
|
2020-05-31 11:04:10 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-08-28 20:20:13 +00:00
|
|
|
return feature_lib.get_packages(files, features)
|
2020-05-26 21:30:05 +00:00
|
|
|
end
|
2020-05-03 19:35:01 +00:00
|
|
|
|
2020-05-31 11:04:10 +00:00
|
|
|
-- This involves running a few processes to evaluate site.mk, so we add a simple cache
|
2020-05-26 21:30:05 +00:00
|
|
|
local class_cache = {}
|
|
|
|
local function class_packages(class)
|
|
|
|
if class_cache[class] then
|
|
|
|
return class_cache[class]
|
|
|
|
end
|
2020-05-03 19:35:01 +00:00
|
|
|
|
2020-05-26 21:30:05 +00:00
|
|
|
local features = site_vars(string.format('$(GLUON_FEATURES) $(GLUON_FEATURES_%s)', class))
|
2020-05-31 11:04:10 +00:00
|
|
|
features = compact_list(split(features), false)
|
2020-05-03 19:35:01 +00:00
|
|
|
|
2020-05-26 21:30:05 +00:00
|
|
|
local pkgs = feature_packages(features)
|
2020-05-31 11:04:10 +00:00
|
|
|
pkgs = concat_list(pkgs, split(site_vars(string.format('$(GLUON_SITE_PACKAGES) $(GLUON_SITE_PACKAGES_%s)', class))))
|
2020-05-03 19:35:01 +00:00
|
|
|
|
2020-05-26 21:30:05 +00:00
|
|
|
class_cache[class] = pkgs
|
|
|
|
return pkgs
|
|
|
|
end
|
2019-06-17 23:33:12 +00:00
|
|
|
|
2020-05-26 21:30:05 +00:00
|
|
|
local enabled_packages = {}
|
|
|
|
-- Arguments: package name and config value (true: y, nil: m, false: unset)
|
|
|
|
-- Ensures precedence of y > m > unset
|
|
|
|
local function config_package(pkg, v)
|
2022-08-23 20:53:45 +00:00
|
|
|
-- HACK: Handle virtual default packages
|
|
|
|
local subst = {
|
|
|
|
nftables = 'nftables-nojson'
|
|
|
|
}
|
|
|
|
if subst[pkg] then
|
|
|
|
pkg = subst[pkg]
|
|
|
|
end
|
|
|
|
|
2020-05-26 21:30:05 +00:00
|
|
|
if v == false then
|
|
|
|
if not enabled_packages[pkg] then
|
|
|
|
lib.try_config('PACKAGE_' .. pkg, false)
|
2020-05-26 20:40:12 +00:00
|
|
|
end
|
2020-05-26 21:30:05 +00:00
|
|
|
return
|
|
|
|
end
|
2020-05-26 20:40:12 +00:00
|
|
|
|
2020-05-26 21:30:05 +00:00
|
|
|
if v == true or not enabled_packages[pkg] then
|
|
|
|
lib.config('PACKAGE_' .. pkg, v, string.format("unable to enable package '%s'", pkg))
|
|
|
|
enabled_packages[pkg] = true
|
2020-05-26 20:40:12 +00:00
|
|
|
end
|
2020-05-26 21:30:05 +00:00
|
|
|
end
|
2020-05-26 20:40:12 +00:00
|
|
|
|
2020-05-26 21:30:05 +00:00
|
|
|
local function handle_target_pkgs(pkgs)
|
|
|
|
for _, pkg in ipairs(pkgs) do
|
|
|
|
if string.sub(pkg, 1, 1) == '-' then
|
|
|
|
config_package(string.sub(pkg, 2), false)
|
|
|
|
else
|
|
|
|
config_package(pkg, true)
|
2020-03-27 18:08:13 +00:00
|
|
|
end
|
2019-06-17 23:33:12 +00:00
|
|
|
end
|
2020-05-26 21:30:05 +00:00
|
|
|
end
|
2020-03-27 18:08:13 +00:00
|
|
|
|
2022-08-23 20:59:55 +00:00
|
|
|
local function get_default_pkgs()
|
|
|
|
local targetinfo_target = string.gsub(openwrt_config_target, '_', '/')
|
|
|
|
local target_matches = false
|
|
|
|
for line in io.lines('openwrt/tmp/.targetinfo') do
|
|
|
|
local target_match = string.match(line, '^Target: (.+)$')
|
|
|
|
if target_match then
|
|
|
|
target_matches = (target_match == targetinfo_target)
|
|
|
|
end
|
|
|
|
|
|
|
|
local default_packages_match = string.match(line, '^Default%-Packages: (.+)$')
|
|
|
|
if target_matches and default_packages_match then
|
|
|
|
return split(default_packages_match)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
io.stderr:write('Error: unable to get default packages for OpenWrt target ', targetinfo_target, '\n')
|
|
|
|
os.exit(1)
|
|
|
|
end
|
|
|
|
|
2020-05-26 21:30:05 +00:00
|
|
|
lib.include('generic')
|
2023-01-30 22:25:02 +00:00
|
|
|
lib.include('generic_' .. env.GLUON_BUILDTYPE)
|
2020-05-26 21:30:05 +00:00
|
|
|
lib.include(target)
|
2019-06-17 23:33:12 +00:00
|
|
|
|
2020-05-26 21:30:05 +00:00
|
|
|
lib.check_devices()
|
2019-06-17 23:33:12 +00:00
|
|
|
|
2022-08-23 20:59:55 +00:00
|
|
|
handle_target_pkgs(concat_list(get_default_pkgs(), lib.target_packages))
|
2019-06-17 23:33:12 +00:00
|
|
|
|
2023-01-30 22:25:02 +00:00
|
|
|
-- the if condition in ipairs checks if a user-configured target is
|
|
|
|
-- trying to build all devices, in which case specific gluon target-definitions are skipped
|
|
|
|
for _, dev in ipairs(lib.configs.TARGET_ALL_PROFILES and {} or lib.devices) do
|
2022-08-23 19:41:03 +00:00
|
|
|
local device_pkgs = {}
|
2020-05-26 21:30:05 +00:00
|
|
|
local function handle_pkgs(pkgs)
|
2022-08-23 19:41:03 +00:00
|
|
|
for _, pkg in ipairs(pkgs) do
|
|
|
|
if string.sub(pkg, 1, 1) ~= '-' then
|
|
|
|
config_package(pkg, nil)
|
|
|
|
end
|
|
|
|
device_pkgs = append_to_list(device_pkgs, pkg)
|
|
|
|
end
|
2019-06-17 23:33:12 +00:00
|
|
|
end
|
|
|
|
|
2020-05-26 21:30:05 +00:00
|
|
|
handle_pkgs(lib.target_packages)
|
2022-08-23 19:41:03 +00:00
|
|
|
handle_pkgs(dev.options.packages or {})
|
2023-01-30 22:25:02 +00:00
|
|
|
|
|
|
|
if env.GLUON_BUILDTYPE == 'gluon' then
|
|
|
|
handle_pkgs(class_packages(dev.options.class))
|
|
|
|
handle_pkgs(site_packages(dev.image))
|
|
|
|
else
|
|
|
|
handle_pkgs(lib.target_class_packages[dev.options.class] or {})
|
|
|
|
end
|
2022-08-23 19:41:03 +00:00
|
|
|
|
|
|
|
local profile_config = string.format('%s_DEVICE_%s', openwrt_config_target, dev.name)
|
|
|
|
lib.config(
|
|
|
|
'TARGET_DEVICE_' .. profile_config, true,
|
|
|
|
string.format("unable to enable device '%s'", dev.name)
|
|
|
|
)
|
|
|
|
lib.config(
|
|
|
|
'TARGET_DEVICE_PACKAGES_' .. profile_config,
|
|
|
|
table.concat(device_pkgs, ' ')
|
|
|
|
)
|
2019-06-17 23:33:12 +00:00
|
|
|
end
|
2020-05-26 21:30:05 +00:00
|
|
|
|
|
|
|
return lib
|