#!/usr/bin/make -f
# -*- makefile -*-
# https://www.debian.org/doc/debian-policy/ch-source.html#s-debianrules
# https://manpages.debian.org/stretch/debhelper/debhelper.7.en.html

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

export DEB_BUILD_MAINT_OPTIONS = hardening=+all

export DEB_CFLAGS_MAINT_APPEND=-g -O3
export DEB_CXXFLAGS_MAINT_APPEND=-g -O3

version := $(shell dpkg-parsechangelog -S Version | sed -rne 's,([^-\+]+)+(\+dfsg)*.*,\1,p'i)
source := $(shell dpkg-parsechangelog -S Source)
upstreampck := $(source)_$(version).orig.tar.gz

%:
	dh $@ --with python3

clean:
	dh_testdir
	dh_auto_clean || true
	dh_clean

override_dh_auto_configure:
	dh_auto_configure -- --with-pdfixed --with-thrift --with-nanomsg --with-pi

override_dh_auto_install:
	make DESTDIR=$(CURDIR)/debian/p4lang-bmv2 install
	autoreconf -fi targets/simple_switch_grpc/
	cd targets/simple_switch_grpc/ && ./configure --prefix=/usr --sysconfdir=/etc --localstatedir=/var --disable-silent-rules --disable-maintainer-mode --disable-dependency-tracking --with-thrift
	make -C targets/simple_switch_grpc/ -j$(nproc)
	make -C targets/simple_switch_grpc/ DESTDIR=$(CURDIR)/debian/p4lang-bmv2 install
	find $(CURDIR)/debian/p4lang-bmv2 -name __pycache__ -type d | xargs rm -rf
