Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

buildsystem: allow building custom buildtypes #2781

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ GLUON_PACKAGEDIR ?= $(GLUON_OUTPUTDIR)/packages
GLUON_DEBUGDIR ?= $(GLUON_OUTPUTDIR)/debug
GLUON_TARGETSDIR ?= targets
GLUON_PATCHESDIR ?= patches
GLUON_PREFIX ?= openwrt

$(eval $(call mkabspath,GLUON_TMPDIR))
$(eval $(call mkabspath,GLUON_OUTPUTDIR))
Expand All @@ -60,6 +61,7 @@ GLUON_MULTIDOMAIN ?= 0
GLUON_AUTOREMOVE ?= 0
GLUON_DEBUG ?= 0
GLUON_MINIFY ?= 1
GLUON_BUILDTYPE ?= gluon

# Can be overridden via environment/command line/... to use the Gluon
# build system for non-Gluon builds
Expand All @@ -71,7 +73,7 @@ GLUON_VARS = \
GLUON_VERSION GLUON_SITE_VERSION \
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_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

unexport $(GLUON_VARS)
Expand Down
8 changes: 8 additions & 0 deletions package/gluon-core/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ config GLUON_VERSION
config GLUON_MINIFY
bool "Minify Gluon scripts"
default y

config GLUON_BASE
bool "Exclude everything except the very most basic"
default n
endef

define Package/gluon-core/conffiles
Expand All @@ -38,6 +42,10 @@ define Package/gluon-core/install

$(INSTALL_DIR) $(1)/lib/gluon
echo '$(call qstrip,$(CONFIG_GLUON_VERSION))' > $(1)/lib/gluon/gluon-version

ifdef CONFIG_GLUON_BASE
find $(1)/lib/gluon/upgrade/ -type f -and ! -name "998-commit" -and ! -name "005-set-domain" -and ! -name "010-primary-mac" -and ! -name "030-system" -and ! -name "120-ntp-servers" -and ! -name "150-poe-passthrough" -and ! -name "300-firewall-rules" -and ! -name "820-dns-config" -and ! -name "999-version" -delete
endif
endef

$(eval $(call BuildPackageGluon,gluon-core))
2 changes: 1 addition & 1 deletion scripts/copy_output.lua
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ lib.include(target)

local function image_source(image)
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)
end

Expand Down
14 changes: 11 additions & 3 deletions scripts/target_config_lib.lua
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,16 @@ local function get_default_pkgs()
end

lib.include('generic')
lib.include('generic_' .. env.GLUON_BUILDTYPE)
lib.include(target)

lib.check_devices()

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 function handle_pkgs(pkgs)
for _, pkg in ipairs(pkgs) do
Expand All @@ -192,9 +195,14 @@ for _, dev in ipairs(lib.devices) do
end

handle_pkgs(lib.target_packages)
handle_pkgs(class_packages(dev.options.class))
handle_pkgs(dev.options.packages or {})
handle_pkgs(site_packages(dev.image))

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

local profile_config = string.format('%s_DEVICE_%s', openwrt_config_target, dev.name)
lib.config(
Expand Down
40 changes: 39 additions & 1 deletion scripts/target_lib.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ M.site_code = assert(
dofile('scripts/site_config.lua')('site.conf').site_code, 'site_code missing in site.conf'
)
M.target_packages = {}
M.target_class_packages = {}
M.configs = {}
M.devices = {}
M.images = {}
Expand Down Expand Up @@ -202,6 +203,17 @@ function F.packages(pkgs)
end
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)
if type(v) == 'table' then
return v
Expand Down Expand Up @@ -270,12 +282,38 @@ function F.defaults(options)
default_options = merge(default_options, options)
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)
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)
return f()
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()
local device_list = {}
Expand Down
84 changes: 0 additions & 84 deletions targets/generic
Original file line number Diff line number Diff line change
@@ -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)
if env.SUBTARGET ~= '' then
config(string.format('TARGET_%s_%s', env.BOARD, env.SUBTARGET), true)
end

-- Disable non-default feeds in distfeeds.conf
config('FEED_gluon_base', false)

local default_feeds = {}
for feed in string.gmatch(exec_capture_raw('. scripts/default_feeds.sh && echo "$DEFAULT_FEEDS"'), '%S+') do
default_feeds[feed] = true
Expand All @@ -32,51 +14,6 @@ for feed in string.gmatch(exec_capture_raw('. scripts/modules.sh && echo -n "$FE
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
config('DEBUG', true)
config('NO_STRIP', true)
Expand All @@ -85,24 +22,3 @@ if istrue(env.GLUON_DEBUG) then

try_config('TARGET_ROOTFS_PARTSIZE', 500)
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 changes: 84 additions & 0 deletions targets/generic_gluon
Original file line number Diff line number Diff line change
@@ -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',
}