1 |
|
|
2 |
import os |
import os |
3 |
|
import sys |
4 |
from distutils.core import setup, Extension |
from distutils.core import setup, Extension |
5 |
|
from distutils.util import convert_path |
6 |
|
|
7 |
# try to determine the directory where the shapelib source files are. |
# try to determine the directory where the shapelib source files are. |
8 |
# There are currently two supported situations. |
# There are currently two supported situations. |
9 |
# |
# |
10 |
# 1. "Standalone" build: the parent directory is the shapelib source |
# 1. "Standalone" build: the parent directory is the shapelib source |
11 |
# directory |
# directory |
12 |
# 2. Built in the Thuban source tree where it's ../shapelib/ relative to |
# 2. Built in the Thuban source tree where ../shapelib/ relative to the |
13 |
# the directory containing this setup.py |
# directory containing this setup.py contains (the relevant parts of) |
14 |
|
# shapelib |
15 |
|
# |
16 |
|
# 3. Binary build with e.g. bdist_rpm. This takes place deep in the |
17 |
|
# build directory. |
18 |
|
|
19 |
# os.path expects filenames in OS-specific form so we have to construct |
# os.path expects filenames in OS-specific form so we have to construct |
20 |
# the files with os.path functions. distutils, OTOH, uses posix-style |
# the files with os.path functions. distutils, OTOH, uses posix-style |
21 |
# filenames exclusively, so we posix when making filenames for |
# filenames exclusively, so we use posix conventions when making |
22 |
# distutils. |
# filenames for distutils. |
23 |
if os.path.exists(os.path.join(os.pardir, "shpeopen.c")): |
for shp_dir in ["..", "../shapelib", "../../../../../../shapelib"]: |
24 |
shp_dir = ".." |
if (os.path.isdir(convert_path(shp_dir)) |
25 |
elif os.path.exists(os.path.join(os.pardir, "shapelib")): |
and os.path.exists(os.path.join(convert_path(shp_dir), "shpopen.c"))): |
26 |
shp_dir = "../shapelib" |
# shp_dir contains shpopen.c, so assume it's the directory with |
27 |
|
# the shapefile library to use |
28 |
|
break |
29 |
|
else: |
30 |
|
print >>sys.stderr, "no shapelib directory found" |
31 |
|
sys.exit(1) |
32 |
|
|
33 |
|
def dbf_macros(): |
34 |
|
"""Return the macros to define when compiling the dbflib wrapper. |
35 |
|
|
36 |
|
The returned list specifies one macro, HAVE_UPDATE_HEADER, which is |
37 |
|
'1' if the dbflib version we will be compiling with has the |
38 |
|
DBFUpdateHeader function and '0' otherwise. To check whether |
39 |
|
DBFUpdateHeader is available, we scan shapefil.h for the string |
40 |
|
'DBFUpdateHeader'. |
41 |
|
""" |
42 |
|
f = open(convert_path(shp_dir + "/shapefil.h")) |
43 |
|
contents = f.read() |
44 |
|
f.close() |
45 |
|
if contents.find("DBFUpdateHeader") >= 0: |
46 |
|
return [("HAVE_UPDATE_HEADER", "1")] |
47 |
|
else: |
48 |
|
return [("HAVE_UPDATE_HEADER", "0")] |
49 |
|
|
50 |
extensions = [Extension("shapelibc", |
extensions = [Extension("shapelibc", |
51 |
["shapelib_wrap.c", |
["shapelib_wrap.c", |
58 |
Extension("dbflibc", |
Extension("dbflibc", |
59 |
["dbflib_wrap.c", |
["dbflib_wrap.c", |
60 |
shp_dir + "/dbfopen.c"], |
shp_dir + "/dbfopen.c"], |
61 |
include_dirs = [shp_dir])] |
include_dirs = [shp_dir], |
62 |
|
define_macros = dbf_macros())] |
63 |
|
|
64 |
setup(name = "pyshapelib", |
setup(name = "pyshapelib", |
65 |
version = "0.3", |
version = "0.3", |