/* XTREK Imakefile sccsid = "%W%" */

#ifdef BandAidCompiler
#include BandAidCompiler
#endif

/*
 * User Selectable options:
 *
 *  -DCUSTOMSHIP - allows players to customize their ships as described in
 *		  xtrek_ship(6).  If not defined, then ships are static.
 *
 *  -DNO_INETD - This is useful if you are using it as a long-lived daemon
 *		  rather than running under inetd, which you probably want
 *		  to do if you are not root.  Be sure to add the line
 *			#define NO_INETD
 *		  in addition to adding -DNO_INETD to the options list; the
 *		  Makefile must change along with the source.
 *  -DEXCLUDE - Don't allow more than one session per display.
 *  -DOPENWINDOWS - Define for Suns running open windows.  Will install
 *		fonts correctly.
 *  -DDEFAULTSERV - Define the default server, if no env 
 */
/*#define OPTIONS -DCUSTOMSHIP -DNO_INETD*/
#define OPTIONS -DCUSTOMSHIP -DEXCLUDE
/*#define NO_INETD*/

/* Default defines */
#define NEWINET /* as nothing */
#define SUNV    /* as nothing */
#define LOC_CF	/* as nothing */
#define LOC_LIB /* as nothing */
#define	HPCFLAGS	/* as nothing */
#define	OPENWINDOWS	/* as nothing */

#if defined(SunArchitecture) && SunOSPlatform && OSMajorVersion >= 4
#undef  NEWINET
#define NEWINET -DNEWINET
#undef  SUNV
#define SUNV    -DSUN40
#undef LOC_LIB
#define	LOC_LIB	-ldbm -Bstatic
#undef LOC_CF
#define	LOC_CF	-DNDBM
#undef OPENWINDOWS
#define	OPENWINDOWS	-DOPENWINDOWS
#endif

#if defined(SGIArchitecture)
#define NEWINET -DNEWINET
#define LOC_CF  -I/usr/include/bsd
#define LOC_LIB -lsun -lbsd
#endif

#if defined(HPArchitecture)
#undef LOC_LIB
#define LOC_LIB -lBSD -lndbm
#define LOC_LIB -lBSD -lndbm
#undef HPCFLAGS
#define HPCFLAGS -Dhpux -DSYSV -Wc,-Np500		/* For HP9000/300 */
/*#define HPCFLAGS -Dhpux -DSYSV 			/* For HP9000/800 */
/*#define XLIB kludge.libX11.a		/* For s800, kludge.libX11.a is linked in */
#endif

#ifdef RtArchitecture
#if defined(NEWINET)
#undef NEWINET
#endif
#define NEWINET	-DNEWINET
#if defined(LOC_LIB)
#undef LOC_LIB
#endif
#define LOC_LIB	-ldbm
#if defined(LOC_CF)
#undef LOC_CF
#endif
#define LOC_CF	-DNDBM
#endif

/* What's the daemon going to be called? */
#ifdef NO_INETD
       XTREKD = xtrekd
#else
       XTREKD = in.xtrekd
#endif
#define DEFSERV -DDEFAULTSERV=\"tecpserv\"

     XTREKDIR = /vol/X11/share/xtrek
      DEFINES = DEFSERV NEWINET SUNV OPTIONS LOC_CF HPCFLAGS -DMAINDIR=\"$(XTREKDIR)\"
     LOCALINC = bitmaps.h data.h defs.h planets.h struct.h xtrekfont.h \
                clock.bitmap
        SRCS1 = bitmaps.c colors.c coup.c data.c death.c detonate.c dmessage.c \
                enter.c getship.c inform.c input.c interface.c main.c \
                newwin.c orbit.c phaser.c planetlist.c playerlist.c \
                pstats.c redraw.c smessage.c subdaemon.c stats.c torp.c \
                util.c warning.c random.c rmove.c scorelist.c \
                trigtab.c itoa.c minisubs.c war.c DBG.c
        OBJS1 = bitmaps.o colors.o coup.o data.o death.o detonate.o dmessage.o \
                enter.o getship.o inform.o input.o interface.o main.o \
                newwin.o orbit.o phaser.o planetlist.o playerlist.o \
                pstats.o redraw.o smessage.o subdaemon.o stats.o torp.o \
                util.o warning.o random.o rmove.o scorelist.o \
                trigtab.o itoa.o minisubs.o war.o DBG.o
    LINTFILES = bitmaps.ln colors.ln coup.ln data.ln death.ln detonate.ln \
                dmessage.ln enter.ln getship.ln inform.ln input.ln \
                interface.ln main.ln newwin.ln orbit.ln phaser.ln \
                planetlist.ln playerlist.ln pstats.ln redraw.ln smessage.ln \
                subdaemon.ln stats.ln torp.ln util.ln warning.ln random.ln \
                rmove.ln scorelist.ln trigtab.ln itoa.ln minisubs.ln \
                war.ln DBG.ln
        SRCS2 = xtrek.c
        OBJS2 = xtrek.o
        SRCS3 = xtrekb.c
        OBJS3 = xtrekb.o
         SRCS = $(SRCS1) $(SRCS2) $(SRCS3)
        SRCSF = xtrek.bdf
        OBJSF = xtrek.snf
         OBJS = $(OBJSF)
     PROGRAMS = bitmaps.h xtrek $(XTREKD) xtrekb
     INCLUDES = -I$(TOP)
     LINTOPTS = -iabchu
         LIBS = LOC_LIB $(XLIB) -lm
           FC = bdftosnf

