#!/usr/bin/make -f
# You must remove unused comment lines for the released package.
#export DH_VERBOSE = 1
export DEB_BUILD_MAINT_OPTIONS = hardening=+all
#export DEB_CFLAGS_MAINT_APPEND  = -Wall -pedantic
#export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed

DPKG_EXPORT_BUILDFLAGS = 1
include /usr/share/dpkg/buildflags.mk

include /usr/share/dpkg/architecture.mk

include /usr/share/dpkg/buildtools.mk

# Produce .debug_info (used by dh_dwz)
CXXFLAGS += -g

# Enable PIE
#CXXFLAGS += -fpie
#LDFLAGS += -pie

#stackrpms,2: I put APP_NAME_SUFFIX in Makefile
# libatomic stuff is for ubuntu only

%:
	dh $@ --sourcedirectory=FreeFileSync/Source

execute_after_dh_auto_clean:
	# Now, auto_clean RealTimeSync
	dh_auto_clean --sourcedirectory=FreeFileSync/Source/RealTimeSync

execute_after_dh_auto_build:
	# Now, auto_build RealTimeSync
	dh_auto_build --sourcedirectory=FreeFileSync/Source/RealTimeSync

override_dh_auto_install:
	# desktop files
	# handled by dh_install through debian/install

	# mimetypes
	# handled by dh_installmime through debian/sharedmimeinfo

	# icons
	unzip -u FreeFileSync/Build/Resources/Icons.zip cfg_batch.png database.png start_sync.png FreeFileSync.png RealTimeSync.png
	for size in 16 24 32 48 64 128 256; do \
	  mkdir -p debian/tmp/usr/share/icons/hicolor/$${size}x$${size}/apps ; \
	  convert FreeFileSync.png -filter Lanczos -resize $${size}x$${size} debian/tmp/usr/share/icons/hicolor/$${size}x$${size}/apps/FreeFileSync.png ; \
	  convert RealTimeSync.png -filter Lanczos -resize $${size}x$${size} debian/tmp/usr/share/icons/hicolor/$${size}x$${size}/apps/RealTimeSync.png ; \
	  mkdir -p debian/tmp/usr/share/icons/hicolor/$${size}x$${size}/mimetypes ; \
	  convert cfg_batch.png -filter Lanczos -resize $${size}x$${size} debian/tmp/usr/share/icons/hicolor/$${size}x$${size}/mimetypes/application-x-freefilesync-batch.png ; \
	  convert database.png -filter Lanczos -resize $${size}x$${size} debian/tmp/usr/share/icons/hicolor/$${size}x$${size}/mimetypes/application-x-freefilesync-db.png ; \
	  convert start_sync.png -filter Lanczos -resize $${size}x$${size} debian/tmp/usr/share/icons/hicolor/$${size}x$${size}/mimetypes/application-x-freefilesync-gui.png ; \
	  convert RealTimeSync.png -filter Lanczos -resize $${size}x$${size} debian/tmp/usr/share/icons/hicolor/$${size}x$${size}/mimetypes/application-x-freefilesync-real.png ; \
	done
