#	$Id: Makefile.in,v 1.11 2006/05/06 12:02:49 quozl Exp $	
#
#	Installers, you should not need to edit this file.
#	Everything should be setup in the configuration script.
#

PACKAGE=netrek-server-vanilla
VERSION=2.14.0

RANLIB =  ranlib

srcdir = .

CONFIG = system.mk

include $(CONFIG)

.PHONY: rmdependencies clean reallyclean install installbin \
	do_library do_server do_listener do_robots do_robotd \
	do_utilities do_rsa_utilities do_xsg do_pledit do_gum

all: null $(PMAKE) \
	do_library do_server do_listener do_robots do_robotd \
	do_utilities do_rsa_utilities 

minimal: null $(PMAKE) \
	do_library do_server do_listener do_robots do_robotd \
	do_utilities do_rsa_utilities 

depend: system.mk
	cd ntserv;    $(MAKE) depend
	cd robots;    $(MAKE) depend
	cd newstartd; $(MAKE) depend
	cd tools;     $(MAKE) depend
	cd keycomp;   $(MAKE) depend
	cd sequencer; $(MAKE) depend
	-@if [ -f res-rsa/Makefile ]; then \
		(cd res-rsa; $(MAKE) depend) \
	fi

null: 
	touch null
	$(MAKE) depend

system.mk: ${srcdir}/system.mk.in ${srcdir}/include/config.h.in ${srcdir}/configure
	if [ -f config.status ]; then \
		./config.status; \
	else \
		${srcdir}/configure -v; \
	fi

config.h: system.mk
	touch config.h

do_library: null
	cd ntserv; $(MAKE) libnetrek.a

do_server: null do_rsa_library
	cd ntserv; $(MAKE)

do_robots: do_library
	cd robots; $(MAKE)

do_robotd: 
	cd robotd; $(MAKE)

do_gum: do_library
	cd gum; $(MAKE)

do_xsg: do_library
	cd xsg; $(MAKE);

do_pledit: do_library
	cd pledit; $(MAKE) 

do_rsa_library:	
	-@if [ -f res-rsa/Makefile ]; then \
		(cd res-rsa; $(MAKE) librsa.a) \
	fi

do_utilities: do_rsa_library do_library
	cd tools; $(MAKE) 
	cd sequencer; $(MAKE)

do_rsa_utilities: do_library
	cd keycomp; $(MAKE)

do_listener: do_library
	cd newstartd; $(MAKE)

cflags.h: Makefile $(CONFIG)
	cd ntserv;  $(MAKE) cflags

lint:
	cd ntserv;  $(MAKE) lint
	cd robots;  $(MAKE) lint
	cd keycomp; $(MAKE) lint
	cd tools;   $(MAKE) lint

clean:
	cd ntserv;    $(MAKE) clean
	cd robots;    $(MAKE) clean
	cd robotd;    $(MAKE) clean
	if [ x = xdo_gum ]; then \
		cd gum;       $(MAKE) clean; \
	fi
	cd newstartd; $(MAKE) clean
	cd tools;     $(MAKE) clean
	cd sequencer; $(MAKE) clean
	cd keycomp;   $(MAKE) clean
	-@if [ -f res-rsa/Makefile ]; then \
		cd res-rsa; echo "	cd res-rsa; make clean"; $(MAKE) clean; \
	fi
	rm -f make.out cflags.h *~ null #*#

reallyclean:
	cd ntserv;    $(MAKE) reallyclean
	cd robots;    $(MAKE) reallyclean
	cd robotd;    $(MAKE) reallyclean
	if [ x = xdo_gum ]; then \
		cd gum;       $(MAKE) distclean; \
	fi
	cd newstartd; $(MAKE) reallyclean
	cd tools;     $(MAKE) reallyclean
	cd sequencer; $(MAKE) reallyclean
	cd keycomp;   $(MAKE) reallyclean
	-@if [ -f res-rsa/Makefile ]; then \
		cd res-rsa; echo "	cd res-rsa; make reallyclean"; \
		$(MAKE) reallyclean; \
	fi
	rm -f make.out cflags.h config.cache config.log tools/trekon *~ null #*#

distclean: clean reallyclean rmdependencies

maintainer-clean: distclean
	@echo 'This command is intended for maintainers to use; it'
	@echo 'deletes files that may need special tools to rebuild.'
	rm -f Makefile */Makefile */*/Makefile
	rm -rf */.depend
	rm -rf autom4te.cache conf*.dir
	rm -f config.* configure libtool ltmain.sh aclocal.m4 system.mk
	rm -f docs/sample_sysdef

installbin: all
	cd ntserv;    $(MAKE) install DESTDIR=$(DESTDIR)
	cd robots;    $(MAKE) install DESTDIR=$(DESTDIR)
	cd robotd;    $(MAKE) install DESTDIR=$(DESTDIR)
	if [ x = xdo_gum ]; then \
		cd gum;       $(MAKE) install DESTDIR=$(DESTDIR); \
	fi
	cd newstartd; $(MAKE) install DESTDIR=$(DESTDIR)
	-@if [ -f res-rsa/Makefile ]; then \
		cd res-rsa; echo "	cd res-rsa; make install"; $(MAKE) install DESTDIR=$(DESTDIR); \
	fi
	cd tools;     $(MAKE) install DESTDIR=$(DESTDIR)
	cd tools/admin; $(MAKE) install DESTDIR=$(DESTDIR)
	cd keycomp;   $(MAKE) install DESTDIR=$(DESTDIR)
	cd sequencer; $(MAKE) install DESTDIR=$(DESTDIR)

