#!/usr/bin/make -f

# See debhelper(7) (uncomment to enable).
# Output every command that modifies files on the build system.
#export DH_VERBOSE = 1


# See FEATURE AREAS in dpkg-buildflags(1).
#export DEB_BUILD_MAINT_OPTIONS = hardening=+all

export DEB_BUILD_MAINT_OPTIONS = hardening=+all

# See ENVIRONMENT in dpkg-buildflags(1).
# Package maintainers to append CFLAGS.
#export DEB_CFLAGS_MAINT_APPEND  = -Wall -pedantic

export DEB_CFLAGS_MAINT_APPEND = -DNO_SSLv2

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

DEB_BUILD_DIR=build
UDEB_BUILD_DIR=build-udeb

ifeq ($(filter noudeb,$(DEB_BUILD_PROFILES)),)
BUILD_UDEB=1
else
BUILD_UDEB=0
endif

# Package maintainers to append LDFLAGS.
#export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed


%:
	dh $@ --without autoreconf --builddir=$(DEB_BUILD_DIR)


# dh_make generated override targets.
# This is an example for Cmake (see <https://bugs.debian.org/641051>).
#override_dh_auto_configure:
#	dh_auto_configure -- \
#	-DCMAKE_LIBRARY_PATH=$(DEB_HOST_MULTIARCH)

override_dh_auto_clean:
	-dh_auto_clean
	-dh_auto_clean -B$(UDEB_BUILD_DIR)
	rm -f po/*.gmo po/wget.pot po/en@boldquot.po po/en@quot.po \
	    doc/wget.inf* doc/version.texi
	rm -rf config.sub config.guess $(UDEB_BUILD_DIR) $(DEB_BUILD_DIR)

override_dh_auto_configure:
	@echo "d/rules: running configure for wget"
	dh_auto_configure -- \
		--enable-ipv6 \
		--with-ssl \
		--with-libidn
ifeq ($(BUILD_UDEB),1)
	@echo "d/rules: will configure and build binary package wget-udeb"
	@echo "d/rules: running configure for wget-udeb"
	DEB_CFLAGS_MAINT_APPEND="${DEB_CFLAGS_MAINT_APPEND} -Os" dh_auto_configure -B$(UDEB_BUILD_DIR) --reload-all-buildenv-variables -- \
		--enable-ipv6 \
		--with-ssl=openssl \
		--without-libpsl \
		--disable-debug \
		--disable-nls \
		--disable-iri
endif

override_dh_auto_build:
	@echo "d/rules: building for wget"
	dh_auto_build
	cd build/po; make wget.pot
ifeq ($(BUILD_UDEB),1)
	@echo "d/rules: building for wget-udeb"
	dh_auto_build -B$(UDEB_BUILD_DIR)
endif

override_dh_auto_test:
ifeq ($(filter nocheck,$(DEB_BUILD_PROFILES)),)
	@echo "d/rules: running tests for wget"
	dh_auto_test
ifeq ($(BUILD_UDEB),1)
	@echo "d/rules: running tests for wget-udeb"
	dh_auto_test -B$(UDEB_BUILD_DIR)
endif
endif