#!/usr/bin/make -f
export DH_VERBOSE=1

NS3VER=3.12.1
NS3_DIR=ns-$(NS3VER)
PYBINDGENV_DIR=pybindgen-0.15.0.795
REFTRACE_DIR=ns-$(NS3VER)-ref-traces
NSC_DIR=nsc-0.5.2

RELEASE=debug

PYVERS=$(shell pyversions -s)
PYVER_DEFAULT=$(shell pyversions -d)
PYVER_ALT=$(shell echo "$(PYVERS)" | sed "s/$(PYVER_DEFAULT)//g")


%:
	dh $@ --with python2


override_dh_auto_configure:
	cp ./debian/upstream-back/build.config ./.config
	cd ./debian/waf-*; ./configure
	cp ./debian/waf-*/waf ./$(NS3_DIR)/waf

override_dh_auto_build:
	###############make document
	-make html man -C ./$(NS3_DIR)/doc/manual/
	-make html man -C ./$(NS3_DIR)/doc/models/
	-make html man -C ./$(NS3_DIR)/doc/tutorial/

	######	build and install static libraries
	cp debian/upstream-back/build-static.py ./build.py
	./build.py
	cd ./$(NS3_DIR);./waf install --destdir=../debian/tmp
	
#	######## build and install shared libraries, python bindings for none default python.
#	if [ ! -z `echo "$(PYVER_ALT)" | sed "s/ //g"` ]; then \
#		$(PYVER_ALT) ./build.py; \
#		cd ./$(NS3_DIR); \
#		./waf install --destdir=../debian/tmp; fi
	
	####### build and install shared libraries, python bindings for default python.
	cp debian/upstream-back/build-shared.py ./build.py
	./build.py --enable-tests
	cd ./$(NS3_DIR);./waf install --destdir=../debian/tmp
	
	####### cp the default build.py back
	cp debian/upstream-back/build.py ./build.py
	
	######## build doxygen
	-cd $(NS3_DIR); ./waf --doxygen
	

override_dh_auto_test:
	-cd ./$(NS3_DIR); ./test.py

override_dh_prep:
	#I install files here when build.
	#The upstream cannot work well for us.
	#I will remove this dir when dh_clean, surely.
	dh_prep -Xdebian/tmp
	
override_dh_auto_install:


override_dh_install:
	-rm ns-3.*/doc/*/build/*/_static/jquery.js
	-rm ns-3.*/doc/*/build/*/_static/underscore.js
	dh_install

override_dh_python2:
	#### upstream now can only build for the default version of python.
	dh_python2 --no-guessing-versions
	
override_dh_installchangelogs:
	dh_installchangelogs ./$(NS3_DIR)/CHANGES.html

override_dh_strip:
	dh_strip -plibns3-3 --dbg-package=libns3-3-dbg 
	dh_strip -ppython-ns3 --dbg-package=python-ns3-dbg
	dh_strip

override_dh_auto_clean:
	-sh ./debian/clean-tree.sh
