#!/usr/bin/make -f

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

export DEB_HOST_ARCH_OS ?= $(shell dpkg-architecture -qDEB_HOST_ARCH_OS)       
                                                                               
ifeq ($(DEB_HOST_ARCH_OS),kfreebsd)                                            
PLATFORM=freebsd
endif                                                                          
ifeq ($(DEB_HOST_ARCH_OS),linux)                                               
PLATFORM=linux
endif                                                                          
  
%:
	dh $@

override_dh_auto_build:
	$(MAKE) all installdir=/usr/share/gw6c platform=$(PLATFORM) 
	$(MAKE) -C tspc-advanced/conf gw6c.conf.sample PLATFORM=$(PLATFORM) PLATFORM_DIR=../platform installdir=/usr/share/gw6c BIN_DIR=.

override_dh_auto_clean:
	$(MAKE) clean platform=$(PLATFORM) 
	-rm tspc-advanced/conf/gw6c.conf.sample

override_dh_auto_install:
	install -D tspc-advanced/conf/gw6c.conf.sample debian/gw6c/etc/gw6c/gw6c.conf
ifeq ($(DEB_HOST_ARCH_OS),linux)                                            
	echo 'platform:Depends=iproute' >> debian/gw6c.substvars
else
	echo 'platform:Depends=' >> debian/gw6c.substvars
endif                                                                          

override_dh_install:
	dh_install tspc-advanced/template/$(PLATFORM).sh usr/share/gw6c/template

override_dh_fixperms:
	dh_fixperms
	chmod 600 debian/gw6c/etc/gw6c/gw6c.conf
