# Makefile for any machine
# - based on my newer makefile and the GREATE
# modifications by Mike Battersby
###############################################################################
#
# CONFIGURATION OPTIONS
#

# Choose your machine type. Possible types as of this version (4.11)
# are
#  hpalib, hplow, hp3, dec, solaris, sparc, linux, freebsd, sgi,
#  soundblaster, aix, next, sbos2
# GNU make needed to handle this file in FreeBSD or OS/2
MACHINE = sbos2
VERSION = 4.31

# The extension of the object and excutable files
EXE = .exe
O = .obj

# The name of your C compiler. For most machines this will be
# either 'cc' or 'gcc'.
CC = gcc

OPTS=-c

SHELL=bash

# User interface type. Right now, this is Unix as there are no alternatives.
UI = OS2/

PREFIX=e:/users/bruno/tracker
# Destination directory for tracker binaries and manpage.
#
# If you don't wish to use the 'make install' and 'make install.man'
# commands, you can ignore these.
BIN_DIR = $(PREFIX)/bin
MAN_DIR = $(PREFIX)/man

# Where to put the compression methods description
COMPRESSION_FILE=/users/bruno/tracker/compression_methods

# How to install the binaries and manpage. If you have a unix system,
# use the GNU install program if you have it, otherwise try 'cp'. For
# non-unix systems, make this the command for copying a file with the
# following syntax
#  <program_name> <source_name> <destination_name>
#
# If you don't wish to use the 'make install' and 'make install.man'
# commands, you can ignore this.
INSTALL = install

# Permissions and user/group id's to install with. Non-unix users
# should comment these out (alternatively, you can use these to
# provide arguments for the above $(INSTALL) program). If you want
# to install tracker setuid root (which will allow it to renice
# itself when non-root users run it), change the "-m 755" below to
# "-m 4755". If you do so, you must be root to run make install.
#
# If you don't wish to use the 'make install' and 'make install.man'
# commands, you can ignore these.
INST_BIN_OPT = -c -s -m 755 -o root -g root
INST_MAN_OPT = -c -m 644 -o root -g root
###############################################################################
#
# C compiler flags and libraries for each machine.
# Unless you are porting this to a new architecture, you shouldn't
# need to change these (on the other hand, if you understand what you
# are doing, go ahead!).
#

CFLAGS_next = -O3 -fomit-frame-pointer -funroll-loops -ffast-math -Wall
LIBS_next   =
AUDIODIR_next = NeXT/
CONFIG_next = NeXT/

CFLAGS_hpalib = +O3 +OS +ESlit
LIBS_hpalib   = -lAt -lAlib -lm
AUDIODIR_hpalib=Hpux/
AUDIONAME_hpalib=alib_
CONFIG_hpalib = Hpux/

CFLAGS_hplow = -Ae +O3 -Wl, -a,archive -s
LIBS_hplow=-lM
AUDIODIR_hplow=Hpux/
AUDIONAME_hplow=low_
CONFIG_hplow = Hpux/

# yet another port to hp! This one might be the best yet.
CFLAGS_hp3 = +O3 +OS +ESlit
LIBS_hp3   = -lAt -lAlib -lm
AUDIODIR_hp3=Hpux/
AUDIONAME_hp3=3_
CONFIG_hp3 = Hpux/

CFLAGS_solaris = -O
LIBS_solaris   = -lm
AUDIODIR_solaris=Sparc/
CONFIG_solaris = Sparc/solaris_


#CFLAGS_sparc = -g
#CFLAGS_sparc = -O4 -Bstatic
#CFLAGS_sparc = -g -D__USE_FIXED_PROTOTYPES__
CFLAGS_sparc = -O2 -finline-functions -funroll-loops -Wall \
-D__USE_FIXED_PROTOTYPES__ -static
LIBS_sparc   = -lm
AUDIODIR_sparc=Sparc/
CONFIG_sparc = Sparc/

CFLAGS_dec = -O
LIBS_dec   = -lm -lAF
AUDIODIR_dec=AF/
CONFIG_dec = AF/dec_

