#!/usr/bin/make -f

include /usr/share/dpkg/architecture.mk

export DH_VERBOSE = 1

ARCH := $(DEB_TARGET_ARCH)
ifeq ($(ARCH), amd64)
	ARCH := x64
else ifeq ($(ARCH), i386)
	ARCH := x86
else ifeq ($(ARCH), armhf)
	ARCH := armv7
else ifeq ($(ARCH), mips64el)
	ARCH := mips64le
endif

# Uncomment which build type should be used:
# There are 3 main build types:
#     Base is a build with minimal additions (not much useful)
#     Core includes a little bit more stuff than the Base
#     Bulk is a build which includes almost everything.
#
# BUILD_TYPE := base
# BUILD_TYPE := core
BUILD_TYPE := bulk

%:
	dh $@

override_dh_auto_clean:
	rm -fr build
	rm -fr temp
	rm -fr make/tmp
	rm -f reb-lib-doc.txt
	rm -f src/core/b-boot.c
	rm -rf src/generated
	rm -f src/include/ext-types.h
	rm -f src/include/gen-*.h
	rm -f src/include/host-*.h
	rm -f src/mezz/base-collected.reb
	rm -f src/include/reb-dialect.h
	rm -f src/include/reb-evtypes.h
	rm -f src/include/reb-lib.h
	rm -f src/include/reb-lib-lib.h
	rm -f src/include/reb-types.h

override_dh_auto_build:
	siskin make/rebol3.nest %rebol3-${BUILD_TYPE}-linux-${ARCH}

override_dh_auto_test:
	./build/rebol3-${BUILD_TYPE}-linux-${ARCH} -v
	./build/rebol3-${BUILD_TYPE}-linux-${ARCH} \
		--do 'print "Debian package build test: OK"'

override_dh_auto_install:
	install -Dm755 build/rebol3-${BUILD_TYPE}-linux-${ARCH} \
		debian/rebol/usr/bin/rebol
	install -d debian/rebol-src/usr/share/rebol-src
	cp -a make src \
		debian/rebol-src/usr/share/rebol-src/
	rm -fr debian/rebol-src/usr/share/rebol-src/make/tmp

