blob: e302d9ec98fc34b69d5d5d8e3ca0d09637372f21 [file] [log] [blame]
Daniel Veillard0fea6f42002-02-22 22:51:13 +00001#!/usr/bin/python -u
2#
3# Setup script for libxml2 and libxslt if found
4#
5import sys, os
6from distutils.core import setup, Extension
7
8
9def missing(file):
10 if os.access(file, os.R_OK) == 0:
11 return 1
12 return 0
13
14xml_files = ["libxml2-api.xml", "libxml2-python-api.xml",
15 "libxml.c", "libxml.py", "libxml_wrap.h", "types.c",
16 "xmlgenerator.py", "README", "TODO"]
17
18xslt_files = ["libxslt-api.xml", "libxslt-python-api.xml",
19 "libxslt.c", "libxsl.py", "libxslt_wrap.h",
20 "xsltgenerator.py"]
21
22if missing("libxml2-py.c") or missing("libxml2.py"):
23 try:
24 try:
25 import xmlgenerator
26 except:
27 import generator
28 except:
29 print "failed to find and generate stubs for libxml2, aborting ..."
30 print sys.exc_type, sys.exc_value
31 sys.exit(1)
32
33 head = open("libxml.py", "r")
34 generated = open("libxml2class.py", "r")
35 result = open("libxml2.py", "w")
36 for line in head.readlines():
37 result.write(line)
38 for line in generated.readlines():
39 result.write(line)
40 head.close()
41 generated.close()
42 result.close()
43
44with_xslt=0
45if missing("libxslt-py.c") or missing("libxslt.py"):
46 if missing("xsltgenerator.py") or missing("libxslt-api.xml"):
47 print "libxslt stub generator not found, libxslt not built"
48 else:
49 try:
50 import xsltgenerator
51 except:
52 print "failed to generate stubs for libxslt, aborting ..."
53 print sys.exc_type, sys.exc_value
54 else:
55 head = open("libxsl.py", "r")
56 generated = open("libxsltclass.py", "r")
57 result = open("libxslt.py", "w")
58 for line in head.readlines():
59 result.write(line)
60 for line in generated.readlines():
61 result.write(line)
62 head.close()
63 generated.close()
64 result.close()
65 with_xslt=1
66else:
67 with_xslt=1
68
69
70descr = "libxml2 package"
71modules = [ 'libxml2' ]
72c_files = ['libxml2-py.c', 'libxml.c', 'types.c' ]
73includes= ["/usr/include/libxml2"]
74libs = ["xml2", "m", "z"]
75macros = []
76if with_xslt == 1:
77 descr = "libxml2 and libxslt package"
78 #
79 # We are gonna build 2 identical shared libs with merge initializing
80 # both libxml2mod and libxsltmod
81 #
82 c_files = c_files + ['libxslt-py.c', 'libxslt.c']
83 libs.insert(0, 'xslt')
84 includes.append("/usr/include/libxslt")
85 modules.append('libxslt')
86 macros.append(('MERGED_MODULES', '1'))
87
88
89extens=[Extension('libxml2mod', c_files, include_dirs=includes,
90 libraries=libs, define_macros=macros)]
91if with_xslt == 1:
92 extens.append(Extension('libxsltmod', c_files, include_dirs=includes,
93 libraries=libs))
94
95if missing("MANIFEST"):
96 global xml_files
97
98 manifest = open("MANIFEST", "w")
99 manifest.write("setup.py\n")
100 for file in xml_files:
101 manifest.write(file + "\n")
102 if with_xslt == 1:
103 for file in xslt_files:
104 manifest.write(file + "\n")
105 manifest.close()
106
107setup (name = "libxml2-python",
Daniel Veillardfa49d872002-03-09 10:20:00 +0000108 version = "@LIBXML_VERSION@",
Daniel Veillard0fea6f42002-02-22 22:51:13 +0000109 description = descr,
110 author = "Daniel Veillard",
111 author_email = "veillard@redhat.com",
112 url = "http://xmlsoft.org/python.html",
113 licence="MIT Licence",
114
115 py_modules=modules,
116 ext_modules=extens,
117 )
118
119sys.exit(0)
120