# PyEPL: hardware/sound/Makefile
#
# Copyright (C) 2003-2005 Michael J. Kahana
# Authors: Ian Schleifer, Per Sederberg, Aaron Geller, Josh Jacobs
# URL: http://memory.psych.upenn.edu/programming/pyepl
#
# Distributed under the terms of the GNU Lesser General Public License
# (LGPL). See the license.txt that came with this file.

all: _eplSound.so _soundFile.so

INCLUDEPY=$(shell python -c "import distutils.sysconfig;print distutils.sysconfig.get_config_var('INCLUDEPY')")

PLATFORM = $(shell uname)

ifeq ($(PLATFORM), Linux)
########################################################
#
# Make rules for linux
#
########################################################
SOUND_DRIVER=ALSA

_eplSound.so: eplSound.o eplSound.i RtAudio.o fifo.o
	swig -c++ -python eplSound.i
	g++ -pthread -fno-strict-aliasing -DNDEBUG -O2 -Wall -fPIC -I$(INCLUDEPY) -c eplSound_wrap.cxx -o eplSound_wrap.o
	g++ -lpthread -lasound -shared eplSound_wrap.o eplSound.o RtAudio.o fifo.o -o _eplSound.so

eplSound.o: eplSound.cpp eplSound.h
	g++ -pthread -fno-strict-aliasing -DNDEBUG -O2 -Wall -fPIC -I$(INCLUDEPY) -c eplSound.cpp -o eplSound.o

fifo.o: fifo.cpp
	g++ -pthread -fno-strict-aliasing -DNDEBUG -O2 -Wall -fPIC -I$(INCLUDEPY) -c fifo.cpp -o fifo.o

RtAudio.o: RtAudio.cpp
	g++ -O2 -Wall -fPIC -D__LINUX_$(SOUND_DRIVER)__  -c RtAudio.cpp -o RtAudio.o

soundFile.o: soundFile.cpp soundFile.h
	g++ -pthread -fno-strict-aliasing -DNDEBUG -O2 -Wall -fPIC -c soundFile.cpp -o soundFile.o

_soundFile.so: soundFile.i soundFile.o
	swig -c++ -python soundFile.i
	g++ -pthread -fno-strict-aliasing -DNDEBUG -O2 -Wall -fPIC -I$(INCLUDEPY) -c soundFile_wrap.cxx -o soundFile_wrap.o
	g++ -lpthread -shared soundFile_wrap.o soundFile.o -lsndfile -lsamplerate -o _soundFile.so

endif

ifeq ($(PLATFORM), Darwin)
########################################################
#
# Make rules for mac
#
########################################################

LIBDIR = -L/usr/local/lib -L/opt/local/lib -L/sw/lib
INCLUDEDIR = -I/usr/local/include -I/opt/local/include -I/sw/include

INCLUDEPY=$(shell python -c "import distutils.sysconfig;print distutils.sysconfig.get_config_var('INCLUDEPY')")
LIBPY=$(shell python -c "import distutils.sysconfig;print distutils.sysconfig.get_config_var('LIBPL')")
PYTHON_INC = $(INCLUDEPY)
PYTHON_LIB = $(LIBPY)
FLAGS1 = -Wno-long-double -DHAVE_CONFIG_H
FLAGS2 = -bundle -undefined suppress -flat_namespace -lpthread -framework CoreAudio
FLAGS3 = -fno-strict-aliasing -Wno-long-double -no-cpp-precomp	\
-mno-fused-madd -fno-common -dynamic -DNDEBUG -O2 -Wall	

_eplSound.so: eplSound.o eplSound.i RtAudio.o fifo.o
	swig -c++ -python eplSound.i
	g++ $(FLAGS1) -I$(PYTHON_INC) -L$(PYTHON_LIB) -c eplSound_wrap.cxx 
	g++ $(FLAGS2) eplSound.o eplSound_wrap.o RtAudio.o fifo.o -o _eplSound.so 

eplSound.o: eplSound.cpp eplSound.h
	g++ $(FLAGS3) -I$(PYTHON_INC) -c eplSound.cpp -o eplSound.o

fifo.o: fifo.cpp fifo.h
	g++ $(FLAGS3) -I$(PYTHON_INC) -c fifo.cpp -o fifo.o

RtAudio.o: RtAudio.cpp
	g++ -O2 -Wall -D__MACOSX_CORE__ -c RtAudio.cpp -o RtAudio.o

soundFile.o: soundFile.cpp soundFile.h
	g++  -O2 -W -Wall -Wcast-align -Wcast-qual -Wwrite-strings -pipe -fpascal-strings -c soundFile.cpp -o soundFile.o $(LIBDIR) $(INCLUDEDIR)

_soundFile.so: soundFile.i soundFile.o
	swig -c++ -python soundFile.i		
	g++ -Wno-long-double -c soundFile_wrap.cxx -DHAVE_CONFIG_H -I$(PYTHON_INC)
	g++ -bundle -undefined suppress -flat_namespace soundFile_wrap.o soundFile.o -lsndfile -lsamplerate -o _soundFile.so $(LIBDIR) $(INCLUDEDIR)

test_epl: eplSound.o RtAudio.o test_epl.cpp
	g++ -O2 -I../  -D__MACOSX_CORE__ -o test_epl test_epl.cpp eplSound.o RtAudio.o -lstdc++ -lpthread  -framework CoreAudio

endif

clean:
	rm *.o *.so *.cxx
