
CXX		= g++
CXXFLAGS	= -isysroot /Developer/SDKs/MacOSX10.4u.sdk -O3 -arch i386 -arch ppc -msse -msse2 -I../include -I../vamp-plugin-sdk -Irubberband -Isrc
LDFLAGS		= -L../lib -L../vamp-plugin-sdk/vamp-sdk

LIBRARY_LIBS		= -lsamplerate -lfftw3 -lfftw3f
PROGRAM_LIBS		= -lsndfile $(LIBRARY_LIBS)
VAMP_PLUGIN_LIBS	= -lvamp-sdk $(LIBRARY_LIBS)
LADSPA_PLUGIN_LIBS	= $(LIBRARY_LIBS)

MKDIR		= mkdir
AR		= ar

PROGRAM_TARGET := bin/rubberband
STATIC_TARGET  := lib/librubberband.a
DYNAMIC_TARGET := lib/librubberband.dylib
VAMP_TARGET    := lib/vamp-rubberband.dylib
LADSPA_TARGET  := lib/ladspa-rubberband.dylib

#DYNAMIC_LDFLAGS	:= -shared -Wl,-Bsymbolic
DYNAMIC_LDFLAGS := -dynamiclib

all: bin lib $(PROGRAM_TARGET) $(STATIC_TARGET) $(DYNAMIC_TARGET) $(VAMP_TARGET) $(LADSPA_TARGET)

PUBLIC_INCLUDES := \
	rubberband/TimeStretcher.h \
	rubberband/RubberBandStretcher.h

LIBRARY_INCLUDES := \
	src/AudioCurve.h \
	src/ConstantAudioCurve.h \
	src/FFT.h \
	src/HighFrequencyAudioCurve.h \
	src/PercussiveAudioCurve.h \
	src/Resampler.h \
	src/RingBuffer.h \
	src/Scavenger.h \
	src/StretchCalculator.h \
	src/StretcherImpl.h \
	src/StretcherChannelData.h \
	src/Thread.h \
	src/Window.h \
	src/sysutils.h

LIBRARY_SOURCES := \
	src/RubberBandStretcher.cpp \
	src/ConstantAudioCurve.cpp \
	src/HighFrequencyAudioCurve.cpp \
	src/PercussiveAudioCurve.cpp \
	src/AudioCurve.cpp \
	src/Resampler.cpp \
	src/StretchCalculator.cpp \
	src/StretcherImpl.cpp \
	src/StretcherProcess.cpp \
	src/StretcherChannelData.cpp \
	src/FFT.cpp \
	src/Thread.cpp \
	src/sysutils.cpp

PROGRAM_SOURCES := \
	src/main.cpp

VAMP_HEADERS := \
	src/vamp/RubberBandVampPlugin.h

VAMP_SOURCES := \
	src/vamp/RubberBandVampPlugin.cpp \
	src/vamp/libmain.cpp

LADSPA_HEADERS := \
	src/ladspa/RubberBandPitchShifter.h

LADSPA_SOURCES := \
	src/ladspa/RubberBandPitchShifter.cpp \
	src/ladspa/libmain.cpp

LIBRARY_OBJECTS := $(LIBRARY_SOURCES:.cpp=.o)
PROGRAM_OBJECTS := $(PROGRAM_SOURCES:.cpp=.o)
VAMP_OBJECTS    := $(VAMP_SOURCES:.cpp=.o)
LADSPA_OBJECTS  := $(LADSPA_SOURCES:.cpp=.o)

$(PROGRAM_TARGET):	$(LIBRARY_OBJECTS) $(PROGRAM_OBJECTS)
	$(CXX) -o $@ $^ $(PROGRAM_LIBS) $(PROGRAM_LIBS) $(LDFLAGS)

$(STATIC_TARGET):	$(LIBRARY_OBJECTS)
	$(AR) rsc $@ $^

$(DYNAMIC_TARGET):	$(LIBRARY_OBJECTS)
	$(CXX) $(DYNAMIC_LDFLAGS) $^ -o $@ $(LIBRARY_LIBS) $(LDFLAGS)

