br2-external 2.1 KB

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