lbmk 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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 [ "${0##*/}" = "blobutil" ]; then
  36. ./update blobs $@ || exit 1
  37. exit 0
  38. elif [ $# -lt 1 ]; then
  39. die "Too few arguments. Try: ${0} help"
  40. fi
  41. buildpath="./resources/scripts/${0##*/}"
  42. mode="${1}"
  43. ./.gitcheck
  44. if [ "${mode}" != "dependencies" ]; then
  45. ./resources/scripts/misc/versioncheck
  46. fi
  47. if [ "${mode}" = help ]; then
  48. usage $0
  49. exit 0
  50. elif [ $# -lt 2 ]; then
  51. usage $0
  52. exit 0
  53. fi
  54. option="${2}"
  55. shift 2
  56. case "${option}" in
  57. list)
  58. printf "Options for mode '%s':\n\n" ${mode}
  59. listoptions "${mode}"
  60. ;;
  61. all)
  62. for option in $(listoptions "${mode}"); do
  63. "${buildpath}/${mode}/${option}" $@
  64. done
  65. ;;
  66. *)
  67. if [ ! -d "${buildpath}/${mode}" ]; then
  68. usage $0
  69. die "Invalid mode '${mode}'. Run: ${0} help"
  70. elif [ ! -f "${buildpath}/${mode}/${option}" ]; then
  71. usage $0
  72. printf "Invalid option for '%s'." ${mode}
  73. die "Run: ${0} ${mode} list'."
  74. fi
  75. "${buildpath}/${mode}/${option}" $@ || die "lbmk error"
  76. esac
  77. ./.gitcheck clean
  78. }
  79. # Takes exactly one mode as parameter
  80. listoptions()
  81. {
  82. for option in "${buildpath}/${1}/"*; do
  83. printf '%s\n' ${option##*/}
  84. done
  85. }
  86. usage()
  87. {
  88. progname=${0}
  89. cat <<- EOF
  90. USAGE: ${progname} <MODE> <OPTION>
  91. possible values for 'mode':
  92. $(listmodes)
  93. Example: ${progname} module all
  94. Example: ${progname} module flashrom [static]
  95. Example: ${progname} roms withgrub
  96. Example: ${progname} clean all
  97. Refer to ${projectname} documentation for more info.
  98. EOF
  99. }
  100. listmodes()
  101. {
  102. for mode in "${buildpath}"/*; do
  103. printf '%s\n' ${mode##*/}
  104. done
  105. }
  106. die()
  107. {
  108. ./.gitcheck clean
  109. printf "Error: %s\n" "${@}" 1>&2
  110. exit 1
  111. }
  112. main $@