From ab6596115a58b1bb984c366431cd6926a5c3c2ef Mon Sep 17 00:00:00 2001
From: Matthias Schiffer <mschiffer@universe-factory.net>
Date: Mon, 11 May 2020 23:08:02 +0200
Subject: [PATCH] build: introduce GLUON_AUTOREMOVE flag

---
 Makefile                      | 5 +++--
 contrib/actions/run-build.sh  | 1 +
 docs/user/getting_started.rst | 6 ++++++
 targets/generic               | 5 +++++
 4 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/Makefile b/Makefile
index 7358cac6c..b220afe9f 100644
--- a/Makefile
+++ b/Makefile
@@ -44,6 +44,7 @@ $(eval $(call mkabspath,GLUON_TARGETSDIR))
 $(eval $(call mkabspath,GLUON_PATCHESDIR))
 
 GLUON_MULTIDOMAIN ?= 0
+GLUON_AUTOREMOVE ?= 0
 GLUON_DEBUG ?= 0
 GLUON_MINIFY ?= 1
 
@@ -54,8 +55,8 @@ src-link gluon_base ../../package
 endef
 
 GLUON_VARS = \
-	GLUON_RELEASE GLUON_REGION GLUON_MULTIDOMAIN GLUON_DEBUG GLUON_MINIFY GLUON_DEPRECATED GLUON_DEVICES \
-	GLUON_TARGETSDIR GLUON_PATCHESDIR GLUON_TMPDIR GLUON_IMAGEDIR GLUON_PACKAGEDIR \
+	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_SITEDIR GLUON_RELEASE GLUON_BRANCH GLUON_LANGS GLUON_BASE_FEEDS \
 	GLUON_TARGET BOARD SUBTARGET
 
diff --git a/contrib/actions/run-build.sh b/contrib/actions/run-build.sh
index 62b641ad0..c68816306 100755
--- a/contrib/actions/run-build.sh
+++ b/contrib/actions/run-build.sh
@@ -1,6 +1,7 @@
 #!/bin/bash
 
 export BROKEN=1
+export GLUON_AUTOREMOVE=1
 export GLUON_DEPRECATED=1
 export GLUON_SITEDIR="contrib/ci/minimal-site"
 export GLUON_TARGET=$1
diff --git a/docs/user/getting_started.rst b/docs/user/getting_started.rst
index f4be37fdf..64d7aed4e 100644
--- a/docs/user/getting_started.rst
+++ b/docs/user/getting_started.rst
@@ -208,6 +208,12 @@ GLUON_TARGET
 Special variables
 .................
 
+GLUON_AUTOREMOVE
+  Setting ``GLUON_AUTOREMOVE=1`` enables the ``CONFIG_AUTOREMOVE`` OpenWrt setting, which will delete package build
+  directories after a package build has finished to save space. This is mostly useful for CI builds from scratch. Do
+  not set this flag during development (or generally, when you want you reuse your build tree for subsequent builds),
+  as it significantly increases incremental build times.
+
 GLUON_DEBUG
   Setting ``GLUON_DEBUG=1`` will provide firmware images including debugging symbols usable with GDB or
   similar tools. Requires a device or target with at least 16 MB of flash space, e.g. `x86-64`. Unset by default.
diff --git a/targets/generic b/targets/generic
index 7672833de..702f52bd2 100644
--- a/targets/generic
+++ b/targets/generic
@@ -31,6 +31,7 @@ end
 
 config '# CONFIG_TARGET_ROOTFS_INITRAMFS is not set'
 
+config 'CONFIG_DEVEL=y'
 config 'CONFIG_ALL_NONSHARED=y'
 
 config '# CONFIG_PACKAGE_usbip is not set' -- fails to build
@@ -51,6 +52,10 @@ if istrue(env.GLUON_MULTIDOMAIN) then
 	config 'CONFIG_GLUON_MULTIDOMAIN=y'
 end
 
+if istrue(env.GLUON_AUTOREMOVE) then
+	config 'CONFIG_AUTOREMOVE=y'
+end
+
 if istrue(env.GLUON_DEBUG) then
 	config 'CONFIG_DEBUG=y'
 	config 'CONFIG_NO_STRIP=y'
-- 
GitLab