#!/usr/bin/make -f
# -*- makefile -*-

# 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

DATA_DIR=/usr/share/games/boswars
CCFLAGS=-DSTRATAGUS_LIB_PATH=\\\"/usr/share/games/boswars\\\"

CFLAGS = -Wall -g

ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
	CFLAGS += -O0
else
	CFLAGS += -O2
endif

#Architecture
build: build-arch build-indep

build-arch: build-arch-stamp
build-arch-stamp:
	scons CCFLAGS=$(CCFLAGS)
	touch $@

build-indep: build-indep-stamp
build-indep-stamp:
	# Adjust the permissions
	chmod +x languages/makesame.py

	# Copy (and rename) an icon to be used as desktop file
	cp units/tank/ico_tank.png debian/boswars.png

	touch $@

clean:
	dh_testdir
	dh_testroot
	rm -f build-arch-stamp build-indep-stamp

	# Add here commands to clean up after the build process.
	scons -c

	# Scons is stupid and leaves them behind no matter what.
	rm  -f .sconsign.dblite
	rm -rf .sconf_temp
	rm  -f build_conf_cache.py build_options.py config.log

	# Additional icon (see build-indep-stamp)
	rm  -f debian/boswars.png

	dh_clean

install: install-indep install-arch
install-indep:
	dh_testdir
	dh_testroot
	dh_prep -k -i
	dh_installdirs -i
	dh_install -i

	# Remove unneeded files.
	for i in genpot.sh makesame.py updatepo.sh ; do \
		rm -f debian/boswars-data/usr/share/games/boswars/languages/$$i ; \
	done

install-arch:
	dh_testdir
	dh_testroot
	dh_prep -k -s
	dh_installdirs -s
	dh_installman -pboswars debian/boswars.6
	dh_install -s

# Must not depend on anything. This is to be called by
# binary-arch/binary-indep
# in another 'make' thread.
binary-common:
	dh_testdir
	dh_testroot
	dh_installchangelogs CHANGELOG
	dh_installdocs
	dh_installmenu
	dh_link
	dh_strip
	dh_compress
	dh_fixperms
	dh_makeshlibs
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

# Build architecture independant packages using the common target.
binary-indep: build-indep install-indep
	$(MAKE) -f debian/rules DH_OPTIONS=-i binary-common

# Build architecture dependant packages using the common target.
binary-arch: build-arch install-arch
	rm -f debian/boswars/usr/share/doc/boswars/html/README-SDL.txt
	rm -f debian/boswars/usr/share/doc/boswars/html/*copyright*

	$(MAKE) -f debian/rules DH_OPTIONS=-s binary-common

binary: binary-arch binary-indep
.PHONY: build clean binary-indep binary-arch binary install install-indep install-arch
