Boksi is a C89 cross platform library for putting a message box on the screen.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

build 5.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. #!/bin/bash
  2. #************
  3. #***CONFIG***
  4. #************
  5. #If COMPILER isn't set, the script will attempt to figure it out itself.
  6. #If you change the compiler, you'll need to clean your build.
  7. #COMPILER=musl-gcc
  8. #If this isn't set, the script will attempt to find ninja and samu, in that order.
  9. #Alternatives include samurai's "samu"
  10. #NINJACOMMAND=ninja
  11. #Directories
  12. BUILDDIR=meson
  13. BINDIR=bin
  14. LIBDIR=lib
  15. DEPDIR=subprojects
  16. SCRIPTDIR=scripts
  17. #*************
  18. #***LICENSE***
  19. #*************
  20. #
  21. # MIT License
  22. #
  23. # Copyright (c) 2018 Dirkson
  24. #
  25. # Permission is hereby granted, free of charge, to any person obtaining a copy
  26. # of this software and associated documentation files (the "Software"), to deal
  27. # in the Software without restriction, including without limitation the rights
  28. # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  29. # copies of the Software, and to permit persons to whom the Software is
  30. # furnished to do so, subject to the following conditions:
  31. #
  32. # The above copyright notice and this permission notice shall be included in all
  33. # copies or substantial portions of the Software.
  34. #
  35. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  36. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  37. # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  38. # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  39. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  40. # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  41. # SOFTWARE.
  42. #
  43. #Functions
  44. mesonbuild_help () {
  45. echo "Usage: build -mode [target]"
  46. echo "Mode is one of the following:"
  47. echo "-d : debug"
  48. echo "-r : release"
  49. echo "-c : clean"
  50. echo "-a : address sanitizer"
  51. echo "-w : cross-compile for win32"
  52. echo "-w64 : cross-compile for win64"
  53. echo "Target will be passed to ninja directly"
  54. }
  55. mesonbuild_clean () {
  56. rm -rf $BUILDDIR $BINDIR $LIBDIR
  57. }
  58. mesonbuild_symlink () {
  59. FILES="$(find $1 -maxdepth 1 -type f $2 2> /dev/null)"
  60. if [ ! -z "$FILES" ]; then
  61. mkdir -p $3 2> /dev/null
  62. rm -rf $3/* 2> /dev/null
  63. for I in $FILES; do
  64. ln -s ../$I $3/
  65. done
  66. fi
  67. }
  68. mesonbuild_get () {
  69. if [ ! -d "$1" ]; then
  70. $2
  71. if [ ! $? -eq 0 ]; then
  72. echo "Git command failed: $1"
  73. exit 1
  74. fi
  75. if [ ! -d "$1" ]; then
  76. echo "Could not find directory: $1"
  77. exit 1
  78. fi
  79. fi
  80. }
  81. clear
  82. err=0;
  83. if [[ "${BASH_SOURCE[0]}" != "${0}" ]]; then
  84. err=1
  85. echo "Er... Yeah, don't source this file."
  86. return 1
  87. fi
  88. #What type of build?
  89. case "$1" in
  90. -d)
  91. DIR=debug
  92. BLD=debug
  93. MESONOPTS="--werror"
  94. ;;
  95. -a)
  96. DIR=debug
  97. BLD=debug
  98. MESONOPTS=-Db_sanitize=address
  99. MESONOPTS="--werror"
  100. ;;
  101. -r)
  102. DIR=release
  103. BLD=release
  104. ;;
  105. -w)
  106. DIR=release
  107. BLD=release
  108. MESONOPTS="--cross-file scripts/win32cross.txt"
  109. ;;
  110. -w64)
  111. DIR=release
  112. BLD=release
  113. MESONOPTS="--cross-file scripts/win64cross.txt"
  114. ;;
  115. -c)
  116. if [ "$#" -ne 1 ]; then
  117. echo "You passed additional arguments to clean. I have no idea what you want. Did not clean."
  118. exit 1
  119. fi
  120. mesonbuild_clean
  121. rm -rf $DEPDIR
  122. echo "Cleaned."
  123. exit 0
  124. ;;
  125. *)
  126. mesonbuild_help
  127. err=1
  128. ;;
  129. esac
  130. #do some basic error checking for the user
  131. if [ -z "$NINJACOMMAND" ]; then
  132. NINJACOMMAND=ninja
  133. if [ ! -x "$(command -v $NINJACOMMAND)" ]; then
  134. NINJACOMMAND=samu
  135. if [ ! -x "$(command -v $NINJACOMMAND)" ]; then
  136. echo "Neither ninja nor samu are installed. One of the two is required to build."
  137. echo "Please install either samurai's samu of ninja-build's ninja."
  138. err=1;
  139. fi
  140. fi
  141. else
  142. if [ ! -x "$(command -v $NINJACOMMAND)" ]; then
  143. echo "Manually specified ninja command not found"
  144. err=1;
  145. fi
  146. fi
  147. if [ ! -x "$(command -v meson)" ]; then
  148. echo "Meson not installed. The meson build system is required to build, please install.";
  149. err=1;
  150. fi
  151. if [ -z "$COMPILER" ]; then
  152. if [ -x "$(command -v clang)" ]; then
  153. COMPILER="clang"
  154. elif [ -x "$(command -v musl-gcc)" ]; then
  155. COMPILER="musl-gcc -static"
  156. elif [ -x "$(command -v gcc)" ]; then
  157. COMPILER="gcc"
  158. elif [ -x "$(command -v tcc)" ]; then
  159. COMPILER="tcc"
  160. elif [ -x "$(command -v icc)" ]; then
  161. COMPILER="icc"
  162. else
  163. echo "Unable to find any compiler at all. Please install one: clang, musl-gcc, gcc, tcc, icc"
  164. err=1
  165. fi
  166. else
  167. if [ ! -x "$(command -v $COMPILER)" ]; then
  168. echo "Manually specified compiler does not exist. Failing."
  169. err=1
  170. fi
  171. fi
  172. if [ ! -x "$(command -v ccache)" ]; then
  173. echo "ccache not installed. Installing it could speed the build up. Hint Hint.";
  174. fi
  175. if [ "$#" -gt 2 ]; then
  176. echo "Too many parameters. Failing."
  177. mesonbuild_help
  178. echo "Too many parameters. Failing."
  179. err=1;
  180. fi
  181. #Note: For exit '0' is 'true' and '1' in 'false', in spite of all logic.
  182. if [ $err -ne 0 ]; then
  183. exit 1
  184. fi
  185. #Grab dependencies
  186. if [ -d "$SCRIPTDIR" ] && [ -e scripts/dependencies ]; then
  187. mkdir -p $DEPDIR 2> /dev/null
  188. cd "$DEPDIR"
  189. source ../scripts/dependencies
  190. cd ../
  191. fi
  192. #Set up basic directory structure, if needed
  193. mkdir -p $BUILDDIR 2> /dev/null
  194. if [ ! -d "$BUILDDIR/$DIR" ]; then
  195. export CC="$COMPILER"
  196. #Run meson if required
  197. mkdir $BUILDDIR/$DIR
  198. meson $BUILDDIR/$DIR $MESONOPTS --buildtype $BLD
  199. if [ ! $? -eq 0 ]; then
  200. #Generally an error here means we need to clean before the next run
  201. #TODO - We should copy out the log
  202. mesonbuild_clean
  203. exit 1
  204. fi
  205. fi
  206. #Actually build
  207. cd $BUILDDIR/$DIR
  208. $NINJACOMMAND $2
  209. if [ ! $? -eq 0 ]; then
  210. cd ../../
  211. exit 1
  212. fi
  213. cd ../../
  214. #set up symlinks
  215. mesonbuild_symlink "$BUILDDIR/$DIR/*" "-name *.a -o -name *.so -o -name *.dll" $LIBDIR
  216. mesonbuild_symlink "$BUILDDIR/$DIR/*" "-not -name *.so -not -name *.dll -executable -not -name sanitycheckc.exe" $BINDIR
  217. exit 0