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

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

include /usr/share/dpkg/pkg-info.mk
VER  ?= $(shell sh -c 'printf "$${1%%+repack*}"' -- "$(DEB_VERSION_UPSTREAM)")
$(info VER=$(VER))

$(info DEB_BUILD_OPTIONS:$(origin DEB_BUILD_OPTIONS)=$(DEB_BUILD_OPTIONS))

export DEB_BUILD_MAINT_OPTIONS = hardening=+all
$(info DEB_BUILD_MAINT_OPTIONS:$(origin DEB_BUILD_MAINT_OPTIONS)=$(DEB_BUILD_MAINT_OPTIONS))

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

%:
	dh $@ --builddirectory=_build --with quilt

override_dh_quilt_patch:
## Patch for Bookworm:
	if dpkg --compare-versions $$(dpkg --status libimgui-dev | grep Version | cut -d' ' -f2) lt 1.89; then \
            echo "series_bookworm" > .pc/.quilt_series ;\
        fi
	dh_quilt_patch


override_dh_auto_configure:
	cp -a cmake-modules cmake/external/rpavlik-cmake-modules
	cp -a librocket lib/libRocket
	cp -a lib/imgui/extensions code/imgui_extensions
	dh_auto_configure -- \
            -DCMAKE_BUILD_TYPE=Release \
            -DCMAKE_INSTALL_PREFIX=/usr/games/ \
        ;

#execute_after_dh_auto_build:
#	## building developer's documentation
#	doxygen _build/fs2open.Doxyfile

execute_after_dh_auto_clean:
	$(RM) -rf code/imgui_extensions
	$(RM) -rf lib/libRocket
	$(RM) -rf cmake/external/rpavlik-cmake-modules

override_dh_link:
	dh_link \
            /usr/games/fs2_open_$(VER)         /usr/games/fs2_open \
            /usr/games/fs2_open                /usr/share/games/freespace2-open/fs2_open \
            /usr/games/fs2_open_$(VER)         /usr/share/games/freespace2-open/fs2_open_$(VER) \
            /usr/share/man/man6/fs2_open.6.gz  /usr/share/man/man6/fs2_open_$(VER).6.gz \
        ;