-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py.in
142 lines (126 loc) · 4.37 KB
/
setup.py.in
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#!/usr/bin/env python
#
# Python installation script
# $Id: setup.py.in 931 2012-07-10 21:42:15Z pletzer $
#
# Python installation script. Will install the shared library
# and libCFConfig.py in the directory where python puts its
# modules (generally /usr/lib/python<VERSION>/site-packages.
# setup.py will be created upon configuring, with some autoconf
# settings filled in when configuring.
#
from distutils.core import setup, Extension
import types
import re
import glob
import os.path
# constants
PAT_LIBDIR = re.compile(r'^-L') # UNIX
PAT_LIBRARY = re.compile(r'^-l') # UNIX
PAT_UNIT_TEST = re.compile(r'tst_') # our way of distinguishing unit tests
# list all the directories that contain source file to be compiled
# into a shared library
EXTDIRS = ['@abs_srcdir@/src',
'@abs_srcdir@/gridspec_api/global',
'@abs_srcdir@/gridspec_api/axis',
'@abs_srcdir@/gridspec_api/coord',
'@abs_srcdir@/gridspec_api/grid',
'@abs_srcdir@/gridspec_api/data',
'@abs_srcdir@/gridspec_api/regrid',
'@abs_srcdir@/gridspec_api/mosaic',
'@abs_srcdir@/gridspec_api/host',
]
LIBS = "@LIBS@"
def findNetcdfIncludeDir():
# assumes -I <path>
incdirs = re.sub(r'\-I\s*', ' ', "@CPPFLAGS@").split()
for d in incdirs:
if os.path.exists(d + '/netcdf.h'):
return d
return ''
netcdfinc = findNetcdfIncludeDir()
if not netcdfinc:
print('*** error: could not find netcdf.h file in CPPFLAGS')
sys.exit(1)
# list all the include directories
incdirs = [netcdfinc,
'@abs_srcdir@/include',
'@abs_srcdir@/src',
'@abs_srcdir@/gridspec_api/global',
'@abs_srcdir@/gridspec_api/axis',
'@abs_srcdir@/gridspec_api/coord',
'@abs_srcdir@/gridspec_api/grid',
'@abs_srcdir@/gridspec_api/data',
'@abs_srcdir@/gridspec_api/regrid',
'@abs_srcdir@/gridspec_api/mosaic',
'@abs_srcdir@/gridspec_api/host',
'@abs_builddir@',] # config.h
def contractPath(path):
"""
Remove ../ from the path
"""
return re.sub(r'\/[^\/]+\/\.\.', '', path)
def getLibraryDirs(libs):
"""
Extract the library paths from string libs
"""
res = []
for word in libs.split():
if re.match(PAT_LIBDIR, word):
res.append( re.sub(PAT_LIBDIR, '', word) )
return res
def getLibraries(libs):
"""
Extract the list of libraries to link against from string libs
"""
res = []
for word in libs.split():
if re.match(PAT_LIBRARY, word):
res.append( re.sub(PAT_LIBRARY, '', word) )
return res
def getAllLibFiles(dirs):
"""
Given a list of directories, return all the source files,
excluding 'tst_' files
"""
listOfFiles = []
for d in dirs:
allSrcFiles = glob.glob(d + '/*.c')
libFiles = []
for f in allSrcFiles:
if not re.search(PAT_UNIT_TEST, f):
f2 = contractPath(f)
libFiles.append(f2)
listOfFiles += libFiles
return listOfFiles
#
# Packages and extensions
#
source_files = getAllLibFiles(EXTDIRS)
library_dirs = getLibraryDirs(LIBS)
libraries = getLibraries(LIBS)
if @HAVE_UUID@:
libraries.append('uuid')
defs = {'HAVE_LAPACK_LIB': @HAVE_LAPACK_LIB@,
'HAVE_LAPACK_NO_UNDERSCORE': @HAVE_LAPACK_NO_UNDERSCORE@,
'HAVE_LAPACK_UNDERSCORE': @HAVE_LAPACK_UNDERSCORE@}
define_macros = []
if defs['HAVE_LAPACK_LIB'] == 1:
define_macros.append( ('HAVE_LAPACK_LIB', None) ) #define HAVE_LAPACK_LIB
define_macros.append( ('HAVE_LAPACK_NO_UNDERSCORE',
str(defs['HAVE_LAPACK_NO_UNDERSCORE'])) )
define_macros.append( ('HAVE_LAPACK_UNDERSCORE',
str(defs['HAVE_LAPACK_UNDERSCORE'])) )
setup(name = "@PACKAGE_NAME@",
version = "@VERSION@",
description = "A library that supports the creation of CF compliant NetCDF files",
author_email = "[email protected]",
maintainer_email = "[email protected]",
url = "http://www.unidata.ucar.edu/software/libcf/",
packages = ["pycf",],
ext_modules=[Extension('pycf.pylibcf', source_files,
include_dirs = incdirs,
library_dirs = library_dirs,
libraries = libraries,
define_macros = define_macros),],
)