# $Id: Makefile,v 1.16 1996/02/27 22:03:39 bedk Exp $
#
# $Log: Makefile,v $
# Revision 1.16  1996/02/27 22:03:39  bedk
# Typo fixes
#
# Revision 1.15  1996/02/27 21:33:36  bedk
# Added targets for create_mapping, and installation of man pages.
#
# Revision 1.14  1995/07/03 22:11:42  bedk
# Removed -Wall from CFLAGS
#
# Revision 1.13  1995/07/03 21:32:41  bedk
# Added man page to distribution file list and print list.  Updated
# NAME to rasta2_2
#
# Revision 1.12  1995/06/30 21:39:19  bedk
# Added optional includes, defines, and libraries for Matlab I/O
# routines.  To get these to work, include MATLAB=1 in the make
# command line.
#
# Revision 1.11  1995/05/15 17:51:18  davidj
# Added "version" target.
#
# Revision 1.10  1995/04/20  02:10:30  bedk
# Added an INSTALL_FLAGS variable, and set the default to strip
# executable on installation.
#
# Revision 1.9  1995/04/20  01:57:28  bedk
# Added a purify target.
#
# Revision 1.8  1995/04/19  18:47:43  bedk
# Added a TAGS target.
#
# Revision 1.7	1995/02/10  20:47:11  davidj
# Default to no ESPS IO.
#
# Revision 1.6	1995/02/10  20:12:17  davidj
# Added comment.
#
# Revision 1.5	1995/02/10  20:11:50  davidj
# Added ESPS option stuff.
# Added dist target.
#
# Revision 1.4	1995/02/10  19:41:08  davidj
# Created and used CDEFS macro.
#
# Revision 1.3	1995/02/10  19:25:55  davidj
# More tidying up.
# Added install + clean target.
#
# Revision 1.2	1995/02/10  19:14:10  davidj
# Tidied up Makefile - only ESPS version at present.
#
#
# Makefile for RASTA
#
# Some example make command lines:
#
# make ESPS=1			# Include ESPS functionality
# make install NAME=rasta2 PREFIX=/u/drspeech/alpha	Compile and ..
#				# install with a given name in a given place
# make CC=cc CFLAGS=-fast	# A different compiler and flags
# make dist NAME=rasta_9.0
#
# Note - this Makefile is "pmake friendly"


# These are the names of some programs we use during building and installation

SHELL=/bin/sh
CC = gcc
INSTALL = ginstall
INSTALL_PROG = $(INSTALL)
ETAGS = etags

ARCH = sun4

# Here we define some directories, paths and flags

# Define some ESPS-specific macros depending on whether the "ESPS" macro
# is set.  We have to use shell commands to do this as it is the only
# portable way (watch for the apostrophes!)
ESPS =
ESPS_BASE = /usr/local/dsp/esps
ESPS_LIBS = ` \
	if [ $(ESPS) ]; \
	then \
		echo "-L$(ESPS_BASE)/lib -lexv -lhdre -lespsg"; \
	fi`
ESPS_DEFS = ` \
	if [ $(ESPS) ]; \
	then \
		echo "-DIO_ESPS"; \
	fi`
ESPS_INCS = ` \
	if [ $(ESPS) ]; \
	then \
		echo "-I$(ESPS_BASE)/include"; \
	fi`

# Do the same sort of definition tricks for MATLAB.
MATLAB =
MATLAB_BASE = /usr/local/lang/matlab/extern
MATLAB_LIBS = ` \
	if [ $(MATLAB) ]; \
	then \
		echo "-L$(MATLAB_BASE)/lib/$(ARCH) -lmat"; \
	fi`
MATLAB_DEFS = ` \
	if [ $(MATLAB) ]; \
	then \
		echo "-DIO_MAT"; \
	fi`
MATLAB_INCS = ` \
	if [ $(MATLAB) ]; \
	then \
		echo "-I$(MATLAB_BASE)/include"; \
	fi`

PREFIX = /u/drspeech
# The name under which RASTA is installed (e.g. rasta2_0)
NAME = rasta2_2_3
BINDIR = $(PREFIX)/$(ARCH)/bin
SH_BINDIR = $(PREFIX)/share/bin
MANDIR = $(PREFIX)/man/man1
BIN_INSTALL_FLAGS = -s -m 555
MAN_INSTALL_FLAGS = -m 444
INCS = $(ESPS_INCS) $(MATLAB_INCS)
LIBS = $(ESPS_LIBS) $(MATLAB_LIBS) -lm 
CDEFS = -DSUN4 -DOS4 $(ESPS_DEFS) $(MATLAB_DEFS) $(INCS)
# These can be overridden on the command line, so should not include things
# that are always needed.  It's mainly for optimization, warning and 
# debugging flags.
CFLAGS = -O2 -funroll-loops

# Here are the files we use

OBJFILES = rasta.o init.o anal.o powspec.o noise_est.o mapping.o \
	audspec.o nl_audspec.o rasta_filt.o inverse_nl.o post_audspec.o \
	lpccep.o fft.o io.o fvecsubs.o svecsubs.o debug.o

SRCFILES = rasta.c init.c anal.c powspec.c noise_est.c mapping.c \
	audspec.c nl_audspec.c rasta_filt.c inverse_nl.c post_audspec.c \
	lpccep.c fft.c io.c fvecsubs.c svecsubs.c debug.c

