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

#export DH_VERBOSE=1

export PREFIX = /usr
export DESTDIR = $(CURDIR)/debian/tmp
export CONFDIR = $(DESTDIR)/etc/webdis

CFLAGS := $(shell dpkg-buildflags --get CFLAGS)
CPPFLAGS := $(shell dpkg-buildflags --get CPPFLAGS)
LDFLAGS := $(shell dpkg-buildflags --get LDFLAGS)

# Add CPPFLAGS TO CFLAGS since build system does not know about them.
CFLAGS += $(CPPFLAGS)

# Objects to be removed from build procedure
export HIREDIS_OBJ=
export JANSSON_OBJ=
export B64_OBJS=

export CFLAGS += -I. -Ihttp-parser
export LDFLAGS += -levent -pthread -lhiredis -ljansson -lb64

build: build-arch
build-arch: tests/pubsub tests/websocket

tests/% :
	$(MAKE) -C tests $*

%:
	dh $@

override_dh_strip:
	dh_strip --dbg-package=webdis-dbg

override_dh_auto_clean:
	$(MAKE) clean
	$(MAKE) -C tests clean
	# Make sure not to use embedded code copies:
	rm -rf hiredis jansson

override_dh_auto_test:
ifneq (,$(findstring nocheck, $(DEB_BUILD_OPTIONS)))
	@echo "Skipping check (disabled in DEB_BUILD_OPTIONS)."
else
	$(CURDIR)/debian/test.sh $(MAKE) test
endif
