core: do not hard-code inclusion of br2-external in Kconfig
[buildroot-gz.git] / support / scripts / br2-external
blob6c2b85b5ca61f6d9ce8fb06419f4c805bfe0c981
1 #!/bin/bash
2 set -e
4 # The location of the br2-external tree, once validated.
5 declare BR2_EXT
7 main() {
8 local OPT OPTARG
9 local br2_ext ofile
11 while getopts :ho: OPT; do
12 case "${OPT}" in
13 h) help; exit 0;;
14 o) ofile="${OPTARG}";;
15 :) error "option '%s' expects a mandatory argument\n" "${OPTARG}";;
16 \?) error "unknown option '%s'\n" "${OPTARG}";;
17 esac
18 done
19 # Forget options; keep only positional args
20 shift $((OPTIND-1))
22 if [ ${#} -ne 1 ]; then
23 error "need exactly one br2-external tree to be specified\n"
25 br2_ext="${1}"
27 if [ -z "${ofile}" ]; then
28 error "no output file specified (-o)\n"
31 do_validate "${br2_ext}"
33 do_kconfig >"${ofile}"
36 # Validates the br2-external tree passed as argument. Makes it cannonical
37 # and store it in global variable BR2_EXT.
38 do_validate() {
39 local br2_ext="${1}"
41 if [ ! -d "${br2_ext}" ]; then
42 error "'%s': no such file or directory\n" "${br2_ext}"
44 if [ ! -r "${br2_ext}" -o ! -x "${br2_ext}" ]; then
45 error "'%s': permission denied\n" "${br2_ext}"
48 BR2_EXT="$(cd "${br2_ext}"; pwd -P )"
51 # Generate the kconfig snippet for the br2-external tree.
52 do_kconfig() {
53 printf '#\n# Automatically generated file; DO NOT EDIT.\n#\n'
54 printf '\n'
55 printf 'config BR2_EXTERNAL\n'
56 printf '\tstring\n'
57 printf '\tdefault "%s"\n' "${BR2_EXT}"
58 printf '\n'
59 printf 'menu "User-provided options"\n'
60 printf '\tdepends on BR2_EXTERNAL != "support/dummy-external"\n'
61 printf '\n'
62 printf 'source "%s/Config.in"\n' "${BR2_EXT}"
63 printf '\n'
64 printf "endmenu # User-provided options\n"
67 help() {
68 cat <<-_EOF_
69 Usage:
70 ${my_name} -o FILE PATH
72 ${my_name} generates the kconfig snippet to include the configuration
73 options specified in the br2-external tree passed as positional argument.
75 Options:
76 -o FILE
77 FILE in which to generate the kconfig snippet.
79 Returns:
80 0 If no error
81 !0 If any error
82 _EOF_
85 error() { local fmt="${1}"; shift; printf "%s: ${fmt}" "${my_name}" "${@}" >&2; exit 1; }
87 my_name="${0##*/}"
88 main "${@}"