# Makefile for any machine
# - based on my newer makefile and the GREATE
# modifications by Mike Battersby
###############################################################################
#
# CONFIGURATION OPTIONS
#

# Choose your machine type. Possible types are
#  hpalib, hplow, hp3, dec, solaris, sparc, linux, freebsd, sgi, 
#  soundblaster, aix, next, MM1, NAS, sbos2, SVR4
# gmake needed to handle this file in FreeBSD
MACHINE = sparc
VERSION = 4.44

# The name of your C compiler. For most machines this will be
# either 'cc' or 'gcc'.
CC = gcc

OPTS=-c

PREFIX=/users/algo/espie/pub
# 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
INFO_DIR = $(PREFIX)/info

# Where to put the compression methods description
COMPRESSION_FILE=$(PREFIX)/lib/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 = ginstall

# 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.info'
# commands, you can ignore these.
INST_BIN_OPT = -c -s -m 555 -o store -g store
INST_MAN_OPT = -c -m 444 -o store -g store
INST_INFO_OPT = -c -m 444 -o store -g store
###############################################################################
#
# 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_sparc = -g
#CFLAGS_sparc = -O4 -Bstatic -pg
#CFLAGS_sparc = -g -D__USE_FIXED_PROTOTYPES__ -ansi -Wall 
CFLAGS_sparc = -O2 -finline-functions -funroll-loops -Wall \
-D__USE_FIXED_PROTOTYPES__   
LIBS_sparc   = -lm 
AUDIODIR_sparc=Sparc/
CONFIG_sparc = Sparc/
O_sparc = .o
EXE_sparc = 
UI_sparc = Unix/
SHELL_sparc = /bin/sh

CFLAGS_amiga = -O -Wall
LIBS_amiga   = -lm
AUDIODIR_amiga = Amiga/
CONFIG_amiga = Amiga/
O_amiga = .o
EXE_amiga = 
UI_amiga = Amiga/
SHELL_amiga = /bin/sh

CFLAGS_next = -O3 -fomit-frame-pointer -funroll-loops -ffast-math -Wall
LIBS_next   =
AUDIODIR_next = NeXT/
CONFIG_next = NeXT/
O_next = .o
EXE_next = 
UI_next = Unix/
SHELL_next = /bin/sh

CFLAGS_hpalib = -Ae +O3 +ESlit -DVOLUME_CONTROL
LIBS_hpalib   = -lAt -lAlib -lm 
AUDIODIR_hpalib=Hpux/
AUDIONAME_hpalib=alib_
CONFIG_hpalib = Hpux/
O_hpalib = .o
EXE_hpalib = 
UI_hpalib = Unix/
SHELL_hpalib = /bin/sh

CFLAGS_hplow = -Ae +O3 -Wl,-a,archive -s
LIBS_hplow=-lM
AUDIODIR_hplow=Hpux/
AUDIONAME_hplow=low_
CONFIG_hplow = Hpux/
O_hplow = .o
EXE_hplow =
UI_hplow = Unix/
SHELL_hplow = /bin/sh

# yet another port to hp! This one might be the best yet.
CFLAGS_hp3 = -Aa -D_HPUX_SOURCE +e +O3 +ESlit -DVOLUME_CONTROL
LIBS_hp3   = -lAt -lAlib -lm
AUDIODIR_hp3=Hpux/
AUDIONAME_hp3=3_
CONFIG_hp3 = Hpux/
O_hp3 = .o
EXE_hp3 = 
UI_hp3 = Unix/
SHELL_hp3 = /bin/sh

CFLAGS_solaris = -O -DSOLARIS -Wall
LIBS_solaris   = -lm
AUDIODIR_solaris=Sparc/
CONFIG_solaris = Sparc/
O_solaris = .o
EXE_solaris = 
UI_solaris = Unix/
SHELL_solaris = /bin/sh


CFLAGS_dec = -O 
LIBS_dec   = -lm -lAF
AUDIODIR_dec=AF/
CONFIG_dec = AF/dec_
O_dec = .o
EXE_dec = 
UI_dec = Unix/
SHELL_dec = /bin/sh

CFLAGS_sgi = -O2
LIBS_sgi   = -laudio -lm
AUDIODIR_sgi=Sgi/
CONFIG_sgi = Sgi/
O_sgi = .o
EXE_sgi = 
UI_sgi = Unix/
SHELL_sgi = /bin/sh

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_
O_linux = .o
EXE_linux =
UI_linux = Unix/
SHELL_linux = /bin/sh

CFLAGS_freebsd = -O2 -funroll-loops -finline-functions -fno-strength-reduce
LIBS_freebsd = -lm
AUDIODIR_freebsd=PCux/
CONFIG_freebsd = PCux/freebsd_
O_freebsd = .o
EXE_freebsd = 
UI_freebsd = Unix/
SHELL_freebsd = /bin/sh

CFLAGS_aix = -O
LIBS_aix = -lm
AUDIODIR_aix = Aix/
CONFIG_aix = Aix/
O_aix = .o
EXE_aix = 
UI_aix = Unix/
SHELL_aix = /bin/sh

