#!/usr/bin/make -f
# -*- makefile -*-
# Sample debian/rules that uses debhelper.
# This file was originally written by Joey Hess and Craig Small.
# As a special exception, when this file is copied by dh-make into a
# dh-make output file, you may use that output file without restriction.
# This special exception was added by Craig Small in version 0.37 of dh-make.

# modified for node_package by dizzyd@basho.com and jared@basho.com

# Uncomment this to turn on verbose mode.
export DH_VERBOSE=1

ROOTDIR := debian/{{package_name}}

## Clear variables that may confound our build of sub-projects; also
## note that it is necessary to use overlay_vars relative to .. as
## the generate command EXECUTES in rel/
build:
	unset CC CFLAGS CPPFLAGS LDFLAGS CXX CXXFLAGS \
		&& OVERLAY_VARS="overlay_vars=../debian/vars.config" make rel
	touch build

clean:
	dh_clean
	rm -f build
	make clean

## dh_shlibdeps was added to figure out the dependencies on shared libraries
##   and will populate the ${shlibs:Depends} callout in the control file
install: LIBDIR := $(ROOTDIR)/usr/lib/{{package_install_name}}
install: build
	dh_testdir
	dh_testroot
	dh_prep
	dh_installdirs
	dh_install
	dh_installman
	dh_installinit --name={{package_install_name}} --no-start
	dh_fixperms
	chmod 0755 $(ROOTDIR)/etc/{{package_install_name}}
	chmod -R a+rX $(ROOTDIR)/etc/{{package_install_name}}
	for file in lib/env.sh lib/app_epath.sh erts-*/bin/nodetool; do \
		if [ -f $(LIBDIR)/$$file ]; then \
			chmod 0755 $(LIBDIR)/$$file; \
		fi; \
	done
	chmod -R go+rX debian/{{package_name}}/usr/lib/{{package_install_name}}/lib/
	dh_shlibdeps

# We have nothing to do by default.
binary-indep: install build-stamp
build-stamp:

# Build architecture-dependent files here.
binary-arch: install
	dh_strip -a
	dh_compress -a
	dh_installdeb
	dh_gencontrol
	dh_builddeb

binary: binary-indep binary-arch
