#!/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))

ifneq (,$(findstring arm,$(shell dpkg-architecture -qDEB_BUILD_GNU_CPU)))
  GMIC_CFLAGS = -g -O0
else
  ifneq (,$(findstring mips,$(shell dpkg-architecture -qDEB_BUILD_GNU_CPU)))
    GMIC_CFLAGS = -g -O0
  else
    ifeq (yes,$(BUILDD_MEM_OK))
      GMIC_CFLAGS = $(CFLAGS)
	else
	  GMIC_CFLAGS = -g -O0
	endif
  endif
endif


%:
	dh $@

override_dh_auto_test: 
	# no tests please.

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

override_dh_auto_build:
	dh_auto_build -- \
		LDFLAGS="-Wl,--as-needed" \
		CFLAGS="$(GMIC_CFLAGS) -I. -I/usr/include/libavcodec/ -I/usr/include/libavformat/ -I/usr/include/libswscale/"

override_dh_clean:
	rm -f src/gmic_use_lib
	dh_clean

override_dh_install:
	dh_install
	install -d $(CURDIR)/debian/gmic/etc/bash_completion.d
	install -D -m644 src/gmic_bashcompletion.sh \
	                 $(CURDIR)/debian/gmic/etc/bash_completion.d/gmic


.PHONY: override_dh_auto_test override_dh_compress override_dh_auto_build override_dh_clean override_dh_install

# vim:ts=4 sw=2 noet
