# vim: set noexpandtab:
#
# GNU Solfege - ear training for GNOME
# Copyright (C) 2000, 2001, 2002, 2003, 2004  Tom Cato Amundsen
#
# 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

installfiles += $(wildcard soundcard/*.py)
dist_files += soundcard/Makefile \
	$(wildcard soundcard/*.py) \
	$(filter-out solfege_c_midi_wrap.c, $(wildcard soundcard/*.c soundcard/*.i soundcard/*.h)) \
	soundcard/winmidi.dsp soundcard/winmidi.dsw soundcard/winmidi.def

easy-dist-files += soundcard/solfege_c_midi_wrap.c

CFLAGS:=$(CFLAGS) -I/usr/src/linux/include -Wall -pedantic -fPIC
CC:=$(CC) $(CFLAGS) -DHAVE_CONFIG_H 

TARGETS += soundcard/_solfege_c_midi.so

OBJECTS = soundcard/macro_to_function.o \
	soundcard/solfege_c_midi.o \
	soundcard/solfege_c_midi_wrap.o

ifeq ($(ENABLE_TUNER),yes)
OBJECTS += fft.o dsp.o gate.o calc.o xmalloc.o
endif

soundcard/solfege_c_midimodule.so: $(OBJECTS)
	$(CC) -fPIC -shared $(OBJECTS) -o $@ -lc

soundcard/_solfege_c_midi.so: $(OBJECTS)
	$(CC) -fPIC -shared $(OBJECTS) -o $@

soundcard/solfege_c_midi_wrap.o: soundcard/solfege_c_midi_wrap.c soundcard/solfege_c_midi.i
	(cd soundcard; $(CC) $(CFLAGS) -c solfege_c_midi_wrap.c $(PYTHON_INCLUDES))

# win32
# This section is still just a hack and will be completed in a later
# release. At the moment I (tca) use this section to cross-compile
# the win32 sound module 'winmidi.py'

# mkdir ~/X/python23
# cd ~/X/python23
# unzip /mnt/hda9/Python-2.3.exe
# lowercase-filename
# d2u *.h
#
W32CFLAGS=-I/home/tom/X/python23 -I/usr/i586-mingw32msvc/include 
W32GCC=i586-mingw32msvc-gcc

PYDLL=/home/tom/X/python23/python23.dll
DLLWRAP=i586-mingw32msvc-dllwrap

%/winmidi.pyd: %/winmidi.o
	$(DLLWRAP) --dllname=$@ --def=soundcard/winmidi.def $< -o $@ -s --entry=_DllMain@12 -L/usr/i586-mingw32msvc/lib/ -lwinmm $(PYDLL)

%/winmidi.o: %/winmidi.c
	$(W32GCC) $(W32CFLAGS) -c $< -o $@

# end win32

install-soundcard:
ifeq ($(ENABLE_OSS_SOUND),yes)
	mkdir -p $(libdir)/$(PACKAGE)/$(VERSION)
ifeq ($(SWIG_VERSION),1.1)
	$(INSTALL_DATA) soundcard/solfege_c_midimodule.so $(libdir)/$(PACKAGE)/$(VERSION)/
else
	$(INSTALL_DATA) soundcard/_solfege_c_midi.so $(libdir)/$(PACKAGE)/$(VERSION)/
endif
endif

uninstall-soundcard:
ifeq ($(SWIG_VERSION),1.1)
	rm -f $(libdir)/$(PACKAGE)/$(VERSION)/solfege_c_midimodule.so
else
	rm -f $(libdir)/$(PACKAGE)/$(VERSION)/_solfege_c_midi.so
endif
	rmdir $(libdir)/$(PACKAGE)/$(VERSION) || true
	rmdir $(libdir)/$(PACKAGE) || true

clean-files += soundcard/solfege_c_midi_wrap.c \
	$(wildcard soundcard/*.o soundcard/*.so soundcard/*.pyc soundcard/*.pyd soundcard/*.pyo)\
	$(wildcard soundcard/solfege_c_midi.py*)

