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