build 2.4 KB

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