From 9c52365077bee78c35289db3611fc02e80de2d73 Mon Sep 17 00:00:00 2001
From: David Bauer <mail@david-bauer.net>
Date: Mon, 23 Sep 2019 21:46:30 +0200
Subject: [PATCH] build: introduce device classes

This commit allows to define a device-class flag in the target
definitions. This way, it is possible to distinguish between groups
of devices in the build-process in terms of package or feature
selection.
---
 Makefile                      |  6 ++++--
 scripts/target_config_lib.lua | 16 +++++++++++++---
 scripts/target_lib.lua        |  1 +
 3 files changed, 18 insertions(+), 5 deletions(-)

diff --git a/Makefile b/Makefile
index 34343356c..c228db77a 100644
--- a/Makefile
+++ b/Makefile
@@ -112,6 +112,8 @@ lint-sh: FORCE
 	@scripts/lint-sh.sh
 
 GLUON_DEFAULT_PACKAGES := hostapd-mini
+GLUON_CLASS_PACKAGES_standard :=
+GLUON_CLASS_PACKAGES_tiny :=
 
 GLUON_FEATURE_PACKAGES := $(shell scripts/features.sh '$(GLUON_FEATURES)' || echo '__ERROR__')
 ifneq ($(filter __ERROR__,$(GLUON_FEATURE_PACKAGES)),)
@@ -144,12 +146,12 @@ config: $(LUA) FORCE
 	$(foreach conf,site $(patsubst $(GLUON_SITEDIR)/%.conf,%,$(wildcard $(GLUON_SITEDIR)/domains/*.conf)),$(call CheckSite,$(conf)))
 
 	@$(GLUON_CONFIG_VARS) \
-		$(LUA) scripts/target_config.lua '$(GLUON_TARGET)' '$(GLUON_PACKAGES)' \
+		$(LUA) scripts/target_config.lua '$(GLUON_TARGET)' '$(GLUON_DEFAULT_PACKAGES)' '$(GLUON_CLASS_PACKAGES_standard)' '$(GLUON_CLASS_PACKAGES_tiny)' \
 		> openwrt/.config
 	+@$(OPENWRTMAKE) defconfig
 
 	@$(GLUON_CONFIG_VARS) \
-		$(LUA) scripts/target_config_check.lua '$(GLUON_TARGET)' '$(GLUON_PACKAGES)'
+		$(LUA) scripts/target_config_check.lua '$(GLUON_TARGET)' '$(GLUON_DEFAULT_PACKAGES)' '$(GLUON_CLASS_PACKAGES_standard)' '$(GLUON_CLASS_PACKAGES_tiny)'
 
 
 all: config
diff --git a/scripts/target_config_lib.lua b/scripts/target_config_lib.lua
index 71443db77..3f1c35856 100644
--- a/scripts/target_config_lib.lua
+++ b/scripts/target_config_lib.lua
@@ -7,6 +7,10 @@ return function(funcs)
 
 	local target = arg[1]
 	local extra_packages = arg[2]
+	local class_packages = {
+		standard = arg[3],
+		tiny = arg[4],
+	}
 
 	local openwrt_config_target
 	if env.SUBTARGET ~= '' then
@@ -64,13 +68,19 @@ END_MAKE
 			end
 			device_pkgs = device_pkgs .. ' ' .. pkg
 		end
+		local function handle_pkgs(pkgs)
+			local packages = string.gmatch(pkgs or '', '%S+')
+			for pkg in packages do
+				handle_pkg(pkg)
+			end
+		end
 
 		for _, pkg in ipairs(dev.options.packages or {}) do
 			handle_pkg(pkg)
 		end
-		for pkg in string.gmatch(site_packages(dev.image), '%S+') do
-			handle_pkg(pkg)
-		end
+		handle_pkgs(site_packages(dev.image))
+
+		handle_pkgs(class_packages[dev.options.class])
 
 		funcs.config_message(lib.config, string.format("unable to enable device '%s'", profile),
 			'CONFIG_TARGET_DEVICE_%s_DEVICE_%s=y', openwrt_config_target, profile)
diff --git a/scripts/target_lib.lua b/scripts/target_lib.lua
index f3e372b58..1785c3b3d 100644
--- a/scripts/target_lib.lua
+++ b/scripts/target_lib.lua
@@ -39,6 +39,7 @@ local default_options = {
 	aliases = {},
 	manifest_aliases = {},
 	packages = {},
+	class = "standard",
 	deprecated = false,
 	broken = false,
 }
-- 
GitLab