summaryrefslogtreecommitdiff
path: root/support
diff options
context:
space:
mode:
Diffstat (limited to 'support')
-rwxr-xr-xsupport/scripts/br2-external115
1 files changed, 75 insertions, 40 deletions
diff --git a/support/scripts/br2-external b/support/scripts/br2-external
index 281a0847b..d634e693c 100755
--- a/support/scripts/br2-external
+++ b/support/scripts/br2-external
@@ -1,9 +1,9 @@
#!/bin/bash
set -e
-# The name and location of the br2-external tree, once validated.
-declare BR2_NAME
-declare BR2_EXT
+# The names and locations of the br2-external trees, once validated.
+declare -a BR2_EXT_NAMES
+declare -A BR2_EXT_PATHS
# URL to manual for help in converting old br2-external trees.
# Escape '#' so that make does not consider it a comment.
@@ -26,13 +26,6 @@ main() {
# Forget options; keep only positional args
shift $((OPTIND-1))
- # Accept 0 or 1 br2-external tree.
- if [ ${#} -gt 1 ]; then
- error "only zero or one br2-external tree allowed.\n"
- fi
-
- br2_ext="${1}"
-
case "${ofmt}" in
mk|kconfig)
;;
@@ -44,13 +37,14 @@ main() {
exec >"${ofile}"
- do_validate "${br2_ext}"
+ do_validate ${@//:/ }
do_${ofmt}
}
-# Validates the br2-external tree passed as argument. Makes it cannonical
-# and store it in global variable BR2_EXT.
+# Validates the br2-external trees passed as arguments. Makes each of
+# them canonical and store them in the global arrays BR2_EXT_NAMES
+# and BR2_EXT_PATHS.
#
# Note: since this script is always first called from Makefile context
# to generate the Makefile fragment before it is called to generate the
@@ -59,14 +53,22 @@ main() {
# snippet means that there were no error.
#
do_validate() {
- local br2_ext="${1}"
- local br2_name n
+ local br2_ext
- # No br2-external tree is valid
- if [ -z "${br2_ext}" ]; then
+ if [ ${#} -eq 0 ]; then
+ # No br2-external tree is valid
return
fi
+ for br2_ext in "${@}"; do
+ do_validate_one "${br2_ext}"
+ done
+}
+
+do_validate_one() {
+ local br2_ext="${1}"
+ local br2_name n
+
if [ ! -d "${br2_ext}" ]; then
error "'%s': no such file or directory\n" "${br2_ext}"
fi
@@ -88,6 +90,10 @@ do_validate() {
error "'%s': name '%s' contains invalid chars: '%s'\n" \
"${br2_ext}" "${br2_name//\$/\$\$}" "${n//\$/\$\$}"
fi
+ if [ -n "${BR2_EXT_PATHS["${br2_name}"]}" ]; then
+ error "'%s': name '%s' is already used in '%s'\n" \
+ "${br2_ext}" "${br2_name}" "${BR2_EXT_PATHS["${br2_name}"]}"
+ fi
if [ ! -f "${br2_ext}/external.mk" ]; then
error "'%s/external.mk': no such file or directory\n" "${br2_ext}"
fi
@@ -95,51 +101,80 @@ do_validate() {
error "'%s/Config.in': no such file or directory\n" "${br2_ext}"
fi
- BR2_NAME="${br2_name}"
- BR2_EXT="$(cd "${br2_ext}"; pwd -P )"
+ # Register this br2-external tree
+ BR2_EXT_NAMES+=( "${br2_name}" )
+ BR2_EXT_PATHS["${br2_name}"]="${br2_ext}"
}
# Generate the .mk snippet that defines makefile variables
# for the br2-external tree
do_mk() {
+ local br2_name br2_ext
+
printf '#\n# Automatically generated file; DO NOT EDIT.\n#\n'
printf '\n'
- printf 'BR2_EXTERNAL ?= %s\n' "${BR2_EXT}"
- printf 'BR2_EXTERNAL_NAME = \n'
- printf 'BR2_EXTERNAL_MK =\n'
+ # We can't use ${BR2_EXT_NAMES[@]} directly: it is not guaranteed
+ # to be in the order paths were added (because it is an associative
+ # array). So we need to iterate on BR2_EXT_NAMES, which is sorted
+ # in the order names were added (because it is an indexed array).
+ printf 'BR2_EXTERNAL ?='
+ for br2_name in "${BR2_EXT_NAMES[@]}"; do
+ printf ' %s' "${BR2_EXT_PATHS["${br2_name}"]}"
+ done
printf '\n'
- if [ -z "${BR2_NAME}" ]; then
+ printf 'BR2_EXTERNAL_NAMES = \n'
+ printf 'BR2_EXTERNAL_DIRS = \n'
+ printf 'BR2_EXTERNAL_MKS = \n'
+
+ if [ ${#BR2_EXT_NAMES[@]} -eq 0 ]; then
+ printf '\n'
printf '# No br2-external tree defined.\n'
return
fi
- printf 'BR2_EXTERNAL_NAME = %s\n' "${BR2_NAME}"
- printf 'BR2_EXTERNAL_MK = %s/external.mk\n' "${BR2_EXT}"
- printf 'BR2_EXTERNAL_%s_PATH = %s\n' "${BR2_NAME}" "${BR2_EXT}"
+ for br2_name in "${BR2_EXT_NAMES[@]}"; do
+ br2_ext="${BR2_EXT_PATHS["${br2_name}"]}"
+ printf '\n'
+ printf 'BR2_EXTERNAL_NAMES += %s\n' "${br2_name}"
+ printf 'BR2_EXTERNAL_%s_PATH = %s\n' "${br2_name}" "${br2_ext}"
+ printf 'BR2_EXTERNAL_DIRS += %s\n' "${br2_ext}"
+ printf 'BR2_EXTERNAL_MKS += %s/external.mk\n' "${br2_ext}"
+ done
}
# Generate the kconfig snippet for the br2-external tree.
do_kconfig() {
+ local br2_name br2_ext
+
printf '#\n# Automatically generated file; DO NOT EDIT.\n#\n'
printf '\n'
- if [ -z "${BR2_NAME}" ]; then
+ if [ ${#BR2_EXT_NAMES[@]} -eq 0 ]; then
printf '# No br2-external tree defined.\n'
return
fi
- printf 'menu "User-provided options"\n'
- printf '\n'
- printf 'comment "%s (in %s)"\n' "${BR2_NAME}" "${BR2_EXT}"
- printf '\n'
- printf 'config BR2_EXTERNAL_%s_PATH\n' "${BR2_NAME}"
- printf '\tstring\n'
- printf '\tdefault "%s"\n' "${BR2_EXT}"
- printf '\n'
- printf 'source "$BR2_EXTERNAL_%s_PATH/Config.in"\n' "${BR2_NAME}"
+ printf 'menu "External options"\n'
printf '\n'
+
+ for br2_name in "${BR2_EXT_NAMES[@]}"; do
+ br2_ext="${BR2_EXT_PATHS["${br2_name}"]}"
+ if [ ${#BR2_EXT_NAMES[@]} -gt 1 ]; then
+ printf 'menu "%s"\n' "${br2_name}"
+ fi
+ printf 'comment "%s (in %s)"\n' "${br2_name}" "${br2_ext}"
+ printf 'config BR2_EXTERNAL_%s_PATH\n' "${br2_name}"
+ printf '\tstring\n'
+ printf '\tdefault "%s"\n' "${br2_ext}"
+ printf 'source "%s/Config.in"\n' "${br2_ext}"
+ if [ ${#BR2_EXT_NAMES[@]} -gt 1 ]; then
+ printf 'endmenu # %s\n' "${br2_name}"
+ fi
+ printf '\n'
+ done
+
printf "endmenu # User-provided options\n"
}
@@ -149,12 +184,12 @@ help() {
${my_name} <-m|-k> -o FILE PATH
With -m, ${my_name} generates the makefile fragment that defines
- variables related to the br2-external tree passed as positional
- argument.
+ variables related to the br2-external trees passed as positional
+ arguments.
With -k, ${my_name} generates the kconfig snippet to include the
- configuration options specified in the br2-external tree passed
- as positional argument.
+ configuration options specified in the br2-external trees passed
+ as positional arguments.
Using -k and -m together is not possible. The last one wins.