# MinGW specific Makefile for libsamplerate.

@SET_MAKE@

PROGRAMS = sndfile-resample.exe
TARGETS = libsamplerate.dll $(PROGRAMS) varispeed-play.exe samplerate.pc

AR = @AR@
CC = @CC@
CFLAGS = @CFLAGS@ -Isrc
COMPILER_IS_GCC = @COMPILER_IS_GCC@
CPP = @CPP@
CPPFLAGS = @CPPFLAGS@
CXX = @CXX@
DLLTOOL = @DLLTOOL@
DLLWRAP = @DLLWRAP@
FFTW3_CFLAGS = @FFTW3_CFLAGS@
FFTW3_LIBS = @FFTW3_LIBS@
INSTALL = @INSTALL@
INSTALL_DATA = ${INSTALL} -m 644
install_sh = @install_sh@
LDFLAGS = @LDFLAGS@
LN_S = @LN_S@
PEXPORTS = @PEXPORTS@
PACKAGE = @PACKAGE@
PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
PACKAGE_NAME = @PACKAGE_NAME@
PACKAGE_STRING = @PACKAGE_STRING@
PACKAGE_TARNAME = @PACKAGE_TARNAME@
PACKAGE_VERSION = @PACKAGE_VERSION@
RANLIB = @RANLIB@
SNDFILE_CFLAGS = -std=c99 @SNDFILE_CFLAGS@
SNDFILE_LIBS = @SNDFILE_LIBS@
STRIP = @STRIP@

#====================================================================
# Target directories.

bindir = @bindir@
exec_prefix = @exec_prefix@
htmldocdir = @htmldocdir@
includedir = @includedir@
libdir = @libdir@
pkgconfigdir = @libdir@/pkgconfig
prefix = @prefix@

#====================================================================
# Targets

all : $(TARGETS)

clean :
	rm -f  $(TARGETS) *.del *.lib src/*.o tests/*.o tests/*.exe

install : $(TARGETS)
	$(install_sh) -c libsamplerate.dll $(libdir)
	$(install_sh) -c samplerate.pc $(pkgconfigdir)
	@for prog in $(PROGRAMS); do \
		echo "installing ... $$prog" ; \
		$(install_sh) -c "$$prog" $(bindir) ; \
		done;
	$(install_sh) -c src/samplerate.h $(includedir)
 
uninstall :
	rm -f $(libdir)/libsamplerate.dll
	rm -f $(pkgconfigdir)/samplerate.pc
	@for prog in $(PROGRAMS); do \
		echo "removing ... $(bindir)/$$prog" ; \
		rm -f $(bindir)/"$$prog" ; \
		done;
	rm -f $(includedir)/samplerate.h

#====================================================================

LINK_OBJS = \
	src/src_linear.o \
	src/src_sinc.o \
	src/src_zoh.o \
	src/samplerate.o

libsamplerate.dll libsamplerate.lib : $(LINK_OBJS)
	$(DLLWRAP) --def Win32/libsamplerate.def $(LINK_OBJS) --output-lib libsamplerate.lib -o libsamplerate.dll
	$(STRIP) libsamplerate.dll

sndfile-resample.exe : examples/sndfile-resample.c libsamplerate.lib
	$(CC) $(CFLAGS) $(SNDFILE_CFLAGS) $+ $(SNDFILE_LIBS) -o $@

varispeed-play.exe : examples/varispeed-play.c examples/audio_out.o libsamplerate.lib
	$(CC) $(CFLAGS) $(SNDFILE_CFLAGS) $+ $(SNDFILE_LIBS) -lwinmm -o $@

examples/audio_out.o : examples/audio_out.c
	$(CC) $(CFLAGS) $(SNDFILE_CFLAGS) -c $+ -o $@

samplerate.pc : samplerate.pc.in config.status
	@./config.status $@

config.status :
	./configure

#====================================================================
# Testing programs.

TEST_PROGS = \
     tests/misc_test.exe \
     tests/termination_test.exe \
     tests/simple_test.exe \
	 tests/callback_test.exe \
     tests/reset_test.exe \
     tests/multi_channel_test.exe \
	 tests/float_short_test.exe \
     tests/snr_bw_test.exe


check : $(TEST_PROGS)
	tests/misc_test.exe
	tests/termination_test.exe
	tests/simple_test.exe
	tests/callback_test.exe
	tests/reset_test.exe
	tests/multi_channel_test.exe
	tests/float_short_test.exe
	tests/snr_bw_test.exe
	@echo ----------------------------------------------------------------------
	@echo libsamplerate passed all tests
	@echo ----------------------------------------------------------------------

#====================================================================
# Test programs.

tests/misc_test.exe : tests/misc_test.c tests/util.c libsamplerate.lib
	$(CC) $(CFLAGS) $+ -o $@

tests/termination_test.exe : tests/termination_test.c tests/util.c libsamplerate.lib
	$(CC) $(CFLAGS) $+ -o $@

tests/simple_test.exe : tests/simple_test.c tests/util.c libsamplerate.lib
	$(CC) $(CFLAGS) $+ -o $@

tests/callback_test.exe : tests/callback_test.c tests/util.c libsamplerate.lib
	$(CC) $(CFLAGS) $+ -o $@

tests/reset_test.exe : tests/reset_test.c tests/util.c libsamplerate.lib
	$(CC) $(CFLAGS) $+ -o $@

tests/float_short_test.exe : tests/float_short_test.c tests/util.c libsamplerate.lib
	$(CC) $(CFLAGS) $+ -o $@

tests/multi_channel_test.exe : tests/multi_channel_test.c tests/util.c tests/calc_snr.c libsamplerate.lib
	$(CC) $(CFLAGS) $(FFTW3_CFLAGS) $+ $(FFTW3_LIBS) -o $@

tests/snr_bw_test.exe : tests/snr_bw_test.c tests/util.c tests/calc_snr.c libsamplerate.lib
	$(CC) $(CFLAGS) $(FFTW3_CFLAGS) $+ $(FFTW3_LIBS) -o $@

# End of Makefile
#====================================================================
