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

export DPKG_GENSYMBOLS_CHECK_LEVEL=4
export CONTENT_HUB_TESTING=1
export DEB_BUILD_MAINT_OPTIONS=hardening=+all

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)

ifneq (,$(findstring cross,$(DEB_BUILD_PROFILES)))
  PROJECT_DH_OPTIONS = --with click
else
  PROJECT_DH_OPTIONS = --with click,translations
endif

# Enable Ubuntu.Content compatibility layer in UBports build.
CONFIGURE_OPTS := -DENABLE_UBUNTU_COMPAT=ON

ifneq (,$(findstring nocheck,$(DEB_BUILD_OPTIONS)))
  CONFIGURE_OPTS += -DENABLE_TESTS=OFF
  DEB_BUILD_PROFILES += noinsttest
endif

ifneq (,$(findstring nodoc,$(DEB_BUILD_OPTIONS)))
  CONFIGURE_OPTS += -DENABLE_DOC=OFF
endif

%:
	dh $@ $(PROJECT_DH_OPTIONS) --with migrations -- -B build

override_dh_missing:
	dh_missing --fail-missing

override_dh_auto_test:
	dh_auto_test --no-parallel

override_dh_auto_configure:
	dh_auto_configure -- $(CONFIGURE_OPTS)

override_dh_auto_install:
ifneq (,$(findstring nocheck,$(DEB_BUILD_PROFILES)))
	mkdir -p debian/content-hub-testability
endif
	dh_auto_install
	dh_apparmor -pcontent-hub-testability --profile-name=content-hub-testability
	mkdir -p debian/tmp/var/cache/content-hub/peers

override_dh_translations:
	make -C po content-hub.pot
