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