# 
# 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 = /usr/local/lib/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.

# Select the Linux/FreeBSD audio driver
SYSTEM := $(SYSTEM) -DAU_LINUX
SYSEXTRAS := $(SYSEXTRAS) linux_audio.c
EXTRAINCS := $(EXTRAINCS)
EXTRALIBS := $(EXTRALIBS)

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

## Select the Sun audio driver
#SYSTEM := $(SYSTEM) -DSUN -D__USE_GNU -DAU_SUN
#SYSEXTRAS := $(SYSEXTRAS) sun_audio.c
#EXTRAINCS := $(EXTRAINCS) -I/usr/demo/SOUND
#EXTRALIBS := $(EXTRALIBS) -L/usr/demo/SOUND -laudio

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

# Select the ncurses full-screen interface
SYSTEM := $(SYSTEM) -DIA_NCURSES
SYSEXTRAS := $(SYSEXTRAS) ncurses_ctl.c
EXTRAINCS := $(EXTRAINCS) -I/usr/include/ncurses
EXTRALIBS := $(EXTRALIBS) -lncurses

## Select the S-Lang full-screen interface
#SYSTEM := $(SYSTEM) -DIA_SLANG
#SYSEXTRAS := $(SYSEXTRAS) slang_ctl.c
#EXTRAINCS := $(EXTRAINCS) -I/usr/include/slang
#EXTRALIBS := $(EXTRALIBS) -lslang

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

## Uncomment this to compile on an unknown little-endian machine
#SYSTEM := $(SYSTEM) -DLITTLE_ENDIAN

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

CC = gcc
DEBUGFLAGS = -Wall -O2

#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.2e
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 instruments.c \
	tables.c controls.c output.c filtering.c \
	wave_audio.c raw_audio.c dumb_ctl.c

# Optional installation-specific sources
OPTSRCS = hpux_audio.c linux_audio.c sun_audio.c ncurses_ctl.c slang_ctl.c filtering.c

# All headers
CHDRS = config.h common.h readmidi.h playmidi.h resample.h instruments.h \
	tables.h controls.h output.h filtering.h

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

MANPAGE = timidity.man
DOCS = README COPYING INSTALL CHANGES TODO FAQ $(MANPAGE)
CONFIGF = timidity.cfg gsdrum.cfg gravis.cfg wowpats.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)

all: $(PROJ)

clean:
	rm -f $(COBJS) core

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

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

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

.depend dep:
	$(CC) $(CFLAGS) -MM $(CSRCS) $(OPTSRCS) > .depend

include .depend

########### 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) $(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 timidity.txt index.html \
		INSTALL faq.html COPYING
	rm changes.html timidity.txt index.html
	tupload /home/titoivon/putup.tgz dload

$(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
