#!/bin/bash

SYSROOT="$(pwd)/sysroot"
# CLANG_PATH=/usr/local/opt/llvm@16/bin
CLANG_PATH="/usr/lib/llvm-14/bin"

export PATH="$CLANG_PATH:$PATH"
export CC="clang"
export CXX="clang++"
export LD="ld.lld"

# export PKG_CONFIG_PATH=$SYSROOT/usr/lib/arm-linux-gnueabihf/pkgconfig
# export CFLAGS="--target=armv7-linux-gnueabihf -march=armv7-a -mfpu=vfpv3-d16 -mfloat-abi=hard --sysroot=$SYSROOT"
# export CXXFLAGS="--target=armv7-linux-gnueabihf -march=armv7-a -mfpu=vfpv3-d16 -mfloat-abi=hard --sysroot=$SYSROOT"
# export LDFLAGS="--target=armv7-linux-gnueabihf -march=armv7-a -mfpu=vfpv3-d16 -mfloat-abi=hard -fuse-ld=lld --sysroot=$SYSROOT"

BUILD_DIR="./build"
# mkdir -p "$BUILD_DIR"
# rm -rf "$BUILD_DIR"/*

rm -rf "$BUILD_DIR"
mkdir -p "$BUILD_DIR"

cd "$BUILD_DIR"

# cmake -GNinja \
#   -DCMAKE_SYSTEM_NAME=Linux \
#   -DCMAKE_SYSROOT="$SYSROOT" \
#   -DUSE_ALSA_ADAPTER=ON \
#   ../../
# #  -DCMAKE_BUILD_TYPE=Debug \
# #  -DCMAKE_C_FLAGS="$CFLAGS -g" \
# #  -DCMAKE_CXX_FLAGS="$CXXFLAGS -g" \
# #  -DCMAKE_EXE_LINKER_FLAGS="$LDFLAGS -g" \
# #  ../../

cmake -GNinja \
  -DCMAKE_SYSTEM_NAME=Linux \
  -DUSE_ALSA_ADAPTER=ON \
  -DCMAKE_BUILD_TYPE=Release \
  -DCMAKE_C_COMPILER="$CC" \
  -DCMAKE_CXX_COMPILER="$CXX" \
  -DCMAKE_C_FLAGS="$CFLAGS" \
  -DCMAKE_CXX_FLAGS="$CXXFLAGS" \
  -DCMAKE_EXE_LINKER_FLAGS="$LDFLAGS" \
  .. 


ninja