All of lore.kernel.org
 help / color / mirror / Atom feed
From: Yann E. MORIN <yann.morin.1998@free.fr>
To: buildroot@busybox.net
Subject: [Buildroot] [PATCH 1/9 v4] core: do not hard-code inclusion of br2-external in Kconfig
Date: Mon,  5 Sep 2016 23:49:34 +0200	[thread overview]
Message-ID: <5304e7067c629517a0f1a8b7a24d9f7fbb0bce23.1473109655.git.yann.morin.1998@free.fr> (raw)
In-Reply-To: <cover.1473109655.git.yann.morin.1998@free.fr>

Move the inclusion of br2-external's Config.in to the generated kconfig
snippet.

This will ultimately allow us to use more than one br2-external tree.

Offload the "User-provided options" menu to the generated Kconfig
snippet. We can also move the definition of the Kconfig-version of
BR2_EXTERNAL into this snippet.

Signed-off-by: "Yann E. MORIN" <yann.morin.1998@free.fr>
Cc: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
Cc: Arnout Vandecappelle <arnout@mind.be>
Cc: Romain Naour <romain.naour@openwide.fr>
---
 Config.in                    | 11 ------
 Makefile                     |  2 +-
 support/scripts/br2-external | 85 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 86 insertions(+), 12 deletions(-)
 create mode 100755 support/scripts/br2-external

diff --git a/Config.in b/Config.in
index 3f53f25..65d8832 100644
--- a/Config.in
+++ b/Config.in
@@ -14,10 +14,6 @@ config BR2_HOSTARCH
 	string
 	option env="HOSTARCH"
 
-config BR2_EXTERNAL
-	string
-	option env="BR2_EXTERNAL"
-
 config BR2_BUILD_DIR
 	string
 	option env="BUILD_DIR"
@@ -761,11 +757,4 @@ source "package/Config.in.host"
 
 source "Config.in.legacy"
 
-menu "User-provided options"
-	depends on BR2_EXTERNAL != "support/dummy-external"
-
-source "$BR2_EXTERNAL/Config.in"
-
-endmenu
-
 source "$BR2_BUILD_DIR/.br2-external.in"
diff --git a/Makefile b/Makefile
index dfef021..513a989 100644
--- a/Makefile
+++ b/Makefile
@@ -886,7 +886,7 @@ endif
 # value of BR2_EXTERNAL is changed.
 .PHONY: $(BUILD_DIR)/.br2-external.in
 $(BUILD_DIR)/.br2-external.in: $(BUILD_DIR)
-	@touch $@
+	$(Q)support/scripts/br2-external -o "$(@)" $(BR2_EXTERNAL)
 
 # printvars prints all the variables currently defined in our
 # Makefiles. Alternatively, if a non-empty VARS variable is passed,
