# This is a makefile for the Unix/X version of iP6, PC-6000/
# PC-6600 series emulator. Following #defines can be customized:
#
# UNIX      - Should always be present in the Unix version.
# LSB_FIRST - Use this if your CPU has least-significant-byte-first
#             architecture (Intel 80x86, Alpha, etc.).
# DEBUG     - Define this option if you have a little runtime
#             debugger to be compiled into the emulator. It
#             slows down the emulation though.
# MITSHM    - Put this if you are going to use MIT Shared Memory
#             Extensions for XWindows. Using them greatly speeds
#             up screen updates, although they can't be used on
#             remote X-terminals. Note that MITSHM can always
#             be disabled from the command line using -noshm
#             option. 
# SOUND     - Use this option if you have /dev/dsp [present in
#             Linux and FreeBSD] or /dev/audio [SunOS and Solaris]
#             and would like to have sound.
# LINUX     - Define this if you compile sound support on a Linux
#             machine.
# SUN_AUDIO - Define this if you are compiling sound support via
#             SunOS-compatible /dev/audio.

# These are the compiler name, #defines, and the flags used to
# build iP6. Always set flags for the highest possible speed
# optimization. For GCC compiler, it will be
#
#        -O3 -fomit-frame-pointer -funroll-loops
#
# If you are getting errors about not found X11 header files,
# change the -I/usr/X11R6/include to the directory where X11
# headers are located on your system.
# If you are getting linker errors about not found X11 functions,
# change the -L/usr/X11R6/lib to the directory where X11
# libraries libX11.* and libXext.* are located on your system.


# OS Selector    by Windy
# Please select one of them and comment out the following lines
#OS      = LINUX
#OS      = BSDI
OS      = FREEBSD
#OS      = MACX11
#OS      = SDL


CC      = gcc
CXX     = g++
SDL_CONF= sdl11-config

FMGEN   = fmgen/
VPATH   = ${FMGEN}:sdl/


# *************** DEFINES *****************************
# ======== for Linux ================
ifeq ($(OS),LINUX)
    DEFINES = -DUNIX -DLSB_FIRST -DDEBUG -DMITSHM -DSOUND -DLINUX
endif
# ======= for BSDI BSD/OS ===========
ifeq ($(OS),BSDI)
    DEFINES = -DUNIX -DLSB_FIRST -DDEBUG -DMITSHM
endif
# ======= for freeBSD ===============
ifeq ($(OS),FREEBSD)
    DEFINES = -DUNIX -DLSB_FIRST -DDEBUG -DMITSHM -DSOUND
endif
# ======= for Mac OS X (X11) =======
ifeq ($(OS),MACX11)
    DEFINES = -DUNIX   -DDEBUG -DMITSHM
endif
# ======= for SDL ==================
ifeq ($(OS),SDL)
    DEFINES = -DSDL  -DLSB_FIRST -DDEBUG  -DSOUND
endif

# *******************  CFLAGS ***************************
# ======= Default setting ==========
CFLAGS  = -g -O3 -fomit-frame-pointer -funroll-loops \
	-I/usr/X11R6/include -L/usr/X11R6/lib ${DEFINES}
# ======= for Mac OS X (X11) =======
ifeq ($(OS),MACX11)
    CFLAGS  = -O1 -fomit-frame-pointer -funroll-loops \
	-I/usr/X11R6/include -L/usr/X11R6/lib ${DEFINES}
endif
# ======= for SDL (test) ===========
ifeq ($(OS),SDL)
    CFLAGS  = -O1 -fomit-frame-pointer -funroll-loops \
	-I/usr/X11R6/include -L/usr/X11R6/lib ${DEFINES} `${SDL_CONF} --cflags`
endif

OUTPUT_OPTION = ${CFLAGS}

# ****************** LDLIBS ******************************
# ======= Default setting ==========
LDLIBS  = -lXaw -lXt -lXmu -lXext -lX11 -lm

# ======= for BSDI BSD/OS ==========
ifeq ($(OS),BSDI)
    LDLIBS  = -lXaw -lXt -lXmu -lXext -lX11 -lSM -lICE -lipc
endif
# ======= for SDL ==================
ifeq ($(OS),SDL)
    LDLIBS  = `${SDL_CONF} --libs`
endif

# ****************** OBJECTS ******************************
OBJECTS = iP6.o P6.o Z80.o Debug.o Unix.o Refresh.o ossSound.o Xconf.o Option.o fdc.o disk.o d88.o fm.o error.o message.o  buffer.o\
 file.o fmgen.o fmtimer.o opm.o opna.o psg.o \
#sdl.o sdlsound.o sdlcgrom.o SDL_kanji.o


# ****************** MAKE rules ***************************
# Make the standard distribution: iP6
all:	iP6

# iP6 Unix/X requires X11 libraries. See note above if you are
# experiencing any problems.
iP6:	${OBJECTS}
	${CXX} ${CFLAGS} -o iP6 ${OBJECTS} ${LDLIBS}

# Clean up.
clean:
	rm -f *.o *~ iP6

# Dependencies for the object files.
iP6.o:		iP6.c P6.h Z80.h Help.h
P6.o:		P6.c P6.h Z80.h
Z80.o:		Z80.c Z80.h Codes.h CodesED.h CodesCB.h CodesXX.h Tables.h CodesXCB.h
Unix.o:		Unix.c P6.h Z80.h Keydef.h Build.h
Refresh.o:	Refresh.c Unix.h
ossSound.o:	ossSound.c P6.h
Debug.o:	Debug.c Z80.h
Xconf.o:	Xconf.c Xconf.h Xconfdef.h P6.h
Option.o:      Option.c Help.h
fdc.o:      fdc.c
disk.o:     disk.c
d88.o:      d88.c
error.o:    error.c
message.o:  message.c
fm.o:       fm.cpp
buffer.o:   buffer.c

#sdlcgrom.o: sdl/sdlcgrom.c
#sdl.o:      sdl/sdl.c
#SDL_kanji.o: sdl/SDL_kanji.c

file.o:		fmgen/file.cpp
fmgen.o:	fmgen/fmgen.cpp
fmtimer.o:	fmgen/fmtimer.cpp
opm.o:		fmgen/opm.cpp
opna.o:		fmgen/opna.cpp
psg.o:		fmgen/psg.cpp