$(VAMP_TARGET):		$(LIBRARY_OBJECTS) $(VAMP_OBJECTS)
	$(CXX) $(DYNAMIC_LDFLAGS) -o $@ $^ $(VAMP_PLUGIN_LIBS) $(LDFLAGS)

$(LADSPA_TARGET):	$(LIBRARY_OBJECTS) $(LADSPA_OBJECTS)
	$(CXX) $(DYNAMIC_LDFLAGS) -o $@ $^ $(LADSPA_PLUGIN_LIBS) $(LDFLAGS)

bin:
	$(MKDIR) $@
lib:
	$(MKDIR) $@

clean:
	rm -f $(LIBRARY_OBJECTS) $(PROGRAM_OBJECTS) $(LADSPA_OBJECTS) $(VAMP_OBJECTS)

distclean:	clean
	rm -f $(PROGRAM_TARGET) $(STATIC_TARGET) $(DYNAMIC_TARGET) $(VAMP_TARGET) $(LADSPA_TARGET)

# DO NOT DELETE

src/AudioCurve.o: src/AudioCurve.h
src/ConstantAudioCurve.o: src/ConstantAudioCurve.h src/AudioCurve.h
src/FFT.o: src/FFT.h src/Thread.h
src/HighFrequencyAudioCurve.o: src/HighFrequencyAudioCurve.h src/AudioCurve.h
src/HighFrequencyAudioCurve.o: src/Window.h
src/main.o: rubberband/RubberBandStretcher.h rubberband/TimeStretcher.h
src/PercussiveAudioCurve.o: src/PercussiveAudioCurve.h src/AudioCurve.h
src/Resampler.o: src/Resampler.h
src/RubberBandStretcher.o: src/StretcherImpl.h
src/RubberBandStretcher.o: rubberband/RubberBandStretcher.h
src/RubberBandStretcher.o: rubberband/TimeStretcher.h src/Window.h
src/RubberBandStretcher.o: src/Thread.h src/RingBuffer.h src/Scavenger.h
src/RubberBandStretcher.o: src/FFT.h src/sysutils.h
src/StretchCalculator.o: src/StretchCalculator.h
src/StretcherChannelData.o: src/StretcherChannelData.h src/StretcherImpl.h
src/StretcherChannelData.o: rubberband/RubberBandStretcher.h
src/StretcherChannelData.o: rubberband/TimeStretcher.h src/Window.h
src/StretcherChannelData.o: src/Thread.h src/RingBuffer.h src/Scavenger.h
src/StretcherChannelData.o: src/FFT.h src/sysutils.h src/Resampler.h
src/StretcherImpl.o: src/StretcherImpl.h rubberband/RubberBandStretcher.h
src/StretcherImpl.o: rubberband/TimeStretcher.h src/Window.h src/Thread.h
src/StretcherImpl.o: src/RingBuffer.h src/Scavenger.h src/FFT.h
src/StretcherImpl.o: src/sysutils.h src/PercussiveAudioCurve.h
src/StretcherImpl.o: src/AudioCurve.h src/HighFrequencyAudioCurve.h
src/StretcherImpl.o: src/ConstantAudioCurve.h src/StretchCalculator.h
src/StretcherImpl.o: src/StretcherChannelData.h src/Resampler.h
src/StretcherProcess.o: src/StretcherImpl.h rubberband/RubberBandStretcher.h
src/StretcherProcess.o: rubberband/TimeStretcher.h src/Window.h src/Thread.h
src/StretcherProcess.o: src/RingBuffer.h src/Scavenger.h src/FFT.h
src/StretcherProcess.o: src/sysutils.h src/PercussiveAudioCurve.h
src/StretcherProcess.o: src/AudioCurve.h src/HighFrequencyAudioCurve.h
src/StretcherProcess.o: src/ConstantAudioCurve.h src/StretchCalculator.h
src/StretcherProcess.o: src/StretcherChannelData.h src/Resampler.h
src/sysutils.o: src/sysutils.h
src/Thread.o: src/Thread.h
