#!/usr/bin/make -f

BUILDD_MEM := $(shell awk '/^MemTotal:/ {print $$2}' /proc/meminfo)
BUILDD_MEM_OK := $(strip $(shell test $(BUILDD_MEM) -gt 1800000 && echo yes))

BUILDD_SLOW_ARCH := $(strip $(shell dpkg-architecture -qDEB_BUILD_ARCH_CPU | \
  									grep -q -E '^(arm|mips|sh4|m68k).*' && echo yes))


ifneq (yes,$(BUILDD_MEM_OK))
  GMIC_CFLAGS = -O0 -g
else
  ifneq (yes,$(BUILDD_SLOW_ARCH))
    GMIC_CFLAGS = -O3 -g
  else
    GMIC_CFLAGS = -O1 -g -fno-tree-pre
  endif
endif


%:
	dh $@ --sourcedirectory=src

clean:
	if [ -f zart/Makefile_old ]; then mv zart/Makefile_old zart/Makefile; fi
	rm -f src/gmic_use_lib
	dh $@ --sourcedirectory=src

override_dh_auto_configure:
	cp zart/Makefile zart/Makefile_old
	dh_auto_configure

override_dh_auto_test: 
	# no tests please.

override_dh_compress:
	dh_compress -X.shtml -X.rss -X.js -X.ppm

override_dh_auto_build:
	export MANDATORY_LDFLAGS="-Wl,--as-needed" ;\
		export MANDATORY_CFLAGS="$(GMIC_CFLAGS) -I. -I/usr/include/libavcodec/ -I/usr/include/libavformat/ -I/usr/include/libswscale/" ;\
		dh_auto_build --sourcedirectory=src


override_dh_install:
	chmod 755 debian/libgmic*.install
	dh_install --fail-missing

.PHONY: override_dh_auto_test override_dh_compress override_dh_auto_build override_dh_install

# vim:ts=4 sw=2 noet
