#  Makefile for xz80, an X11 Spectrum Emulator.
#  Copyright (C) 1994 Ian Collier.

#  This program 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 of the License, or
#  (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

CC=gcc

# Note: beware of extra spaces in the SRC macro.  If in doubt, leave
# no spaces after the equals sign and type a "#" directly after the
# definition.
# Note2: try reducing the level of optimisation if the compiler
# runs out of memory or takes too long when compiling z80.c.

INCLUDE=-I/users/X11R5/include       # Any extra include directories
SRC=.#                               # Directory containing the source
OPTFLAG= -O2                         # Flags to use when optimising
DEBUGFLAG= -g -DDEBUG                # Flags to use when debugging
CCFLAG=-I$(SRC) $(INCLUDE) -finline  # Flags to use in any case
LIBS=-lXext -lX11                    # C libraries to use
LIBSSVGA=-lvgagl -lvga               # Libs for svgalib ver. on Linux

# Define SCALE to an integer between 1 and 4.  1 gives the smallest
# and fastest emulator window.
SCALE=1
SCALDEF = -DSCALE=$(SCALE)

# Insert the default library search path
LIBDEF = -DLIBPATH=\".:/usr/local/xz80/lib\"

# Include the MIT-SHM code.  If possible, do.
SHMDEF = -DMITSHM

# Include a few kludges for Sun workstations.  Probably only necessary
# on SunOS (but not Solaris).
# KLUDGEDEF = -DSunKludge

# Define this if your system has the uname() call.
NAMEDEF = -DHAS_UNAME

#Define this to the system app-defaults directory, or leave undefined.
# XAPPLDEF = -DXAPPLRESDIR=\"/usr/lib/X11/app-defaults\"

# Define DEV_AUDIO if you want to use Sparc-style audio.
# Also define DEV_AUDIO_IN if you want to be able to input as well as
#   output.
# Also define SUN_AUDIO if you want to use the Sun AUDIO_DRAIN ioctl
#   to synchronise the sound.  You must have <sun/audioio.h> in order
#   to define this.  Don't define it unless the synchronisation goes
#   wrong, since it seems to degrade the sound.
# Define LINUX_FRAG on Linux to use the SNDCTL_DSP_SETFRAGMENT
#   ioctl to synchronise the sound. It shouldn't degrade the sound.
#   You probably want it enabled if you want sound under Linux.
# Optionally define AUDIODEV to the filename of the audio device.
AUDIODEF = -DDEV_AUDIO -DDEV_AUDIO_IN#-DLINUX_FRAG -DSUN_AUDIO -DAUDIODEV=\"/dev/audio\"

# Define FANCYBORDER if you want to compile in the code for "-border full".
BORDDEF=-DFANCYBORDER

# Define this if you want to use the Linux svgalib instead of the X
# interface.
# LINUXDEF = -DLINUX_SVGALIB

# End of configuration options
#####################################################################

OBJS= z80.o  xspectrum.o  util.o  main.o
OBJSD=z80d.o xspectrumd.o utild.o maind.o
OBJSSVGA=z80.o xspectrum.o util.o main.o linuxcon.o

DEFINES = $(SHMDEF) $(KLUDGEDEF) $(NAMEDEF) $(LIBDEF) $(SCALDEF) \
          $(AUDIODEF) $(XAPPLDEF) $(LINUXDEF) $(BORDDEF)

all: xz80

svga: lz80

d: xz80d

xz80: $(OBJS)
	$(CC) -o xz80 $(OBJS) $(LIBS)

xz80d: $(OBJSD)
	$(CC) -g -o xz80d $(OBJSD) $(LIBS)

lz80: $(OBJSSVGA)
	$(CC) -o lz80 $(OBJSSVGA) $(LIBSSVGA)

z80.o: $(SRC)/z80.c $(SRC)/z80ops.c $(SRC)/edops.c $(SRC)/cbops.c $(SRC)/z80.h
	@echo 'This may take some time (12 mins on a SPARC2 for gcc -O2)'
	$(CC) -c $(CCFLAG) $(OPTFLAG) $(DEFINES) $(SRC)/z80.c
	
main.o: $(SRC)/main.c $(SRC)/z80.h
	$(CC) -c $(CCFLAG) $(OPTFLAG) $(DEFINES) $(SRC)/main.c
	
util.o: $(SRC)/util.c $(SRC)/z80.h
	$(CC) -c $(CCFLAG) $(OPTFLAG) $(DEFINES) $(SRC)/util.c
	
xspectrum.o: $(SRC)/xspectrum.c $(SRC)/z80.h
	$(CC) -c $(CCFLAG) $(OPTFLAG) $(DEFINES) $(SRC)/xspectrum.c

linuxcon.o: $(SRC)/linuxcon.c $(SRC)/linuxcon.h $(SRC)/rawkey.h
	$(CC) -c $(CCFLAG) $(OPTFLAG) $(DEFINES) $(SRC)/linuxcon.c
	
z80d.o: $(SRC)/z80.c $(SRC)/z80ops.c $(SRC)/edops.c $(SRC)/cbops.c $(SRC)/z80.h
	$(CC) -c -o z80d.o $(DEBUGFLAG) $(CCFLAG) $(DEFINES) $(SRC)/z80.c
	
maind.o: $(SRC)/main.c $(SRC)/z80.h
	$(CC) -c -o maind.o $(DEBUGFLAG) $(CCFLAG) $(DEFINES) $(SRC)/main.c
	
utild.o: $(SRC)/util.c $(SRC)/z80.h
	$(CC) -c -o utild.o $(DEBUGFLAG) $(CCFLAG) $(DEFINES) $(SRC)/util.c
	
xspectrumd.o: $(SRC)/xspectrum.c $(SRC)/z80.h
	$(CC) -c -o xspectrumd.o $(DEBUGFLAG) $(CCFLAG) $(DEFINES) $(SRC)/xspectrum.c
	
