############################################################################
#									   #
# Instructions:								   #
# -------------								   #
# 1. Select the appropriate OS-specific options for your system		   #
# 2. Choose from the options section					   #
# 3. Type "make" and all should (hopefully) work...			   #
#									   #
############################################################################

############################################################################
############################################################################
##									  ##
##			OS-SPECIFIC DEFINITIONS				  ##
##									  ##
############################################################################
############################################################################

############################################################################
#
# Linux/FreeBSD/OSS definitions
#
# for output on linux and FreeBSD Open Sound System (OSS) (/dev/dsp) or 
# Ultrasound driver (/dev/gus)
#
############################################################################

OSDEF=-DOSS
CC = gcc

# if you want to use the Ultra driver uncomment the 3 lines below. 
# You need a Gravis Ultrasound and the library from the Linux Ultrasound 
# project to do this, from http://romeo.pf.jcu.cz/~perex/ultra/
#ULTRA=-DULTRA
#ULTRALIB=-lgus
#ULTRADRV=drv_ultra.o

#define this if you need <linux/sched.h> rather than <sched.h> for the 
#CPUTIME_SNAGGER option, e.g. in RedHat with libc 5.3.12
#BROKEN_SCHED=-DBROKEN_SCHED

OSFLAGS = -O3 -Wall -funroll-loops $(OSDEF) $(ULTRA) $(BROKEN_SCHED)
#debug options
DEBUGFLAGS = -O3 -funroll-loops -pg -g -Wall $(OSDEF) $(ULTRA) $(BROKEN_SCHED)
DEBUG=1

LIBS=-lncurses -lm $(ULTRALIB)
DRIVERS = drv_nos.o drv_raw.o drv_vox.o $(ULTRADRV)

############################################################################
#
# SUN / Solaris definitions (including Solaris/i386)
#
# for output on the Sun audio device (/dev/audio)
#
############################################################################

# for SunOS 4.1.x, enable -DSUNOS, for Solaris 2.x, enable -DSOLARIS
#OSDEF=-DSUNOS -I/usr/5include
#OSDEF=-DSOLARIS

#CC = gcc

# defines
# For Solaris/i386, remove the -DMM_BIG_ENDIAN
# Check NEEDS_USLEEP below also, Solaris 2.4 and previous may need it.
#CDEFS=-DNEED_UNISTD -DMM_BIG_ENDIAN -DSUN $(OSDEF)

# Enable this for speed on v8 sparc (microSPARC and newer)
#OSFLAGS = -g -O2 -mv8 -msupersparc -I./include $(CDEFS)
# Enable this to work on v7 sparc
#OSFLAGS = -g -O2 -I./include $(CDEFS)
# SPARCompiler C 4.0 options
#OSFLAGS = -Iinclude -fast $(CDEFS)

# Use SysV curses. Gets us the lame SysV libc too. Oh well
#LIBS=-L/usr/5lib -lcurses -lm
# Disable the above and use this on Solaris
#LIBS=-lcurses -lm -lposix4

#DRIVERS = drv_nos.o drv_raw.o drv_sun.o

############################################################################
#
# DEC Alpha / AudioFile definitions
#
# systems using Digital AudioFile library, available from 
# ftp://crl.dec.com/pub/DEC/AF
#
############################################################################

#OSDEF=-DALPHA

# Choose between DEC cc
#CC = cc -g3

# and GNU gcc
#CC = gcc -g -Wall

# Locations of AudioFile stuff
#INCDIR=-I/usr/local/vol/AudioFile/include
#LIBDIR=-L/usr/local/vol/AudioFile/lib

#OSFLAGS = -O2 $(OSDEF) $(INCDIR)
#DRIVERS = drv_nos.o drv_raw.o drv_AF.o
#LIBS=$(LIBDIR) -lcurses -lm -lAF

############################################################################
#
#   AIX definitions
#
############################################################################
 
#OSDEF=-DAIX
#CC = gcc

#OSFLAGS = -O3 -fsigned-char $(OSDEF) -DMM_BIG_ENDIAN

#LIBS=-lcurses -lm
#DRIVERS = drv_nos.o drv_aix.o drv_raw.o

############################################################################
#
#   HP 9000 series / HP-UX definitions
#
############################################################################

#OSDEF=-DHPUX

# To use gcc instead of HP's cc, uncomment the following two lines.
# HP's cc (NOT THE BUNDLED ONE) produces about 6% faster code here 
#CC = gcc
#OSFLAGS = -Wall -O3 -funroll-loops -mpa-risc-1-1 -mschedule=7100 $(OSDEF) -DMM_BIG_ENDIAN

# OR use HP's CC:

#CC = cc
#OSFLAGS = -Ae +O3 $(OSDEF) -DMM_BIG_ENDIAN

