##### Makefile for CCS64

### Variables

# X11 libraries

LIBDIR = -L/usr/X11R6/lib
LIBS = -lXaw -lXmu -lXt $(SHMLIB) -lXext -lX11

# GUI object files

GUIOBJS = dialog.o filedialog.o init.o keyboard.o menu.o util.o ui.o
GUIDEFS = -D_BSD_SOURCE -DVERSION=\"$(VERSION)\"

# Code from the Free Widget Foundation

FWFDIR = widgets/
FWFOBJS = $(addprefix $(FWFDIR),DirMgr.o Directory.o FChooser.o)
FWFDEFS = -D_BSD_SOURCE -DNO_REGEXP

# The zlib compression/decompression library (not defined if not used)

ZLIB = -L/usr/lib -lz

# Libraries for the MIT Shared Memory Extension (not defined if not used)
SHMLIB = -lSM -lICE

# CCS64 Emulator engine (proprietary)

EMUVERSION = 1.09
EMUDIR = emulator/
EMUOBJS = $(addprefix $(EMUDIR),emulator.o c1541.o cpu.o cpu1541.o sid.o siddata.o vic.o)
EMUDEFS =
EMULIB = $(EMUDIR)libccs64-$(EMUVERSION).a

# Object files
OBJS = $(GUIOBJS) $(FWFOBJS)

# Version number (emulator version and GUI patchlevel)
VERSION = $(EMUVERSION).1

# Target file name
TARGET = ccs64
DOCS = ccs64.ps ccs64.cat

## Compiler set-up

CC = gcc
CFLAGS = -ggdb -Wall -ansi -pedantic
#CFLAGS = -m486 -O9 -s -fomit-frame-pointer -funroll-loops -ffast-math
ifndef ZLIB
  CFLAGS += -DNO_ZLIB
endif
ifndef SHMLIB
  CFLAGS += -DNO_SHM
endif
CXXFLAGS = $(CFLAGS)

### Targets

.phony: all docs clean reallyclean

all: $(TARGET) $(DOCS)

docs: $(DOCS)

clean:
	rm -f $(OBJS)

reallyclean: clean
	rm -f $(TARGET) $(EMUOBJS) $(DOCS)

### Rules

$(TARGET): $(OBJS) $(EMULIB)
	$(CC) -o $@ $^ $(ZLIB) $(LIBDIR) $(LIBS)

$(GUIOBJS):
	$(CC) $(CFLAGS) -I$(FWFDIR) -I$(EMUDIR) $(GUIDEFS) -c $< -o $@
$(FWFOBJS):
	$(CC) $(CFLAGS) $(FWFDEFS) -c $< -o $@
#$(EMULIB): $(EMUOBJS)
#	ar rc $@ $^
$(EMUOBJS):
	$(CC) $(CFLAGS) $(EMUDEFS) -c $< -o $@

ccs64.ps: ccs64.1
	groff -Tps -man $< > $@
ccs64.cat: ccs64.1
	groff -Tlatin1 -man $< > $@

### Dependencies

ui.o:		ui.C ui.h init.h menu.h keyboard.h dialog.h filedialog.h \
		$(EMUDIR)emulator.h $(EMUDIR)c1541.h
init.o:		init.c init.h util.h menu.h dialog.h
keyboard.o:	keyboard.c keyboard.h init.h
util.o:		util.c util.h
dialog.o:	dialog.c dialog.h util.h
filedialog.o:	filedialog.c filedialog.h util.h $(FWFDIR)FChooser.h
menu.o:		menu.c menu.h util.h

$(FWFDIR)DirMgr.o:	$(FWFDIR)DirMgr.c $(FWFDIR)DirMgr.h
$(FWFDIR)Directory.o:	$(FWFDIR)Directory.c $(FWFDIR)Directory.h
$(FWFDIR)FChooser.o:	$(FWFDIR)FChooser.c $(FWFDIR)FChooser.h \
			$(FWFDIR)FChooserP.h $(FWFDIR)DirMgr.h

$(EMUDIR)c1541.o:	$(EMUDIR)c1541.cpp $(EMUDIR)c1541.h \
			$(EMUDIR)cpu1541.h $(EMUDIR)emulator.h
$(EMUDIR)cpu.o:		$(EMUDIR)cpu.cpp $(EMUDIR)emulator.h $(EMUDIR)cpu.h \
			$(EMUDIR)cpu_defs.h
$(EMUDIR)cpu1541.o:	$(EMUDIR)cpu1541.cpp $(EMUDIR)c1541.h \
			$(EMUDIR)cpu1541.h $(EMUDIR)cpud1541.h \
			$(EMUDIR)emulator.h
$(EMUDIR)emulator.o:	$(EMUDIR)emulator.cpp $(EMUDIR)emulator.h \
			$(EMUDIR)cpu.h $(EMUDIR)sid.h $(EMUDIR)vic.h \
			$(EMUDIR)c1541.h
$(EMUDIR)sid.o:		$(EMUDIR)sid.cpp $(EMUDIR)emulator.h $(EMUDIR)sid.h
$(EMUDIR)siddata.o:	$(EMUDIR)siddata.cpp $(EMUDIR)emulator.h $(EMUDIR)sid.h
$(EMUDIR)vic.o:		$(EMUDIR)vic.cpp $(EMUDIR)emulator.h \
			$(EMUDIR)vic_defs.h $(EMUDIR)vic.h
