include Rules.make

# These only get built on Linux
ifeq ($(OPSYS),Linux)
  SUBDIRS  = common first second tilo
  MANPAGES = maketilo.1 tilo.1
endif

# These get built on Linux and Solaris
MANPAGES += silo.8 silo.conf.5
SUBDIRS  += silo

all dep depend clean:
	@for I in $(SUBDIRS); do $(MAKE) -C $$I $@ || exit 1; done

ifeq ($(OPSYS),$(findstring $(OPSYS),Linux Solaris))
install:
	install -d -m755 $(DESTDIR)/etc $(DESTDIR)/sbin $(DESTDIR)/usr/sbin
	install -m755 silo/silo $(DESTDIR)/sbin
	install -m755 silo/silocheck $(DESTDIR)/usr/sbin
	[ -f $(DESTDIR)/etc/silo.conf ] || \
		install -m644 etc/silo.conf $(DESTDIR)/etc/
 ifeq ($(OPSYS),Linux)
	install -d -m755 $(DESTDIR)/boot $(DESTDIR)/usr/bin
	install -m644 first/*.b second/*.b $(DESTDIR)/boot/
	install -m755 tilo/maketilo $(DESTDIR)/usr/bin/
	install -m755 tilo/tilo.sh $(DESTDIR)/usr/bin/tilo
 endif
	for manpage in $(MANPAGES); do \
		sect=`echo $$manpage | sed 's/.*\([1-8]\)$$/\1/'`; \
		install -d -m755 $(DESTDIR)/usr/share/man/man$$sect; \
		install -m644 man/$$manpage $(DESTDIR)/usr/share/man/man$$sect/; \
	done
	if test x"$(DESTDIR)" = x; then \
		echo "You need to run 'silo -f' now, to update the boot block" 1>&2; \
	fi
else
install:
	@echo SILO is only supported on SPARC Linux and Solaris.
endif

# This is just for me to make release tarballs
release: ../silo-loaders-$(VERSION).tar.gz ../silo-$(VERSION).tar.gz ../silo-$(VERSION).tar.bz2
	rm -rf ../silo-$(VERSION) boot

../silo-loaders-$(VERSION).tar%:
	if ! test -d boot; then \
		for I in first second; do $(MAKE) -C $$I all || exit 1; done; \
		install -d -m755  boot; \
		install -m644 first/*.b second/*.b boot/; \
	fi
	case "$*" in .gz) foo="gzip -c9";; .bz2) foo="bzip2 -c9";; *) foo=cat;; esac; \
		tar cf - boot | $$foo > $@
	rm -rf boot

../silo-$(VERSION).tar%: clean
	if ! test -d ../silo-$(VERSION); then \
		install -d -m755 ../silo-$(VERSION); \
		cp -a ./ ../silo-$(VERSION); \
	fi
	cd ../silo-$(VERSION) && find -name .\#\* -o -name CVS -o -name .cvsignore | \
		xargs -r rm -rf
	case "$*" in .gz) foo="gzip -c9";; .bz2) foo="bzip2 -c9";; *) foo=cat;; esac; \
		(cd ../ && tar cf - silo-$(VERSION)) | $$foo > $@