# Both need these:
#LIBS = -lcurses -L/lib/pa1.1 -lm
#DRIVERS = drv_nos.o drv_raw.o drv_hp.o

# And check NEEDS_USLEEP below also...

############################################################################
#
#   SGI definitions
#
############################################################################

#OSDEF=-DSGI
#CC = gcc

#CFLAGS = -Wall -O2 $(OSDEF) $(ZIP) $(USLEEP) $(NCURSES) -DMM_BIG_ENDIAN
#
#LIBS=-lcurses -laudio -lm 
#DRIVERS = drv_nos.o drv_raw.o drv_sgi.o

############################################################################
############################################################################
##									  ##
##			OPTIONS DEFINITIONS				  ##
##									  ##
############################################################################
############################################################################

# if you have unzip etc. installed, enable this for transparent loading of
# zipped mods. If you define this, you may need programs to extract zip,
# lha, gz, arj and zoo archives. Define the locations for these in mikmod.h
ZIP=-DUSE_ZIP

# -s will renice the program to -19, -S will attempt to give it a
# realtime priority (ie. it'll get all the cpu it wants) using
# sched_setscheduler(). Default behaviour remains the same, i.e. to not use
# these
# Some Linux systems may need BROKEN_SCHED to be defined also.
SNAG=-DCPUTIME_SNAGGER

# Does your system have usleep()? If not, you'll need to uncomment this...
#USLEEP=-DNEEDS_USLEEP

# Does your system have curses or ncurses? If the latter, define NCURSES.
#NCURSES=-DNCURSES

CFLAGS = -Dunix $(OSFLAGS) $(ZIP) $(SNAG) $(USLEEP) $(NCURSES) 

ifdef DEBUG
CFLAGS = -Dunix $(DEBUGFLAGS) $(ZIP) $(SNAG) $(USLEEP) $(NCURSES) 
endif

############################################################################
############################################################################
##									  ##
##  Common / standard definitions - shouldn't need to touch below here!   ##
##									  ##
############################################################################
############################################################################

LOADERS = load_mod.o load_m15.o load_mtm.o load_s3m.o load_stm.o load_xm.o load_ult.o load_uni.o load_669.o
OBJ = mloader.o munitrk.o mmio.o
OBJ2 = virtch.o mloader.o mdriver.o mplayer.o munitrk.o mmio.o
INTERFACE = mikmodux.o ui.o display.o mlist.o
TCLINTERFACE = tclmikmodux.o tclui.o tcldisplay.o tcllist.o
ARC = marchive.o

all:	mikmod mikcvt

debug:	mikmod-debug

libmikmod: $(OBJ2) $(LOADERS) $(ARC) $(DRIVERS)
	ar r libmikmod.a $(OBJ2) $(LOADERS) $(ARC) $(DRIVERS)
	ranlib libmikmod.a

mikmod-debug: libmikmod $(INTERFACE)
	$(CC) $(CFLAGS) -o mikmod-debug $(INTERFACE) -L./ -lmikmod $(LIBS)

mikmod: mikmod-debug
	cp mikmod-debug mikmod
	strip mikmod

tclmikmod-debug: libmikmod $(TCLINTERFACE)
	$(CC) $(CFLAGS) -o tclmikmod-debug $(TCLINTERFACE) -L./ -lmikmod $(LIBS)

tclmikmod: tclmikmod-debug
	cp tclmikmod-debug tclmikmod
	strip tclmikmod
	cp tclmikmod tcl

#mikmod-e: $(OBJ2) $(LOADERS) $(DRIVERS) $(ARC)
#	$(CC) $(CFLAGS) $(ARC) $(OBJ2) $(LOADERS) $(DRIVERS) -o mikmod-debug -lefence $(LIBS)

mikcvt: libmikmod
	$(CC) $(CFLAGS) -o mikcvt mikcvt.c -L./ -lmikmod $(LIBS)
	strip mikcvt

clean:
	rm -f $(OBJ) $(OBJ2) $(DRIVERS) $(ARC) $(LOADERS) \
	$(INTERFACE) $(TCLINTERFACE) libmikmod.a \
	mikmod mikcvt mikmod-debug tclmikmod tclmikmod-debug gmon.out \
	tcl/tclmikmod tcl/tclmikmod-debug tcl/gmon.out *~

semiclean:
	rm -f $(OBJ) $(OBJ2) $(DRIVERS) $(ARC) $(LOADERS) mikmod-debug \
		tclmikmod-debug $(INTERFACE) $(TCLINTERFACE) *~

newpatch:
	./make-script newpatch

tgz:	clean
	(cd ../../ ;tar -cvf - mikmod-2.15-devel8/* |gzip -9 >mikmod-2.15-devel.tar.gz)
#	cp ../docs/Changes ../docs/ToDo ../..
