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

TARGET="main.cu"
MODULES="matrix.cu"

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

mkdir -p bin

cc=nvcc
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)"
	rm -f           bin/${target}.out
	$cc $ccargs -o bin/${target}.out $modules $inputs
done
