# Makefile for X11 interface to Xconq.
# Copyright (C) 1991-1995, 1997 Stanley T. Shebs.

# Xconq is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.

prefix = /usr/games

exec_prefix = $(prefix)
bindir = $(exec_prefix)/bin
libdir = $(exec_prefix)/lib
datadir = $(prefix)/lib/xconqdir
mandir = $(prefix)/man
man6dir = $(mandir)/man6
infodir = $(prefix)/info
docdir = $(datadir)/doc

appdefaultsdir = /usr/lib/X11/app-defaults

x11libdir = $(datadir)/lib-x11

srcdir = .

krnsrcdir = $(srcdir)/../kernel

GAMEUID = games
GAMEGRP = bin

GAMEPERM = 04755
DIRPERM  = 0755
FILEPERM = 0644

SHELL = /bin/sh

INSTALL = install -c
INSTALL_PROGRAM = $(INSTALL)
INSTALL_DATA = $(INSTALL)

CC = cc

CFLAGS = -g

LDFLAGS =

X11_LIB = -lXmu -lX11

XAW_LIB = -lXaw -lXt $(X11_LIB) -lXext -lm

# Override this to disable SelFile calls.

SELFILE_CFLAGS = -DHAVE_SELFILE

# Override this to point at or disable SelFile library.

SELFILE_LIB = -L../SelFile -lXgnu

# Override this in order to point at the Xpm include files.

XPM_INCLUDE_FLAGS =

# Override this in order to point at the Xpm library.

XPM_LIB = -lXpm

WITH_LIBS = 

KERNEL_LIB = ../kernel/libconq.a

LOW_LIB = ../kernel/libconqlow.a

# Host and target-dependent makefile fragments come in here.
####
# End of host and target-dependent makefile fragments.

GAME_H = $(krnsrcdir)/game.h \
	 $(krnsrcdir)/gvar.def \
	 $(krnsrcdir)/utype.def \
	 $(krnsrcdir)/mtype.def \
	 $(krnsrcdir)/ttype.def \
	 $(krnsrcdir)/table.def

UNIT_H = $(krnsrcdir)/unit.h \
	 $(krnsrcdir)/action.def \
	 $(krnsrcdir)/plan.def \
	 $(krnsrcdir)/task.def

ALL_H = $(krnsrcdir)/conq.h \
	$(krnsrcdir)/config.h \
	$(krnsrcdir)/misc.h \
	$(krnsrcdir)/dir.h \
	$(krnsrcdir)/lisp.h \
	$(krnsrcdir)/module.h \
	$(GAME_H) \
	$(krnsrcdir)/player.h \
	$(krnsrcdir)/side.h \
	$(UNIT_H) \
	$(krnsrcdir)/goal.def \
	$(krnsrcdir)/world.h \
	$(krnsrcdir)/score.h \
	$(krnsrcdir)/history.h \
	$(krnsrcdir)/ai.h

X_H =	$(srcdir)/xconq.h \
	$(srcdir)/xcmd.def \
	$(srcdir)/ximf.h \
	$(krnsrcdir)/cmd.def \
	$(krnsrcdir)/imf.h \
	$(krnsrcdir)/ui.h \
	$(krnsrcdir)/print.h

# Interface-specific object files.

XOBJS =	xconq.o \
	xinit.o \
	xmap.o \
	xdraw.o \
	xcloseup.o \
	xcmd.o \
	xprint.o \
	xdesign.o \
	xhelp.o \
	ximf.o

XUTOBJS = ximf.o \
	 xutil.o

UNIX_CFLAGS = -DUNIX -DIMFLIB=\"$(x11libdir)\"

ALL_CFLAGS = $(CFLAGS) $(SELFILE_CFLAGS) $(XPM_CFLAGS) $(REQD_CFLAGS) $(UNIX_CFLAGS) -I$(srcdir) -I$(krnsrcdir) $(X11_INCLUDE_FLAGS) $(XPM_INCLUDE_FLAGS)

.c.o:
	$(CC) -c $(ALL_CFLAGS) $<

# Do it all.

all:	xconq Xconq Xconq-color x2imf imf2x xshowimf XShowimf XShowimf-color xconq.6

# The game itself.

xconq: $(XOBJS) $(KERNEL_LIB) $(LOW_LIB)
	rm -f xconq
	$(CC) -o xconq $(ALL_CFLAGS) $(LDFLAGS) $(XOBJS) $(KERNEL_LIB) $(LOW_LIB) $(X11_LIB_FLAGS) $(WITH_LIBS) $(XAW_LIB) $(NET_EXTRA_LIBS)

xconqad.h:	Xconq.ad
	$(srcdir)/../Ad2c/ad2c.script Xconq.ad >xconqad.h-new
	$(srcdir)/../move-if-change xconqad.h-new xconqad.h

