#!/usr/bin/make -f

include /usr/share/gnome-pkg-tools/1/rules/gnome-get-source.mk

export DEB_LDFLAGS_MAINT_APPEND = -Wl,-O1 -Wl,--as-needed
include /usr/share/dpkg/buildflags.mk

ifneq (,$(findstring amd64,$(DEB_BUILD_ARCH)))
export DEB_BUILD_MAINT_OPTIONS = hardening=+fortify,-stackprotector,+relro,+bindnow,-pie
else
export DEB_BUILD_MAINT_OPTIONS = hardening=+fortify,-stackprotector,+relro,+bindnow,+pie
endif

devi := $(shell lsb_release -r -s | cut -d '.'  -f1)
DEBVE1=no
ifeq ($(shell if [ $(devi) -gt 7 ] ; then echo gt ; else echo lt ; fi),gt)
DEBVE1=yes
endif
DEBVE2=no
ifeq ($(shell if [ $(devi) -gt 8 ] ; then echo gt ; else echo lt ; fi),gt)
DEBVE2=yes
endif

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

OPTI_FLAGS_LIBONLY := -fomit-frame-pointer
ifeq ($(DEB_HOST_ARCH),i386)
ifeq ($(DEBVE1),yes)
    OPTI_FLAGS_LIBONLY += -march=i686 -mtune=generic -mmmx -msse -mfpmath=sse -fexcess-precision=fast
 
else
    OPTI_FLAGS_LIBONLY += -march=i586 -mtune=generic -mmmx -mno-sse 
endif
else
ifeq ($(DEB_HOST_ARCH),i486)
ifeq ($(DEBVE1),yes)
    OPTI_FLAGS_LIBONLY += -march=i686 -mtune=generic -mmmx -msse -mfpmath=sse -fexcess-precision=fast
 
else
    OPTI_FLAGS_LIBONLY += -march=i586 -mtune=generic -mmmx -mno-sse 
endif
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)
CXXFLAGS= -O3 $(OPTI_FLAGS_LIBONLY)
export CXXFLAGS= -O3 $(OPTI_FLAGS_LIBONLY)

endif


%:
	dh $@ --with autoreconf,gir,gnome

override_dh_auto_configure:
	dh_auto_configure -- \
		--enable-gtk-doc \
		--enable-introspection=yes

override_dh_install:
	dh_install --list-missing

override_dh_strip:
ifeq ($(DEBVE1),yes)
	dh_strip --dbgsym-migration='libjson-glib-1.0-0-dbg (<< 1.2.2-1~)'
else
	dh_strip --dbg-package=libjson-glib-1.0-0-dbg
endif

override_dh_makeshlibs:
	dh_makeshlibs -V -- -c4
