CFLAGS=@CFLAGS@ -O3 @X_CFLAGS@ -Wall -W -Wstrict-prototypes -Wno-parentheses -fomit-frame-pointer 
#-malign-functions=0
LDFLAGS=@LDFLAGS@
LIBS=@LIBS@ 
XLIBS=@X_LIBS@
CC=@CC@

# Installation commands
INSTALL = install
INSTALL_PROGRAM = $(INSTALL) --mode=755
INSTALL_DATA = $(INSTALL) --mode=644

# Standard installation directories

# Installation root directory
prefix = /usr/local
# Machine-specific prefix
exec_prefix = $(prefix)

# Executable file installation

# Normal binaries
# this is a game
bindir = $(prefix)/games
# Super user binaries
sbindir = $(prefix)/sbin
# Executables used only by programs
libexecdir = $(exec_prefix)/libexec

# Data file installation
# ro arch-independent data files
datadir = $(prefix)/share
# ro ASCII host-configuration files
sysconfdir = $(prefix)/etc
# rw arch-independent data files
sharedstatedir = $(prefix)/com
# rw arch-dependent data
localstatedir = $(prefix)/var

# Dirs that are necessary for running program
# object files and libraries of object code.
libdir = $(exec_prefix)/lib
# elisp files
lispdir =
# include files
includedir = $(prefix)/include

# Documentation
# Info root
infodir = $(prefix)/info
# Man root
mandir=$(prefix)/man
man1dir = $(mandir)/man1
man2dir = $(mandir)/man2
man3dir = $(mandir)/man3
man4dir = $(mandir)/man4
man5dir = $(mandir)/man5
man6dir = $(mandir)/man6
man7dir = $(mandir)/man7
man8dir = $(mandir)/man8
man9dir = $(mandir)/man9

all: server 0verkill @X0VERKILL@ @XEDITOR@ editor test_server avi bot @XAVI@

clean:
	rm -f *.o server 0verkill editor test_server x0verkill xeditor avi xavi bot core

distclean: clean
	rm config.h config.cache config.log config.status Makefile

.PHONY: install install-program install-data

install: install-program install-doc install-data

install-program: all
	$(INSTALL_PROGRAM) 0verkill $(bindir)/overkill
	$(INSTALL_PROGRAM) @X0VERKILL@ $(bindir)/xoverkill
	$(INSTALL_PROGRAM) server $(bindir)/overkill-server
	$(INSTALL_PROGRAM) test_server $(bindir)/overkill-test-server
	$(INSTALL_PROGRAM) editor $(bindir)/overkill-editor
	$(INSTALL_PROGRAM) bot $(bindir)/overkill-bot

