lbmk 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. #!/usr/bin/env sh
  2. # generic script for calling other scripts in lbmk
  3. #
  4. # Copyright (C) 2014,2015,2020,2021,2023 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. [ "x${DEBUG+set}" = 'xset' ] && set -v
  23. set -u -e
  24. projectname="$(cat projectname)"
  25. buildpath=""
  26. mode=""
  27. option=""
  28. main()
  29. {
  30. if [ "${0##*/}" = "lbmk" ]; then
  31. die "Do not run the lbmk script directly!"
  32. elif [ "${0##*/}" = "download" ]; then
  33. ./update module $@ || exit 1
  34. exit 0
  35. elif [ $# -lt 1 ]; then
  36. die "Too few arguments. Try: ${0} help"
  37. fi
  38. buildpath="./resources/scripts/${0##*/}"
  39. mode="${1}"
  40. ./.gitcheck
  41. if [ "${mode}" != "dependencies" ]; then
  42. ./resources/scripts/misc/versioncheck
  43. fi
  44. if [ "${mode}" = help ]; then
  45. usage $0
  46. exit 0
  47. elif [ $# -lt 2 ]; then
  48. usage $0
  49. exit 0
  50. fi
  51. option="${2}"
  52. shift 2
  53. case "${option}" in
  54. list)
  55. printf "Options for mode '%s':\n\n" ${mode}
  56. listoptions "${mode}"
  57. ;;
  58. all)
  59. for option in $(listoptions "${mode}"); do
  60. "${buildpath}/${mode}/${option}" $@
  61. done
  62. ;;
  63. *)
  64. if [ ! -d "${buildpath}/${mode}" ]; then
  65. usage $0
  66. die "Invalid mode '${mode}'. Run: ${0} help"
  67. elif [ ! -f "${buildpath}/${mode}/${option}" ]; then
  68. usage $0
  69. printf "Invalid option for '%s'." ${mode}
  70. die "Run: ${0} ${mode} list'."
  71. fi
  72. "${buildpath}/${mode}/${option}" $@ || die "lbmk error"
  73. esac
  74. ./.gitcheck clean
  75. }
  76. # Takes exactly one mode as parameter
  77. listoptions()
  78. {
  79. for option in "${buildpath}/${1}/"*; do
  80. printf '%s\n' ${option##*/}
  81. done
  82. }
  83. usage()
  84. {
  85. progname=${0}
  86. cat <<- EOF
  87. USAGE: ${progname} <MODE> <OPTION>
  88. possible values for 'mode':
  89. $(listmodes)
  90. Example: ${progname} module all
  91. Example: ${progname} module flashrom [static]
  92. Example: ${progname} roms withgrub
  93. Example: ${progname} clean all
  94. Refer to ${projectname} documentation for more info.
  95. EOF
  96. }
  97. listmodes()
  98. {
  99. for mode in "${buildpath}"/*; do
  100. printf '%s\n' ${mode##*/}
  101. done
  102. }
  103. die()
  104. {
  105. ./.gitcheck clean
  106. printf "Error: %s\n" "${@}" 1>&2
  107. exit 1
  108. }
  109. main $@