#!/bin/sh
cd "$(dirname "$(realpath "$0")")"
set -e
alias log="echo '[build.sh]'"

TARGET="ex1.cu ex2.cu ex3.cu"
MODULES="conv.cu"

if [ $# -gt 0 ]
then targets="$@"
else targets="$TARGET"
fi

rm -fr bin
mkdir -p bin

ccargs="-O2"
#ccargs="$ccargs -g -G -Xcompiler -fsanitize=address"

for target in $targets
do
	sources="$MODULES $target"
	inputs="$(for src in $sources; do echo "src/$src"; done | xargs)"
	nvcc $ccargs -o bin/${target}.out $modules $inputs
	./bin/${target}.out
done
