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

# output every command that modifies files on the build system.
#DH_VERBOSE = 1

DPKG_EXPORT_BUILDFLAGS = 1
include /usr/share/dpkg/default.mk

include /usr/share/dpkg/architecture.mk

export DEB_BUILD_MAINT_OPTIONS = hardening=+all

# package maintainers to append CFLAGS
#export DEB_CFLAGS_MAINT_APPEND  = -Wall -pedantic
# package maintainers to append LDFLAGS
#export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed

export GEM2DEB_TEST_RUNNER = --check-dependencies
export DH_RUBY = --gem-install
export DH_RUBY_GEM_INSTALL_WHITELIST_APPEND = platform_check.rb version.rb

export DH_RUBY_IGNORE_TESTS = all

export V = 1

LD_LIBRARY_PATH += :$(CURDIR)/debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)

override_dh_auto_build:
	# Fake included protobuf .proto files
	mkdir -p $(CURDIR)/Ithird_party/protobuf/
	ln -s /usr/include $(CURDIR)/third_party/protobuf/src
	$(MAKE) shared prefix=/usr
	dh_auto_build -O--buildsystem=ruby

override_dh_auto_test:
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
#	make test_c
endif

override_dh_auto_install:
	$(MAKE) INSTALL_LIBDIR=/lib/$(DEB_HOST_MULTIARCH) \
		install prefix=$(CURDIR)/debian/tmp/usr
	TOPDIR=$(CURDIR)/debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH) \
		dh_auto_install -O--buildsystem=ruby
	find $(CURDIR)/debian/ruby-grpc/ \
		\( -name ca.pem -o -name server1.key -o -name server1.pem \) \
		-exec chmod a-x {} \;

%:
	dh $@ --list-missing

.PHONY: override_dh_auto_build override_dh_auto_test override_dh_auto_install
