buildsystem: allow building custom buildtypes

This adds GLUON_BUILDTYPE, which is an option that allows specifying an alternate
base configuration

Other additions:

- GLUON_PREFIX option to specify the filename prefix, if
  VERSION_DIST is set

- Skip gluon target-definitions if TARGET_ALL_PROFILES is set

- Allow overriding any file in targets/ by adding the file to site/
  - Allow loading the original file using include_gluon() from gluon
This commit is contained in:
Maciej Krüger 2023-01-30 23:25:02 +01:00
parent 1780bafafc
commit e5be1a6b76
No known key found for this signature in database
GPG Key ID: 0D948CE19CF49C5F
6 changed files with 138 additions and 90 deletions

View File

@ -45,6 +45,7 @@ GLUON_PACKAGEDIR ?= $(GLUON_OUTPUTDIR)/packages
GLUON_DEBUGDIR ?= $(GLUON_OUTPUTDIR)/debug GLUON_DEBUGDIR ?= $(GLUON_OUTPUTDIR)/debug
GLUON_TARGETSDIR ?= targets GLUON_TARGETSDIR ?= targets
GLUON_PATCHESDIR ?= patches GLUON_PATCHESDIR ?= patches
GLUON_PREFIX ?= openwrt
$(eval $(call mkabspath,GLUON_TMPDIR)) $(eval $(call mkabspath,GLUON_TMPDIR))
$(eval $(call mkabspath,GLUON_OUTPUTDIR)) $(eval $(call mkabspath,GLUON_OUTPUTDIR))
@ -60,6 +61,7 @@ GLUON_MULTIDOMAIN ?= 0
GLUON_AUTOREMOVE ?= 0 GLUON_AUTOREMOVE ?= 0
GLUON_DEBUG ?= 0 GLUON_DEBUG ?= 0
GLUON_MINIFY ?= 1 GLUON_MINIFY ?= 1
GLUON_BUILDTYPE ?= gluon
# Can be overridden via environment/command line/... to use the Gluon # Can be overridden via environment/command line/... to use the Gluon
# build system for non-Gluon builds # build system for non-Gluon builds
@ -71,7 +73,7 @@ GLUON_VARS = \
GLUON_VERSION GLUON_SITE_VERSION \ GLUON_VERSION GLUON_SITE_VERSION \
GLUON_RELEASE GLUON_REGION GLUON_MULTIDOMAIN GLUON_AUTOREMOVE GLUON_DEBUG GLUON_MINIFY GLUON_DEPRECATED \ GLUON_RELEASE GLUON_REGION GLUON_MULTIDOMAIN GLUON_AUTOREMOVE GLUON_DEBUG GLUON_MINIFY GLUON_DEPRECATED \
GLUON_DEVICES GLUON_TARGETSDIR GLUON_PATCHESDIR GLUON_TMPDIR GLUON_IMAGEDIR GLUON_PACKAGEDIR GLUON_DEBUGDIR \ GLUON_DEVICES GLUON_TARGETSDIR GLUON_PATCHESDIR GLUON_TMPDIR GLUON_IMAGEDIR GLUON_PACKAGEDIR GLUON_DEBUGDIR \
GLUON_SITEDIR GLUON_AUTOUPDATER_BRANCH GLUON_AUTOUPDATER_ENABLED GLUON_LANGS GLUON_BASE_FEEDS \ GLUON_SITEDIR GLUON_BUILDTYPE GLUON_AUTOUPDATER_BRANCH GLUON_AUTOUPDATER_ENABLED GLUON_LANGS GLUON_BASE_FEEDS GLUON_PREFIX \
GLUON_TARGET BOARD SUBTARGET GLUON_TARGET BOARD SUBTARGET
unexport $(GLUON_VARS) unexport $(GLUON_VARS)

View File

@ -35,7 +35,7 @@ lib.include(target)
local function image_source(image) local function image_source(image)
return string.format( return string.format(
'openwrt/bin/targets/%s/openwrt-%s-%s%s%s', 'openwrt/bin/targets/%s/' .. (env.GLUON_PREFIX or 'openwrt') .. '-%s-%s%s%s',
bindir, openwrt_target, image.name, image.in_suffix, image.extension) bindir, openwrt_target, image.name, image.in_suffix, image.extension)
end end

