
from distutils.core import setup, Extension

# The following code helps you find libgpk.so and libgpkio.so,
# so long as they are somewhere on LD_LIBRARY_PATH.    This may be important
# if you are using a binary distribution which may have its own limited idea
# of a search path, and you have added more directories (for your own software)
# to LD_LIBRARY_PATH.
import os
GPKLIB_LIB = None
pl = os.environ['LD_LIBRARY_PATH'].split(':')
for p in pl:
	for ext in ['so', 'a']:
		pp = os.path.join(p, 'libgpk.%s' % ext)
		if os.path.isfile(pp) and os.access(pp, os.R_OK):
			GPKLIB_LIB = p
			break
	if GPKLIB_LIB is not None:
		break
assert GPKLIB_LIB is not None, "Cannot find gpklib.so"
# GPKLIB_LIB = '/home/mace/gpk/local/lib'
print 'lib=', GPKLIB_LIB

# This tells where the libgpk include files go:
GPKLIB_INCLUDES = os.path.join(os.path.split(GPKLIB_LIB)[0], 'include')
# GPKLIB_INCLUDES = '/home/mace/gpk/local/include'
print 'includes=', GPKLIB_INCLUDES

import numpy

setup(name="gpkimg", version="1.2.5",
	description = "Interface to gpkio 2-D image formats",
	author = "Greg Kochanski",
	author_email = "gpk@kochanski.org",
	py_modules = ["gpkimgclass"],
	ext_modules = [
		Extension("gpkimg", [ "gpkimg.cc" ],
				libraries = ["gpk", "gpkio"],

				# Places to look for gpklib.h and gpkio.h:
				include_dirs = [
						GPKLIB_INCLUDES,
						numpy.get_include()
						],

				# Places to look or libgpk and libgpkio:
				library_dirs = [
						GPKLIB_LIB
						],
				language = 'c++'
			)
		]
	)
