build 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. #!/bin/sh
  2. # generic build script, for building components (all of them)
  3. #
  4. # Copyright (C) 2014, 2015, 2020, 2021 Leah Rowe <info@minifree.org>
  5. # Copyright (C) 2015 Patrick "P. J." McDermott <pj@pehjota.net>
  6. # Copyright (C) 2015, 2016 Klemens Nanni <contact@autoboot.org>
  7. #
  8. # This program is free software: you can redistribute it and/or modify
  9. # it under the terms of the GNU General Public License as published by
  10. # the Free Software Foundation, either version 3 of the License, or
  11. # (at your option) any later version.
  12. #
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU General Public License
  19. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. #
  21. [ "x${DEBUG+set}" = 'xset' ] && set -v
  22. set -u -e
  23. projectname="$(cat projectname)"
  24. ./resources/scripts/misc/versioncheck
  25. build=./resources/scripts/build
  26. listmodes() {
  27. for mode in "${build}"/*; do
  28. printf '%s\n' "${mode##*/}"
  29. done
  30. }
  31. # Takes exactly one mode as parameter
  32. listoptions() {
  33. for option in "${build}"/"${1}"/*; do
  34. printf '%s\n' "${option##*/}"
  35. done
  36. }
  37. help() {
  38. cat <<- EOF
  39. USAGE: ./build <MODE> <OPTION>
  40. possible values for 'mode':
  41. $(listmodes)
  42. Example: ./build module all
  43. Example: ./build module flashrom [static]
  44. Example: ./build roms withgrub
  45. Example: ./build clean all
  46. Refer to the ${projectname} documentation for more information.
  47. EOF
  48. }
  49. die() {
  50. printf 'Error: %s\n' "${@}" 1>&2
  51. exit 1
  52. }
  53. if [ $# -lt 1 ]; then
  54. die "Wrong number of arguments specified. See './build help'."
  55. fi
  56. mode="${1}"
  57. [ "${mode}" = help ] && help && exit 0
  58. if [ $# -gt 1 ]; then
  59. option="${2}"
  60. shift 2
  61. case "${option}" in
  62. list)
  63. printf "Available options for mode '%s':\n\n" "${mode}"
  64. listoptions "${mode}"
  65. ;;
  66. all)
  67. for option in $(listoptions "${mode}"); do
  68. "${build}"/"${mode}"/"${option}" $@
  69. done
  70. ;;
  71. *)
  72. if [ -d "${build}"/"${mode}"/ ]; then
  73. if [ -f "${build}"/"${mode}"/"${option}" ]; then
  74. "${build}"/"${mode}"/"${option}" $@
  75. else
  76. help
  77. die "Invalid option for '${mode}'. See './build ${mode} list'."
  78. fi
  79. else
  80. help
  81. die "Invalid mode '${mode}'. See './build help'."
  82. fi
  83. esac
  84. else
  85. help
  86. exit 0
  87. fi