View File

@ -174,13 +174,16 @@ local function get_default_pkgs()
end end
lib.include('generic') lib.include('generic')
lib.include('generic_' .. env.GLUON_BUILDTYPE)
lib.include(target) lib.include(target)
lib.check_devices() lib.check_devices()
handle_target_pkgs(concat_list(get_default_pkgs(), lib.target_packages)) handle_target_pkgs(concat_list(get_default_pkgs(), lib.target_packages))
for _, dev in ipairs(lib.devices) do -- 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
local device_pkgs = {} local device_pkgs = {}
local function handle_pkgs(pkgs) local function handle_pkgs(pkgs)
for _, pkg in ipairs(pkgs) do for _, pkg in ipairs(pkgs) do
@ -192,9 +195,14 @@ for _, dev in ipairs(lib.devices) do
end end
handle_pkgs(lib.target_packages) handle_pkgs(lib.target_packages)
handle_pkgs(class_packages(dev.options.class))
handle_pkgs(dev.options.packages or {}) handle_pkgs(dev.options.packages or {})
if env.GLUON_BUILDTYPE == 'gluon' then
handle_pkgs(class_packages(dev.options.class))
handle_pkgs(site_packages(dev.image)) handle_pkgs(site_packages(dev.image))
else
handle_pkgs(lib.target_class_packages[dev.options.class] or {})
end
local profile_config = string.format('%s_DEVICE_%s', openwrt_config_target, dev.name) local profile_config = string.format('%s_DEVICE_%s', openwrt_config_target, dev.name)
lib.config( lib.config(

View File

@ -25,6 +25,7 @@ M.site_code = assert(
dofile('scripts/site_config.lua')('site.conf').site_code, 'site_code missing in site.conf' dofile('scripts/site_config.lua')('site.conf').site_code, 'site_code missing in site.conf'
) )
M.target_packages = {} M.target_packages = {}
M.target_class_packages = {}
M.configs = {} M.configs = {}
M.devices = {} M.devices = {}
M.images = {} M.images = {}
@ -202,6 +203,17 @@ function F.packages(pkgs)
end end
M.packages = F.packages M.packages = F.packages
function F.class_packages(target, pkgs)
if not M.target_class_packages[target] then
M.target_class_packages[target] = {}
end
for _, pkg in ipairs(pkgs) do
table.insert(M.target_class_packages[target], pkg)
end
end
M.class_packages = F.class_packages
local function as_table(v) local function as_table(v)
if type(v) == 'table' then if type(v) == 'table' then
return v return v
@ -270,12 +282,38 @@ function F.defaults(options)
default_options = merge(default_options, options) default_options = merge(default_options, options)
end end
local function load_and_assert(...)
for _, path in ipairs(arg) do
local fd = io.open(path, 'r')
if fd ~= nil then
fd:close()
-- only assert if file exists. this allows trying multiple files.
return assert(loadfile(path))
end
end
assert(nil)
end
-- this function allows including target configurations from the first source
-- that a file is found
-- targets are loaded in the following order:
-- - current working directory
-- - site
-- - gluon
function F.include(name) function F.include(name)
local f = assert(loadfile(env.GLUON_TARGETSDIR .. '/' .. name)) local f = load_and_assert('./' .. name, env.GLUON_SITEDIR .. '/' .. name, env.GLUON_TARGETSDIR .. '/' .. name)
setfenv(f, funcs) setfenv(f, funcs)
return f() return f()
end end
-- this function allows including target configurations from gluon
-- can be used to include original targets via site, for example
function F.include_gluon(name)
local f = load_and_assert(env.GLUON_TARGETSDIR .. '/' .. name)
setfenv(f, funcs)
return f()
end
function M.check_devices() function M.check_devices()
local device_list = {} local device_list = {}

View File

@ -1,26 +1,8 @@
assert(env.GLUON_LANGS)
config('GLUON_SITEDIR', env.GLUON_SITEDIR)
config('GLUON_VERSION', env.GLUON_VERSION)
config('GLUON_SITE_VERSION', env.GLUON_SITE_VERSION)
config('GLUON_RELEASE', env.GLUON_RELEASE)
try_config('GLUON_AUTOUPDATER_BRANCH', env.GLUON_AUTOUPDATER_BRANCH)
try_config('GLUON_AUTOUPDATER_ENABLED', istrue(env.GLUON_AUTOUPDATER_ENABLED))
for lang in string.gmatch(env.GLUON_LANGS, '%S+') do
try_config('GLUON_WEB_LANG_' .. lang, true)
end
config('TARGET_' .. env.BOARD, true) config('TARGET_' .. env.BOARD, true)
if env.SUBTARGET ~= '' then if env.SUBTARGET ~= '' then
config(string.format('TARGET_%s_%s', env.BOARD, env.SUBTARGET), true) config(string.format('TARGET_%s_%s', env.BOARD, env.SUBTARGET), true)
end end
-- Disable non-default feeds in distfeeds.conf
config('FEED_gluon_base', false)
local default_feeds = {} local default_feeds = {}
for feed in string.gmatch(exec_capture_raw('. scripts/default_feeds.sh && echo "$DEFAULT_FEEDS"'), '%S+') do for feed in string.gmatch(exec_capture_raw('. scripts/default_feeds.sh && echo "$DEFAULT_FEEDS"'), '%S+') do
default_feeds[feed] = true default_feeds[feed] = true
@ -32,51 +14,6 @@ for feed in string.gmatch(exec_capture_raw('. scripts/modules.sh && echo -n "$FE
end end
end end
config('TARGET_ROOTFS_INITRAMFS', false)
config('DEVEL', true)
config('ALL_NONSHARED', true)
try_config('PACKAGE_usbip', false) -- fails to build
try_config('PACKAGE_ATH_DEBUG', true)
try_config('PACKAGE_dnsmasq_full_dhcpv6', false)
try_config('PACKAGE_dnsmasq_full_auth', false)
try_config('PACKAGE_dnsmasq_full_ipset', false)
try_config('PACKAGE_dnsmasq_full_nftset', false)
try_config('PACKAGE_dnsmasq_full_conntrack', false)
try_config('PACKAGE_dnsmasq_full_noid', false)
try_config('PACKAGE_dnsmasq_full_broken_rtc', false)
try_config('PACKAGE_dnsmasq_full_rtc', false)
try_config('TARGET_SQUASHFS_BLOCK_SIZE', 256)
config('KERNEL_PROC_STRIPPED', true)
config('KERNEL_AIO', false)
config('KERNEL_IO_URING', false)
config('KERNEL_FHANDLE', false)
config('KERNEL_FANOTIFY', false)
config('KERNEL_CGROUPS', false)
config('KERNEL_IP_MROUTE', false)
config('KERNEL_IPV6_MROUTE', false)
config('KERNEL_IPV6_SEG6_LWTUNNEL', false)
config('SECCOMP', false)
config('KERNEL_SECCOMP', false)
-- kmod-mt7915e pulls in CONFIG_KERNEL_RELAY
-- use try_config, so enabling the package is still possible
try_config('PACKAGE_kmod-mt7915e', false)
config('COLLECT_KERNEL_DEBUG', true)
config('TARGET_MULTI_PROFILE', true)
config('TARGET_PER_DEVICE_ROOTFS', true)
config('GLUON_MULTIDOMAIN', istrue(env.GLUON_MULTIDOMAIN))
config('AUTOREMOVE', istrue(env.GLUON_AUTOREMOVE))
if istrue(env.GLUON_DEBUG) then if istrue(env.GLUON_DEBUG) then
config('DEBUG', true) config('DEBUG', true)
config('NO_STRIP', true) config('NO_STRIP', true)
@ -85,24 +22,3 @@ if istrue(env.GLUON_DEBUG) then
try_config('TARGET_ROOTFS_PARTSIZE', 500) try_config('TARGET_ROOTFS_PARTSIZE', 500)
end end
config('GLUON_MINIFY', istrue(env.GLUON_MINIFY))
packages {
'-ca-bundle',
'-dnsmasq',
'-kmod-ipt-offload',
'-kmod-nft-offload',
'-libustream-wolfssl',
'-libwolfssl',
'-nftables',
'-odhcpd-ipv6only',
'-ppp',
'-ppp-mod-pppoe',
'-wpad-mini',
'-wpad-basic',
'-wpad-basic-wolfssl',
'-firewall4',
'gluon-core',
'ip6tables-zz-legacy',
}

84
targets/generic_gluon Normal file
View File

@ -0,0 +1,84 @@
assert(env.GLUON_LANGS)
config('GLUON_SITEDIR', env.GLUON_SITEDIR)
config('GLUON_VERSION', env.GLUON_VERSION)
config('GLUON_SITE_VERSION', env.GLUON_SITE_VERSION)
config('GLUON_RELEASE', env.GLUON_RELEASE)
try_config('GLUON_AUTOUPDATER_BRANCH', env.GLUON_AUTOUPDATER_BRANCH)
try_config('GLUON_AUTOUPDATER_ENABLED', istrue(env.GLUON_AUTOUPDATER_ENABLED))
for lang in string.gmatch(env.GLUON_LANGS, '%S+') do
try_config('GLUON_WEB_LANG_' .. lang, true)
end
-- Disable non-default feeds in distfeeds.conf
config('FEED_gluon_base', false)
config('TARGET_ROOTFS_INITRAMFS', false)
config('DEVEL', true)
config('ALL_NONSHARED', true)
try_config('PACKAGE_usbip', false) -- fails to build
try_config('PACKAGE_ATH_DEBUG', true)
try_config('PACKAGE_dnsmasq_full_dhcpv6', false)
try_config('PACKAGE_dnsmasq_full_auth', false)
try_config('PACKAGE_dnsmasq_full_ipset', false)
try_config('PACKAGE_dnsmasq_full_nftset', false)
try_config('PACKAGE_dnsmasq_full_conntrack', false)
try_config('PACKAGE_dnsmasq_full_noid', false)
try_config('PACKAGE_dnsmasq_full_broken_rtc', false)
try_config('PACKAGE_dnsmasq_full_rtc', false)
try_config('TARGET_SQUASHFS_BLOCK_SIZE', 256)
config('KERNEL_PROC_STRIPPED', true)
config('KERNEL_AIO', false)
config('KERNEL_IO_URING', false)
config('KERNEL_FHANDLE', false)
config('KERNEL_FANOTIFY', false)
config('KERNEL_CGROUPS', false)
config('KERNEL_IP_MROUTE', false)
config('KERNEL_IPV6_MROUTE', false)
config('KERNEL_IPV6_SEG6_LWTUNNEL', false)
config('SECCOMP', false)
config('KERNEL_SECCOMP', false)
-- kmod-mt7915e pulls in CONFIG_KERNEL_RELAY
-- use try_config, so enabling the package is still possible
try_config('PACKAGE_kmod-mt7915e', false)
config('COLLECT_KERNEL_DEBUG', true)
config('TARGET_MULTI_PROFILE', true)
config('TARGET_PER_DEVICE_ROOTFS', true)
config('GLUON_MULTIDOMAIN', istrue(env.GLUON_MULTIDOMAIN))
config('AUTOREMOVE', istrue(env.GLUON_AUTOREMOVE))
config('GLUON_MINIFY', istrue(env.GLUON_MINIFY))
packages {
'-ca-bundle',
'-dnsmasq',
'-kmod-ipt-offload',
'-kmod-nft-offload',
'-libustream-wolfssl',
'-libwolfssl',
'-nftables',
'-odhcpd-ipv6only',
'-ppp',
'-ppp-mod-pppoe',
'-wpad-mini',
'-wpad-basic',
'-wpad-basic-wolfssl',
'-firewall4',
'gluon-core',
'ip6tables-zz-legacy',
}