#!/usr/bin/make -f

export QT_SELECT=6
include /usr/share/dpkg/default.mk

DEB_BUILD_ARCH ?= $(shell dpkg-architecture -qDEB_BUILD_ARCH)
DEB_BUILD_OPTIONS=nocheck

SYSTYPE = $(shell cat /usr/lib/deepin/desktop-version | grep Type= | awk -F'=' '{print $$2}')

# 检测是否为 Professional 版本
define detect_edition
ifneq (,$(shell test -f /etc/os-version && grep -q "EditionName=Professional" /etc/os-version && echo yes))
    PROFESSIONAL_DEPS=,\\n libusec-recoverykey
    PROFESSIONAL_DEPS2=,\\n dlnfs
else
    PROFESSIONAL_DEPS=
    PROFESSIONAL_DEPS2=
endif
endef

# 调用版本检测
$(eval $(call detect_edition))

# 生成 control 文件（需要处理换行符）
$(shell sed -e 's|@PROFESSIONAL_DEPS@|$(PROFESSIONAL_DEPS)|g' \
            -e 's|@PROFESSIONAL_DEPS2@|$(PROFESSIONAL_DEPS2)|g' \
            debian/control.in | sed 's|\\n|\n|g' > debian/control)

%:
	dh $@ --parallel

override_dh_shlibdeps:
	dh_shlibdeps -l$(shell pwd)/debian/dde-sharefiles/usr/share/dde-file-manager/sharefiles/lib

override_dh_auto_configure:
	dh_auto_configure -- \
        -DCMAKE_INSTALL_PREFIX=/usr \
	-DCMAKE_BUILD_TYPE=Release \
	-DAPP_VERSION=$(DEB_VERSION_UPSTREAM) -DVERSION=$(DEB_VERSION_UPSTREAM) LIB_INSTALL_DIR=/usr/lib/$(DEB_HOST_MULTIARCH)

override_dh_auto_build:
	dh_auto_build -- -j8

override_dh_auto_install:
	dh_auto_install --destdir=debian/tmp
	
override_dh_shlibdeps:
	dh_shlibdeps --dpkg-shlibdeps-params=--ignore-missing-info