#! /bin/bash
export CXX=clang++
export CC=clang
export HIPCXX=clang++
export PATH=/usr/lib/llvm-21/bin:$PATH

archbuild(){
	local gpuarch=$1
	[ -d build/$gpuarch ] || mkdir -p build/$gpuarch
	[ -d build/$gpuarch/_deps ] || mkdir -p build/$gpuarch/_deps
	[ -L build/$gpuarch/_deps/gtest-src ] || \
		ln -s /usr/src/googletest build/$gpuarch/_deps/gtest-src
        (cd build/$gpuarch && \
		DEB_PYTHON_INSTALL_LAYOUT=deb \
		PKG_CONFIG=/usr/bin/pkg-config \
		cmake -DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_SYSCONFDIR=/etc \
		-DCMAKE_INSTALL_LOCALSTATEDIR=/var \
		-DCMAKE_FIND_USE_PACKAGE_REGISTRY=OFF \
		-DFETCHCONTENT_FULLY_DISCONNECTED=ON \
		-DCMAKE_INSTALL_RUNSTATEDIR=/run \
		-DCMAKE_PREFIX_PATH=/usr \
		-DCMAKE_SKIP_INSTALL_ALL_DEPENDENCY=ON \
		"-GUnix Makefiles" \
		-DCMAKE_VERBOSE_MAKEFILE=ON \
		-DCMAKE_CXX_COMPILER=/usr/bin/hipcc \
		-DCMAKE_INSTALL_LIBDIR=/usr/lib/x86_64-linux-gnu \
		-DCMAKE_INSTALL_INCLUDEDIR=/usr/include \
		-DCMAKE_BUILD_TYPE=Release \
		-DCMAKE_C_FLAGS="-U_FORTIFY_SOURCE" \
		-DCMAKE_CXX_FLAGS="-U_FORTIFY_SOURCE" \
		-DHIP_PLATFORM=amd \
		-DBUILD_TESTING=ON \
		-DGPU_TARGETS="$gpuarch" ../..
	)
		#-DUSE_SYSTEM_CK=ON \
		#
}

for arch in gfx908 gfx90a gfx942 gfx950 gfx10-3-generic gfx11-generic gfx12-generic
do
	archbuild $arch
done

# Build test with:
# make -j tests CXX_FLAGS="-Wno-character-conversion -Wno-missing-variable-declarations"
