ogl_beamforming

Ultrasound Beamforming Implemented with OpenGL
git clone anongit@rnpnr.xyz:ogl_beamforming.git
Log | Files | Refs | Feed | Submodules | LICENSE

build.sh (4341B)


      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-function -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 -lSynchronization"
     34 	extra_ldflags="-lSynchronization"
     35 	if [ ! ${NO_MATLAB} ]; then
     36 		libcflags="${libcflags} -DMATLAB_CONSOLE"
     37 		extra_ldflags="${extra_ldflags} -llibmat -llibmex"
     38 	fi
     39 	${cc} ${libcflags} -O3 helpers/ogl_beamformer_lib.c -o helpers/ogl_beamformer_lib.dll \
     40 		-L'C:/Program Files/MATLAB/R2022a/extern/lib/win64/microsoft' \
     41 		${extra_ldflags}
     42 	;;
     43 Linux*)
     44 	glfw="libglfw.so"
     45 	glfw_flags="-D_GLFW_X11"
     46 	raylib="libraylib.so"
     47 	main="main_linux.c"
     48 	libname="beamformer.so"
     49 	cflags="${cflags} -D_DEFAULT_SOURCE"
     50 
     51 	${cc} ${libcflags} -O3 helpers/ogl_beamformer_lib.c -o helpers/ogl_beamformer_lib.so
     52 	;;
     53 esac
     54 
     55 if [ ! -f external/raylib/README.md ] || [ "$(git status --short external/raylib)" ]; then
     56 	git submodule update --init --depth=1 external/raylib
     57 fi
     58 
     59 mkdir -p external/lib
     60 
     61 build_raylib()
     62 {
     63 	cp external/raylib/src/rlgl.h external/include/
     64 	cppflags="${2} -DPLATFORM_DESKTOP_GLFW -DGRAPHICS_API_OPENGL_43"
     65 	cppflags="${cppflags} -Iexternal/raylib/src -Iexternal/raylib/src/external/glfw/include"
     66 
     67 	case ${1} in
     68 	shared)
     69 		${cc} ${cflags} ${cppflags} -fPIC -shared -DBUILD_LIBTYPE_SHARED \
     70 		        external/rcore_extended.c \
     71 		        external/raylib/src/rshapes.c external/raylib/src/rtext.c \
     72 		        external/raylib/src/rtextures.c external/raylib/src/utils.c \
     73 			-o ${raylib}
     74 			;;
     75 	static)
     76 		${cc} ${cflags} ${cppflags} -c external/rcore_extended.c       -o external/lib/rcore.c.o
     77 		${cc} ${cflags} ${cppflags} -c external/raylib/src/rshapes.c   -o external/lib/rshapes.c.o
     78 		${cc} ${cflags} ${cppflags} -c external/raylib/src/rtext.c     -o external/lib/rtext.c.o
     79 		${cc} ${cflags} ${cppflags} -c external/raylib/src/rtextures.c -o external/lib/rtextures.c.o
     80 		${cc} ${cflags} ${cppflags} -c external/raylib/src/utils.c     -o external/lib/utils.c.o
     81 		ar rc external/lib/libraylib.a external/lib/rcore.c.o external/lib/rshapes.c.o \
     82 		      external/lib/rtext.c.o external/lib/rtextures.c.o external/lib/rtextures.c.o \
     83 		      external/lib/utils.c.o
     84 		;;
     85 	esac
     86 }
     87 
     88 check_and_rebuild_libs()
     89 {
     90 	# NOTE(rnp): we need to build glfw separately so that we can use functions from
     91 	# glfw directly - raylib doesn't let us open multiple opengl contexts even if
     92 	# we never plan on using them with raylib
     93 	case "${1}" in
     94 	static)
     95 		if [ "./build.sh" -nt "${glfw}" ] || [ ! -f ${glfw} ]; then
     96 			${cc} ${cflags} ${glfw_flags} -static  \
     97 				-c external/raylib/src/rglfw.c -o external/lib/rglfw.o
     98 			ar rc ${glfw} external/lib/rglfw.o
     99 		fi
    100 		;;
    101 	shared)
    102 		if [ "./build.sh" -nt "${glfw}" ] || [ ! -f "${glfw}" ]; then
    103 			[ "${win32}" ] && glfw_flags="${glfw_flags} -D_GLFW_BUILD_DLL"
    104 			${cc} ${cflags} ${glfw_flags} -fPIC -shared \
    105 				external/raylib/src/rglfw.c -o ${glfw}
    106 		fi
    107 		;;
    108 	esac
    109 	if [ "./build.sh" -nt "${raylib}" ] || [ ! -f "${raylib}" ]; then
    110 		[ ${1} = "static" ] && build_raylib ${1} "-static"
    111 		[ ${1} = "shared" ] && build_raylib ${1} "-L. -lglfw ${ldflags}"
    112 	fi
    113 }
    114 
    115 case "${build}" in
    116 debug)
    117 	cflags="${cflags} -O0 -D_DEBUG -Wno-unused-function"
    118 	if [ "${win32}" ]; then
    119 		# NOTE(rnp): export pdb on win32; requires clang
    120 		cflags="${cflags} -fuse-ld=lld -g -gcodeview -Wl,--pdb="
    121 	else
    122 		cflags="${cflags} -ggdb -Wl,-rpath,."
    123 	fi
    124 	check_and_rebuild_libs "shared"
    125 	ldflags="-L. -lglfw -lraylib ${ldflags}"
    126 	${cc} ${cflags} -fPIC -shared beamformer.c -o ${libname} ${ldflags}
    127 	;;
    128 release)
    129 	cflags="${cflags} -O3"
    130 	raylib="external/lib/libraylib.a"
    131 	glfw="external/lib/libglfw.a"
    132 	ldflags="${raylib} ${glfw} ${ldflags}"
    133 	check_and_rebuild_libs "static"
    134 	;;
    135 esac
    136 
    137 ${cc} ${cflags} -o ogl ${main} ${ldflags}