64e12a370c
Now that we generate a kconfig snippet, we can conditionally include the BR2_EXTERNAL's Config.in only when BR2_EXTERNAL is supplied by the user, which means our empty/dummy Config.in is no needed. As for external.mk, we can also include it only when BR2_EXTERNAL is supplied by the user, which means our empty/dummy external.mk is no longer needed. Ditch both of those files, and: - only generate actual content in the Kconfig snippet when we actually do have a BR2_EXTERNAL provided by the user (i.e. BR2_EXTERNAL is not empty); - add a variable that contains the path to the external.mk provided by the user, or empty if none, and include the path set in that variable (make can 'include' nothing without any problem! ;-) ) 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> Cc: Julien CORJON <corjon.j@ecagroup.com> Signed-off-by: Peter Korsgaard <peter@korsgaard.com>
101 lines
2.3 KiB
Bash
Executable File
101 lines
2.3 KiB
Bash
Executable File
#!/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))
|
|
|
|
# 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}"
|
|
|
|
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}"
|
|
|
|
# No br2-external tree is valid
|
|
if [ -z "${br2_ext}" ]; then
|
|
return
|
|
fi
|
|
|
|
if [ ! -d "${br2_ext}" ]; then
|
|
error "'%s': no such file or directory\n" "${br2_ext}"
|
|
fi
|
|
if [ ! -r "${br2_ext}" -o ! -x "${br2_ext}" ]; then
|
|
error "'%s': permission denied\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'
|
|
|
|
if [ -z "${BR2_EXT}" ]; then
|
|
printf '# No br2-external tree defined.\n'
|
|
return
|
|
fi
|
|
|
|
printf 'config BR2_EXTERNAL\n'
|
|
printf '\tstring\n'
|
|
printf '\tdefault "%s"\n' "${BR2_EXT}"
|
|
printf '\n'
|
|
printf 'menu "User-provided options"\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 "${@}"
|