diff --git a/support/scripts/br2-external b/support/scripts/br2-external
new file mode 100755
index 0000000..c15c21c
--- /dev/null
+++ b/support/scripts/br2-external
@@ -0,0 +1,85 @@
+#!/bin/bash
+set -e
+
+# The location of the br2-external tree, once validated.
+declare BR2_EXT
+
+main() {
+    local OPT OPTARG
+    local br2_ext ofile
+
+    while getopts :ho: OPT; do
+        case "${OPT}" in
+        h)  help; exit 0;;
+        o)  ofile="${OPTARG}";;
+        :)  error "option '%s' expects a mandatory argument\n" "${OPTARG}";;
+        \?) error "unknown option '%s'\n" "${OPTARG}";;
+        esac
+    done
+    # Forget options; keep only positional args
+    shift $((OPTIND-1))
+
+    if [ ${#} -ne 1 ]; then
+        error "need exactly one br2-external tree to be specified\n"
+    fi
+    br2_ext="${1}"
+
+    if [ -z "${ofile}" ]; then
+        error "no output file specified (-o)\n"
+    fi
+
+    do_validate "${br2_ext}"
+
+    do_kconfig >"${ofile}"
+}
+
+# Validates the br2-external tree passed as argument. Makes it cannonical
+# and store it in global variable BR2_EXT.
+do_validate() {
+    local br2_ext="${1}"
+
+    if [ ! -d "${br2_ext}" ]; then
+        error "'%s': no such file or directory\n" "${br2_ext}"
+    fi
+
+    BR2_EXT="$(cd "${br2_ext}"; pwd -P )"
+}
+
+# Generate the kconfig snippet for the br2-external tree.
+do_kconfig() {
+    printf '#\n# Automatically generated file; DO NOT EDIT.\n#\n'
+    printf '\n'
+    printf 'config BR2_EXTERNAL\n'
+    printf '\tstring\n'
+    printf '\tdefault "%s"\n' "${BR2_EXT}"
+    printf '\n'
+    printf 'menu "User-provided options"\n'
+    printf '\tdepends on BR2_EXTERNAL != "support/dummy-external"\n'
+    printf '\n'
+    printf 'source "%s/Config.in"\n' "${BR2_EXT}"
+    printf '\n'
+    printf "endmenu # User-provided options\n"
+}
+
+help() {
+    cat <<-_EOF_
+	Usage:
+	    ${my_name} -o FILE PATH
+
+	${my_name} generates the kconfig snippet to include the configuration
+	options specified in the br2-external tree passed as positional argument.
+
+	Options:
+	    -o FILE
+	        FILE in which to generate the kconfig snippet.
+
+	Returns:
+	    0   If no error
+	    !0  If any error
+	_EOF_
+}
+
+error()  { local fmt="${1}"; shift; printf "%s: ${fmt}" "${my_name}" "${@}" >&2; exit 1; }
+
+my_name="${0##*/}"
+main "${@}"
-- 
2.7.4

  reply	other threads:[~2016-09-05 21:49 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-05 21:49 [Buildroot] [PATCH 0/9 v4] br2-external: support multiple trees at once (branch yem/multi-br2-external-10) Yann E. MORIN
2016-09-05 21:49 ` Yann E. MORIN [this message]
2016-09-05 21:49 ` [Buildroot] [PATCH 2/9 v4] core: get rid of our dummy br2-external tree Yann E. MORIN
2016-09-06 10:21   ` Julien CORJON
2016-09-06 20:49     ` Yann E. MORIN
2016-09-05 21:49 ` [Buildroot] [PATCH 3/9 v4] core: offload handling of BR2_EXTERNAL into the script Yann E. MORIN
2016-09-05 21:49 ` [Buildroot] [PATCH 4/9 v4] core/br2-external: validate even more Yann E. MORIN
2016-09-05 21:49 ` [Buildroot] [PATCH 5/9 v4] core: introduce per br2-external NAME Yann E. MORIN
2016-09-05 21:49 ` [Buildroot] [PATCH 6/9 v4] docs/manual: document the " Yann E. MORIN
2016-09-06 10:21   ` Julien CORJON
2016-09-06 20:58     ` Yann E. MORIN
2016-09-05 21:49 ` [Buildroot] [PATCH 7/9 v4] core: add support for multiple br2-external trees Yann E. MORIN
2016-09-06 10:21   ` Julien CORJON
2016-09-05 21:49 ` [Buildroot] [PATCH 8/9 v4] docs/manual: document multi br2-external Yann E. MORIN
2016-09-05 21:49 ` [Buildroot] [PATCH 9/9 v4] docs/manual: add appendix to convert old br2-external trees Yann E. MORIN
2016-09-06 10:21   ` Julien CORJON
2016-09-06 21:06     ` Yann E. MORIN
2016-09-06 10:29 ` [Buildroot] [PATCH 0/9 v4] br2-external: support multiple trees at once (branch yem/multi-br2-external-10) Yann E. MORIN

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5304e7067c629517a0f1a8b7a24d9f7fbb0bce23.1473109655.git.yann.morin.1998@free.fr \
    --to=yann.morin.1998@free.fr \
    --cc=buildroot@busybox.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.