$(KERNEL_LIB):
	(cd ../kernel; make libconq.a)

$(LOW_LIB):
	(cd ../kernel; make libconqlow.a)

# X-related utilities.

x2imf:	x2imf.o $(XUTOBJS) $(LOW_LIB)
	$(CC) -o x2imf $(ALL_CFLAGS) $(LDFLAGS) x2imf.o $(XUTOBJS) $(LOW_LIB) $(X11_LIB_FLAGS) $(WITH_LIBS) $(XAW_LIB) $(NET_EXTRA_LIBS)

imf2x:	imf2x.o $(XUTOBJS) $(LOW_LIB)
	$(CC) -o imf2x $(ALL_CFLAGS) $(LDFLAGS) imf2x.o $(XUTOBJS) $(LOW_LIB) $(X11_LIB_FLAGS) $(WITH_LIBS) $(XAW_LIB) $(NET_EXTRA_LIBS)

xshowimf:	xshowimf.o $(XUTOBJS) $(LOW_LIB)
	$(CC) -o xshowimf $(ALL_CFLAGS) $(LDFLAGS) xshowimf.o $(XUTOBJS) $(LOW_LIB) $(X11_LIB_FLAGS) $(WITH_LIBS) $(SELFILE_LIB) $(XAW_LIB) $(NET_EXTRA_LIBS)

# Resources.

Xconq:	Xconq.ad
	cp $(srcdir)/Xconq.ad Xconq

Xconq-color:	Xconq-co.ad
	cp $(srcdir)/Xconq-co.ad Xconq-color

XShowimf:	XShowimf.ad
	cp $(srcdir)/XShowimf.ad XShowimf

XShowimf-color:	XShowimf-co.ad
	cp $(srcdir)/XShowimf-co.ad XShowimf-color

# Man pages.

xconq.6:	xconq.6in ../kernel/cmdline.6in
	sed -e '/.so ...kernel.cmdline.6in/r $(srcdir)/../kernel/cmdline.6in' -e '/.so ...kernel.cmdline.6in/d' $(srcdir)/xconq.6in >xconq.6.new
	$(srcdir)/../move-if-change xconq.6.new xconq.6

# Installation.

install: all install-only

install-only:
	srcroot=`cd $(srcroot); pwd`; export srcroot; \
	$(INSTALL_PROGRAM) xconq $(bindir); \
	chown $(GAMEUID) $(bindir)/xconq; \
	chgrp $(GAMEGRP) $(bindir)/xconq; \
	chmod $(GAMEPERM) $(bindir)/xconq; \
	$(INSTALL_DATA) Xconq $(appdefaultsdir); \
	$(INSTALL_DATA) Xconq-color $(appdefaultsdir); \
	$(INSTALL_PROGRAM) imf2x $(bindir); \
	$(INSTALL_PROGRAM) x2imf $(bindir); \
	$(INSTALL_PROGRAM) xshowimf $(bindir); \
	$(INSTALL_DATA) XShowimf $(appdefaultsdir); \
	$(INSTALL_DATA) XShowimf-color $(appdefaultsdir); \
	$(INSTALL_DATA) xconq.6 $(man6dir)
	for i in `ls $(srcdir)/../lib-x11/*`; do \
		echo $$i; \
		$(INSTALL_DATA) $(srcdir)/../lib-x11/$$i $(x11libdir); \
	done
	chown $(GAMEUID) $(x11libdir) $(x11libdir)/*
	chgrp $(GAMEGRP) $(x11libdir) $(x11libdir)/*
	chmod $(DIRPERM) $(x11libdir)
	chmod $(FILEPERM) $(x11libdir)/*

# Cleanliness support.

clean:
	rm -f *.o lint.out core
	rm -f xconq xconq.6 *.conq *.xconq Xconq Xconq-color
	rm -f imf2x x2imf xshowimf XShowimf XShowimf-color

distclean: clean
	rm -f Makefile config.status

extraclean: distclean
	rm -f *~* .*~*

realclean: distclean

Makefile: Makefile.in $(host_makefile_frag) $(target_makefile_frag)
	$(SHELL) config.status

# Dependencies.

xconq.o:	$(ALL_H) $(X_H) $(srcdir)/xconqad.h
xinit.o:	$(ALL_H) $(X_H)
xmap.o:		$(ALL_H) $(X_H)
xcmd.o:		$(ALL_H) $(X_H)
xdraw.o:	$(ALL_H) $(X_H)
xcloseup.o:	$(ALL_H) $(X_H)
xprint.o:	$(ALL_H) $(X_H)
xdesign.o:	$(ALL_H) $(X_H)
xhelp.o:	$(ALL_H) $(X_H)
ximf.o:		$(ALL_H) $(X_H)
