diff mbox

[OpenWrt-Devel,13/14] target/sdk: Allow building a more complete SDK from within an SDK

Message ID 1451800982-112057-14-git-send-email-openwrt@daniel.thecshore.com
State Rejected
Headers show

Commit Message

Daniel Dickinson Jan. 3, 2016, 6:03 a.m. UTC
From: Daniel Dickinson <openwrt@daniel.thecshore.com>

This patch allows using and SDK to build additional packages to
create a more complete SDK (e.g. you could start with a base
system SDK and use it to create an SDK that has libraries from
both base and packages feed).  This allows for new workflows
that build a common base and then branch in different directions
depending on the type of system being build (e.g. router vs.
NAS).

Signed-off-by: Daniel Dickinson <openwrt@daniel.thecshore.com>
---
 .gitignore                    |  3 +-
 config/Config-build.in        |  2 ++
 config/Config-version.in      | 26 ++++++++---------
 target/Makefile               |  6 ++--
 target/imagebuilder/Config.in |  1 +
 target/sdk/Config-in-sdk.in   |  8 ++++++
 target/sdk/Config.in          | 20 +++++++++++++
 target/sdk/Makefile           | 67 +++++++++++++++++++++++++++++++++++++++----
 target/sdk/files/Config.in    | 20 +++++++++++--
 target/sdk/files/Makefile     | 10 +++++--
 10 files changed, 135 insertions(+), 28 deletions(-)
 create mode 100644 target/sdk/Config-in-sdk.in

Comments

Felix Fietkau Jan. 3, 2016, 3 p.m. UTC | #1
On 2016-01-03 07:03, openwrt@daniel.thecshore.com wrote:
> From: Daniel Dickinson <openwrt@daniel.thecshore.com>
> 
> This patch allows using and SDK to build additional packages to
> create a more complete SDK (e.g. you could start with a base
> system SDK and use it to create an SDK that has libraries from
> both base and packages feed).  This allows for new workflows
> that build a common base and then branch in different directions
> depending on the type of system being build (e.g. router vs.
> NAS).
> 
> Signed-off-by: Daniel Dickinson <openwrt@daniel.thecshore.com>
I'm not sure I like where this is going. I think this is encouraging
people too much to reuse other people's binary crap without regard for
shipping proper corresponding source code.
I certainly would not like to see proliferation of such SDKs in the
wild, as many people and organizations tend to be careless about
shipping corresponding source code.
Even though it may take a bit longer to build, I'd much rather have SDKs
contain forks of relevant source packages instead.

- Felix
diff mbox

Patch

diff --git a/.gitignore b/.gitignore
index cd86e34..eb85c1f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -15,7 +15,8 @@ 
 /files
 /package/feeds
 /package/openwrt-packages
-key-build*
+key-base*
+key-sdk*
 *.orig
 *.rej
 *~
diff --git a/config/Config-build.in b/config/Config-build.in
index 5867f53..bf10922 100644
--- a/config/Config-build.in
+++ b/config/Config-build.in
@@ -21,6 +21,8 @@  menu "Global build settings"
 	config BUILD_KEY_TYPE
 		string
 		prompt "Name for build key with signed package lists"
+		default "base" if !IN_SDK
+		default "sdk" if IN_SDK
 		depends on SIGNED_PACKAGES
 
 	comment "General build options"
diff --git a/config/Config-version.in b/config/Config-version.in
index f995b92..e48afd9 100644
--- a/config/Config-version.in
+++ b/config/Config-version.in
@@ -96,18 +96,18 @@  if VERSIONOPT
 			Enable this to include the version number in firmware image, SDK-
 			and Image Builder archive file names
 
-	config VERSION_FLAVOUR
-		string
-		prompt "Release flavour"
-		help
-			This is an optional string that gets added to
-			output filenames and is part of the version id,
-			which identifies a 'flavour' of build (for example
-			for differentiating between SDK's/images build with
-			NAS vs router appropriate settings).
-			It is enabled by default when using the SDK
-			and building a second SDK (so filenames will
-			be distinct).
-
 endif
 
