#!/usr/bin/make -f

DEB_HOST_ARCH_OS ?= $(shell dpkg-architecture -qDEB_HOST_ARCH_OS)
DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)

export DEB_BUILD_MAINT_OPTIONS = hardening=+all,-PIE,-pie

# These are used for cross-compiling and for saving the configure script
# from having to guess our platform (since we know it already)
DEB_HOST_GNU_TYPE   ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
DEB_BUILD_GNU_TYPE  ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)

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

DEB_HOST_ARCH = $(shell dpkg-architecture -qDEB_HOST_ARCH)
OPTI_FLAGS_LIBONLY := -funswitch-loops -fpredictive-commoning -fgcse-after-reload -ftree-vectorize -fomit-frame-pointer
### PICCORO optimizer flags for i386 x86 machines
ifeq ($(DEB_HOST_ARCH),i386)
    OPTI_FLAGS_LIBONLY += -march=i586 -mtune=generic -mmmx -fexcess-precision=fast
else
ifeq ($(DEB_HOST_ARCH),i486)
    OPTI_FLAGS_LIBONLY += -march=i586 -mtune=generic -mmmx -fexcess-precision=fast
endif
endif

ifeq ($(DEB_HOST_ARCH),amd64)
    OPTI_FLAGS_LIBONLY += -mmmx -msse -msse2 -mfpmath=sse -fexcess-precision=fast
endif

CFLAGS= -O3 $(OPTI_FLAGS_LIBONLY)
export CFLAGS= -O3 $(OPTI_FLAGS_LIBONLY)

CPPFLAGS= -O3 $(OPTI_FLAGS_LIBONLY)
export CPPFLAGS= -O3 $(OPTI_FLAGS_LIBONLY)

endif

CFLAGS += $(CPPFLAGS)
CXXFLAGS += $(CPPFLAGS)

LDFLAGS=$(shell dpkg-buildflags --get LDFLAGS)

#export DEB_BUILD_MAINT_OPTIONS = hardening=+all

%:
	dh ${@}

override_dh_autoreconf:
	dh_autoreconf ./autogen.sh --

override_dh_auto_configure:
ifeq ($(DEB_HOST_ARCH_OS),linux)
	dh_auto_configure -- --with-plugins=all --disable-silent-rules
else
	# omit netstat plugin on non-linux, requires wireless-tools
	dh_auto_configure -- --with-plugins=all,-netstat --disable-silent-rules --disable-alsa
endif

override_dh_strip:
	dh_strip --dbg-package=lxpanel-dbg

override_dh_makeshlibs:
	# package does not provide public shared libs so disable processing

# remove unused .la file from the package
override_dh_auto_install:
	dh_auto_install
	rm -f debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)/lxpanel/*.la