CFLAGS_sgi = -j -O
LIBS_sgi   = -laudio -lm
AUDIODIR_sgi=Sgi/
CONFIG_sgi = Sgi/

CFLAGS_soundblaster = -O
LIBS_soundblaster   = -lm
AUDIODIR_soundblaster=Soundblaster/
CONFIG_soundblaster = Soundblaster/

CFLAGS_linux = -N -O2 -funroll-loops
LIBS_linux   = -lm
AUDIODIR_linux=PCux/
CONFIG_linux = PCux/linux_

CFLAGS_freebsd = -O2 -funroll-loops -finline-functions
LIBS_freebsd = -lm
AUDIODIR_freebsd=PCux/
CONFIG_freebsd = PCux/freebsd_

CFLAGS_aix = -O
LIBS_aix = -lm
AUDIODIR_aix = Aix/
CONFIG_aix = Aix/

CFLAGS_sbos2 = -O2 -ZC++-comments -Zomf -D__OS2__
LIBS_sbos2   = -lm
AUDIODIR_sbos2 = SBOS2/
CONFIG_sbos2 = SBOS2/

CFLAGS_NAS = -O -I/usr/X11R6
LIBS_NAS = -lm -L/usr/X11R6/lib -laudio -lX11
AUDIODIR_NAS = NAS/
CONFIG_NAS = NAS/

CFLAGS_SVR4 = -O -I/usr/X/include
LIBS_SVR4 = -L/usr/X/lib $(LIBS_NAS) -lsocket -lnsl -lc /usr/ucblib/libucb.a
AUDIODIR_SVR4 = $(AUDIODIR_NAS)
CONFIG_SVR4 = $(CONFIG_NAS)


CFLAGS = $(CFLAGS_${MACHINE})
COPTS = $(OPTS) $(CFLAGS)
LIBS = $(LIBS_${MACHINE})
CONFIG = Arch/$(CONFIG_${MACHINE})
AUDIODIR = Arch/$(AUDIODIR_${MACHINE})
AUDIONAME = $(AUDIONAME_${MACHINE})
AUDIO = $(AUDIODIR)$(AUDIONAME)

OBJ_TRACKER = main$O $(AUDIO)audio$O st_read$O commands$O \
resample$O automaton$O st_play$O getopt$O open$O tools$O \
dump_song$O setup_audio$O notes$O display$O empty$O \
$(UI)ui$O prefs$O tags$O autoinit$O color$O version$O

OBJ_ANALYZER = analyzer$O st_read$O open$O dump_song$O tools$O notes$O \
prefs$O autoinit$O ${UI}ui$O display$O empty$O color$O version$O

OBJ_SPLITMOD = split$O tools$O st_read$O dump_song$O open$O notes$O \
display$O prefs$O autoinit$O $(UI)ui$O empty$O color$O version$O

all:	version.c config.h tracker$(EXE) randomize$(EXE) tcheck$(EXE) splitmod$(EXE)

config.h: $(CONFIG)config.h Makefile
	cp $(CONFIG)config.h config.h

version.c: Makefile
	echo >version.c char \*VERSION=\"${VERSION}\"\;\

install:
	$(INSTALL) $(INST_BIN_OPT) tracker$(EXE) $(BIN_DIR)
	$(INSTALL) $(INST_BIN_OPT) randomize$(EXE) $(BIN_DIR)
	$(INSTALL) $(INST_BIN_OPT) tcheck$(EXE) $(BIN_DIR)
	$(INSTALL) $(INST_BIN_OPT) splitmod$(EXE) $(BIN_DIR)
	[ -f ${COMPRESSION_FILE} ] || \
		$(INSTALL) $(INST_MAN_OPT) compression_methods ${COMPRESSION_FILE}

install.man:
	$(INSTALL) $(INST_MAN_OPT) man/tracker.1 $(MAN_DIR)/man1/tracker.1



devel:
	-rm -f $(BIN_DIR)/dtracker$(EXE) #$(BIN_DIR)/splitmod
	cp tracker $(BIN_DIR)/dtracker$(EXE)
