Annotation of pkgsrc/textproc/py-libxslt/files/setup.py, Revision 1.4
1.1 minskim 1: #!/usr/bin/python -u
2: #
1.4 ! dholland 3: # $NetBSD: setup.py,v 1.3 2017/05/16 13:48:05 dholland Exp $
1.1 minskim 4: # Setup script for libxslt
5: #
6: import sys, os
7: from distutils.core import setup, Extension
8:
9: # Thread-enabled libxml2
10: with_threads = 1
11:
12: # If this flag is set (windows only),
13: # a private copy of the dlls are included in the package.
14: # If this flag is not set, the libxml2 and libxslt
15: # dlls must be found somewhere in the PATH at runtime.
16: WITHDLLS = 1 and sys.platform.startswith('win')
17:
18: def missing(file):
19: if os.access(file, os.R_OK) == 0:
20: return 1
21: return 0
22:
23: try:
24: HOME = os.environ['HOME']
25: except:
26: HOME="C:"
27:
28: if sys.platform.startswith('win'):
29: libraryPrefix = 'lib'
30: platformLibs = []
31: else:
32: libraryPrefix = ''
33: platformLibs = ["m","z"]
34:
35: # those are examined to find
36: # - libxml2/libxml/tree.h
37: # - iconv.h
38: # - libxslt/xsltconfig.h
39: includes_dir = [
40: "@LIBXML2DIR@/include",
41: "@LIBXSLTDIR@/include"
42: ];
43:
44: xml_includes=""
45: for dir in includes_dir:
46: if not missing(dir + "/libxml2/libxml/tree.h"):
47: xml_includes=dir + "/libxml2"
48: break;
49:
50: if xml_includes == "":
51: print "failed to find headers for libxml2: update includes_dir"
52: sys.exit(1)
53:
1.2 tnn 54: iconv_includes="@LIBICONVDIR@/include"
1.1 minskim 55:
56: # those are added in the linker search path for libraries
1.4 ! dholland 57: libdirs = ["@LIBXML2DIR@/lib", "@PYSHLIBDIR@"]
1.1 minskim 58:
59: xml_files = ["libxml2-api.xml", "libxml2-python-api.xml",
60: "libxml.c", "libxml.py", "libxml_wrap.h", "types.c",
61: "xmlgenerator.py", "README", "TODO", "drv_libxml2.py"]
62:
63: xslt_files = ["libxslt-api.xml", "libxslt-python-api.xml",
64: "libxslt.c", "libxsl.py", "libxslt_wrap.h",
65: "generator.py"]
66:
67: if 0:
68: try:
69: try:
70: import xmlgenerator
71: except:
72: import generator
73: except:
74: print "failed to find and generate stubs for libxml2, aborting ..."
75: print sys.exc_type, sys.exc_value
76: sys.exit(1)
77:
78: head = open("libxml.py", "r")
79: generated = open("libxml2class.py", "r")
80: result = open("libxml2.py", "w")
81: for line in head.readlines():
82: if WITHDLLS:
83: result.write(altImport(line))
84: else:
85: result.write(line)
86: for line in generated.readlines():
87: result.write(line)
88: head.close()
89: generated.close()
90: result.close()
91:
92: with_xslt=0
93: if missing("libxslt-py.c") or missing("libxslt.py"):
94: if missing("generator.py") or missing("libxslt-python-api.xml"):
95: print "libxslt stub generator not found, libxslt not built"
96: else:
97: try:
98: import generator
99: except:
100: print "failed to generate stubs for libxslt, aborting ..."
101: print sys.exc_type, sys.exc_value
102: else:
103: head = open("libxsl.py", "r")
104: generated = open("libxsltclass.py", "r")
105: result = open("libxslt.py", "w")
106: for line in head.readlines():
107: if WITHDLLS:
108: result.write(altImport(line))
109: else:
110: result.write(line)
111: for line in generated.readlines():
112: result.write(line)
113: head.close()
114: generated.close()
115: result.close()
116: with_xslt=1
117: else:
118: with_xslt=1
119:
120: if with_xslt == 1:
121: xslt_includes=""
122: for dir in includes_dir:
123: if not missing(dir + "/libxslt/xsltconfig.h"):
124: xslt_includes=dir + "/libxslt"
125: break;
126:
127: if xslt_includes == "":
128: print "failed to find headers for libxslt: update includes_dir"
129: with_xslt = 0
130:
131:
132: descr = "libxml2 package"
133: modules = []
134: c_files = []
135: includes= [xml_includes, iconv_includes]
1.4 ! dholland 136: libs = ["xml2mod"] + platformLibs
1.1 minskim 137: macros = []
138: if with_threads:
139: macros.append(('_REENTRANT','1'))
140: if with_xslt == 1:
141: descr = "libxslt package"
142: if not sys.platform.startswith('win'):
143: #
144: # We are gonna build 2 identical shared libs with merge initializing
145: # both libxml2mod and libxsltmod
146: #
147: c_files = c_files + ['libxslt-py.c', 'libxslt.c']
148: xslt_c_files = c_files
149: macros.append(('MERGED_MODULES', '1'))
150: else:
151: #
152: # On windows the MERGED_MODULE option is not needed
153: # (and does not work)
154: #
155: xslt_c_files = ['libxslt-py.c', 'libxslt.c', 'types.c']
156: libs.insert(0, libraryPrefix + 'exslt')
157: libs.insert(0, libraryPrefix + 'xslt')
158: includes.append(xslt_includes)
159: modules.append('libxslt')
160:
161:
162: extens=[]
163: if with_xslt == 1:
164: extens.append(Extension('libxsltmod', xslt_c_files, include_dirs=includes,
1.4 ! dholland 165: library_dirs=libdirs,
! 166: runtime_library_dirs=libdirs,
1.1 minskim 167: libraries=libs, define_macros=macros))
168:
169: if missing("MANIFEST"):
170:
171: manifest = open("MANIFEST", "w")
172: manifest.write("setup.py\n")
173: for file in xml_files:
174: manifest.write(file + "\n")
175: if with_xslt == 1:
176: for file in xslt_files:
177: manifest.write(file + "\n")
178: manifest.close()
179:
180: if WITHDLLS:
181: ext_package = "libxmlmods"
182: if sys.version >= "2.2":
183: base = "lib/site-packages/"
184: else:
185: base = ""
186: data_files = []
187: else:
188: ext_package = None
189: data_files = []
190:
191: setup (name = "libxslt-python",
192: # On *nix, the version number is created from setup.py.in
193: # On windows, it is set by configure.js
194: version = os.environ['PYLIBXSLTVERSION'],
195: description = descr,
196: author = "Daniel Veillard",
197: author_email = "veillard@redhat.com",
198: url = "http://xmlsoft.org/python.html",
199: licence="MIT Licence",
200: py_modules=modules,
201: ext_modules=extens,
202: ext_package=ext_package,
203: data_files=data_files,
204: )
205:
206: sys.exit(0)
207:
CVSweb <webmaster@jp.NetBSD.org>