#!/usr/bin/make -f
export DEB_BUILD_MAINT_OPTIONS = hardening=+all
export DEB_CFLAGS_MAINT_APPEND = -mcpu=cell -mtune=cell
include /usr/share/dpkg/architecture.mk
LIBDIR := usr/lib/$(DEB_HOST_MULTIARCH)

%:
	dh $@

# packages/walnut/tools/ps3-spu/Makefile: `ppe` (libspeq, speq-dxt, speq-bench, spurun) here in the ppc64 chroot,
# `spu` (the SPU programs and the runtime they link) with spu-elf GCC on PATH (our host
# toolchain, tools/deb-build.sh INDEP_PATH)
override_dh_auto_build-arch:
	dh_auto_build -- ppe OUT=b
override_dh_auto_build-indep:
	dh_auto_build -- spu OUT=b SPU_CC=spu-elf-gcc SPU_AR=spu-elf-ar

# speq-dxt --check, the dlopen check, the queue on the fake backend (queue-test,
# speq-bench-fake --quick), synth-test and speq-skin-fake --check, natively (big-endian)
override_dh_auto_test-arch:
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
	$(MAKE) test TEST_OUT=b/test
endif
override_dh_auto_test-indep:

override_dh_auto_install-arch:
	install -D -m 755 b/spurun debian/ps3-spu/usr/lib/ps3/bin/spurun
	install -D -m 755 b/speq-dxt debian/ps3-spu/usr/lib/ps3/bin/speq-dxt
	install -D -m 755 b/speq-bench debian/ps3-spu/usr/lib/ps3/bin/speq-bench
	install -D -m 755 b/speq-skin debian/ps3-spu/usr/lib/ps3/bin/speq-skin
	install -d debian/ps3-spu/usr/bin
	ln -s ../lib/ps3/bin/spurun debian/ps3-spu/usr/bin/spurun
	ln -s ../lib/ps3/bin/speq-dxt debian/ps3-spu/usr/bin/speq-dxt
	ln -s ../lib/ps3/bin/speq-bench debian/ps3-spu/usr/bin/speq-bench
	ln -s ../lib/ps3/bin/speq-skin debian/ps3-spu/usr/bin/speq-skin
	install -D -m 644 debian/spufs.conf debian/ps3-spu/usr/lib/modules-load.d/spufs.conf
	install -D -m 644 b/libspeq.so.0 debian/libspeq0/$(LIBDIR)/libspeq.so.0
	install -D -m 644 lib/speq.h debian/libspeq-dev/usr/include/speq.h
	install -d debian/libspeq-dev/$(LIBDIR)
	ln -s libspeq.so.0 debian/libspeq-dev/$(LIBDIR)/libspeq.so
override_dh_auto_install-indep:
	install -d debian/ps3-spu-programs/usr/lib/ps3/spu
	install -m 644 b/*.spu debian/ps3-spu-programs/usr/lib/ps3/spu/

# SPU ELF objects: the host strip/dwz tools don't know them
override_dh_strip-indep override_dh_dwz-indep override_dh_shlibdeps-indep:

override_dh_auto_clean:
	rm -rf b

# spufs mounted at /spu at boot (debian/ps3-spu.spu.mount)
override_dh_installsystemd-arch:
	dh_installsystemd -p ps3-spu
	dh_installsystemd -p ps3-spu --name=spu
