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 6.4KB

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