#!/usr/bin/make -f

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

# This has to be exported to make some magic below work.
export DH_OPTIONS

# Hardcode correct absolute path to sed
export ac_cv_path_SED = $(shell command -v sed)

SANE_ARCHS := amd64

# Enable parallel builds
PARALLEL=--parallel

export SED := /bin/sed

# Make the shell scripts fail after first failed command (important for SAPI loops)
SHELL := /bin/sh -e

# enable dpkg build flags
export DEB_BUILD_MAINT_OPTIONS = hardening=+all optimize=-lto
DPKG_EXPORT_BUILDFLAGS = 1
include /usr/share/dpkg/default.mk

LIBTOOL_VERSION := $(shell dpkg-query -f'$${Version}' -W libtool)

# Disable the test now
RUN_TESTS := no

# specify some options to our patch system
QUILT_DIFF_OPTS := -p
QUILT_NO_DIFF_TIMESTAMPS := 1
export QUILT_DIFF_OPTS QUILT_NO_DIFF_TIMESTAMPS

export PROG_SENDMAIL := /usr/sbin/sendmail
ifeq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
  DEB_CFLAGS_MAINT_APPEND += -O2
else
  DEB_CFLAGS_MAINT_APPEND += -O0
endif
DEB_CFLAGS_MAINT_APPEND += -Wno-error=implicit-function-declaration -Wno-implicit-function-declaration -Wno-deprecated-declarations -fsigned-char -fno-strict-aliasing
DEB_CFLAGS_MAINT_APPEND += $(shell getconf LFS_CFLAGS)

# OpenSSL 3.0 support
DEB_CFLAGS_MAINT_APPEND += -DOPENSSL_SUPPRESS_DEPRECATED

# Enable IEEE-conformant floating point math on alphas (not the default)
ifeq (alpha-linux-gnu,$(DEB_HOST_GNU_TYPE))
  DEB_CFLAGS_MAINT_APPEND += -mieee
endif

# Enable producing of debugging information
DEB_CFLAGS_MAINT_APPEND += -g

DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed

export DEB_CFLAGS_MAINT_APPEND
export DEB_LDFLAGS_MAINT_APPEND


##include $(CURDIR)/debian/rules.d/*.mk

%:
	dh $@ --with systemd --with apache2 --without=build-stamp --without autoreconf $(PARALLEL)

override_dh_auto_clean:
	rm -rf test-results.txt

#override_dh_auto_configure-indep:

override_dh_auto_configure:
	./configure --prefix=/home/xtreamcodes/iptv_xtream_codes/php --with-zlib-dir --with-freetype-dir=/home/xtreamcodes/iptv_xtream_codes/freetype2 --enable-mbstring --enable-calendar --with-curl --with-gd --disable-rpath --enable-inline-optimization --with-bz2 --with-zlib --enable-sockets --enable-sysvsem --enable-sysvshm --enable-pcntl --enable-mbregex --enable-exif --enable-bcmath --with-mhash --enable-zip --with-pcre-regex --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-openssl --with-fpm-user=xtreamcodes --with-fpm-group=xtreamcodes --with-libdir=/lib/x86_64-linux-gnu --with-gettext --with-xmlrpc --with-xsl --enable-opcache --enable-fpm --enable-libxml --enable-static --disable-shared --with-jpeg-dir --enable-gd-jis-conv --with-webp-dir --with-xpm-dir
#	for target in $(TARGETS); do \
#	  dh_auto_configure --builddirectory $${target}-build $(PARALLEL) -- $$(eval echo \$${$${target}_config}); \
#	done

#override_dh_auto_build-indep:

#override_dh_auto_build-arch:
#	for target in $(TARGETS); do \
#	  dh_auto_build --builddirectory $${target}-build $(PARALLEL); \
#	done

override_dh_auto_install:
	dh_auto_install -- install INSTALL_ROOT=$(CURDIR)/debian/xtreamui-php && rm -rf $(CURDIR)/debian/xtreamui-php/usr
#	for target in $(TARGETS); do \
#	  dh_auto_install --builddirectory $${target}-build $(PARALLEL) -- install INSTALL_ROOT=$(CURDIR)/debian/tmp; \
#	done

override_dh_auto_test-indep:

