#  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

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

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

# 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. May or may not be
# necessary, depending on your setup...
KLUDGEDEF = -DSunKludge

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

# Define DEV_AUDIO if you want to use Sparc-style audio.
# 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.
# Optionally define AUDIODEV to the filename of the audio device.
AUDIODEF = -DDEV_AUDIO  # -DSUN_AUDIO -DAUDIODEV=\"/dev/audio\"

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

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

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

all: xz80

d: xz80d

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

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

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
	
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
	
