3 # Setup script for libxml2 and libxslt if found
6 from distutils
.core
import setup
, Extension
8 # Below ROOT, we expect to find include, include/libxml2, lib and bin.
9 # On *nix, it is not needed (but should not harm),
10 # on Windows, it is set by configure.js.
13 # Thread-enabled libxml2
16 # If this flag is set (windows only),
17 # a private copy of the dlls are included in the package.
18 # If this flag is not set, the libxml2 and libxslt
19 # dlls must be found somewhere in the PATH at runtime.
20 WITHDLLS
= 1 and sys
.platform
.startswith('win')
23 if os
.access(file, os
.R_OK
) == 0:
28 HOME
= os
.environ
['HOME']
33 # libxml dlls (expected in ROOT/bin)
34 dlls
= [ 'iconv.dll','libxml2.dll','libxslt.dll','libexslt.dll' ]
35 dlls
= [os
.path
.join(ROOT
,'bin',dll
) for dll
in dlls
]
37 # create __init__.py for the libxmlmods package
38 if not os
.path
.exists("libxmlmods"):
39 os
.mkdir("libxmlmods")
40 open("libxmlmods/__init__.py","w").close()
43 s
= s
.replace("import libxml2mod","from libxmlmods import libxml2mod")
44 s
= s
.replace("import libxsltmod","from libxmlmods import libxsltmod")
47 if sys
.platform
.startswith('win'):
52 platformLibs
= ["m","z"]
54 # those are examined to find
55 # - libxml2/libxml/tree.h
57 # - libxslt/xsltconfig.h
62 os
.path
.join(ROOT
,'include'),
67 for dir in includes_dir
:
68 if not missing(dir + "/libxml2/libxml/tree.h"):
69 xml_includes
=dir + "/libxml2"
72 if xml_includes
== "":
73 print("failed to find headers for libxml2: update includes_dir")
77 for dir in includes_dir
:
78 if not missing(dir + "/iconv.h"):
82 if iconv_includes
== "":
83 print("failed to find headers for libiconv: update includes_dir")
86 # those are added in the linker search path for libraries
88 os
.path
.join(ROOT
,'lib'),
91 xml_files
= ["libxml2-api.xml", "libxml2-python-api.xml",
92 "libxml.c", "libxml.py", "libxml_wrap.h", "types.c",
93 "xmlgenerator.py", "README", "TODO", "drv_libxml2.py"]
95 xslt_files
= ["libxslt-api.xml", "libxslt-python-api.xml",
96 "libxslt.c", "libxsl.py", "libxslt_wrap.h",
99 if missing("libxml2-py.c") or missing("libxml2.py"):
106 print("failed to find and generate stubs for libxml2, aborting ...")
107 print(sys
.exc_info()[0], sys
.exc_info()[1])
110 head
= open("libxml.py", "r")
111 generated
= open("libxml2class.py", "r")
112 result
= open("libxml2.py", "w")
113 for line
in head
.readlines():
115 result
.write(altImport(line
))
118 for line
in generated
.readlines():
125 if missing("libxslt-py.c") or missing("libxslt.py"):
126 if missing("xsltgenerator.py") or missing("libxslt-api.xml"):
127 print("libxslt stub generator not found, libxslt not built")
132 print("failed to generate stubs for libxslt, aborting ...")
133 print(sys
.exc_info()[0], sys
.exc_info()[1])
135 head
= open("libxsl.py", "r")
136 generated
= open("libxsltclass.py", "r")
137 result
= open("libxslt.py", "w")
138 for line
in head
.readlines():
140 result
.write(altImport(line
))
143 for line
in generated
.readlines():
154 for dir in includes_dir
:
155 if not missing(dir + "/libxslt/xsltconfig.h"):
156 xslt_includes
=dir + "/libxslt"
159 if xslt_includes
== "":
160 print("failed to find headers for libxslt: update includes_dir")
164 descr
= "libxml2 package"
165 modules
= [ 'libxml2', 'drv_libxml2' ]
167 modules
.append('libxmlmods.__init__')
168 c_files
= ['libxml2-py.c', 'libxml.c', 'types.c' ]
169 includes
= [xml_includes
, iconv_includes
]
170 libs
= [libraryPrefix
+ "xml2"] + platformLibs
173 macros
.append(('_REENTRANT','1'))
175 descr
= "libxml2 and libxslt package"
176 if not sys
.platform
.startswith('win'):
178 # We are gonna build 2 identical shared libs with merge initializing
179 # both libxml2mod and libxsltmod
181 c_files
= c_files
+ ['libxslt-py.c', 'libxslt.c']
182 xslt_c_files
= c_files
183 macros
.append(('MERGED_MODULES', '1'))
186 # On windows the MERGED_MODULE option is not needed
187 # (and does not work)
189 xslt_c_files
= ['libxslt-py.c', 'libxslt.c', 'types.c']
190 libs
.insert(0, libraryPrefix
+ 'exslt')
191 libs
.insert(0, libraryPrefix
+ 'xslt')
192 includes
.append(xslt_includes
)
193 modules
.append('libxslt')
196 extens
=[Extension('libxml2mod', c_files
, include_dirs
=includes
,
197 library_dirs
=libdirs
,
198 libraries
=libs
, define_macros
=macros
)]
200 extens
.append(Extension('libxsltmod', xslt_c_files
, include_dirs
=includes
,
201 library_dirs
=libdirs
,
202 libraries
=libs
, define_macros
=macros
))
204 if missing("MANIFEST"):
206 manifest
= open("MANIFEST", "w")
207 manifest
.write("setup.py\n")
208 for file in xml_files
:
209 manifest
.write(file + "\n")
211 for file in xslt_files
:
212 manifest
.write(file + "\n")
216 ext_package
= "libxmlmods"
217 if sys
.version
>= "2.2":
218 base
= "lib/site-packages/"
221 data_files
= [(base
+"libxmlmods",dlls
)]
226 setup (name
= "libxml2-python",
227 # On *nix, the version number is created from setup.py.in
228 # On windows, it is set by configure.js
231 author
= "Daniel Veillard",
232 author_email
= "veillard@redhat.com",
233 url
= "http://xmlsoft.org/python.html",
234 licence
="MIT Licence",
237 ext_package
=ext_package
,
238 data_files
=data_files
,