# Yoy shouldn't have to change anything in this file

CONFIG = system.mk

#
#       Do Not Edit below here. Everything should be setup in the config dir
#

include config/$(CONFIG)

LIBS = $(RSA_LIBS) $(EXTRALIBS)

INCS = $(RSA_INCS) $(EXTRAINCS)

CFLAGS = $(RSA_FLAGS) $(EXTRACFLAGS)

all: server startup utils 

# note: xsg not automatically made
xsg: 
	-if [ -d xsgd ] ; then cd xsgd; make ; fi

# make the server binaries and such
server: cflags.h
	cd ntserv; make 

utils: cflags.h
	cd tools; make 

# make the startup program
startup: cflags.h
	cd ntstart; make

cflags.h: Makefile
	echo static char cflags[]=\"$(LIBS) $(CFLAGS)\"\; > cflags.h
	echo static char arch[]=\"$(ARCH)\"\; >> cflags.h

clean:
	cd ntserv; make clean
	cd ntstart; make clean
	cd tools; make clean
	-if [ -d xsgd ] ; then cd xsgd; make clean ; fi
	rm -f make.out name.o name core

reallyclean:
	cd ntserv; make reallyclean
	cd ntstart; make reallyclean
	cd tools; make reallyclean
	-if [ -d xsgd ] ; then cd xsgd; make reallyclean ; fi
	rm -f make.out core

installbin: all
	cd ntserv; make installbin
	cd ntstart; make install
	cd scripts; make install
	-if [ -d xsgd ] ; then cd xsgd; make install ; fi
	cd tools; make install

install: installbin
	cd ntserv; make installinf

depend:	cflags.h
	cd ntserv; make depend
	cd ntstart; make depend
	cd tools; make depend
	-if [ -d xsgd ] ; then cd xsgd; make depend ; fi

name: name.c version.h patchlevel.h
	$(CC) $(CFLAGS) -o name name.c

patches: name
	cd $(PATCHDIR); make name
	@echo Making INL`./name`\-`$(PATCHDIR)/name`.diffs
	-rm ../INL`./name`\-`$(PATCHDIR)/name`.diffs
	-for f in `cat manifest` ; do \
	if [ ! -f $(PATCHDIR)/$${f} ] ; then touch $(PATCHDIR)/$${f} ; fi ; \
	diff -c $(PATCHDIR)/$${f} $${f} >> ../INL`./name`\-`$(PATCHDIR)/name`.diffs ;\
	done

#archive is for yourself so you get absolutely everything including RCS files
archive: reallyclean name
	tar cvf - . | gzip > ../INL`./name`.archive.tar.gz

# a distribution of INL code. xsg is not included in distribution
# 	-cd ntserv; rm reserved.c; ln -s reserved.c.shipped reserved.c
# ^^^^^^^^ intelligent people will use links so let's not make life hard
dist: name 
	tar cvf - `cat manifest` | gzip  > ../INL`./name`.tar.gz

# should indent all the source to gnu format
indent: 
	cd ntserv; make indent
	cd tools; make indent
	cd ntstart; make indent


# a distribution of the bare necessities
# maybe inefficient but it works
bindist: all name
	rm -rf /tmp/bindisttmp
	cd ntserv; make BINDIR=/tmp/bindisttmp installbin; make BINDIR=/tmp/bindisttmp installinf
	cd ntstart; make BINDIR=/tmp/bindisttmp install
	cd scripts; make BINDIR=/tmp/bindisttmp install
	cd tools; make BINDIR=/tmp/bindisttmp install
	-if [ -d xsgd ] ; then cd xsgd; make BINDIR=/tmp/bindisttmp install ; fi
	cd /tmp/bindisttmp; rsa_getkeys
	tar cvf - -C /tmp/bindisttmp . | gzip > ../INL`./name`.dec.ultrix.tar.gz
	rm -rf /tmp/bindisttmp

binclean:
	cd $(BINDIR); rm -fr .global .players .planets .conquer logfile \
		inl_log inl_stats startup.err startup.log \
		Players.* Global.* Conquer.* INL_log.* INL_stats.* \
		Logfile.* PWstats.* Planets.* slots

