#!/usr/bin/make -f
# -*- makefile -*-
# Sample debian/rules that uses debhelper.
#
# This file was originally written by Joey Hess and Craig Small.
# As a special exception, when this file is copied by dh-make into a
# dh-make output file, you may use that output file without restriction.
# This special exception was added by Craig Small in version 0.37 of dh-make.
#
# Modified to make a template file for a multi-binary package with separated
# build-arch and build-indep targets  by Bill Allombert 2001

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

# Uncomment to view all compilation commands and fix W-compiler-flags-hidden
export VERBOSE=1

# Add 'atomic' build flag to mak sure armel and mipsel compile
ifneq (,$(filter $(DEB_HOST_ARCH), armel mipsel m68k sh4))
  export DEB_LDFLAGS_MAINT_APPEND += -Wl,--no-as-needed -latomic -Wl,--as-needed
endif

#CMake silently ignores CPPFLAGS. Below will properly set CFLAGS/CXXFLAGS
#https://wiki.debian.org/Hardening#Notes_for_packages_using_CMake
CPPFLAGS:=$(shell dpkg-buildflags --get CPPFLAGS)
CFLAGS:=$(shell dpkg-buildflags --get CFLAGS) $(CPPFLAGS)
CXXFLAGS:=$(shell dpkg-buildflags --get CXXFLAGS) $(CPPFLAGS)
LDFLAGS:=$(shell dpkg-buildflags --get LDFLAGS)

override_dh_auto_configure:
	dh_auto_configure -- -DCMAKE_INSTALL_PREFIX=/usr -DBINDIR=/usr/games -DCMAKE_BUILD_TYPE="RelWithDebInfo" -DUSE_SYSTEM_TINYXML="TRUE" -DCMAKE_VERBOSE_MAKEFILE="FALSE" -DBUILD_MYGUI_PLUGIN="FALSE" -DOPENMW_USE_SYSTEM_RECASTNAVIGATION=On

override_dh_auto_build:
	# False positive from blhc. See #1125781.
	@echo 'blhc: ignore-line-regexp: /usr/(bin|lib)/(ccache/)?c\+\+ (?:-std=\S+ )?-w -dM -E (?:-c )?/usr/share/cmake-[0-9.]+/Modules/CMakeCXXCompilerABI.cpp .*'
	dh_auto_build

override_dh_installchangelogs:
	dh_installchangelogs CHANGELOG.md

# Fail to build if some files were not installed anywhere
override_dh_install:
	dh_install --exclude=usr/lib/lib*.a --exclude=usr/include/*.h  -Xlicenses
	dh_missing --list-missing --exclude=usr/lib/lib*.a --exclude=usr/include/*.h  -Xlicenses


%:
	dh $@ --builddirectory=build