override_dh_auto_test-arch:

# override__dh_auto_install:
#	dh_auto_install


#override_dh_installdirs:
#	dh_installdirs
#	dh_install --fail-missing


#override_dh_installinit:
#	dh_installinit --restart-after-upgrade

#override_dh_systemd_start:
#	dh_systemd_start --restart-after-upgrade

#override_dh_apache2:
#	for sapi in apache2 cgi fpm; do \
#	    $(SAPI_PACKAGE) \
#	    < debian/$${versionless}.apache2 $(SED_REPLACEMENT) > debian/$${package}.apache2; \
#	done
#	dh_apache2 --conditional=php_enable

#override_dh_installdocs-indep:
#	dh_installdocs -i

#override_dh_installdocs-arch:
#	dh_installdocs -p$(PHP_COMMON)
#	dh_installdocs -a --remaining-packages --link-doc=$(PHP_COMMON)

#override_dh_compress:
#	dh_compress -Xphp.ini

#override_dh_installchangelogs-arch:
#	dh_installchangelogs -a -p$(PHP_COMMON) NEWS

#override_dh_installchangelogs-indep:
#	dh_installchangelogs -i NEWS

#override_dh_strip:
#	dh_strip --dbgsym-migration='php$(PHP_NAME_VERSION)-dbg' || dh_strip

#override_dh_makeshlibs-arch:
#	dh_makeshlibs -a -p$(PHP_LIBEMBED) -V '$(PHP_LIBEMBED) (>= $(PHP_MAJOR_VERSION).$(PHP_MINOR_VERSION))'

#override_dh_gencontrol-arch:
#	# Bail-out if PHPAPI has changed
#	stored=$$(cat debian/phpapi); \
#	for sapi in $(REAL_TARGETS); do \
#	    $(SAPI_PACKAGE) \
#	    $${sapi}-build/sapi/cli/php -n -r '$(BUILTIN_EXTENSION_CHECK)' \
#	      >> debian/$${package}.substvars; \
#	    phpapi=$$(sh $${sapi}-build/scripts/php-config --phpapi); \
#	    if [ "$${phpapi}" != "$${stored}" ]; then \
#	        echo "PHPAPI has changed from $${stored} to $${phpapi}, please modify debian/phpapi"; \
#	        exit 1; \
#	    fi; \
#	    echo "php:Provides=phpapi-$${phpapi}" >> debian/$${package}.substvars; \
#	done; \
#	if dpkg --compare-versions $(LIBTOOL_VERSION) gt 2.4.6-0.1~; then \
#	    echo "libtool:Depends=libtool (>= 2.4.6-0.1~)" >> debian/php$(PHP_NAME_VERSION)-dev.substvars; \
#	else \
#	    echo "libtool:Depends=libtool" >> debian/php$(PHP_NAME_VERSION)-dev.substvars; \
#	fi
#	dh_gencontrol -a
#
#debian/control: debian/control.in debian/rules debian/changelog debian/source.lintian-overrides debian/rules.d/* debian/php-module.control.in
#	$(SED) -e "s/@PHP_VERSION@/$(PHP_NAME_VERSION)/g" -e "s/@BUILT_USING@/$(BUILT_USING)/g" >$@ <$<
#	for ext in $(sort $(ext_PACKAGES)); do \
#	  package=php$(PHP_NAME_VERSION)-$${ext}; \
#	  description=$$(eval echo \$${$${ext}_DESCRIPTION}); \
#	  echo >>$@; \
#	  $(SED) -e "s|@ext@|$${ext}|" -e "s|@package@|$${package}|" -e "s|@description@|$${description}|" >>$@ <debian/php-module.control.in; \
#	done
#	mkdir -p debian/tests
#	for f in debian/tests.in/*; do \
#	  t=$$(basename $${f}); \
#	  < debian/tests.in/$${t} $(SED_REPLACEMENT) > debian/tests/$${t}; \
#	done
#
#debian/source.lintian-overrides: debian/source.lintian-overrides.in debian/rules debian/changelog
#	$(SED) -e "s/@PHP_VERSION@/$(PHP_NAME_VERSION)/g" >$@ <$<

#.PHONY: prepared unprepared debian/control debian/source.lintian-overrides
