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

# Copyright (c) 2006 SUSE LINUX Products GmbH, Nuernberg, Germany
# This file and all modifications and additions to the pristine package
# are under the same license as the package itself.
#
# Please submit bugfixes or commens via http://bugs.opensuse.org

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

SHELL=/bin/bash

BUILDROOT:=$(CURDIR)/debian/obs-build

configure: configure-stamp
configure-stamp:
	dh_testdir
	touch configure-stamp


build: build-stamp

build-stamp: configure-stamp 
	dh_testdir
	touch build-stamp

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp configure-stamp

	dh_clean 

install: build
	dh_testdir
	dh_testroot
	dh_prep
	dh_installdirs
	make DESTDIR=$(BUILDROOT) install
	cd $(BUILDROOT)/usr/lib/build/configs/ && ln -s ubuntu20.04.conf default.conf
	cd $(BUILDROOT)/usr/lib/build/ && ln -sf baselibs_configs/baselibs_global-deb.conf baselibs_global.conf

binary-arch: build install
	dh_testdir
	dh_testroot
	dh_installchangelogs
	dh_installdocs
	dh_installexamples
	dh_installman
	dh_link
	dh_strip
	dh_compress
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

binary-indep: build install

binary: binary-indep binary-arch tests

export BUILD_IGNORE_2ND_STAGE=1
export BUILD_DIR=$(CURDIR)
tests:
	for i in build build-* ;\
	  do bash -n $$i || exit 1;\
	done
	LANG=C make test || exit 1
	# The tests can not run in fakeroot:
	# when chroot runs, it triggers the following error:
	#   d.so: object 'libfakeroot-sysv.so' from LD_PRELOAD cannot be preloaded (cannot open shared object file)
	cd test && tar czf libdummy_0.0.orig.tar.gz libdummy
	chmod a+x $(CURDIR)/debian/deb_sums.sh
	cd test && $(CURDIR)/debian/deb_sums.sh libdummy_0.0.orig.tar.gz >> libdummy.dsc
	if [ -f "$(BUILDROOT)/usr/lib/build/configs/default.conf" ]; then \
	  cp -av $(BUILDROOT)/usr/lib/build/configs/default.conf configs/; \
	  sed -i 's,build-mkbaselibs,,' configs/*.conf; \
	  if [ ! -e /.build.packages/rpmlint-Factory.rpm ]; then \
	    sed -i 's,rpmlint-Factory,,' configs/*.conf; \
	  fi; \
	  sed -i '/^Preinstall: util-linux/i Preinstall: libfakeroot fakeroot' configs/default.conf; \
#	  cd test && ./testbuild.sh /.build.binaries/ || exit 1; \
	fi
.PHONY: build clean binary-indep binary-arch binary install configure tests
