#!/usr/bin/make -f
# -*- makefile -*-
#
# debian/rules for simgear, by Markus Wanner
# based on the dh7 template provided by dh_make(1)

# http://wiki.debian.org/Hardening#Notes_for_packages_using_CMake
CPPFLAGS:=$(shell dpkg-buildflags --get CPPFLAGS)
ifneq (,$(findstring $(DEB_HOST_ARCH) , amd64 i386 mipsel ia64 armel armhf arm64 ))

# Note the spaces in the condition above. They stop 'mips' from
# matching 'mipsel'
CFLAGS:=$(shell dpkg-buildflags --get CFLAGS) $(CPPFLAGS)
CXXFLAGS:=$(shell dpkg-buildflags --get CXXFLAGS) $(CPPFLAGS)
else

# Required on big-endian architectures, see bug #722115
CFLAGS:=$(shell dpkg-buildflags --get CFLAGS) $(CPPFLAGS) -fno-strict-aliasing
CXXFLAGS:=$(shell dpkg-buildflags --get CXXFLAGS) $(CPPFLAGS) -fno-strict-aliasing
endif
LDFLAGS:=$(shell dpkg-buildflags --get LDFLAGS)

CMAKE_FLAGS = \
	-DCMAKE_BUILD_TYPE="RelWithDebInfo" \
	-DCMAKE_C_FLAGS="$(CFLAGS)" \
	-DCMAKE_CXX_FLAGS="$(CXXFLAGS)" \
	-DCMAKE_CXX_FLAGS_RELWITHDEBINFO="-g -DNDEBUG" \
	-DCMAKE_SHARED_LINKER_FLAGS="$(LDFLAGS)" \
	-DCMAKE_VERBOSE_MAKEFILE=ON \
	-DCMAKE_INSTALL_PREFIX:PATH=/usr \
	-DSIMGEAR_SHARED=OFF \
	-DSYSTEM_EXPAT=ON \
	-DENABLE_DNS=ON

%:
	dh $@ --buildsystem=cmake --builddirectory=build --parallel

override_dh_auto_configure:
	mkdir build
	cd build && cmake .. $(CMAKE_FLAGS)

override_dh_clean:
	dh_clean
	rm -rf CMakeFiles

override_dh_auto_test:
	DEB_BUILD_OPTIONS=$(patsubst \
		parallel=%,parallel=1,$(DEB_BUILD_OPTIONS)) \
		dh_auto_test

get-orig-source:
	uscan --download-current-version --verbose --rename
