#
# Makefile for libDSP
# Copyright (C) 2000-2003 Jussi Laako
#
# 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#

CC = gcc
CXX = g++

# gcc 3.0.x
#CFLAGS = -march=athlon -mcpu=athlon -O6 -fomit-frame-pointer -ffast-math -funroll-loops -malign-loops=5 -malign-jumps=5 -malign-functions=5 -mpreferred-stack-boundary=5 -mfancy-math-387 -Wall -Werror #-ggdb
#OPTCFLAGS = -march=athlon -O3 -ffast-math -funroll-loops -malign-loops=5 -malign-jumps=5 -malign-functions=5 -mpreferred-stack-boundary=5 -mfancy-math-387 -Wall -Werror #-ggdb
# gcc 3.1.x
#  -tbird, -4, -xp, -mp
CFLAGS = -march=pentium2 -mcpu=athlon-xp -mmmx
#CFLAGS = -march=athlon-tbird -mcpu=athlon-xp -m3dnow # -msse -mfpmath=sse
#CFLAGS = -march=pentium3 -mcpu=pentium3 -msse -mfpmath=sse
#CFLAGS = -march=pentium4 -mcpu=pentium4 -msse2 -mfpmath=sse -m128bit-long-double
CFLAGS += -O3 -ffast-math -funroll-loops -fprefetch-loop-arrays -Wall -Werror #-ggdb
CFLAGS += -ftracer
OPTCFLAGS = -march=pentium2 -mcpu=athlon-xp -mmmx
#OPTCFLAGS = -march=athlon-tbird -mcpu=athlon-xp -m3dnow 
#OPTCFLAGS = -march=pentium3 -mcpu=pentium3 -msse
#OPTCFLAGS = -march=pentium4 -mcpu=pentium4 -msse2 -m128bit-long-double
OPTCFLAGS += -O3 -ffast-math -funroll-loops -fprefetch-loop-arrays -Wall -Werror #-ggdb
OPTCFLAGS += -ftracer
CXXFLAGS = $(CFLAGS)

# thread safety
DEFS = -D_REENTRANT -D_THREAD_SAFE
# define if your compiler/c-library is ISO C 9x standard compliant
DEFS += -D_ISOC9X_SOURCE
# define if you are using GNU C++-compiler and GNU C-library
DEFS += -D_GNU_SOURCE
# use memmove() for copying data instead of built-in routine, for gcc inlining
#DEFS += -DUSE_MEMMOVE
# define for x86 platform specific optimizations
DEFS += -DDSP_X86

INCS = -I. #-I/usr/local/include

LDFLAGS = #-ggdb

LIBS = -lm #-ldrfftw -ldfftw

LIBTOOL = libtool

PREFIX = /usr/local

VERSION = 5:0:4

CSRC = c
CCSRC = cc
OBJ = o
LOBJ = lo

SRCS = DSPOp.$(CCSRC) \
	Decimator.$(CCSRC) \
	FFTDecimator.$(CCSRC) \
	FFTInterpolator.$(CCSRC) \
	FFTMultiRate.$(CCSRC) \
	Filter.$(CCSRC) \
	Filter2.$(CCSRC) \
	FIRDecimator.$(CCSRC) \
	FIRInterpolator.$(CCSRC) \
	FIRMultiRate.$(CCSRC) \
	Hankel.$(CCSRC) \
	IIRCascade.$(CCSRC) \
	IIRDecimator.$(CCSRC) \
	IIRInterpolator.$(CCSRC) \
	IIRMultiRate.$(CCSRC) \
	ReBuffer.$(CCSRC) \
	RecDecimator.$(CCSRC) \
	RecInterpolator.$(CCSRC) \
	Transform4.$(CCSRC) \
	Transform8.$(CCSRC) \
	TransformS.$(CCSRC) \
	cdspop.$(CCSRC) \
	X86.$(CSRC)

OBJS = DSPOp.$(OBJ) \
	Decimator.$(OBJ) \
	FFTDecimator.$(OBJ) \
	FFTInterpolator.$(OBJ) \
	FFTMultiRate.$(OBJ) \
	Filter.$(OBJ) \
	Filter2.$(OBJ) \
	FIRDecimator.$(OBJ) \
	FIRInterpolator.$(OBJ) \
	FIRMultiRate.$(OBJ) \
	Hankel.$(OBJ) \
	IIRCascade.$(OBJ) \
	IIRDecimator.$(OBJ) \
	IIRInterpolator.$(OBJ) \
	IIRMultiRate.$(OBJ) \
	ReBuffer.$(OBJ) \
	RecDecimator.$(OBJ) \
	RecInterpolator.$(OBJ) \
	Transform4.$(OBJ) \
	Transform8.$(OBJ) \
	TransformS.$(OBJ) \
	cdspop.$(OBJ) \
	X86.$(OBJ)

