#!/usr/bin/make -f
# -*- makefile -*-

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

TMPDIR = $(CURDIR)/debian/objcryst-fox

include /usr/share/dpkg/buildflags.mk

# The package's SSE fast-math path (ObjCryst/Quirks/sse_mathfun.h, guarded by
# HAVE_SSE_MATHFUN/USE_SSE2) includes x86-only intrinsics headers
# (<xmmintrin.h>/<emmintrin.h>) and is compiled with -march=native.  These do
# not exist on non-x86 architectures (arm64/loong64/riscv64), so disable the
# SSE path there; the code falls back to the plain C++ implementation.
DEB_HOST_ARCH ?= $(shell dpkg-architecture -qDEB_HOST_ARCH)
ifneq ($(filter amd64 i386 x32,$(DEB_HOST_ARCH)),)
SSE_ARGS =
else
SSE_ARGS = sse=0
endif

%:
	dh $@ --buildsystem=makefile

override_dh_auto_build:
	dh_auto_build --sourcedir=Fox -- --file=gnu.mak shared-fftw=1 \
		 shared-wxgtk=1 shared-glut=1 shared-newmat=1 shared-boost=0 \
		 shared-cctbx=1 RPM_OPT_FLAGS="$(CXXFLAGS)" $(SSE_ARGS)

override_dh_auto_clean:
	dh_auto_clean --sourcedir=Fox -- --file=gnu.mak
	rm -rf Fox/sglite/*.o Fox/sglite/*.a Fox/atominfo/*.o Fox/atominfo/*.a
	rm -f Fox-LastOptimizationStop.xml
	rm -rf static-libs

override_dh_auto_install:
	# Install the package into debian/objcryst-fox and rename executable to "fox"
	dh_auto_install --sourcedir=Fox -- --file=gnu.mak DESTDIR=$(TMPDIR)/usr/bin
	mv $(TMPDIR)/usr/bin/Fox $(TMPDIR)/usr/bin/fox
	dh_install debian/fox.xpm usr/share/pixmaps/
	dh_install debian/fox.desktop usr/share/applications/
	# Install the example files
	cp -a Fox/example $(TMPDIR)/usr/share/doc/objcryst-fox/
	rm -rf $(TMPDIR)/usr/share/doc/objcryst-fox/example/.svn
	rm -rf $(TMPDIR)/usr/share/doc/objcryst-fox/example/tutorial-*/.svn