#-	cp splitmod $(BIN_DIR)/splitmod$(EXE)

tracker$(EXE): ${OBJ_TRACKER}
	${CC} -o tracker$(EXE) ${CFLAGS} ${OBJ_TRACKER} ${LIBS}

dtracker$(EXE): ${OBJ_TRACKER}
	${CC} -o dtracker$(EXE) ${CFLAGS} ${OBJ_TRACKER} ${LIBS}

tcheck$(EXE): ${OBJ_ANALYZER}
	$(CC) -o tcheck$(EXE) ${CFLAGS} ${OBJ_ANALYZER} ${LIBS}

randomize$(EXE): randomize.c
	$(CC) -o randomize$(EXE) ${CFLAGS} randomize.c

splitmod$(EXE): ${OBJ_SPLITMOD}
	$(CC) -o splitmod$(EXE) ${CFLAGS} ${OBJ_SPLITMOD} ${LIBS}

main$O: main.c song.h
	$(CC) ${COPTS} main.c

tools$O: main.c
	$(CC) ${COPTS} tools.c

$(AUDIO)audio$O: $(AUDIO)audio.c Arch/common.c
	cd $(AUDIODIR); $(CC) -I../.. ${COPTS} $(AUDIONAME)audio.c

$(UI)ui$O: $(UI)ui.c
	cd $(UI); $(CC) -I.. ${COPTS} ui.c

split$O: split.c
	$(CC) ${COPTS} split.c

open$O: open.c Makefile
	$(CC) ${COPTS} -DCOMPRESSION_FILE='\"${COMPRESSION_FILE}\"' open.c

resample$O: resample.c
	$(CC) ${COPTS} resample.c

automaton$O: automaton.c song.h channel.h
	$(CC) ${COPTS} automaton.c

getopt$O: getopt.c getoption.h
	$(CC) ${COPTS} getopt.c

player$O: player.c song.h channel.h
	$(CC) ${COPTS} player.c

st_read$O: st_read.c song.h
	$(CC) ${COPTS} st_read.c

st_play$O: st_play.c song.h
	$(CC) ${COPTS} st_play.c

commands$O: commands.c channel.h song.h
	$(CC) ${COPTS} commands.c

dump_song$O: dump_song.c
	$(CC) $(COPTS) dump_song.c
analyzer$O: analyzer.c
	$(CC) $(COPTS) analyzer.c
setup_audio$O: setup_audio.c
	$(CC) $(COPTS) setup_audio.c
notes$O: notes.c
	$(CC) $(COPTS) notes.c

display$O: display.c
	$(CC) $(COPTS) display.c
color$O: color.c
	$(CC) $(COPTS) color.c

prefs$O: prefs.c prefs.h
	$(CC) ${COPTS} prefs.c
tags$O: tags.c tags.h
	$(CC) ${COPTS} tags.c
autoinit$O: autoinit.c
	$(CC) ${COPTS} autoinit.c
empty$O: empty.c song.h
	$(CC) ${COPTS} empty.c
version$O: version.c
	$(CC) $(COPTS) version.c

clean:
	-rm -f $(OBJ_TRACKER) $(OBJ_ANALYZER) $(OBJ_SPLITMOD) randomize$O
	-rm -f tracker$(EXE) randomize$(EXE) splitmod$(EXE) tcheck$(EXE) core
	-rm -f tracker*.tar tracker\*.tar.Z tracker\*.lzh
	-rm -f config.h version.c
	find . -name \*.bak -exec rm {} \

export:
	-rm tracker*.tar.Z tracker*.lzh tracker*.lha
	cd ..; tar -cvof tracker/tracker-$(VERSION).tar -T tracker/arc.list
	mv tracker-$(VERSION).tar /tmp
	cd /tmp; tar xvf tracker-$(VERSION).tar
	cd /tmp; lha a tracker-$(VERSION).lzh tracker
	compress /tmp/tracker-$(VERSION).tar
	cp /tmp/tracker-$(VERSION).lzh .
	cp /tmp/tracker-$(VERSION).tar.Z .
	rm -rf /tmp/tracker*


