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

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

#export DEB_BUILD_MAINT_OPTIONS = hardening=+all,-pie

DEB_BUILD_ARCH ?= $(shell dpkg-architecture -qDEB_BUILD_ARCH)

ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
CUFLAGS += -O0
else
ifneq (,$(findstring i386,$(DEB_BUILD_ARCH)))
CUFLAGS += -O2 -fomit-frame-pointer -march=pentium -mmmx -mno-sse4 -mno-sse3 
else
ifneq (,$(findstring i486,$(DEB_BUILD_ARCH)))
CUFLAGS += -O2 -fomit-frame-pointer -march=pentium -mmmx -mno-sse4 -mno-sse3 
else
CUFLAGS += -O2 -fomit-frame-pointer -mno-sse4 -mno-sse3 -mno-sse2 
endif
endif
endif

ifneq (,$(findstring amd64,$(DEB_BUILD_ARCH)))
CUFLAGS += -O2 -fomit-frame-pointer -mmmx -msse -msse2 -mno-sse4 -mno-sse3 
endif


CFLAGS=$(CUFLAGS) -fwrapv
export CFLAGS=$(CUFLAGS) -fwrapv
CXXFLAGS=$(CUFLAGS) -fwrapv
export CXXFLAGS=$(CUFLAGS) -fwrapv

#liblzo2_source := $(shell dpkg-query -W -f='$${source:Package} (= $${source:Version})\n' liblzo2-dev | head -n 1)


%:
	dh $@ --with autoreconf

#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
#	dh_auto_build

#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
#	dh_auto_clean

override_dh_auto_configure:
#	dh_auto_configure -- --program-suffix=09 --bindir=/usr/bin --enable-psx --with-external-mpcdec --with-external-tremor --with-external-trio --with-external-lzo
	dh_auto_configure -- --program-suffix=09 --bindir=/usr/bin --enable-psx --disable-nls 

override_dh_install:
	dh_install -- 
	

#override_dh_gencontrol-arch:
#	dh_gencontrol -a -- '-Vbu:liblzo2=$(liblzo2_source)'