install-doc:
	./mkinstalldirs $(datadir)/doc/overkill
	$(INSTALL_DATA) doc/* $(datadir)/doc/overkill

install-data:
	./mkinstalldirs $(datadir)/overkill $(datadir)/overkill/data \
         $(datadir)/overkill/grx
	$(INSTALL_DATA) data/* $(datadir)/overkill/data
	$(INSTALL_DATA) grx/* $(datadir)/overkill/grx
	$(INSTALL_PROGRAM) grx/make_hero $(datadir)/overkill/grx/make_hero
	#$(INSTALL_DATA) develop/0verkill_icon_64x64.png $(datadir)/overkill/overkill_icon.png

bot.o: bot.c config.h sprite.h data.h cfg.h net.h hash.h time.h math.h getopt.h error.h
avi.o: avi.c console.h blit.h time.h help.h error.h
blit.o: blit.c blit.h console.h cfg.h config.h error.h
net.o: net.c net.h crc32.h error.h
crc32.o: crc32.c crc32.h error.h
hash.o: hash.c hash.h data.h error.h
console.o: console.c console.h kbd.h kbd.c config.h error.h
kbd.o: kbd.c kbd.h cfg.h console.h error.h
sprite.o: sprite.c sprite.h console.h cfg.h data.h blit.h config.h md5.h error.h
data.o: data.c cfg.h data.h hash.h time.h math.h config.h error.h
server.o: server.c server.h net.h data.h hash.h cfg.h time.h math.h config.h error.h
client.o: client.c data.h sprite.h cfg.h net.h hash.h time.h math.h console.h help.h blit.h config.h error.h
xclient.o: client.c data.h sprite.h cfg.h net.h hash.h time.h math.h console.h help.h config.h error.h
	gcc -c $(CFLAGS) -DXWINDOW -o xclient.o client.c
time.o: time.c time.h error.h
help.o:	help.c blit.h error.h
avihelp.o: avihelp.c blit.h error.h
editor.o: editor.c sprite.h console.h data.h cfg.h hash.h time.h math.h blit.h error.h
test_server.o: test_server.c net.h data.h error.h
xinterface.o: xinterface.c console.h kbd.h x.h cfg.h icon.h config.h error.h
xkbd.o: xkbd.c kbd.h console.h x.h cfg.h time.h error.h
md5.o: md5.c md5.h error.h
md5hl.o: md5hl.c md5.h error.h
error.o: error.c error.h
io.o: io.c io.h

avi: avi.o blit.o console.o kbd.o time.o avihelp.o error.o io.o
	gcc $(LDFLAGS) -o avi avi.o blit.o console.o kbd.o error.o \
time.o avihelp.o io.o $(LIBS)

xavi: avi.o blit.o xinterface.o xkbd.o time.o avihelp.o error.o io.o
	gcc $(LDFLAGS) -o xavi avi.o blit.o xinterface.o xkbd.o \
error.o time.o avihelp.o io.o $(LIBS) $(XLIBS)

bot: bot.o data.o hash.o time.o net.o crc32.o md5.o md5hl.o error.o io.o
	gcc $(LDFLAGS) -o bot bot.o data.o hash.o time.o net.o \
	error.o md5.o md5hl.o crc32.o sprite.o io.o $(LIBS)

0verkill: client.o data.o sprite.o blit.o console.o hash.o time.o \
net.o error.o crc32.o md5.o md5hl.o kbd.o help.o io.o
	gcc $(LDFLAGS) -o 0verkill client.o data.o sprite.o blit.o \
console.o error.o hash.o time.o md5.o md5hl.o kbd.o net.o crc32.o \
help.o io.o $(LIBS)
	@OVERKILL_SPECIAL@

x0verkill: xclient.o data.o sprite.o blit.o xinterface.o hash.o time.o \
net.o crc32.o error.o xkbd.o help.o md5.o md5hl.o io.o
	gcc $(LDFLAGS) -o x0verkill xclient.o data.o blit.o sprite.o \
	xinterface.o xkbd.o error.o md5.o md5hl.o hash.o time.o net.o \
	crc32.o help.o io.o $(LIBS) $(XLIBS)

server: server.o data.o sprite.o blit.o console.o hash.o time.o kbd.o \
	net.o crc32.o md5.o md5hl.o error.o io.o
	gcc $(LDFLAGS) -o server server.o data.o sprite.o blit.o \
	console.o hash.o time.o kbd.o md5.o md5hl.o error.o net.o \
	crc32.o io.o $(LIBS)

editor: editor.o data.o blit.o sprite.o console.o hash.o time.o kbd.o md5.o md5hl.o error.o io.o
	gcc $(LDFLAGS) -o editor editor.o data.o blit.o sprite.o \
console.o hash.o md5.o md5hl.o error.o time.o kbd.o io.o $(LIBS) 

xeditor: editor.o data.o blit.o sprite.o xinterface.o hash.o time.o \
xkbd.o md5.o md5hl.o error.o io.o
	gcc $(LDFLAGS) -o xeditor editor.o data.o blit.o sprite.o \
xinterface.o hash.o md5.o error.o md5hl.o time.o xkbd.o io.o $(LIBS) $(XLIBS)

test_server: test_server.o net.o data.o crc32.o blit.o sprite.o \
time.o hash.o console.o kbd.o md5.o md5hl.o error.o io.o
	gcc $(LDFLAGS) -o test_server test_server.o net.o data.o \
crc32.o blit.o sprite.o time.o hash.o md5.o md5hl.o error.o console.o \
kbd.o io.o $(LIBS) 
