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

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

TARGET_BUILD=iwyu-build
VERSION=$(shell dpkg-parsechangelog |grep "^Version:"|sed -e "s|Version: \(.*\)|\1|")
DEB_BUILD_ARCH?=$(shell dpkg-architecture -qDEB_BUILD_ARCH)
ADDITIONAL_CXX_FLAGS=""

ifneq (,$(filter $(DEB_BUILD_ARCH),mips64el))
	ADDITIONAL_CXX_FLAGS += -mxgot
endif

%:
	dh $@ --buildsystem=cmake --builddirectory=$(TARGET_BUILD)

override_dh_auto_configure:
	dh_auto_configure -- -DCMAKE_CXX_FLAGS="$(ADDITIONAL_CXX_FLAGS)" -DLLVM_PATH=/usr/lib/llvm-5.0/


override_dh_auto_build:
	dh_auto_build
	help2man --no-info --version-string "$(VERSION)" -n "Analyze #includes in C and C++ source files" $(TARGET_BUILD)/include-what-you-use > $(TARGET_BUILD)/include-what-you-use.1
	cd $(TARGET_BUILD) && ln -s include-what-you-use.1 iwyu.1 && \
	cp ../fix_includes.py fix_include

override_dh_auto_install:
	dh_auto_install
	cd debian/iwyu/usr/bin; \
		rm -f fix_includes.py; \
		mv iwyu_tool.py iwyu_tool


override_dh_auto_clean:
	rm -rf $(TARGET_BUILD)
