##############################################################################
#
# makefile for xmame/xmess
#
# by Juan Antonio Martinez
# http:/drake.dit.upm.es/~mame/
# mailto:j.w.r.degoede@et.tudelft.nl
#
##############################################################################

VERSION = 0.34b5.2
DATE    = 20-Oktober-1998
NAME    = ps1mame

#########################################################################
#									#
# READ COMMENTS AND MODIFY CONFIGURABLE OPTIONS WITH CARE...		#
#									#
# Members of Mame and X-Mame project assumes no responsability  	#
# implicit or explicit about illegal or incorrect use of this   	#
# sofware and about possible hard/soft damage derived of it   	  	#
#									#
# THIS SOFTWARE IS DISTRIBUTED "AS IS" . USE AT YOUR OWN RISK		#
#									#
# Mame and X-Mame are Copyright of Nicola Salmoria and Mirko buffoni	#
# and distributed under terms simular to the GNU General Public License #
# see doc/README.unix for more details                                  #
#									#
# Arcade ROM images are copyright of their authors. DISTRIBUTING MAME   #
# OR X-MAME INCLUDING ROM IMAGES IN THE SAME PACKAGE IS ILLEGAL AND	#
# CONSTITUTES A VIOLATION OF TERMS OF COPYRIGHT				#
#									#
#########################################################################

##############################################################################
# *** compiler options 
##############################################################################

# GNU MAKE is MANDATORY !!!
# so please give me the path...
# if GNU make is "native" use this
MAKE	= gmake

# *** Choose your compiler
CC	= psx-gcc

# *** Choose your host compiler (that generates binaries for the machine you're using to compile)
HOST_CC = gcc

# *** Suffix for executable names for host machine (leave blank for Unix, specify .exe for DOS/Windows)
HOST_EXE_SUFFIX =

# *** Choose your linker ( some OS's needs native linker instead GNU one )
# normal
LD	= $(CC) 

# *** does your platform have ranlib (leave this untouched unless you are
# using irix
RANLIB = mipsel-unknown-elf-ranlib

# *** set to aproppiate flag if want to debug/optimize
 DBGFLAGS    = -g

### optimization flags
OPTFLAGS    =  -Ofast -Wall

# *** Does your compiler supports inline funcs?. use appropiate item:
# do not use IL = inline : wont work due to Z80 and 6809 stuffs
# if strict ansi used set IL to "static"
# IL	= '-DINLINE=static inline'
IL     = -DINLINE=static


# Desired TV video mode. Can be VMODE_PAL or VMODE_NTSC

PSX_VIDEO_MODE = VMODE_PAL

# License file used 

ARCH  = psx
DISPLAY_METHOD = psx

# License file used when making CD image
PSX_CD_LICENSE_FILE = /usr/local/psxsdk/share/licenses/infoeur.dat

##############################################################################
# **** Architecture dependent defs. Only change if you know what're you doing...
##############################################################################
#note : -D$(ARCH) is added automaticly later on.
DEFS.psx   =  -DLSB_FIRST  -D_PLAYSTATION_


#############################################################################
# these are the object subdirectories that need to be created.
#############################################################################
OBJDIRS = obj \
	obj/psx \
	obj/drivers \
	obj/machine \
	obj/sndhrdw \
	obj/vidhrdw \
	obj/z80 \
	obj/m6809

INCDIRS =  -Isrc \
	-Isrc/drivers \
	-Isr-Isrc/machine \
	-Isrc/sndhrdw \
	-Isrc/vidhrdw \
	-Isrc/z80

all: objdirs osdepend $(NAME).exe

include makefile.objs

# Perhaps one day original mame/mess sources will use POSIX strcasecmp and M_PI
# instead MS-DOS counterparts... ( a long and sad history ...)
CFLAGS = $(TD) $(DBGFLAGS) $(OPTFLAGS) $(IL) $(INCDIRS) $(CFLAGS.$(ARCH)) \
	 -Dstricmp=strcasecmp -DPI=M_PI -DUNIX -DSIGNED_SAMPLES $(CFG_CFLAGS) \
	 $(DEFS.$(ARCH)) -D$(ARCH) -D$(DISPLAY_METHOD) $(MAMENET) -DPSX_VIDEO_MODE=$(PSX_VIDEO_MODE)

#CONFIG are the cflags used to build the unix tree, this is were most defines go
CONFIG = $(CFLAGS) $(CFLAGS.$(DISPLAY_METHOD)) $(ZLIB) \
	 $(JOY) $(JS) "-DX11_JOYNAME='$(JSNAME)'" $(JSPOLL) $(S_LIN) \
	 $(S_TIM) $(S_AFR) -DROMPATH='$(ROMPATH)' -DCHEATFILE='$(CHEATFILE)'\
	 -DSPOOLDIR='$(SDIR)' -DMAMERC='$(MRC)' -DDISPLAY='$(DP)' \
	 -DVERSION='\"$(VERSION)\"' -DNAME='\"$(NAME)\"' \

OBJS = $(OBJCORE) obj/psx/osd.o
#OBJS   = $(OBJCORE) obj/unix.$(DISPLAY_METHOD)/osdepend.a

configure: configure.c
	$(HOST_CC) -o configure$(HOST_EXE_SUFFIX) configure.c

$(NAME).exe: $(NAME).$(DISPLAY_METHOD)
	elf2exe $(NAME).$(DISPLAY_METHOD) $(NAME).exe

$(NAME).$(DISPLAY_METHOD): $(OBJS)
	$(LD) -o $@ $(OBJS) $(JSLIB) $(ZLIB_LIB) $(LIBS.$(ARCH)) $(LIBS.$(DISPLAY_METHOD)) -lm

$(OBJDIRS) obj/unix.$(DISPLAY_METHOD):
	-mkdir $@

objdirs: $(OBJDIRS) obj/unix.$(DISPLAY_METHOD)

xlistdev: contrib/xlistdev.c
	$(CC) $(X11INC) contrib/xlistdev.c -o xlistdev $(JSLIB) $(LIBS.$(ARCH)) $(LIBS.$(DISPLAY_METHOD)) -lm

osdepend:

obj/%.o: src/%.c
	$(CC) $(CFLAGS) -o $@ -c $<

obj/%.a:
	ar -rcv $@ $^
	$(RANLIB) $@

cd_image: $(NAME).$(DISPLAY_METHOD)
	mkdir -p cd_root
	cp ps1mame.exe cd_root
	systemcnf ps1mame.exe > cd_root/system.cnf
	mkisofs -o ps1mame.hsf -V PS1MAME -sysid PLAYSTATION cd_root
	mkpsxiso ps1mame.hsf ps1mame.bin $(PSX_CD_LICENSE_FILE)
	rm -fr cd_root
	rm -f ps1mame.hsf

clean: 
	rm -fR obj $(NAME).* xlistdev configure$(HOST_EXE_SUFFIX)
