From cedfe135ab102ac2f8390dd82b496de3c383d3cc Mon Sep 17 00:00:00 2001
From: Felix Fietkau <nbd@openwrt.org>
Date: Mon, 10 Mar 2014 18:58:49 +0000
Subject: [PATCH] target/sdk: generate a Config.in file with the settings of
 the build that the SDK was generated from

This allows make oldconfig/menuconfig to run

Signed-off-by: Felix Fietkau <nbd@openwrt.org>

SVN-Revision: 39864
---
 target/sdk/Makefile          |  1 +
 target/sdk/convert-config.pl | 31 +++++++++++++++++++++++++++++++
 target/sdk/files/Config.in   |  1 +
 3 files changed, 33 insertions(+)
 create mode 100755 target/sdk/convert-config.pl

diff --git a/target/sdk/Makefile b/target/sdk/Makefile
index 2318f4d09b..376aef8eb0 100644
--- a/target/sdk/Makefile
+++ b/target/sdk/Makefile
@@ -64,6 +64,7 @@ $(BIN_DIR)/$(SDK_NAME).tar.bz2: clean
 	rm -rf \
 		$(SDK_BUILD_DIR)/target/linux/*/files* \
 		$(SDK_BUILD_DIR)/target/linux/*/patches*
+	./convert-config.pl $(TOPDIR)/.config > $(SDK_BUILD_DIR)/Config-build.in
 	$(CP) -L \
 		$(TOPDIR)/LICENSE \
 		$(TOPDIR)/rules.mk \
diff --git a/target/sdk/convert-config.pl b/target/sdk/convert-config.pl
new file mode 100755
index 0000000000..9fd2c362e6
--- /dev/null
+++ b/target/sdk/convert-config.pl
@@ -0,0 +1,31 @@
+#!/usr/bin/env perl
+use strict;
+
+while (<>) {
+	chomp;
+	next unless /^CONFIG_([^=]+)=(.*)$/;
+
+	my $var = $1;
+	my $val = $2;
+	my $type;
+
+	if ($val eq 'y') {
+		$type = "bool";
+	} elsif ($val eq 'm') {
+		$type = "tristate";
+	} elsif ($val =~ /^".*"$/) {
+		$type = "string";
+	} elsif ($val =~ /^\d+$/) {
+		$type = "int";
+	} else {
+		warn "WARNING: no type found for symbol CONFIG_$var=$val\n";
+		next;
+	}
+
+	print <<EOF;
+config $var
+	$type
+	default $val
+
+EOF
+}
diff --git a/target/sdk/files/Config.in b/target/sdk/files/Config.in
index 214466b5b2..4a2f12e74f 100644
--- a/target/sdk/files/Config.in
+++ b/target/sdk/files/Config.in
@@ -1 +1,2 @@
+source "Config-build.in"
 source "tmp/.config-package.in"
-- 
GitLab