install: installbin
	mkdir -p $(DESTDIR)$(LIBDIR) $(DESTDIR)$(BINDIR) $(DESTDIR)$(SYSCONFDIR) $(DESTDIR)$(LOCALSTATEDIR)
	cd docs;   $(MAKE) install DESTDIR=$(DESTDIR)
	cd tools;  $(MAKE) installtrekon DESTDIR=$(DESTDIR)
	@echo
	@echo "Vanilla Netrek Server installation is completed."
	@echo "To start your Netrek server, type $(BINDIR)/netrekd"
	@echo "Then start a Netrek client with '-h localhost'"

rmdependencies:
	cd ntserv;    $(MAKE) rmdependencies
	cd robots;    $(MAKE) rmdependencies
	cd newstartd; $(MAKE) rmdependencies
	cd tools;     $(MAKE) rmdependencies
	cd keycomp;   $(MAKE) rmdependencies
	cd sequencer; $(MAKE) rmdependencies
	-@if [ -f res-rsa/Makefile ]; then \
		cd res-rsa; echo "      cd res-rsa; make rmdependencies"; \
		$(MAKE) rmdependencies; \
	fi

NAME=$(PACKAGE)-$(VERSION)
dist:
	chmod +x debian/rules tools/mktrekon configure
	mkdir $(NAME)
        # what has changed
	cp -p ChangeLog NEWS $(NAME)/
        # what needs to change
	cp -p BUGS PROJECTS $(NAME)/
        # top level documentation
	cp -p INSTALL INSTALL.INL INSTALL.Newbie INSTALL.RSA README \
	README.developers README.releasing CHANGES EXAMPLE $(NAME)/
        # configuration
	cp -p configure.in Makefile.in system.mk.in configure config.sub \
	config.guess install-sh name.c $(NAME)/
        # subdirectories
	cp -rp docs gum include keycomp motd newstartd ntserv php \
	pledit res-rsa robotd robots sequencer tools xsg $(NAME)/
        # packaging subdirectories (debian)
	mkdir $(NAME)/debian $(NAME)/rpm
	cp -p debian/README.Debian debian/changelog debian/control \
	debian/copyright debian/*.init debian/postinst debian/rules \
	$(NAME)/debian
	cp -pr debian/po $(NAME)/debian
        # packaging subdirectories (rpm)
	cp -rp rpm $(NAME)/
        # strip out surplus
	rm -rf $(NAME)/*/CVS $(NAME)/*/*/CVS 
	rm -rf $(NAME)/.cvsignore $(NAME)/*/.cvsignore
	rm -rf $(NAME)/*/.deps $(NAME)/*~ $(NAME)/*/*~
        # build
	GZIP=--best tar cfz $(NAME).tar.gz $(NAME)
	rm -rf $(NAME)

dist-minimal:
	mkdir $(NAME)-minimal
        # what has changed
	cp -p ChangeLog NEWS $(NAME)-minimal/
        # top level documentation
	cp -p INSTALL INSTALL.INL INSTALL.Newbie INSTALL.RSA README \
	README.developers $(NAME)-minimal/
        # configuration
	cp -p configure.in Makefile.in system.mk.in configure install-sh \
	name.c $(NAME)-minimal/
        # subdirectories
	cp -rp docs include keycomp newstartd ntserv res-rsa robots robotd \
	$(NAME)-minimal/
        # packaging subdirectories (debian)
	mkdir $(NAME)-minimal/debian $(NAME)-minimal/rpm
	cp -p debian/README.Debian debian/changelog debian/control \
	debian/copyright debian/init debian/postinst debian/rules \
	$(NAME)-minimal/debian
        # packaging subdirectories (rpm)
	cp -rp rpm $(NAME)-minimal/
        # strip out surplus
	rm -rf $(NAME)-minimal/*/CVS $(NAME)-minimal/*/*/CVS 
	rm -rf $(NAME)-minimal/.cvsignore $(NAME)-minimal/*/.cvsignore
	rm -rf $(NAME)-minimal/*/.deps $(NAME)-minimal/*~ $(NAME)-minimal/*/*~
        # build
	GZIP=--best tar cfz $(NAME)-minimal.tar.gz $(NAME)-minimal
	rm -rf $(NAME)-minimal

#
# Maintainer's Debian packaging section
#
DEBIAN_VERSION=`head -1 debian/changelog|cut -f2 -d\(|cut -f1 -d\)`
DEBIAN_PACKAGE=`head -1 debian/changelog|cut -f1 -d\ `
DEBIAN_ARCHIVE=~/public_html/external/mine/netrek

source-package:
	fakeroot dpkg-buildpackage -S -us -uc -I_darcs

package:
	fakeroot dpkg-buildpackage -us -uc -I_darcs

upload:
	mv ../$(DEBIAN_PACKAGE)_$(DEBIAN_VERSION)*{.dsc,.changes,.tar.gz,.deb} $(DEBIAN_ARCHIVE)

update:
	(cd $(DEBIAN_ARCHIVE);make)

release: package upload update