build 2.5 KB

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