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.
11 ROOT = r'/Users/liyanage/cvs/entropy/TestXSLT/build/libxml2-gnustyle'
13 # If this flag is set (windows only),
14 # a private copy of the dlls are included in the package.
15 # If this flag is not set, the libxml2 and libxslt
16 # dlls must be found somewhere in the PATH at runtime.
17 WITHDLLS = 1 and sys.platform.startswith('win')
20 if os.access(file, os.R_OK) == 0:
25 HOME = os.environ['HOME']
30 # libxml dlls (expected in ROOT/bin)
31 dlls = [ 'iconv.dll','libxml2.dll','libxslt.dll','libexslt.dll' ]
32 dlls = map(lambda dll: os.path.join(ROOT,'bin',dll),dlls)
34 # create __init__.py for the libxmlmods package
35 if not os.path.exists("libxmlmods"):
36 os.mkdir("libxmlmods")
37 open("libxmlmods/__init__.py","w").close()
40 s = s.replace("import libxml2mod","from libxmlmods import libxml2mod")
41 s = s.replace("import libxsltmod","from libxmlmods import libxsltmod")
44 if sys.platform.startswith('win'):
49 platformLibs = ["m","z"]
51 # those are examined to find
52 # - libxml2/libxml/tree.h
54 # - libxslt/xsltconfig.h
59 os.path.join(ROOT,'include'),
64 for dir in includes_dir:
65 if not missing(dir + "/libxml2/libxml/tree.h"):
66 xml_includes=dir + "/libxml2"
69 if xml_includes == "":
70 print "failed to find headers for libxml2: update includes_dir"
74 for dir in includes_dir:
75 if not missing(dir + "/iconv.h"):
79 if iconv_includes == "":
80 print "failed to find headers for libiconv: update includes_dir"
83 # those are added in the linker search path for libraries
85 os.path.join(ROOT,'lib'),
88 xml_files = ["libxml2-api.xml", "libxml2-python-api.xml",
89 "libxml.c", "libxml.py", "libxml_wrap.h", "types.c",
90 "xmlgenerator.py", "README", "TODO"]
92 xslt_files = ["libxslt-api.xml", "libxslt-python-api.xml",
93 "libxslt.c", "libxsl.py", "libxslt_wrap.h",
96 if missing("libxml2-py.c") or missing("libxml2.py"):
103 print "failed to find and generate stubs for libxml2, aborting ..."
104 print sys.exc_type, sys.exc_value
107 head = open("libxml.py", "r")
108 generated = open("libxml2class.py", "r")
109 result = open("libxml2.py", "w")
110 for line in head.readlines():
112 result.write(altImport(line))
115 for line in generated.readlines():
122 if missing("libxslt-py.c") or missing("libxslt.py"):
123 if missing("xsltgenerator.py") or missing("libxslt-api.xml"):
124 print "libxslt stub generator not found, libxslt not built"
129 print "failed to generate stubs for libxslt, aborting ..."
130 print sys.exc_type, sys.exc_value
132 head = open("libxsl.py", "r")
133 generated = open("libxsltclass.py", "r")
134 result = open("libxslt.py", "w")
135 for line in head.readlines():
137 result.write(altImport(line))
140 for line in generated.readlines():
151 for dir in includes_dir:
152 if not missing(dir + "/libxslt/xsltconfig.h"):
153 xslt_includes=dir + "/libxslt"
156 if xslt_includes == "":
157 print "failed to find headers for libxslt: update includes_dir"
161 descr = "libxml2 package"
162 modules = [ 'libxml2', 'drv_libxml2' ]
164 modules.append('libxmlmods.__init__')
165 c_files = ['libxml2-py.c', 'libxml.c', 'types.c' ]
166 includes= [xml_includes, iconv_includes]
167 libs = [libraryPrefix + "xml2"] + platformLibs
170 descr = "libxml2 and libxslt package"
171 if not sys.platform.startswith('win'):
173 # We are gonna build 2 identical shared libs with merge initializing
174 # both libxml2mod and libxsltmod
176 c_files = c_files + ['libxslt-py.c', 'libxslt.c']
177 xslt_c_files = c_files
178 macros.append(('MERGED_MODULES', '1'))
181 # On windows the MERGED_MODULE option is not needed
182 # (and does not work)
184 xslt_c_files = ['libxslt-py.c', 'libxslt.c', 'types.c']
185 libs.insert(0, libraryPrefix + 'exslt')
186 libs.insert(0, libraryPrefix + 'xslt')
187 includes.append(xslt_includes)
188 modules.append('libxslt')
191 extens=[Extension('libxml2mod', c_files, include_dirs=includes,
192 library_dirs=libdirs,
193 libraries=libs, define_macros=macros)]
195 extens.append(Extension('libxsltmod', xslt_c_files, include_dirs=includes,
196 library_dirs=libdirs,
199 if missing("MANIFEST"):
201 manifest = open("MANIFEST", "w")
202 manifest.write("setup.py\n")
203 for file in xml_files:
204 manifest.write(file + "\n")
206 for file in xslt_files:
207 manifest.write(file + "\n")
211 ext_package = "libxmlmods"
212 if sys.version >= "2.2":
213 base = "lib/site-packages/"
216 data_files = [(base+"libxmlmods",dlls)]
221 setup (name = "libxml2-python",
222 # On *nix, the version number is created from setup.py.in
223 # On windows, it is set by configure.js
226 author = "Daniel Veillard",
227 author_email = "veillard@redhat.com",
228 url = "http://xmlsoft.org/python.html",
229 licence="MIT Licence",
232 ext_package=ext_package,
233 data_files=data_files,