#!/usr/bin/make -f
# Made with the aid of debmake, by Christoph Lameter,
# based on the sample debian/rules file for GNU hello by Ian Jackson.

DESTDIR=debian/tmp
SmallEiffel=/usr/lib/smalleiffel
package=smalleiffel

build:
	$(checkdir)
	
	cd bin_c ;\
	for fmake in *.make; \
	do \
		set -e; \
		chmod a+x $$fmake && \
		echo Running $$fmake && \
		./$$fmake; \
	done

	touch build

clean:
	$(checkdir)
	-rm -f build
	-rm -f `find . -name "*~"`
	-rm -rf debian/tmp debian/files* core debian/substvars
	-rm -f bin/*
	-rm -f bin_c/*.o
	-cd bin_c && rm -f clean compile compile_to_c compile_to_jvm \
	      finder pretty print_jvm_class short

binary-indep:	checkroot build
	$(checkdir)
	echo "There is no binary-independent section of smalleiffel"

binary-arch:	checkroot build
	$(checkdir)
	for fmake in bin_c/*.make; \
	do \
		set -e; \
		cmd=`basename $$fmake .make` && \
		cp  bin_c/$$cmd $(DESTDIR)$(SmallEiffel)/bin/$$cmd; \
	done
	strip $(DESTDIR)$(SmallEiffel)/bin/*
	cp debian/smalleiffel.sh $(DESTDIR)/usr/bin

	find lib_rand lib_show lib_std misc man short sys -print | \
	   cpio -pdum $(DESTDIR)$(SmallEiffel)
	cp debian/menu_entry $(DESTDIR)/usr/lib/menu
	mv $(DESTDIR)$(SmallEiffel)/misc/[HNS]* $(DESTDIR)/usr/doc/smalleiffel
	-cd $(DESTDIR)$(SmallEiffel)/misc && rm [A-Z]*
	-cd $(DESTDIR)$(SmallEiffel)/sys &&\
	   rm *Amiga *DOS *Macintosh *OS2 *VMS *Windows
	mv $(DESTDIR)$(SmallEiffel)/sys/READ_ME $(DESTDIR)/usr/doc/smalleiffel/README.sys
	mv $(DESTDIR)$(SmallEiffel)/lib_rand/READ_ME $(DESTDIR)/usr/doc/smalleiffel/README.lib_rand
	mv $(DESTDIR)$(SmallEiffel)/lib_show/external/READ_ME $(DESTDIR)/usr/doc/smalleiffel/README.lib_show.external
	mv $(DESTDIR)$(SmallEiffel)/lib_show/cecil/READ_ME $(DESTDIR)/usr/doc/smalleiffel/README.lib_show.cecil
	cp READ_ME $(DESTDIR)/usr/doc/smalleiffel
	echo Setting system name.
	/bin/rm -f $(DESTDIR)$(SmallEiffel)/sys/system.se
	echo "UNIX" > $(DESTDIR)$(SmallEiffel)/sys/system.se
	echo Writing default $(DESTDIR)$(SmallEiffel)/sys/loadpath.UNIX
	/bin/rm -f $(DESTDIR)$(SmallEiffel)/sys/loadpath.UNIX
	echo "./"  >  $(DESTDIR)$(SmallEiffel)/sys/loadpath.UNIX
	echo "${SmallEiffel}/lib_std/"  >> $(DESTDIR)$(SmallEiffel)/sys/loadpath.UNIX
	echo "${SmallEiffel}/lib_rand/" >> $(DESTDIR)$(SmallEiffel)/sys/loadpath.UNIX
	echo -n "${SmallEiffel}/lib_show/" >> $(DESTDIR)$(SmallEiffel)/sys/loadpath.UNIX
	cp debian/BUGS.Debian $(DESTDIR)/usr/doc/smalleiffel
	install -m 755 debian/selib2html $(DESTDIR)$(SmallEiffel)/bin
	cp debian/dwww-index $(DESTDIR)/usr/doc/smalleiffel/.dwww-index
	cp -r debian/html $(DESTDIR)/usr/doc/smalleiffel/html
	cd $(DESTDIR)/usr/doc/smalleiffel/html && \
	    uudecode *uu && rm *uu
	cp GNU_LICENSE $(DESTDIR)/usr/doc/smalleiffel/copyright
# Must have debmake installed for this to work. Otherwise please copy
# /usr/bin/debstd into the debian directory and change debstd to debian/debstd
	debstd 
	dpkg-gencontrol
	chown -R root.root debian/tmp
	chmod -R go=rX debian/tmp
	dpkg --build debian/tmp ..

makedirs:
	-rm -rf debian/tmp
	install -d debian/tmp
	cd debian/tmp && install -d `cat ../dirs`

define checkdir
	test -f debian/rules
endef

# Below here is fairly generic really

binary:		makedirs binary-indep binary-arch

checkroot:
	$(checkdir)
	test root = "`whoami`"

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