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

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

liblzo2_source := $(shell dpkg-query -W -f='$${source:Package} (= $${source:Version})' liblzo2-dev)

DEB_HOST_ARCH = $(shell dpkg-architecture -qDEB_HOST_ARCH)
OPTI_FLAGS_LIBONLY = -fomit-frame-pointer -falign-functions=0 -falign-jumps=0 -falign-loops=0
### PICCORO optimizer flags for i386 x86 machines
ifeq ($(DEB_HOST_ARCH),i386)
	OPTI_FLAGS_LIBONLY += -march=i586 -mtune=pentium -mmmx
endif

ifeq ($(DEB_HOST_ARCH),amd64)
	OPTI_FLAGS_LIBONLY += -mmmx -msse
endif

CFLAGS= -O3 $(OPTI_FLAGS_LIBONLY)  -Wno-narrowing -I/usr/include/SDL/
#export CFLAGS= -O3 $(OPTI_FLAGS_LIBONLY)  -Wno-narrowing -I/usr/include/SDL/

CXXFLAGS= -O3 $(OPTI_FLAGS_LIBONLY)  -Wno-narrowing -I/usr/include/SDL/
#export CXXFLAGS= -O3 $(OPTI_FLAGS_LIBONLY)  -Wno-narrowing -I/usr/include/SDL/

CPPFLAGS= -O3 $(OPTI_FLAGS_LIBONLY)  -Wno-narrowing -I/usr/include/SDL/
#export CXXFLAGS= -O3 $(OPTI_FLAGS_LIBONLY)  -Wno-narrowing -I/usr/include/SDL/

%:
	dh $@ --with autoreconf

override_dh_auto_clean:
	# Restore MiniLZO
	[ ! -f src/compress/lzoconf.h.orig ] || mv src/compress/lzoconf.h.orig src/compress/lzoconf.h
	[ ! -f src/compress/lzodefs.h.orig ] || mv src/compress/lzodefs.h.orig src/compress/lzodefs.h
	[ ! -f src/compress/minilzo.c.orig ] || mv src/compress/minilzo.c.orig src/compress/minilzo.c
	[ ! -f src/compress/minilzo.h.orig ] || mv src/compress/minilzo.h.orig src/compress/minilzo.h
# commented, currently system tremot causes troubles, use embebed
#	# Restore bundled source code
#	[ ! -d src/tremor.orig ] || mv src/tremor.orig src/tremor
	dh_auto_clean

override_dh_auto_configure:
	dh_auto_configure -- --program-suffix=08 --bindir=/usr/bin --with-x --x-includes=/usr/include  --disable-rpath
#	dh_auto_configure -- --program-suffix=08 --bindir=/usr/bin --disable-nls 


override_dh_auto_build:
	# Update MiniLZO
	cp src/compress/lzoconf.h src/compress/lzoconf.h.orig
	cp src/compress/lzodefs.h src/compress/lzodefs.h.orig
	cp src/compress/minilzo.c src/compress/minilzo.c.orig
	cp src/compress/minilzo.h src/compress/minilzo.h.orig
	cp /usr/share/lzo/minilzo/*.[ch] src/compress
# commented, currently system tremot causes troubles, use embebed
#	# Move bundled source code for external packages out of the way
#	mv src/tremor src/tremor.orig
	dh_auto_build -- INCLUDES='-I/usr/include/GL'
