#!/usr/bin/make -f

# Don't enable pie, otherwise the unit tests don't work.
export DEB_BUILD_MAINT_OPTIONS = hardening=+bindnow

# Append CPPFLAGS, because cmake doesn't know that.
CFLAGS += $(CPPFLAGS)
CXXFLAGS += $(CPPFLAGS)

# Use this variable to allow options passed to cmake to be overridable
DEB_CMAKE_OPTIONS ?= -DCMAKE_VERBOSE_MAKEFILE=ON \
                     -DCMAKE_INSTALL_PREFIX="/usr" \
		     -DCMAKE_C_FLAGS="$(CFLAGS)" \
		     -DCMAKE_CXX_FLAGS="$(CXXFLAGS)"

DEB_ASE_CMAKE_OPTIONS ?= -DENABLE_UPDATER:BOOL=OFF \
                         -DUSE_SHARED_CURL:BOOL=ON \
                         -DUSE_SHARED_GIFLIB:BOOL=ON \
                         -DUSE_SHARED_JPEGLIB:BOOL=ON \
                         -DUSE_SHARED_LIBPNG:BOOL=ON \
                         -DUSE_SHARED_ZLIB:BOOL=ON \
                         -DUSE_SHARED_TINYXML:BOOL=ON \
                         -DUSE_SHARED_GTEST:BOOL=ON \
                         -DUSE_SHARED_ALLEGRO4:BOOL=ON \
                         -DUSE_SHARED_LIBLOADPNG:BOOL=ON

%:
	dh $@ --parallel

override_dh_auto_clean:
	rm -rf build

override_dh_auto_configure:
	mkdir build && cd build && cmake $(DEB_CMAKE_OPTIONS) $(DEB_ASE_CMAKE_OPTIONS) ..
	mkdir build/gtest && cd build/gtest && cmake $(DEB_CMAKE_OPTIONS) /usr/src/gtest

override_dh_auto_build:
	dh_auto_build -Dbuild/gtest
	dh_auto_build -Dbuild

override_dh_auto_test:
	$(MAKE) --directory=build run_non_ui_unittests

override_dh_auto_install:
	dh_auto_install -Dbuild
	install -D -m 644 data/icons/ase16.png debian/aseprite/usr/share/icons/hicolor/16x16/apps/aseprite.png
	install -D -m 644 data/icons/ase32.png debian/aseprite/usr/share/icons/hicolor/32x32/apps/aseprite.png
	install -D -m 644 data/icons/ase48.png debian/aseprite/usr/share/icons/hicolor/48x48/apps/aseprite.png
	install -D -m 644 data/icons/ase64.png debian/aseprite/usr/share/icons/hicolor/64x64/apps/aseprite.png

override_dh_installchangelogs:
	dh_installchangelogs -k debian/upstream-changelog