+config VERSION_FLAVOUR
+	string
+	prompt "Release flavour" if (VERSIONOPT || IN_SDK)
+	help
+		This is an optional string that gets added to
+		output filenames and is part of the version id,
+		which identifies a 'flavour' of build (for example
+		for differentiating between SDK's/images build with
+		NAS vs router appropriate settings).
+		It is enabled by default when using the SDK
+		and building a second SDK (so filenames will
+		be distinct).
+
diff --git a/target/Makefile b/target/Makefile
index cb68454..420d87b 100644
--- a/target/Makefile
+++ b/target/Makefile
@@ -6,9 +6,9 @@ 
 #
 curdir:=target
 
-$(curdir)/builddirs:=linux sdk imagebuilder toolchain
-$(curdir)/builddirs-default:=linux
-$(curdir)/builddirs-install:=linux $(if $(CONFIG_SDK),sdk) $(if $(CONFIG_IB),imagebuilder) $(if $(CONFIG_MAKE_TOOLCHAIN),toolchain)
+$(curdir)/builddirs:=$(if $(CONFIG_IN_SDK),,linux) sdk $(if $(CONFIG_IN_SDK),,imagebuilder toolchain)
+$(curdir)/builddirs-default:=$(if $(CONFIG_IN_SDK),,linux)
+$(curdir)/builddirs-install:=$(if $(CONFIG_IN_SDK),,linux) $(if $(CONFIG_SDK),sdk) $(if $(CONFIG_IN_SDK),,$(if $(CONFIG_IB),imagebuilder) $(if $(CONFIG_MAKE_TOOLCHAIN),toolchain))
 
 $(curdir)/imagebuilder/install:=$(curdir)/linux/install
 
diff --git a/target/imagebuilder/Config.in b/target/imagebuilder/Config.in
index 9f50b46..af29411 100644
--- a/target/imagebuilder/Config.in
+++ b/target/imagebuilder/Config.in
@@ -9,6 +9,7 @@  config IB
 
 config IB_STANDALONE
 	bool "Include package repositories"
+	default n if SDK_CORE
 	default y
 	depends on IB
 	help
diff --git a/target/sdk/Config-in-sdk.in b/target/sdk/Config-in-sdk.in
new file mode 100644
index 0000000..7ed95dc
--- /dev/null
+++ b/target/sdk/Config-in-sdk.in
@@ -0,0 +1,8 @@ 
+config SDK
+	bool "Build the OpenWrt SDK"
+	depends on !EXTERNAL_TOOLCHAIN || EXTERNAL_TOOLCHAIN_SDK
+	help
+	  Build a second-stage SDK that contain everything in this
+	  SDK plus the STAGING_DIR results of compiling packages
+	  selected for build.
+
diff --git a/target/sdk/Config.in b/target/sdk/Config.in
index 1a82149..52fb30a 100644
--- a/target/sdk/Config.in
+++ b/target/sdk/Config.in
@@ -6,4 +6,24 @@  config SDK
 	  with a precompiled toolchain. It can be used to develop and
 	  test packages for OpenWrt before including them in the buildroot
 