LOBJS = DSPOp.$(LOBJ) \
	Decimator.$(LOBJ) \
	FFTDecimator.$(LOBJ) \
	FFTInterpolator.$(LOBJ) \
	FFTMultiRate.$(LOBJ) \
	Filter.$(LOBJ) \
	Filter2.$(LOBJ) \
	FIRDecimator.$(LOBJ) \
	FIRInterpolator.$(LOBJ) \
	FIRMultiRate.$(LOBJ) \
	Hankel.$(LOBJ) \
	IIRCascade.$(LOBJ) \
	IIRDecimator.$(LOBJ) \
	IIRInterpolator.$(LOBJ) \
	IIRMultiRate.$(LOBJ) \
	ReBuffer.$(LOBJ) \
	RecDecimator.$(LOBJ) \
	RecInterpolator.$(LOBJ) \
	Transform4.$(LOBJ) \
	Transform8.$(LOBJ) \
	TransformS.$(LOBJ) \
	cdspop.$(LOBJ) \
	X86.$(LOBJ)

default: all

all: libdsp.la

.c.o: $(SRCS)
	$(LIBTOOL) --mode=compile $(CC) $(CFLAGS) $(DEFS) $(INCS) -c $<

.cc.o: $(SRCS)
	$(LIBTOOL) --mode=compile $(CXX) $(CXXFLAGS) $(DEFS) $(INCS) -c $<

X86.$(OBJ): X86.$(CSRC)
	$(LIBTOOL) --mode=compile $(CC) $(OPTCFLAGS) $(DEFS) $(INCS) -c $<

libdsp.la: $(OBJS)
	$(LIBTOOL) --mode=link $(CXX) $(LDFLAGS) -rpath $(PREFIX)/lib -version-info $(VERSION) -o libdsp.la $(LOBJS) $(LIBS)

install: libdsp.la
	install -m 755 -d $(PREFIX)/include/dsp
	install -m 644 dsp/DSPConfig.hh $(PREFIX)/include/dsp
	install -m 644 dsp/DSPOp.hh $(PREFIX)/include/dsp
	install -m 644 dsp/DSPVector.hh $(PREFIX)/include/dsp
	install -m 644 dsp/Decimator.hh $(PREFIX)/include/dsp
	install -m 644 dsp/FFTDecimator.hh $(PREFIX)/include/dsp
	install -m 644 dsp/FFTInterpolator.hh $(PREFIX)/include/dsp
	install -m 644 dsp/FFTMultiRate.hh $(PREFIX)/include/dsp
	install -m 644 dsp/Filter.hh $(PREFIX)/include/dsp
	install -m 644 dsp/Filter2.hh $(PREFIX)/include/dsp
	install -m 644 dsp/FIRDecimator.hh $(PREFIX)/include/dsp
	install -m 644 dsp/FIRInterpolator.hh $(PREFIX)/include/dsp
	install -m 644 dsp/FIRMultiRate.hh $(PREFIX)/include/dsp
	install -m 644 dsp/Hankel.hh $(PREFIX)/include/dsp
	install -m 644 dsp/IIRCascade.hh $(PREFIX)/include/dsp
	install -m 644 dsp/IIRDecimator.hh $(PREFIX)/include/dsp
	install -m 644 dsp/IIRInterpolator.hh $(PREFIX)/include/dsp
	install -m 644 dsp/IIRMultiRate.hh $(PREFIX)/include/dsp
	install -m 644 dsp/ReBuffer.hh $(PREFIX)/include/dsp
	install -m 644 dsp/ReBuffer2.hh $(PREFIX)/include/dsp
	install -m 644 dsp/ReBuffer3.hh $(PREFIX)/include/dsp
	install -m 644 dsp/RecDecimator.hh $(PREFIX)/include/dsp
	install -m 644 dsp/RecInterpolator.hh $(PREFIX)/include/dsp
	install -m 644 dsp/Transform4.hh $(PREFIX)/include/dsp
	install -m 644 dsp/Transform8.hh $(PREFIX)/include/dsp
	install -m 644 dsp/TransformS.hh $(PREFIX)/include/dsp
	install -m 644 dsp/dsptypes.h $(PREFIX)/include/dsp
	install -m 644 dsp/dspop.h $(PREFIX)/include/dsp
	install -m 644 dsp/X86.h $(PREFIX)/include/dsp
	$(LIBTOOL) --mode=install install libdsp.la $(PREFIX)/lib

libdsp.dep: $(SRCS)
	$(CXX) $(DEFS) $(INCS) -MM $(SRCS) >libdsp.dep

clean:
	rm -f *.$(OBJ) *.$(LOBJ) *~ libdsp.la core*

cleanall:
	rm -rf *.$(OBJ) *.$(LOBJ) *~ libdsp.dep libdsp.la .libs core*

include libdsp.dep

