/* comment following to disable mit shared memory support 
   mitshm run only in posixcolor in X11R5+ great speedup better intro etc..*/
#define MITSHM
/* have usleep?*/
#define HAVEUSLEEP
/* for network audio server(supported by most unixes)*/
/* it is now in experimental ... koules uses too much sounds*/
/*#define NAS_SOUND*/ /*comented=use own sounds server(linux,freebsd,sun)*/
/* linux joystick support */
/*#define JOYSTICK*/
/* directories*/
KOULESDIR		=/usr/bin/X11
SOUNDDIR		=/usr/local/lib/koules
MANDIR			=/usr/man/man6


DEPLIBS = $(DEPXLIB) 
INCLUDES = -Ixlib
SUBDIRS = xlib

#if defined(LinuxArchitecture)
    SYSDEFS = -Wall -fomit-frame-pointer -O6  -ffast-math
#if !defined(NAS_SOUND)
#define SOUND
    SOUNDSERVER = koules.sndsrv.linux
    SOUNDOBJS = sound.o
    SOUNDDEV = /dev/dsp
#endif
#endif


#if defined(SunArchitecture)
    SYSDEFS =
#if !defined(NAS_SOUND)
#define SOUND
    SOUNDSERVER = koules.sndsrv.sun
    SOUNDOBJS = sound.o
    SOUNDDEV = /dev/audio
#endif
#endif

#if defined(FreeBSDArchitecture)
SYSDEFS = 
#if !defined(NAS_SOUND)
#define SOUND
SOUNDSERVER = koules.sndsrv.freebsd
SOUNDOBJS = sound.o
SOUNDDEV = /dev/dsp
#endif
#endif

#XCOMM ***********************************************************
#XCOMM ---> You shouldn't need to change anything below this <----
#XCOMM ***********************************************************

#ifdef JOYSTICK
JOYSTICK1 = -DJOYSTICK
#endif
#ifdef MITSHM
MITSHM1 = -DMITSHM
#endif
#ifdef HAVEUSLEEP
HAVEUSLEEP1 = -DHAVEUSLEEP
#endif

#ifndef SOUND
#ifndef NAS_SOUND
DEFINES = -DONLYANSI $(MITSHM1) $(HAVEUSLEEP1) $(SYSDEFS) $(JOYSTICK) -Ixlib\
	$(NAMEDEF) 
#else
	INSTALLSOUND = True

	NASLIB = -laudio

	SOUNDOBJS = nas_sound.o

DEFINES = -DONLYANSI -DNAS_SOUND $(MITSHM1) $(HAVEUSLEEP1) $(SYSDEFS) $(JOYSTICK) -Ixlib\
	$(NAMEDEF) \
	-DSOUNDDIR=\"$(SOUNDDIR)\" 
#endif 
#else
	INSTALLSOUND = True

DEFINES = -DONLYANSI -DSOUND $(MITSHM1) $(HAVEUSLEEP1) $(SYSDEFS) $(JOYSTICK) -Ixlib\
	$(NAMEDEF) \
	-DSOUNDSERVER=\"$(KOULESDIR)/$(SOUNDSERVER)\" \
	-DSOUNDDIR=\"$(SOUNDDIR)\" \
	-DSOUNDDEV=\"$(SOUNDDEV)\"
#endif



OBJS = koules.o menu.o gameplan.o font.o intro.o xlib/init.o\
       xlib/interface.o xlib/shmbitmap.o framebuffer.o cmap-x11.o util/usleep.o sound.o nas_sound.o

SRCS = koules.c menu.c gameplan.c font.c intro.c xlib/init.c\
       xlib/interface.c xlib/shmbitmap.c framebuffer.c cmap-x11.c util/usleep.c sound.c nas_sound.c


ComplexProgramTarget(xkoules)

clean::
	rm -f xkoules $(SOUNDSERVER)
	rm -f core `find . -name '*.[oas]' -print`
	rm -f core `find . -name '*~' -print`
	rm -f core `find . -type f -name 'core' -print`



LOCAL_LIBRARIES = $(NASLIB) $(XLIB)  -lm
 

#ifdef SOUND
NormalProgramTarget($(SOUNDSERVER), $(SOUNDSERVER).o,,,)
#endif
#ifdef NAS_SOUND
install:: $(PROGRAMS) $(SOUNDSERVER)
	@echo "Koules directory is " $(KOULESDIR)
	@:
	@echo "Instalin man page to " $(MANDIR)
	$(INSTALL) -c $(INSTBINFLAGS) xkoules.6 $(MANDIR);
	@:
	@echo "Creating directory " $(KOULESDIR)
	@if [ ! -d $(KOULESDIR) ]; then mkdir $(KOULESDIR); fi
	@:
	@if [ "$(INSTALLSOUND)" = "True" ]; 				\
	 then								\
		echo "Creating directory " $(SOUNDDIR); 		\
		if [ ! -d $(SOUNDDIR) ]; then mkdir $(SOUNDDIR); fi;    \
		echo "Copying sound server to directory " $(SOUNDDIR); \
		$(INSTALL) -c -s $(INSTBINFLAGS) $(SOUNDSERVER) $(KOULESDIR); \
		echo "Copying sound files into directory " $(SOUNDDIR); \
		cd ./sounds; set -x;					\
		for file in *.raw; do                                   \
		    auconvert -raw linu8 1 -rate 8000 -volume 40 $$file -file snd `basename $$file .raw`.au ; \
		    $(INSTALL) -c $(INSTDATFLAGS) `basename $$file .raw`.au $(SOUNDDIR); \
		done;                                                   \
	 fi
#else
install:: $(PROGRAMS) $(SOUNDSERVER)
	@echo "Koules directory is " $(KOULESDIR)
	@:
	@echo "Instalin man page to " $(MANDIR)
	$(INSTALL) -c $(INSTBINFLAGS) xkoules.6 $(MANDIR);
	@:
	@echo "Creating directory " $(KOULESDIR)
	@if [ ! -d $(KOULESDIR) ]; then mkdir $(KOULESDIR); fi
	@:
	@if [ "$(INSTALLSOUND)" = "True" ]; 				\
	 then								\
		echo "Creating directory " $(SOUNDDIR); 		\
		if [ ! -d $(SOUNDDIR) ]; then mkdir $(SOUNDDIR); fi;    \
		echo "Copying sound server to directory " $(SOUNDDIR); \
		$(INSTALL) -c -s $(INSTBINFLAGS) $(SOUNDSERVER) $(KOULESDIR); \
		echo "Copying sound files into directory " $(SOUNDDIR); \
		cd ./sounds; set -x;					\
		for file in *.raw; do					\
		    $(INSTALL) -c $(INSTDATFLAGS) $$file $(SOUNDDIR);	\
		done;   						\
	 fi
#endif

#ifdef SOUND
all::xkoules $(SOUNDSERVER)
#else
all::xkoules
#endif
