# makefile for the Mastodon installer and admin tools
# $Id: s.Makefile 1.20 00/09/21 18:00:30-07:00 orc@india.pell.portland.or.us $

SUBDIRS=bin installer admin
LIBDIRS=nd basis
INSTALLDIRS=lib bin include

all install:: libs
	@for x in $(SUBDIRS); do \
	    make -C $$x $@ || exit 1; \
	done

install:: install.libs install.man

install.libs:
	@for x in $(LIBDIRS); do \
	    make -C $$x install || exit 1; \
	done

install.man:
	@if [ "`echo man/*.1`" != 'man/*.1' ]; then \
	    echo "installing man.1 pages"; \
	    mkdir $(DESTDIR)/usr/man/man1; \
	    install -c -o man -g man -m 444 man/*.1 $(DESTDIR)/usr/man/man1; \
	fi
	@if [ "`echo man/*.5`" != 'man/*.5' ]; then \
	    echo "installing man.5 pages"; \
	    mkdir $(DESTDIR)/usr/man/man5; \
	    install -c -o man -g man -m 444 man/*.5 $(DESTDIR)/usr/man/man5; \
	fi
	@if [ "`echo man/*.7`" != 'man/*.7' ]; then \
	    echo "installing man.7 pages"; \
	    mkdir $(DESTDIR)/usr/man/man7; \
	    install -c -o man -g man -m 444 man/*.7 $(DESTDIR)/usr/man/man7; \
	fi
	@if [ "`echo man/*.8`" != 'man/*.8' ]; then \
	    echo "installing man.8 pages"; \
	    mkdir $(DESTDIR)/usr/man/man8; \
	    install -c -o man -g man -m 444 man/*.8 $(DESTDIR)/usr/man/man8; \
	fi

install::
	@if [ ! "$(DESTDIR)" ]; then \
	    echo "DESTDIR not set?"; \
	    exit 1; \
	fi
	install -d $(DESTDIR)/etc/rc.d/rc.s $(DESTDIR)/etc/rc.d/rc.m
	install -d $(DESTDIR)/etc/rc.d/rc.r $(DESTDIR)/etc/rc.d/rc.h
	find rc.d -depth -print | grep -v SCCS | cpio -pdumB $(DESTDIR)/etc
	mv $(DESTDIR)/etc/rc.d/inittab $(DESTDIR)/etc
	rm $(DESTDIR)/etc/rc.d/rc.build

libs: $(INSTALLDIRS)
	@for x in $(LIBDIRS); do \
	    make -C $$x build_install || exit 1; \
	done

clean:
	@for x in $(LIBDIRS) $(SUBDIRS);do \
	    make -C $$x $@ || exit 1; \
	done

spotless:	clean
	rm -rf include lib

tarball:
	@rm -f ../Mastodon.tar.gz
	tar czvf nd/nd.tar.gz nd
	cd ..; tar czvf Mastodon.tar.gz Mastodon
	makepkg Mastodon.pkg > ../Mastodon.src


lib bin include:
	[ -d $@ ] || mkdir $@
