build 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #!/bin/sh
  2. # generic build script, for building components (all of them)
  3. #
  4. # Copyright (C) 2014, 2015, 2020 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. build=./resources/scripts/build
  24. listmodes() {
  25. for mode in "${build}"/*; do
  26. printf '%s\n' "${mode##*/}"
  27. done
  28. }
  29. # Takes exactly one mode as parameter
  30. listoptions() {
  31. for option in "${build}"/"${1}"/*; do
  32. printf '%s\n' "${option##*/}"
  33. done
  34. }
  35. help() {
  36. cat <<- EOF
  37. USAGE: ./build <MODE> <OPTION>
  38. possible values for 'mode':
  39. $(listmodes)
  40. Example: ./build module all
  41. Example: ./build module flashrom [static]
  42. Example: ./build roms withgrub
  43. Example: ./build clean all
  44. Refer to the retroboot documentation for more information.
  45. EOF
  46. }
  47. die() {
  48. printf 'Error: %s\n' "${@}" 1>&2
  49. exit 1
  50. }
  51. if [ $# -lt 1 ]; then
  52. die "Wrong number of arguments specified. See './build help'."
  53. fi
  54. mode="${1}"
  55. [ "${mode}" = help ] && help && exit 0
  56. if [ $# -gt 1 ]; then
  57. option="${2}"
  58. shift 2
  59. case "${option}" in
  60. list)
  61. printf "Available options for mode '%s':\n\n" "${mode}"
  62. listoptions "${mode}"
  63. ;;
  64. all)
  65. for option in $(listoptions "${mode}"); do
  66. "${build}"/"${mode}"/"${option}" $@
  67. done
  68. ;;
  69. *)
  70. if [ -d "${build}"/"${mode}"/ ]; then
  71. if [ -f "${build}"/"${mode}"/"${option}" ]; then
  72. "${build}"/"${mode}"/"${option}" $@
  73. else
  74. help
  75. die "Invalid option for '${mode}'. See './build ${mode} list'."
  76. fi
  77. else
  78. help
  79. die "Invalid mode '${mode}'. See './build help'."
  80. fi
  81. esac
  82. else
  83. help
  84. exit 0
  85. fi