# generic UNIX makefile

CC = gcc				# req. for linux
#CC = cc				# if you don't have gcc

# Configuration options:
#
# No.   Name            Incompatible with   Description
# (1)   -DSERVER        2                   disables cdb debugger 
#                                           (koth server version)
# (2)   -DGRAPHX        1                   enables platform specific 
#                                           core graphics
# (3)   -DXWINGRAPHX    1                   X-Windows graphics (UNIX)
# (4)   -DSDLGRAPHX     1                   SDL graphics (generic)

#DBG = -g -W -Wall -pg
#xwin
#CFLAGS = $(DBG) -DXWINGRAPHX -DEXT94 $(INC)

#-fomit-frame-pointer

#server
CFLAGS = $(DBG) -DSERVER $(INC) -O2 

LFLAGS = -x 
# LIB = -lcurses -ltermlib		# enable this one for curses display

# LIB = -lvgagl -lvga			# enable this one for Linux/SVGA
#LIB = -L/usr/X11R6/lib -lX11		# enable this one for X11

#INC = `sdl-config --cflags`		# enable this one for SDL graphics
#LIB = `sdl-config --libs`		# enable this one for SDL graphics

#ASW -- this is very klunky

#server
LIB = -static -lm

#xwin 
#LIB = -L/usr/X11R6/lib -lX11 -Llibquantum-0.2.2 -lquantum -static -lm

INC = 

SHELL = /bin/sh 

EXESUFFIX=
.SUFFIXES: .o .c .c~ .man .doc .6
MAINFILE = pQmars$(EXESUFFIX)

HEADER = global.h config.h asm.h sim.h rand.h md5.h 
OBJ1 = pQmars.o asm.o eval.o disasm.o cdb.o sim.o cycle.o rand.o md5.o 
OBJ2 = clparse.o global.o token.o 
OBJ3 = str_eng.o 

all: flags $(MAINFILE) pQmars.man chp

flags:
	@echo Making $(MAINFILE) with compiler flags $(CFLAGS)

$(MAINFILE): $(OBJ1) $(OBJ2) $(OBJ3)
	@echo Linking $(MAINFILE)
	@$(CC) $(CFLAGS) -o $(MAINFILE) $(OBJ1) $(OBJ2) $(OBJ3) $(LIB)
	@strip $(MAINFILE)
	@mv $(MAINFILE) .. 
	@echo done

chp: chp.o 
	@echo Linking CHP
	@$(CC) -o chp chp.o 
	@echo done

chp.o: chp.c 

rand.o: rand.h

token.o asm.o disasm.o: asm.h

sim.o cdb.o disasm.o: sim.h 

sim.o: sdldisp.c xwindisp.c md5.h 

cycle.o: sdldisp.c xwindisp.c 

xwindisp.c: xwindisp.h pQmarsicn.h

$(OBJ1) $(OBJ2) $(OBJ3): Makefile config.h global.h

.c.o:
	@echo Compiling $*.o 
	@$(CC) $(CFLAGS) -c $*.c

clean:
	@rm -f $(OBJ1) $(OBJ2) $(OBJ3) core gmon.out chp.o 
.SUFFIXES: .man .6


dist.clean: clean  
	@rm -f pQmars chp pQmars.man 

pQmars.man: pQmars.6 Makefile 

.6.man:
	@echo Building $*.man - online manual
	@nroff -e -man $*.6 > $*.man

