#!/usr/bin/make -f
# Sample debian/rules file - for GNU Hello.
# Copyright 1994,1995 by Ian Jackson.
# I hereby give you perpetual unlimited permission to copy,
# modify and relicense this file, provided that you do not remove
# my name from the file itself.  (I assert my moral right of
# paternity under the Copyright, Designs and Patents Act 1988.)
# This file may have to be extensively modified

package = hello
docdir = debian/tmp/usr/share/doc/$(package)

CFLAGS = -g -Wall
STRIP = true

ifeq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
  CFLAGS += -O2
endif

export DEB_HOST_GNU_TYPE  ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
export DEB_BUILD_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)

# Recommended snippet for Autoconf 2.52 or later
ifeq ($(DEB_BUILD_GNU_TYPE), $(DEB_HOST_GNU_TYPE))
  confflags += --build $(DEB_HOST_GNU_TYPE)
  stripcmd = strip
else
  confflags += --build $(DEB_BUILD_GNU_TYPE) --host $(DEB_HOST_GNU_TYPE)
  stripcmd = $(DEB_HOST_GNU_TYPE)-strip
endif

ifeq (,$(findstring nostrip,$(DEB_BUILD_OPTIONS)))
  STRIP = $(stripcmd) --remove-section=.comment --remove-section=.note
endif

build:
	./configure $(confflags) --prefix=/usr
	$(MAKE) CFLAGS="$(CFLAGS)"
	touch build

clean:
	rm -f build
	[ ! -f Makefile ] || $(MAKE) distclean
	rm -rf *~ debian/tmp debian/*~ debian/files* debian/substvars

binary-indep: build
# There are no architecture-independent files to be uploaded
# generated by this package.  If there were any they would be
# made here.

binary-arch: build
	rm -rf debian/tmp
	install -d debian/tmp/DEBIAN $(docdir)
	$(MAKE) prefix=$$(pwd)/debian/tmp/usr install
	$(STRIP) debian/tmp/usr/bin/hello
	cp -a NEWS debian/copyright $(docdir)
	cp -a debian/changelog $(docdir)/changelog.Debian
	cp -a ChangeLog $(docdir)/changelog
	cd $(docdir) && gzip -9 changelog changelog.Debian
	gzip -r9 debian/tmp/usr/share/man
	gzip -9 debian/tmp/usr/share/info/*
	dpkg-shlibdeps debian/tmp/usr/bin/hello
	dpkg-gencontrol
	chown -R 0:0 debian/tmp
	chmod -R u+w,go=rX debian/tmp
	dpkg --build debian/tmp ..

binary: binary-indep binary-arch

build-arch: build

build-indep: build

.PHONY: binary binary-arch binary-indep build-arch build-indep clean
