
CXX		:= @CXX@
CXXFLAGS	:= -DUSE_PTHREADS -DHAVE_LIBSAMPLERATE -DHAVE_FFTW3 -DFFTW_DOUBLE_ONLY @CXXFLAGS@ @SRC_CFLAGS@ @SNDFILE_CFLAGS@ @FFTW_CFLAGS@ @Vamp_CFLAGS@ -Irubberband -Isrc $(OPTFLAGS)
LDFLAGS		:= @LDFLAGS@ -lpthread $(LDFLAGS)

LIBRARY_LIBS		:= @SRC_LIBS@ @FFTW_LIBS@ 
PROGRAM_LIBS		:= @SNDFILE_LIBS@ $(LIBRARY_LIBS)
VAMP_PLUGIN_LIBS	:= @Vamp_LIBS@ $(LIBRARY_LIBS)
LADSPA_PLUGIN_LIBS	:= $(LIBRARY_LIBS)

MKDIR			:= mkdir
AR			:= ar

DYNAMIC_LDFLAGS		:= -shared -Wl,-Bsymbolic
DYNAMIC_EXTENSION	:= .so

PROGRAM_TARGET 		:= bin/rubberband
STATIC_TARGET  		:= lib/librubberband.a
DYNAMIC_TARGET 		:= lib/librubberband$(DYNAMIC_EXTENSION)
VAMP_TARGET    		:= lib/vamp-rubberband$(DYNAMIC_EXTENSION)
LADSPA_TARGET  		:= lib/ladspa-rubberband$(DYNAMIC_EXTENSION)

INSTALL_BINDIR		:= @prefix@/bin
INSTALL_INCDIR		:= @prefix@/include/rubberband
INSTALL_LIBDIR		:= @prefix@/lib
INSTALL_VAMPDIR		:= @prefix@/lib/vamp
INSTALL_LADSPADIR	:= @prefix@/lib/ladspa
INSTALL_PKGDIR		:= @prefix@/lib/pkgconfig

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/SpectralDifferenceAudioCurve.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/SpectralDifferenceAudioCurve.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) $@

install:	all
	$(MKDIR) -p $(INSTALL_BINDIR)
	$(MKDIR) -p $(INSTALL_INCDIR)
	$(MKDIR) -p $(INSTALL_LIBDIR)
	$(MKDIR) -p $(INSTALL_VAMPDIR)
	$(MKDIR) -p $(INSTALL_LADSPADIR)
	cp $(PROGRAM_TARGET) $(INSTALL_BINDIR)
	cp $(PUBLIC_INCLUDES) $(INSTALL_INCDIR)
	cp $(STATIC_TARGET) $(INSTALL_LIBDIR)
	cp $(DYNAMIC_TARGET) $(INSTALL_LIBDIR)
	cp $(VAMP_TARGET) $(INSTALL_VAMPDIR)
	cp src/vamp/vamp-rubberband.cat $(INSTALL_VAMPDIR)
	cp $(LADSPA_TARGET) $(INSTALL_LADSPADIR)
	cp src/ladspa/ladspa-rubberband.cat $(INSTALL_LADSPADIR)
	sed "s,%PREFIX%,@prefix@," rubberband.pc.in \
	  > $(INSTALL_PKGDIR)/rubberband.pc

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: src/sysutils.h
src/PercussiveAudioCurve.o: src/PercussiveAudioCurve.h src/AudioCurve.h
src/Resampler.o: src/Resampler.h
src/RubberBandStretcher.o: src/StretcherImpl.h src/Window.h src/Thread.h
src/RubberBandStretcher.o: src/RingBuffer.h src/Scavenger.h src/sysutils.h
src/RubberBandStretcher.o: src/FFT.h
src/SpectralDifferenceAudioCurve.o: src/SpectralDifferenceAudioCurve.h
src/SpectralDifferenceAudioCurve.o: src/AudioCurve.h src/Window.h
src/StretchCalculator.o: src/StretchCalculator.h
src/StretcherChannelData.o: src/StretcherChannelData.h src/StretcherImpl.h
src/StretcherChannelData.o: src/Window.h src/Thread.h src/RingBuffer.h
src/StretcherChannelData.o: src/Scavenger.h src/sysutils.h src/FFT.h
src/StretcherChannelData.o: src/Resampler.h
src/StretcherImpl.o: src/StretcherImpl.h src/Window.h src/Thread.h
src/StretcherImpl.o: src/RingBuffer.h src/Scavenger.h src/sysutils.h
src/StretcherImpl.o: src/FFT.h src/PercussiveAudioCurve.h src/AudioCurve.h
src/StretcherImpl.o: src/HighFrequencyAudioCurve.h
src/StretcherImpl.o: src/SpectralDifferenceAudioCurve.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 src/Window.h src/Thread.h
src/StretcherProcess.o: src/RingBuffer.h src/Scavenger.h src/sysutils.h
src/StretcherProcess.o: src/FFT.h src/PercussiveAudioCurve.h src/AudioCurve.h
src/StretcherProcess.o: 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
src/ConstantAudioCurve.o: src/AudioCurve.h
src/HighFrequencyAudioCurve.o: src/AudioCurve.h src/Window.h
src/PercussiveAudioCurve.o: src/AudioCurve.h
src/RingBuffer.o: src/Scavenger.h src/Thread.h src/sysutils.h
src/Scavenger.o: src/Thread.h src/sysutils.h
src/SpectralDifferenceAudioCurve.o: src/AudioCurve.h src/Window.h
src/StretcherChannelData.o: src/StretcherImpl.h src/Window.h src/Thread.h
src/StretcherChannelData.o: src/RingBuffer.h src/Scavenger.h src/sysutils.h
src/StretcherChannelData.o: src/FFT.h
src/StretcherImpl.o: src/Window.h src/Thread.h src/RingBuffer.h
src/StretcherImpl.o: src/Scavenger.h src/sysutils.h src/FFT.h
src/vamp/libmain.o: src/vamp/RubberBandVampPlugin.h
src/vamp/RubberBandVampPlugin.o: src/vamp/RubberBandVampPlugin.h
src/vamp/RubberBandVampPlugin.o: src/StretchCalculator.h
src/ladspa/libmain.o: src/ladspa/RubberBandPitchShifter.h src/RingBuffer.h
src/ladspa/libmain.o: src/Scavenger.h src/Thread.h src/sysutils.h
src/ladspa/RubberBandPitchShifter.o: src/ladspa/RubberBandPitchShifter.h
src/ladspa/RubberBandPitchShifter.o: src/RingBuffer.h src/Scavenger.h
src/ladspa/RubberBandPitchShifter.o: src/Thread.h src/sysutils.h
src/ladspa/RubberBandPitchShifter.o: src/RingBuffer.h src/Scavenger.h
src/ladspa/RubberBandPitchShifter.o: src/Thread.h src/sysutils.h
