#!/usr/bin/make -f
#
# Created 20 December 1997 by Enrique Zanardi <ezanardi@ull.es>
#
# Copying and modification is unlimited, provided that the modified
# version is marked as being modified.

ARCH = $(shell dpkg --print-gnu-build-architecture)

VERSION=0.03
SONAME=0.03

PACKAGEshd=gnewt$(SONAME)
# PACKAGEdev=$(PACKAGEshd)-dev
PACKAGErun=gwhiptail

tmpshd = $(shell pwd)/debian/tmp-shd
tmpdev = $(shell pwd)/debian/tmp-dev
tmprun = $(shell pwd)/debian/tmp-run

docshd = $(tmpshd)/usr/doc/$(PACKAGEshd)
docdev = $(tmpdev)/usr/doc/$(PACKAGEdev)
docrun = $(tmprun)/usr/doc/$(PACKAGErun)

ifeq (ARCH,"alpha")
	LIBCDEV=libc6.1-dev
else
	LIBCDEV=libc6-dev
endif

build: 
	make 
	touch build

clean: 
	$(checkdir)
	./configure
	make clean
	rm -rf  $(tmpshd) $(tmpdev) $(tmprun) $(tmpscr) build \
	        debian/files* debian/substvars debian/*.bak debian/*~ \
	        .depend

binary: binary-indep binary-arch

binary-indep:
	true

binary-arch:  binary-shared binary-runtime # binary-scripting

binary-shared: build checkroot
	$(checkdir)
	-[ -d $(tmpshd) ] && rm -rf $(tmpshd)

	install -d -m 755 $(tmpshd)/usr/lib
	make instroot=$(tmpshd) install-sh 
	strip $(tmpshd)/usr/lib/libgnewt.so.$(SONAME)

	make instroot=$(tmpshd) install

	rm -f $(tmpshd)/usr/bin/gwhiptail 
	rm -f $(tmpshd)/usr/include/newt.h

	install -d -m 755 $(docshd)
	install -m 644 debian/changelog $(docshd)/changelog.Debian
	gzip -9 $(docshd)/*
	install -m 644 debian/copyright $(docshd)/
	
	install -d -m 755 $(tmpshd)/DEBIAN 
	install -m 755 debian/postinst $(tmpshd)/DEBIAN
	install -m 644 debian/shlibs $(tmpshd)/DEBIAN
	dpkg-shlibdeps $(tmpshd)/usr/lib/libgnewt.so.$(SONAME)
	dpkg-gencontrol -P$(tmpshd) -p$(PACKAGEshd)

	chmod -R go=rX $(tmpshd)
	chown -R root.root $(tmpshd)
	dpkg --build $(tmpshd) ..


binary-runtime: build checkroot
	$(checkdir)
	-[ -d $(tmprun) ] && rm -rf $(tmprun)

	install -d -m 755 $(tmprun)/usr/man $(tmprun)/usr/bin
	make instroot=$(tmprun) install
	rm -rf $(tmprun)/usr/lib $(tmprun)/usr/include

	install -d -m 755 $(docrun)
	install -m 644 debian/changelog $(docrun)/changelog.Debian
	gzip -9 $(docrun)/*
	install -m 644 debian/copyright $(docrun)/

	install -d -m 755 $(tmprun)/DEBIAN
	dpkg-gencontrol -P$(tmprun) -p$(PACKAGErun)

	chmod -R go=rX $(tmprun)
	chown -R root.root $(tmprun)
	dpkg --build $(tmprun) ..

define checkdir
	test -f newt.h
endef

source diff:
	@echo >&2 'source and diff are obsolete - use dpkg-source -b'; false

checkroot:
	$(checkdir)
	[ `whoami` = root ]

.PHONY: bin2ary-arch clean source diff checkroot binary binary-indep