HDRFILES = functions.h rasta.h

MAPFILES = create_mapping lsqsolve.c mul_mdmd_md.c create_mapping.1 \
	lsqsolve.1 map_weights.dat

DISTFILES = $(SRCFILES) $(HDRFILES) $(MAPFILES) README rasta.1 Makefile



# This defines how we actually make the program

rasta: $(OBJFILES) Makefile
	$(CC) $(CFLAGS) $(CDEFS) -o rasta $(OBJFILES) $(LIBS)

rasta.pure: $(OBJFILES) Makefile
	purify $(CC) -b static $(CFLAGS) $(CDEFS) -o rasta.pure $(OBJFILES) $(LIBS)

rasta.o: rasta.c functions.h rasta.h Makefile
	$(CC) -c  $(CFLAGS) $(CDEFS) rasta.c

init.o: init.c functions.h rasta.h Makefile
	$(CC) -c  $(CFLAGS) $(CDEFS)  init.c

debug.o: debug.c functions.h rasta.h Makefile
	$(CC) -c  $(CFLAGS) $(CDEFS)  debug.c

io.o: io.c functions.h rasta.h Makefile
	$(CC) -c  $(CFLAGS) $(CDEFS)  io.c

anal.o: anal.c functions.h rasta.h Makefile
	$(CC) -c  $(CFLAGS) $(CDEFS) anal.c

powspec.o: powspec.c functions.h rasta.h Makefile
	$(CC) -c  $(CFLAGS) $(CDEFS) powspec.c

audspec.o: audspec.c functions.h rasta.h Makefile
	$(CC) -c  $(CFLAGS) $(CDEFS) audspec.c

noise_est.o: noise_est.c functions.h rasta.h Makefile
	$(CC) -c  $(CFLAGS) $(CDEFS) noise_est.c

mapping.o: mapping.c functions.h rasta.h Makefile
	$(CC) -c  $(CFLAGS) $(CDEFS) mapping.c	

nl_audspec.o: nl_audspec.c functions.h rasta.h Makefile
	$(CC) -c  $(CFLAGS) $(CDEFS) nl_audspec.c

rasta_filt.o: rasta_filt.c functions.h rasta.h Makefile
	$(CC) -c  $(CFLAGS) $(CDEFS) rasta_filt.c

inverse_nl.o: inverse_nl.c functions.h rasta.h Makefile
	$(CC) -c  $(CFLAGS) $(CDEFS) inverse_nl.c

post_audspec.o: post_audspec.c functions.h rasta.h Makefile
	$(CC) -c  $(CFLAGS) $(CDEFS) post_audspec.c

lpccep.o: lpccep.c functions.h rasta.h Makefile
	$(CC) -c  $(CFLAGS) $(CDEFS) lpccep.c

fft.o: fft.c functions.h rasta.h Makefile
	$(CC) -c  $(CFLAGS) $(CDEFS) fft.c

fvecsubs.o: fvecsubs.c functions.h rasta.h Makefile
	$(CC) -c  $(CFLAGS) $(CDEFS) fvecsubs.c

svecsubs.o: svecsubs.c functions.h rasta.h Makefile
	$(CC) -c  $(CFLAGS) $(CDEFS) svecsubs.c

# Targets for the create_mapping script

lsqsolve: lsqsolve.o mul_mdmd_md.o Makefile
	$(CC) $(CFLAGS) $(CDEFS) -o $@ lsqsolve.o mul_mdmd_md.o -lm

lsqsolve.o: lsqsolve.c Makefile
	$(CC) -c $(CFLAGS) $(CDEFS) lsqsolve.c

mul_mdmd_md.o: mul_mdmd_md.c Makefile
	$(CC) -c $(CFLAGS) $(CDEFS) mul_mdmd_md.c

# Finally some other targets for administrative stuff

purify: rasta.pure 

print: README $(SRCFILES) functions.h rasta.h Makefile rasta.1
	enscript -G README $(SRCFILES) functions.h rasta.h Makefile

clean:
	rm -f *.o rasta rasta.pure lsqsolve

install: rasta lsqsolve create_mapping
	$(INSTALL_PROG) $(BIN_INSTALL_FLAGS) rasta $(BINDIR)/$(NAME)
	$(INSTALL_PROG) $(BIN_INSTALL_FLAGS) lsqsolve $(BINDIR)/lsqsolve
	$(INSTALL_PROG) $(BIN_INSTALL_FLAGS) create_mapping $(BINDIR)/lsqsolve
	$(INSTALL_PROG) $(MAN_INSTALL_FLAGS) rasta.1 $(MANDIR)/rasta.1
	$(INSTALL_PROG) $(MAN_INSTALL_FLAGS) create_mapping.1 $(MANDIR)/create_mapping.1
	$(INSTALL_PROG) $(MAN_INSTALL_FLAGS) lsqsolve.1 $(MANDIR)/lsqsolve.1

TAGS: $(SRCFILES) $(HDRFILES)
	$(ETAGS) $(SRCFILES) $(HDRFILES)

# Use this target to label all distributed
VERSION = Unknown

version:
	rcs "-n$(VERSION):" $(DISTFILES)

dist: clean
	tar cvf $(NAME).tar $(DISTFILES)
	compress -f $(NAME).tar