.SUFFIXES: .ln

AllTarget($(PROGRAMS))
SingleProgramTarget(xtrek,$(OBJS2),,LOC_LIB)
SingleProgramTarget($(XTREKD),$(OBJS1),,$(LIBS))
SingleProgramTarget(xtrekb,$(OBJS3),,$(LIBS))
MakeFonts()
FontTarget(xtrek)
AllTarget($(OBJSF))
DependTarget()

bitmaps.h:   bitmaps.c
	sed -e '1i\
		/* DO NOT EDIT THIS FILE. It is machine generated. */'\
	    -e 's/[ 	]*=[ 	]*{[ 	]*$$/;\
		%MARKTEXT%/'\
	    bitmaps.c |\
	sed -e 's/^char/extern char/'\
	    -e 's/^Pixmap/extern Pixmap/'\
	    -e '/[ 	]*%MARKTEXT%[ 	]*$$/,/[ 	]*}[ 	]*;[ 	]*$$/d'\
	    > bitmaps.h

install::
	-mkdir $(XTREKDIR)
	touch $(XTREKDIR)/planets $(XTREKDIR)/motd
	touch $(XTREKDIR)/scores.dir $(XTREKDIR)/scores.pag
	chmod 600 $(XTREKDIR)/planets $(XTREKDIR)/motd
	chmod 644 $(XTREKDIR)/scores.dir $(XTREKDIR)/scores.pag
	chmod u+s $(XTREKDIR)/$(XTREKD)
	@-chmod u+w $(XTREKDIR)/xtrek.doc > /dev/null 2>&1
	-cp doc $(XTREKDIR)/xtrek.doc
	chmod 444 $(XTREKDIR)/xtrek.doc
#if defined(OPENWINDOWS)
	-(convertfont xtrek.bdf; bldfamily)
	-cp xtrek.ff xtrek31.fb Families.list Synonyms.list $(XTREKDIR)
	-chmod 444 $(XTREKDIR)/xtrek.ff $(XTREKDIR)/xtrek31.fb
	-chmod 444 $(XTREKDIR)/Families.list $(XTREKDIR)/Synonyms.list
#endif

#ifdef NO_INETD
install::
	chmod 4711 $(BINDIR)/$(XTREKD)
#endif

#ifdef NO_INETD
InstallProgram($(XTREKD),$(BINDIR))
#else
InstallProgram($(XTREKD),$(XTREKDIR))
#endif
InstallProgram(xtrek,$(BINDIR))
InstallProgram(xtrekb,$(BINDIR))
InstallManPage(xtrek,$(MANDIR))
InstallManPage(xtrekb,$(MANDIR))
InstallManPage(xtrek_ship,$(MANDIR))
InstallFonts($(XTREKDIR))

lint: $(LINTFILES)
	$(LINT) $(LINTXLIB) *.ln > xtrek.lint 2>&1

/* This is only used on HP 9000/800 to hide duplicate symbols. */
kludge.X11.a:	/usr/lib/libX11.a
	cp /usr/lib/libX11.a kludge.libX11.a	# Copy X11 lib
	chmod u+w kludge.libX11.a		# make our copy writeable
	ar xv kludge.libX11.a Berklib.o		# Copy offending module
	ld -r -o templib.o -h bcopy -h random -h srandom Berklib.o # Hide syms
	ar dv kludge.libX11.a Berklib.o		# Remove offending module
	ar rv kludge.libX11.a templib.o		# Add fixed module
	/bin/rm templib.o			# Remove temp file

shar:
	makekit -s50k -oMANIFEST READ* INSTALL* TODO xtrek.man xtrek_ship.man xtrekb.man Imakefile Makefile doc *.h *.c xtrek.bdf clock.bitmap

cpio:
	for i in READ* INSTALL* TODO xtrek.man xtrek_ship.man xtrekb.man Imakefile Makefile doc *.h *.c xtrek.bdf clock.bitmap; do /bin/echo $$i; done | cpio -ocB > xtrek.cpio

tar:
	tar cf xtrek.tar READ* INSTALL* TODO xtrek.man xtrek_ship.man xtrekb.man Imakefile Makefile doc *.h *.c xtrek.bdf clock.bitmap

.c.ln:
	$(LINT) $(LINTFLAGS) $< > $*.p1 2>&1
