# 
# TiMidity -- Experimental MIDI to WAVE converter
# Copyright (C) 1995 Tuukka Toivonen <titoivon@snakemail.hut.fi>
# 
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
# 

########### Installation options

# Where to install the executable
BIN_DIR = /usr/local/bin

# Where to install the manual page
MAN_DIR = /usr/local/man/man1
MAN_EXTENSION = 1

# Where to install the patches, config files, and MIDI files.
# If you change this, it's a good idea to recompile the binary,
# or you'll need to invoke timidity with the -L option.
TIMID_DIR = c:\timidity

########### Compilation options -- there are more in config.h.  
#
# Uncomment the lines you need. You may need to change include/library
# paths etc.

########### Audio device selection
#
# Select one only. If your make doesn't understand +=, you may have to
# do some axe work.

## Select the Linux/FreeBSD audio driver
#SYSTEM += -DAU_LINUX
#SYSEXTRAS += linux_au.c
#EXTRAINCS +=
#EXTRALIBS += 

## Select the HP-UX network audio server
#SYSTEM += -DHPUX -DAU_HPUX
#SYSEXTRAS += hpux_audio.c
#EXTRAINCS +=
#EXTRALIBS += -lAlib

## Select the Sun audio driver
#SYSTEM += -DSUN -D__USE_GNU -DAU_SUN
#SYSEXTRAS += sun_audi.c
#EXTRAINCS += -I/usr/demo/SOUND
#EXTRALIBS += -L/usr/demo/SOUND -laudio

## Select a DOS SoundBlaster driver
## Please note: If compiling under DJGPP version 2, you must add the
##              -DDJGPP_V2 to the SYSTEM line.
SYSTEM += -DDOS_COMPILE -DLITTLE_ENDIAN -DAU_DOS_SB -m486 # -DDJGPP_V2
SYSEXTRAS += dos_sb.c 
EXTRAINCS += -I.
EXTRALIBS += -L. -lpc

########### Used interface selection
#
# You can select either, neither, or even both :)

## Select the ncurses full-screen interface
#SYSTEM += -DIA_NCURSES
#SYSEXTRAS += ncurses_.c
#EXTRAINCS += -I/usr/include/ncurses
#EXTRALIBS += -lncurses

## Select the S-Lang full-screen interface
SYSTEM += -DIA_SLANG
SYSEXTRAS += slang_ct.c
EXTRAINCS += -I/usr/include/slang -I./
EXTRALIBS += -lslang -lpc # Use the -lpc if compiling under djgpp

########### Other
#

## Uncomment this to compile on an unknown little-endian machine
#SYSTEM += -DLITTLE_ENDIAN

########### Compiler and flags.
#
# igcc (gcc with Intel optimization hack) is recommended for Intel chips.

CC = gcc
DEBUGFLAGS = -O6

#CC = igcc
#DEBUGFLAGS = -Wall -O4 -mpentium

########### Now check out the options in config.h

#########################################################################
# You shouldn't need to change anything beyond this line

VERSION = 0.2g
SUPPVERSION = 0.1

PROJ = timidity
DIST = timidity-$(VERSION).tar.gz
SDIST = timidity-lib-$(SUPPVERSION).tar.gz

CFLAGS= $(DEBUGFLAGS) -DDEFAULT_PATH=\"$(TIMID_DIR)\" \
	-DTIMID_VERSION=\"$(VERSION)\" $(SYSTEM) $(EXTRAINCS)

########### All relevant files

# Sources needed for every installation
CSRCS = timidity.c common.c readmidi.c playmidi.c resample.c mix.c instrume.c \
	tables.c controls.c output.c filterin.c \
	wave_aud.c raw_audi.c dumb_ctl.c

# Optional installation-specific sources
OPTSRCS = hpux_audio.c linux_au.c sun_audi.c ncurses_.c slang_ct.c

# External utility sources
TOOLSRCS = wav2pat.c bag.c

# All headers
CHDRS = config.h common.h readmidi.h playmidi.h resample.h mix.h instrume.h \
	tables.h controls.h output.h filterin.h

# These get printed out by "make listing"
ALLSRCS = $(CSRCS) $(OPTSRCS) $(CHDRS) $(TOOLSRCS) Makefile depnd

MANPAGE = timidity.man
DOCS = README COPYING INSTALL CHANGES TODO FAQ $(MANPAGE)
CONFIGF = timidity.cfg gsdrum.cfg gravis.cfg midia.cfg wowpats.cfg mt32.cfg