CFLAGS_NAS = -O -I/usr/X11R6
LIBS_NAS = -lm -L/usr/X11R6/lib -laudio -lX11
AUDIODIR_NAS = NAS/
CONFIG_NAS = NAS/
O_NAS = .o
EXE_NAS =
UI_NAS = Unix/
SHELL_NAS = /bin/sh

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)
O_SVR4 = .o
EXE_SVR4 = 
UI_SVR4 = Unix/
SHELL_SVR4 = /bin/sh

CFLAGS_MM1 = -T/r0 -I/h0/blarslib/defs -I. -I/dd/defs -Fcc2s300 -uwlibs -mcpu32\ -ucc -O -optasm -gg # -v
LIBS_MM1 =  -s 40 -L/dd/lib -l/dd/blarslib/blarslib.l -lcgfx.l -uwlibs -gg
AUDIODIR_MM1 = mm1/
CONFIG_MM1 = mm1/
SHELL_MM1 = ksh
O_MM1 = .r
EXE_MM1 = 
UI_MM1 = Unix/

CFLAGS_sbos2 = -O2 -ZC++-comments -D__OS2__
LIBS_sbos2   = -lm
AUDIO_sbos2 = SBOS2/
CONFIG_sbos2 = SBOS2/
O_sbos2 = .o
EXE_sbos2 = .exe
UI_sbos2 = OS2/./
SHELL_sbos2 = /bin/sh

CFLAGS = $(CFLAGS_${MACHINE})
COPTS = $(OPTS) $(CFLAGS)
LIBS = $(LIBS_${MACHINE})
CONFIG = Arch/$(CONFIG_${MACHINE})
AUDIODIR = Arch/$(AUDIODIR_${MACHINE})
AUDIONAME = $(AUDIONAME_${MACHINE})
AUDIO = $(AUDIODIR)$(AUDIONAME)
O = $(O_${MACHINE})
EXE = $(EXE_${MACHINE})
UI = Arch/$(UI_${MACHINE})
SHELL = $(SHELL_${MACHINE})


OBJ_TRACKER = main$O st_read$O commands$O \
automaton$O st_play$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 st_virt$O \
play_list$O handle_options$O parse_options$O \
$(AUDIO)audio$O resample$O usage$O # mung$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 \
st_virt$O automaton$O

all:    tracker${EXE} randomize${EXE} splitmod${EXE} Docs/tracker.text

config.h: $(CONFIG)config.h Makefile
	rm -f config.h
	cp $(CONFIG)config.h config.h

# This Makefile entry probably won't work as is on your system

Docs/tracker.doc: Docs/tracker.texinfo Docs/protracker.fmt
	cd Docs; texi2www -dir Html tracker.texinfo
	cd Docs; /usr/local/bin/makeinfo --no-headers tracker.texinfo >tracker.doc 
	cd Docs; /users/algo/espie/pub/bin/makeinfo -o amiga.guide --amiga-39 tracker.texinfo

Docs/tracker.info: Docs/tracker.texinfo
	cd Docs; makeinfo tracker.texinfo

version.c: Makefile
	echo >version.c char \*VERSION=\"${VERSION}\"\;

install: 
	$(INSTALL) $(INST_BIN_OPT) tracker $(BIN_DIR)
	$(INSTALL) $(INST_BIN_OPT) randomize $(BIN_DIR)
	$(INSTALL) $(INST_BIN_OPT) splitmod $(BIN_DIR)
	[ -f ${COMPRESSION_FILE} ] || \
		$(INSTALL) $(INST_MAN_OPT) compression_methods ${COMPRESSION_FILE}

# no manpage available, use the texinfo manual.
install.man:
	@echo Sorry, no manpage available.
	@echo Please use $(MAKE) install.info to install the texinfo manual.
#	$(INSTALL) $(INST_MAN_OPT) man/tracker.1 $(MAN_DIR)/man1/tracker.1

install.info: Docs/tracker.info
	(cd Docs; \
          for f in tracker.info tracker.info-* ; do \
            $(INSTALL) $(INST_INFO_OPT) $$f $(INFO_DIR)/$$f; \
          done)

devel: 
	-rm -f $(BIN_DIR)/dtracker #$(BIN_DIR)/splitmod
	cp tracker $(BIN_DIR)/dtracker
#-	cp splitmod $(BIN_DIR)/splitmod

tracker${EXE}: config.h ${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

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 song.h
	$(CC) $(COPTS) display.c

version$O: version.c
	$(CC) $(COPTS) version.c

clean:
	-rm -f $(OBJ_TRACKER) $(OBJ_ANALYZER) $(OBJ_SPLITMOD) randomize.o
	-rm -f tracker randomize splitmod tcheck core 
	-rm -f tracker*.tar tracker\*.tar.Z tracker\*.lzh
	-rm -f config.h version.c
	find . -name \*.bak -exec rm {} \;

export: Docs/tracker.doc
	-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*;