+config SDK_CORE
+	bool "Build SDK with only Buildroot and Kernel"
+	depends on !EXTERNAL_TOOLCHAIN || EXTERNAL_TOOLCHAIN_SDK
+	depends on SDK
+
+	help
+	  This consists only the build machinery (e.g. toolchain),
+          kernel, and all packages from the source packages on which
+          the build machinery and toolchain depend (and likewise for
+          the full dependency chain).  It is intended to be able build
+          all packages including base packages and the 'full' SDK (that
+          is an SDK with STAGING_DIR populated with the results of
+          InstallDev sections of packages in base), but this core SDK
+          only the dependency to satisfy itself; to be useful one must
+	  build the dependencies for other packages (e.g. by taking this
+          SDK and adding the base feed and building what this SDK doesn't
+          provide (and that build can build the 'full' SDK).
+	  All packages selected by default by this option come from
+	  a source package on which there is a dependency from toolchain or
+          kernel being built.
 
diff --git a/target/sdk/Makefile b/target/sdk/Makefile
index 9b1c192..57c2c8a 100644
--- a/target/sdk/Makefile
+++ b/target/sdk/Makefile
@@ -66,7 +66,59 @@  KERNEL_FILES := $(patsubst $(TOPDIR)/%,%,$(wildcard $(addprefix $(LINUX_DIR)/,$(
 all: compile
 
 $(BIN_DIR)/$(SDK_NAME).tar.bz2: clean
+	rm -rf $(SDK_BUILD_DIR)/package
 	mkdir -p $(SDK_BUILD_DIR)/dl $(SDK_BUILD_DIR)/package
+	# The package Makefile is always needed
+	rm -f $(SDK_BUILD_DIR)/package/Makefile
+	$(CP) \
+		$(TOPDIR)/package/Makefile \
+		$(SDK_BUILD_DIR)/package/
+	# We want to always sign package builds unless deliberately turned off
+	# rm -f $(SDK_BUILD_DIR)/package/signing-key
+	$(CP) \
+		$(TOPDIR)/package/signing-key \
+		$(SDK_BUILD_DIR)/package/
+
+	# Busybox loooks in package subdir for Config.in files
+ 	# So let busybox work from SDK if present (e.g. via base feed)
+	# Note that the feed name must be base for this to work
+	# It would be non-trivial to genericize this
+	mkdir -p $(SDK_BUILD_DIR)/package/utils
+	rm -f $(SDK_BUILD_DIR)/package/utils/busybox
+	ln -s \
+		../../package/feeds/base/busybox \
+		$(SDK_BUILD_DIR)/package/utils/busybox
+
+	# Use placeholders for KConfig definitions not present in SDK (via conversion from
+	# .config to placeholders that maintain the current setting)
+	# Includes making sure signing key is used by default
+	mkdir -p $(SDK_BUILD_DIR)/config
+	$(TOPDIR)/target/convert-config.pl $(TOPDIR)/.config > $(SDK_BUILD_DIR)/config/fromdotconfig.in
+	# Mangle .config and suitable defaults for SDK
+	# Especially base kernel modules shouldn't be attempted to be rebuilt from SDK
+	case "$(BUILD_KEY_TYPE)" in \
+	sdk*) SDKNUM="$$(echo "$(BUILD_KEY_TYPE)" | sed -e 's/sdk\(.*\)/\1/')" ; \
+		if [ "$$SDKNUM" = "" ]; \
+		then export SDKNUM=0; \
+		fi; \
+		export SDKNUM=$$((SDKNUM + 2)) ; \
+		export NEXTSDKNUM=$$((SDKNUM + 1)) ; \
+		;; \
+	*) export SDKNUM="" ; \
+		export NEXTSDKNUM=2 ; \
+		;; \
+	esac; \
+		sed -e 's/CONFIG_SDK_CORE=y/# CONFIG_SDK_CORE is not set/' $(TOPDIR)/.config | \
+		sed -e 's/CONFIG_SDK=y/# CONFIG_SDK is not set/' | \
+		sed -e 's/CONFIG_ALL_KMODS=y/# CONFIG_ALL_KMODS is not set/' | \
+		sed -e 's/^#\? *CONFIG_ALL\(=\| is\).*/CONFIG_ALL=y/' | \
+		sed -e 's/CONFIG_BUILD_KEY_TYPE="base"/CONFIG_BUILD_KEY_TYPE="sdk"/' | \
+		sed -e 's/CONFIG_IB=y/# CONFIG_IB is not set/' | \
+		sed -e 's/CONFIG_MAKE_TOOLCHAIN=y/# CONFIG_MAKE_TOOLCHAIN is not set/' | \
+		sed -e "s/CONFIG_VERSION_FLAVOUR=\"\\(Stage[0-9]*\\)\\?\"/CONFIG_VERSION_FLAVOUR=\"Stage$${NEXTSDKNUM}\"/" | \
+		sed -e '$$a\CONFIG_IN_SDK=y' | \
+		sed -e "s/CONFIG_BUILD_KEY_TYPE=\"sdk[0-9]*\"/CONFIG_BUILD_KEY_TYPE=\"sdk$${SDKNUM}\"/" | \
+		sed -e "/CONFIG_PACKAGE_signing-key/a\\CONFIG_PACKAGE_signing-key-sdk$${SDKNUM}=m" >$(SDK_BUILD_DIR)/.config
 	$(CP) $(INCLUDE_DIR) $(SCRIPT_DIR) $(TOPDIR)/docs $(SDK_BUILD_DIR)/
 	$(TAR) -cf - -C $(TOPDIR) \
 		$(foreach exclude,$(EXCLUDE_DIRS),--exclude="$(exclude)") \
@@ -92,23 +144,26 @@  $(BIN_DIR)/$(SDK_NAME).tar.bz2: clean
 	rm -rf \
 		$(SDK_BUILD_DIR)/target/linux/*/files* \
 		$(SDK_BUILD_DIR)/target/linux/*/patches*
-	$(TOPDIR)/target/convert-config.pl $(TOPDIR)/.config > $(SDK_BUILD_DIR)/Config-build.in
+	mkdir -p $(SDK_BUILD_DIR)/target
+	$(CP) $(TOPDIR)/target/{sdk,Makefile,convert-config.pl} $(SDK_BUILD_DIR)/target/
 	$(CP) -L \
 		$(TOPDIR)/LICENSE \
 		$(TOPDIR)/rules.mk \
-		$(TOPDIR)/.config \
+		$(TOPDIR)/config \
 		./files/Config.in \
 		./files/Makefile \
 		./files/include/prepare.mk \
 		./files/README.SDK \
 		$(SDK_BUILD_DIR)/
-	$(CP) \
-		$(TOPDIR)/package/Makefile \
-		$(SDK_BUILD_DIR)/package/
-
 	# Prevent feeds install and/or rebuilt of packages already built (unless
 	# forced).
 	mkdir -p $(SDK_BUILD_DIR)/$(STAGING_DIR_TARGET)/pkgstamp
+	# SDK from SDK should remember previous SDK's built packages
+	if [ -d $(TOPDIR)/pkgstamp ]; then \
+		$(CP) \
+			$(TOPDIR)/pkgstamp \
+			$(SDK_BUILD_DIR)/; \
+	fi
 	-$(CP) $(STAGING_DIR)/pkgstamp-current/* $(SDK_BUILD_DIR)/pkgstamp/
 	-rm -f $(SDK_BUILD_DIR)/feeds.conf.default
 	$(if $(BASE_FEED),echo "$(BASE_FEED)" > $(SDK_BUILD_DIR)/feeds.conf.default)
diff --git a/target/sdk/files/Config.in b/target/sdk/files/Config.in
index 45f2faf..bce71f2 100644
--- a/target/sdk/files/Config.in
+++ b/target/sdk/files/Config.in
@@ -4,14 +4,28 @@ 
 # See /LICENSE for more information.
 #
 
+mainmenu "OpenWrt Configuration"
+
+source "config/fromdotconfig.in"
+
 config MODULES
+	option modules
 	bool
 	default y
-	option modules
 
-mainmenu "OpenWrt Configuration"
+config HAVE_DOT_CONFIG
+	bool
+	default y
+
+config IN_SDK
+	bool	
+	default y
+
+source "target/sdk/Config-in-sdk.in"
+
+source "config/Config-build.in"
 
-source "Config-build.in"
+source "config/Config-devel.in"
 
 source "config/Config-version.in"
 
diff --git a/target/sdk/files/Makefile b/target/sdk/files/Makefile
index 2edf7b3..86d309d 100644
--- a/target/sdk/files/Makefile
+++ b/target/sdk/files/Makefile
@@ -31,9 +31,15 @@  else
   include rules.mk
   include $(INCLUDE_DIR)/depends.mk
   include $(INCLUDE_DIR)/subdir.mk
+  include target/Makefile
   include package/Makefile
 
-$(package/stamp-compile): $(BUILD_DIR)/.prepared
+$(package/stamp-compile): $(BUILD_DIR)/.prepared $(target/stamp-cleanup)
+$(package/stamp-markforsdk): $(package/stamp-compile)
+$(package/stamp-install): $(package/stamp-compile) $(package/stamp-markforsdk)
+$(target/stamp-compile): $(package/stamp-compile) $(package/stamp-markforsdk)
+$(target/stamp-install): $(package/stamp-compile) $(package/stamp-markforsdk) $(target/stamp-compile)
+
 $(BUILD_DIR)/.prepared: Makefile
 	@mkdir -p $$(dirname $@)
 	@touch $@
@@ -51,7 +57,7 @@  dirclean: clean
 # check prerequisites before starting to build
 prereq: $(package/stamp-prereq) ;
 
-world: prepare $(package/stamp-compile) FORCE
+world: prepare $(target/stamp-compile) $(package/stamp-compile) $(target/stamp-install) FORCE
 	@$(MAKE) package/index
 
 .PHONY: clean dirclean prereq prepare world