build.sh (4580B)
1 #!/bin/sh 2 3 # NOTE(rnp): to rebuild raylib run `touch build.sh` (or delete the so/dll) 4 5 cflags="-march=native -std=c11 -Wall -I./external/include" 6 #cflags="${cflags} -fsanitize=address,undefined" 7 #cflags="${cflags} -fproc-stat-report" 8 #cflags="${cflags} -Rpass-missed=.*" 9 libcflags="${cflags} -fPIC -shared -Wno-unused-variable" 10 ldflags="-lm" 11 12 cc=${CC:-cc} 13 build=release 14 15 for arg in $@; do 16 case "$arg" in 17 clang) cc=clang ;; 18 gcc) cc=gcc ;; 19 debug) build=debug ;; 20 release) build=release ;; 21 *) echo "usage: $0 [release|debug] [gcc|clang]"; exit 1;; 22 esac 23 done 24 25 case $(uname -sm) in 26 MINGW64*) 27 win32=1 28 glfw="libglfw.dll" 29 glfw_flags="-lgdi32 -lwinmm" 30 raylib="libraylib.dll" 31 main="main_w32.c" 32 libname="beamformer.dll" 33 ldflags="${ldflags} -lgdi32 -lwinmm" 34 if [ ! ${NO_MATLAB} ]; then 35 libcflags="${libcflags} -DMATLAB_CONSOLE" 36 extra_ldflags="-llibmat -llibmex" 37 fi 38 ${cc} ${libcflags} helpers/ogl_beamformer_lib.c -o helpers/ogl_beamformer_lib.dll \ 39 -L'C:/Program Files/MATLAB/R2022a/extern/lib/win64/microsoft' \ 40 ${extra_ldflags} 41 ;; 42 Linux*) 43 glfw="libglfw.so.3" 44 glfw_flags="-D_GLFW_X11" 45 raylib="libraylib.so" 46 main="main_linux.c" 47 libname="beamformer.so" 48 cflags="${cflags} -D_DEFAULT_SOURCE" 49 50 ${cc} ${libcflags} helpers/ogl_beamformer_lib.c -o helpers/ogl_beamformer_lib.so 51 ;; 52 esac 53 54 if [ ! -f external/raylib/README.md ] || [ "$(git status --short external/raylib)" ]; then 55 git submodule update --init --depth=1 external/raylib 56 fi 57 58 mkdir -p external/lib 59 60 build_raylib() 61 { 62 cp external/raylib/src/raylib.h external/raylib/src/rlgl.h external/include/ 63 cppflags="${2} -DPLATFORM_DESKTOP_GLFW -DGRAPHICS_API_OPENGL_43" 64 cppflags="${cppflags} -Iexternal/raylib/src -Iexternal/raylib/src/external/glfw/include" 65 66 case ${1} in 67 shared) 68 ${cc} ${cflags} ${cppflags} -fPIC -shared -DBUILD_LIBTYPE_SHARED \ 69 external/raylib/src/raudio.c external/raylib/src/rcore.c \ 70 external/raylib/src/rmodels.c external/raylib/src/rshapes.c \ 71 external/raylib/src/rtext.c external/raylib/src/rtextures.c \ 72 external/raylib/src/utils.c \ 73 -o ${raylib} 74 ;; 75 static) 76 ${cc} ${cflags} ${cppflags} -c external/raylib/src/raudio.c -o external/lib/raudio.c.o 77 ${cc} ${cflags} ${cppflags} -c external/raylib/src/rcore.c -o external/lib/rcore.c.o 78 ${cc} ${cflags} ${cppflags} -c external/raylib/src/rmodels.c -o external/lib/rmodels.c.o 79 ${cc} ${cflags} ${cppflags} -c external/raylib/src/rshapes.c -o external/lib/rshapes.c.o 80 ${cc} ${cflags} ${cppflags} -c external/raylib/src/rtext.c -o external/lib/rtext.c.o 81 ${cc} ${cflags} ${cppflags} -c external/raylib/src/rtextures.c -o external/lib/rtextures.c.o 82 ${cc} ${cflags} ${cppflags} -c external/raylib/src/utils.c -o external/lib/utils.c.o 83 ar rc external/lib/libraylib.a external/lib/raudio.c.o external/lib/rcore.c.o \ 84 external/lib/rmodels.c.o external/lib/rshapes.c.o external/lib/rtext.c.o \ 85 external/lib/rtextures.c.o external/lib/rtextures.c.o external/lib/utils.c.o 86 ;; 87 esac 88 } 89 90 check_and_rebuild_libs() 91 { 92 # NOTE(rnp): we need to build glfw separately so that we can use functions from 93 # glfw directly - raylib doesn't let us open multiple opengl contexts even if 94 # we never plan on using them with raylib 95 case "${1}" in 96 static) 97 if [ "./build.sh" -nt "${glfw}" ] || [ ! -f ${glfw} ]; then 98 ${cc} ${cflags} ${glfw_flags} -static \ 99 -c external/raylib/src/rglfw.c -o external/lib/rglfw.o 100 ar rc ${glfw} external/lib/rglfw.o 101 fi 102 ;; 103 shared) 104 if [ "./build.sh" -nt "${glfw}" ] || [ ! -f "${glfw}" ]; then 105 [ "${win32}" ] && glfw_flags="${glfw_flags} -D_GLFW_BUILD_DLL" 106 ${cc} ${cflags} ${glfw_flags} -fPIC -shared \ 107 external/raylib/src/rglfw.c -o ${glfw} 108 fi 109 ;; 110 esac 111 if [ "./build.sh" -nt "${raylib}" ] || [ ! -f "${raylib}" ]; then 112 [ ${1} = "static" ] && build_raylib ${1} "-static" 113 [ ${1} = "shared" ] && build_raylib ${1} "-L. -lglfw ${ldflags}" 114 fi 115 } 116 117 case "${build}" in 118 debug) 119 cflags="${cflags} -O0 -D_DEBUG -Wno-unused-function" 120 if [ "${win32}" ]; then 121 # NOTE(rnp): export pdb on win32; requires clang 122 cflags="${cflags} -fuse-ld=lld -g -gcodeview -Wl,--pdb=" 123 else 124 cflags="${cflags} -ggdb -Wl,-rpath,." 125 fi 126 check_and_rebuild_libs "shared" 127 ldflags="-L. -lglfw -lraylib ${ldflags}" 128 ${cc} ${cflags} -fPIC -shared beamformer.c -o ${libname} ${ldflags} 129 ;; 130 release) 131 cflags="${cflags} -O3" 132 raylib="external/lib/libraylib.a" 133 glfw="external/lib/libglfw.a" 134 ldflags="${raylib} ${glfw} ${ldflags}" 135 check_and_rebuild_libs "static" 136 ;; 137 esac 138 139 ${cc} ${cflags} -o ogl ${main} ${ldflags}