LIBFOO_DIR = ../../libfoo
LIBS = -lboost_python `python-config --libs` \
       `pkg-config pyside --libs` \
       -lfoo -L$(LIBFOO_DIR) \
       -lpthread -ldl -lutil
CXXFLAGS = -I/usr/share/qt4/mkspecs/linux-g++ -I. \
           -I$(LIBFOO_DIR) \
           `pkg-config pyside --cflags` \
           -I`python-config --includes` \
           -I/usr/include/boost/python
QT4TYPESYSTEM_DIR = `pkg-config --variable=typesystemdir pyside`
QT4HEADER_DIRS = `pkg-config --variable=includedir QtCore`:`pkg-config --variable=includedir QtCore`/..

SOURCES = foo_globals_wrapper.cpp  foo_module_wrapper.cpp  math_wrapper.cpp
OBJECTS = foo_globals_wrapper.o    foo_module_wrapper.o    math_wrapper.o

all: generate compile link

generate:
	boostpythongenerator ../data/global.h \
	--include-paths=$(LIBFOO_DIR):$(QT4HEADER_DIRS):/usr/include \
	--typesystem-paths=../data:$(QT4TYPESYSTEM_DIR) \
	--output-directory=.. \
	../data/typesystem_foo.xml

compile: $(SOURCES)
	g++ -Wall -fPIC -DPIC $(CXXFLAGS) -c foo_globals_wrapper.cpp
	g++ -Wall -fPIC -DPIC $(CXXFLAGS) -c foo_module_wrapper.cpp
	g++ -Wall -fPIC -DPIC $(CXXFLAGS) -c math_wrapper.cpp

link:
	g++ -shared -Wl,-soname,foo.so -o foo.so $(LIBS) $(OBJECTS)

test:
	LD_LIBRARY_PATH=$(LIBFOO_DIR):$LD_LIBRARY_PATH python -c \
	"import PySide.QtCore; import foo; print dir(foo); m = foo.Math(); print \"5 squared is %d\" % m.squared(5)"

clean:
	rm -rf *.o *.so *.?pp *.log
