# vim: set noexpandtab:
#
# GNU Solfege - eartraining for GNOME
# Copyright (C) 2000, 2001, 2002, 2003  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


depth = ..
name = soundcard

include $(depth)/Makefile.inc

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

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

#ifeq ($(ENABLE_OSS_SOUND),yes)
#ifeq ($(SWIG_VERSION),1.1)
#all: solfege_c_midimodule.so
#else
all: _solfege_c_midi.so
#endif
#all:
#endif

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

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

solfege_c_midimodule.so: $(OBJECTS)
	$(CC) -fPIC -shared $(OBJECTS) -o solfege_c_midimodule.so -lc $(LIBS)
	
_solfege_c_midi.so: $(OBJECTS)
	$(CC) -fPIC -shared $(OBJECTS) -o _solfege_c_midi.so $(LIBS)

solfege_c_midi_wrap.o: solfege_c_midi_wrap.c solfege_c_midi.i
	$(CC) $(CFLAGS) -c solfege_c_midi_wrap.c $(PYTHON_INCLUDES)

#solfege_c_midi_wrap.c: solfege_c_midi.c macro_to_function.c solfege_c_midi.i ../config.status
#	# rm all generated swig files to be safe...
#	rm -f _solfege_c_midi.so
#	rm -f solfege_c_midi.py*
#	rm -f solfege_c_midimodule.so
#	$(SWIG) -python solfege_c_midi.i

# 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/python22
# cd ~/X/python22
# unzip /mnt/hda9/Python-2.2.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=winmidi.pyd --def=winmidi.def winmidi.o -s --entry=_DllMain@12 -L/usr/i586-mingw32msvc/lib/ -lwinmm $(PYDLL)

winmidi.o: winmidi.c
	$(W32GCC) $(W32CFLAGS) -c winmidi.c

# end win32

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

uninstall: python-uninstall
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:
	rm -f *.pyc *.pyo *.o *.so *~
	rm -f solfege_c_midi_wrap.*
	rm -f winmidi.pyd winmidi.o
	# generated by swig 13:
	rm -f solfege_c_midi.py*

distclean: clean