PATCHF = patch/acpiano.pat patch/nylongt2.pat
SAMPLEF = midi/cavatina.mid midi/impromptu.mid midi/malaguena.mid \
	  midi/test-decay.mid midi/test-panning.mid midi/test-scale.mid

# These get stuffed in the distribution archive
ALLDIST = $(DOCS) $(ALLSRCS) $(CONFIGF)

# These go in the support archive
SUPPDIST = $(PATCHF) $(SAMPLEF) README-lib

########### Rules

COBJS = $(CSRCS:.c=.o) $(SYSEXTRAS:.c=.o)

TOOLS = $(TOOLSRCS:.c=)

all: $(PROJ) # $(TOOLS)
	strip $(PROJ)
	coff2exe $(PROJ)


clean:
	rm -f $(COBJS) core

dosclean:
	del *.o
	del *.exe
	del $(PROJ)

spotless: clean
	rm -f $(PROJ) $(TOOLS) $(DIST) $(SDIST) \
		$(DIST).CONTENTS $(SDIST).CONTENTS

.c.o:
	$(CC) $(CFLAGS) -c $<

$(PROJ): $(COBJS)
	$(CC) $(CFLAGS) -o $(PROJ) $(COBJS) $(EXTRALIBS) -lm

bag: bag.c
	$(CC) $(CFLAGS) -o bag bag.c

wav2pat: wav2pat.c
	$(CC) $(CFLAGS) -o wav2pat wav2pat.c
	coff2exe wav2pat

depnd dep:
	$(CC) $(CFLAGS) -MM $(CSRCS) $(OPTSRCS) $(TOOLSRCS) > depnd

include depnd

########### Installation targets

install:
	@echo
	@echo Please enter one of the commands below:
	@echo 
	@echo \"make install.bin\" - Install the executable in $(BIN_DIR).
	@echo \"make install.man\" - Install the manual page in $(MAN_DIR).
	@echo \"make install.lib\" - Install the library files in $(TIMID_DIR).
	@echo \"make install.all\" - All of the above.
	@echo

install.all: install.bin install.man install.lib

# install.bin: $(PROJ) Dumb make thinks it has to have $(COBJS) to install...
install.bin:
	mkdir -p $(BIN_DIR)
	install -s -m 755 $(PROJ) $(TOOLS) $(BIN_DIR)

install.man:
	mkdir -p $(MAN_DIR)
	install -m 644 $(MANPAGE) $(MAN_DIR)/$(PROJ).$(MAN_EXTENSION)

install.lib: install.config install.patch

install.config: $(CONFIGF)
	mkdir -p $(TIMID_DIR)
	install -m 644 $(CONFIGF) $(TIMID_DIR)

install.patch: $(PATCHF)
	mkdir -p $(TIMID_DIR)/patch
	install -m 644 $(PATCHF) $(TIMID_DIR)/patch

########## Some special targets

time:
	time ./$(PROJ) -idq -s32 -p32 -Or -o/dev/null \
	-c /usr/local/lib/timidity/timidity.cfg \
	$(HOME)/midi/jazz/jzdwing.mid.gz

listing.ps: $(ALLSRCS)
	a2ps -2 -nP -c $(ALLSRCS) >listing.ps

listing: listing.ps

dist: $(DIST)

sdist: $(SDIST)

putup: $(DIST)
	changes2html < CHANGES > changes.html
	faq2html < FAQ > faq.html
	groff -man -Tlatin1 -P-b -P-u $(MANPAGE) > timidity.txt
	cp /home/titoivon/public_html/timidity/index.html index.html
	tar czvf /home/titoivon/putup.tgz $(DIST) $(DIST).CONTENTS \
		changes.html faq.html timidity.txt index.html \
		INSTALL COPYING
	rm changes.html faq.html timidity.txt index.html

$(DIST): $(ALLDIST)
	cd ..; tar czf $(DIST) $(patsubst %,timidity/%,$(ALLDIST)) &&\
	mv $(DIST) timidity
	tar tzvf $(DIST) >$(DIST).CONTENTS

$(SDIST): $(SUPPDIST)
	cd ..; tar czf $(SDIST) $(patsubst %,timidity/%,$(SUPPDIST)) &&\
	mv $(SDIST) timidity
	tar tzvf $(SDIST) >$(SDIST).CONTENTS

########## End of Makefile
