set eol-style:native
[reactos.git] / reactos / lib / libxml2 / python / setup.py
index a5f8a2f..fd3154d 100644 (file)
-#!/usr/bin/python -u\r
-#\r
-# Setup script for libxml2 and libxslt if found\r
-#\r
-import sys, os\r
-from distutils.core import setup, Extension\r
-\r
-# Below ROOT, we expect to find include, include/libxml2, lib and bin.\r
-# On *nix, it is not needed (but should not harm), \r
-# on Windows, it is set by configure.js.\r
-ROOT = r'/usr' \r
-\r
-# Thread-enabled libxml2\r
-with_threads = 1\r
-\r
-# If this flag is set (windows only), \r
-# a private copy of the dlls are included in the package.\r
-# If this flag is not set, the libxml2 and libxslt\r
-# dlls must be found somewhere in the PATH at runtime.\r
-WITHDLLS = 1 and sys.platform.startswith('win')\r
-\r
-def missing(file):\r
-    if os.access(file, os.R_OK) == 0:\r
-        return 1\r
-    return 0\r
-\r
-try:\r
-    HOME = os.environ['HOME']\r
-except:\r
-    HOME="C:"\r
-\r
-if WITHDLLS:\r
-    # libxml dlls (expected in ROOT/bin)\r
-    dlls = [ 'iconv.dll','libxml2.dll','libxslt.dll','libexslt.dll' ]\r
-    dlls = map(lambda dll: os.path.join(ROOT,'bin',dll),dlls)\r
-\r
-    # create __init__.py for the libxmlmods package\r
-    if not os.path.exists("libxmlmods"):\r
-        os.mkdir("libxmlmods")\r
-        open("libxmlmods/__init__.py","w").close()\r
-\r
-    def altImport(s):\r
-        s = s.replace("import libxml2mod","from libxmlmods import libxml2mod")\r
-        s = s.replace("import libxsltmod","from libxmlmods import libxsltmod")\r
-        return s\r
-\r
-if sys.platform.startswith('win'):\r
-    libraryPrefix = 'lib'\r
-    platformLibs = []\r
-else:\r
-    libraryPrefix = ''\r
-    platformLibs = ["m","z"]\r
-\r
-# those are examined to find \r
-# - libxml2/libxml/tree.h\r
-# - iconv.h \r
-# - libxslt/xsltconfig.h\r
-includes_dir = [\r
-"/usr/include",\r
-"/usr/local/include",\r
-"/opt/include",\r
-os.path.join(ROOT,'include'),\r
-HOME\r
-];\r
-\r
-xml_includes=""\r
-for dir in includes_dir:\r
-    if not missing(dir + "/libxml2/libxml/tree.h"):\r
-        xml_includes=dir + "/libxml2"\r
-       break;\r
-\r
-if xml_includes == "":\r
-    print "failed to find headers for libxml2: update includes_dir"\r
-    sys.exit(1)\r
-\r
-iconv_includes=""\r
-for dir in includes_dir:\r
-    if not missing(dir + "/iconv.h"):\r
-        iconv_includes=dir\r
-       break;\r
-\r
-if iconv_includes == "":\r
-    print "failed to find headers for libiconv: update includes_dir"\r
-    sys.exit(1)\r
-\r
-# those are added in the linker search path for libraries\r
-libdirs = [\r
-os.path.join(ROOT,'lib'),\r
-]\r
-\r
-xml_files = ["libxml2-api.xml", "libxml2-python-api.xml",\r
-             "libxml.c", "libxml.py", "libxml_wrap.h", "types.c",\r
-            "xmlgenerator.py", "README", "TODO", "drv_libxml2.py"]\r
-\r
-xslt_files = ["libxslt-api.xml", "libxslt-python-api.xml",\r
-             "libxslt.c", "libxsl.py", "libxslt_wrap.h",\r
-            "xsltgenerator.py"]\r
-\r
-if missing("libxml2-py.c") or missing("libxml2.py"):\r
-    try:\r
-       try:\r
-           import xmlgenerator\r
-       except:\r
-           import generator\r
-    except:\r
-       print "failed to find and generate stubs for libxml2, aborting ..."\r
-       print sys.exc_type, sys.exc_value\r
-       sys.exit(1)\r
-\r
-    head = open("libxml.py", "r")\r
-    generated = open("libxml2class.py", "r")\r
-    result = open("libxml2.py", "w")\r
-    for line in head.readlines():\r
-        if WITHDLLS:\r
-            result.write(altImport(line))\r
-        else:\r
-            result.write(line)\r
-    for line in generated.readlines():\r
-       result.write(line)\r
-    head.close()\r
-    generated.close()\r
-    result.close()\r
-\r
-with_xslt=0\r
-if missing("libxslt-py.c") or missing("libxslt.py"):\r
-    if missing("xsltgenerator.py") or missing("libxslt-api.xml"):\r
-        print "libxslt stub generator not found, libxslt not built"\r
-    else:\r
-       try:\r
-           import xsltgenerator\r
-       except:\r
-           print "failed to generate stubs for libxslt, aborting ..."\r
-           print sys.exc_type, sys.exc_value\r
-       else:\r
-           head = open("libxsl.py", "r")\r
-           generated = open("libxsltclass.py", "r")\r
-           result = open("libxslt.py", "w")\r
-           for line in head.readlines():\r
-                if WITHDLLS:\r
-                    result.write(altImport(line))\r
-                else:\r
-                    result.write(line)\r
-           for line in generated.readlines():\r
-               result.write(line)\r
-           head.close()\r
-           generated.close()\r
-           result.close()\r
-           with_xslt=1\r
-else:\r
-    with_xslt=1\r
-\r
-if with_xslt == 1:\r
-    xslt_includes=""\r
-    for dir in includes_dir:\r
-       if not missing(dir + "/libxslt/xsltconfig.h"):\r
-           xslt_includes=dir + "/libxslt"\r
-           break;\r
-\r
-    if xslt_includes == "":\r
-       print "failed to find headers for libxslt: update includes_dir"\r
-       with_xslt = 0\r
-\r
-\r
-descr = "libxml2 package"\r
-modules = [ 'libxml2', 'drv_libxml2' ]\r
-if WITHDLLS:\r
-    modules.append('libxmlmods.__init__')\r
-c_files = ['libxml2-py.c', 'libxml.c', 'types.c' ]\r
-includes= [xml_includes, iconv_includes]\r
-libs    = [libraryPrefix + "xml2"] + platformLibs\r
-macros  = []\r
-if with_threads:\r
-    macros.append(('_REENTRANT','1'))\r
-if with_xslt == 1:\r
-    descr = "libxml2 and libxslt package"\r
-    if not sys.platform.startswith('win'):\r
-        #\r
-        # We are gonna build 2 identical shared libs with merge initializing\r
-        # both libxml2mod and libxsltmod\r
-        #\r
-        c_files = c_files + ['libxslt-py.c', 'libxslt.c']\r
-        xslt_c_files = c_files\r
-        macros.append(('MERGED_MODULES', '1'))\r
-    else:\r
-        #\r
-        # On windows the MERGED_MODULE option is not needed\r
-        # (and does not work)\r
-        #\r
-        xslt_c_files = ['libxslt-py.c', 'libxslt.c', 'types.c']\r
-    libs.insert(0, libraryPrefix + 'exslt')\r
-    libs.insert(0, libraryPrefix + 'xslt')\r
-    includes.append(xslt_includes)\r
-    modules.append('libxslt')\r
-\r
-\r
-extens=[Extension('libxml2mod', c_files, include_dirs=includes,\r
-                  library_dirs=libdirs, \r
-                  libraries=libs, define_macros=macros)] \r
-if with_xslt == 1:\r
-    extens.append(Extension('libxsltmod', xslt_c_files, include_dirs=includes,\r
-                           library_dirs=libdirs, \r
-                            libraries=libs, define_macros=macros))\r
-\r
-if missing("MANIFEST"):\r
-\r
-    manifest = open("MANIFEST", "w")\r
-    manifest.write("setup.py\n")\r
-    for file in xml_files:\r
-        manifest.write(file + "\n")\r
-    if with_xslt == 1:\r
-       for file in xslt_files:\r
-           manifest.write(file + "\n")\r
-    manifest.close()\r
-\r
-if WITHDLLS:\r
-    ext_package = "libxmlmods"\r
-    if sys.version >= "2.2":\r
-        base = "lib/site-packages/"\r
-    else:\r
-        base = ""\r
-    data_files = [(base+"libxmlmods",dlls)]\r
-else:\r
-    ext_package = None\r
-    data_files = []\r
-\r
-setup (name = "libxml2-python",\r
-       # On *nix, the version number is created from setup.py.in\r
-       # On windows, it is set by configure.js\r
-       version = "2.6.20",\r
-       description = descr,\r
-       author = "Daniel Veillard",\r
-       author_email = "veillard@redhat.com",\r
-       url = "http://xmlsoft.org/python.html",\r
-       licence="MIT Licence",\r
-       py_modules=modules,\r
-       ext_modules=extens,\r
-       ext_package=ext_package,\r
-       data_files=data_files,\r
-       )\r
-\r
-sys.exit(0)\r
-\r
+#!/usr/bin/python -u
+#
+# Setup script for libxml2 and libxslt if found
+#
+import sys, os
+from distutils.core import setup, Extension
+
+# Below ROOT, we expect to find include, include/libxml2, lib and bin.
+# On *nix, it is not needed (but should not harm), 
+# on Windows, it is set by configure.js.
+ROOT = r'/usr' 
+
+# Thread-enabled libxml2
+with_threads = 1
+
+# If this flag is set (windows only), 
+# a private copy of the dlls are included in the package.
+# If this flag is not set, the libxml2 and libxslt
+# dlls must be found somewhere in the PATH at runtime.
+WITHDLLS = 1 and sys.platform.startswith('win')
+
+def missing(file):
+    if os.access(file, os.R_OK) == 0:
+        return 1
+    return 0
+
+try:
+    HOME = os.environ['HOME']
+except:
+    HOME="C:"
+
+if WITHDLLS:
+    # libxml dlls (expected in ROOT/bin)
+    dlls = [ 'iconv.dll','libxml2.dll','libxslt.dll','libexslt.dll' ]
+    dlls = map(lambda dll: os.path.join(ROOT,'bin',dll),dlls)
+
+    # create __init__.py for the libxmlmods package
+    if not os.path.exists("libxmlmods"):
+        os.mkdir("libxmlmods")
+        open("libxmlmods/__init__.py","w").close()
+
+    def altImport(s):
+        s = s.replace("import libxml2mod","from libxmlmods import libxml2mod")
+        s = s.replace("import libxsltmod","from libxmlmods import libxsltmod")
+        return s
+
+if sys.platform.startswith('win'):
+    libraryPrefix = 'lib'
+    platformLibs = []
+else:
+    libraryPrefix = ''
+    platformLibs = ["m","z"]
+
+# those are examined to find 
+# - libxml2/libxml/tree.h
+# - iconv.h 
+# - libxslt/xsltconfig.h
+includes_dir = [
+"/usr/include",
+"/usr/local/include",
+"/opt/include",
+os.path.join(ROOT,'include'),
+HOME
+];
+
+xml_includes=""
+for dir in includes_dir:
+    if not missing(dir + "/libxml2/libxml/tree.h"):
+        xml_includes=dir + "/libxml2"
+       break;
+
+if xml_includes == "":
+    print "failed to find headers for libxml2: update includes_dir"
+    sys.exit(1)
+
+iconv_includes=""
+for dir in includes_dir:
+    if not missing(dir + "/iconv.h"):
+        iconv_includes=dir
+       break;
+
+if iconv_includes == "":
+    print "failed to find headers for libiconv: update includes_dir"
+    sys.exit(1)
+
+# those are added in the linker search path for libraries
+libdirs = [
+os.path.join(ROOT,'lib'),
+]
+
+xml_files = ["libxml2-api.xml", "libxml2-python-api.xml",
+             "libxml.c", "libxml.py", "libxml_wrap.h", "types.c",
+            "xmlgenerator.py", "README", "TODO", "drv_libxml2.py"]
+
+xslt_files = ["libxslt-api.xml", "libxslt-python-api.xml",
+             "libxslt.c", "libxsl.py", "libxslt_wrap.h",
+            "xsltgenerator.py"]
+
+if missing("libxml2-py.c") or missing("libxml2.py"):
+    try:
+       try:
+           import xmlgenerator
+       except:
+           import generator
+    except:
+       print "failed to find and generate stubs for libxml2, aborting ..."
+       print sys.exc_type, sys.exc_value
+       sys.exit(1)
+
+    head = open("libxml.py", "r")
+    generated = open("libxml2class.py", "r")
+    result = open("libxml2.py", "w")
+    for line in head.readlines():
+        if WITHDLLS:
+            result.write(altImport(line))
+        else:
+            result.write(line)
+    for line in generated.readlines():
+       result.write(line)
+    head.close()
+    generated.close()
+    result.close()
+
+with_xslt=0
+if missing("libxslt-py.c") or missing("libxslt.py"):
+    if missing("xsltgenerator.py") or missing("libxslt-api.xml"):
+        print "libxslt stub generator not found, libxslt not built"
+    else:
+       try:
+           import xsltgenerator
+       except:
+           print "failed to generate stubs for libxslt, aborting ..."
+           print sys.exc_type, sys.exc_value
+       else:
+           head = open("libxsl.py", "r")
+           generated = open("libxsltclass.py", "r")
+           result = open("libxslt.py", "w")
+           for line in head.readlines():
+                if WITHDLLS:
+                    result.write(altImport(line))
+                else:
+                    result.write(line)
+           for line in generated.readlines():
+               result.write(line)
+           head.close()
+           generated.close()
+           result.close()
+           with_xslt=1
+else:
+    with_xslt=1
+
+if with_xslt == 1:
+    xslt_includes=""
+    for dir in includes_dir:
+       if not missing(dir + "/libxslt/xsltconfig.h"):
+           xslt_includes=dir + "/libxslt"
+           break;
+
+    if xslt_includes == "":
+       print "failed to find headers for libxslt: update includes_dir"
+       with_xslt = 0
+
+
+descr = "libxml2 package"
+modules = [ 'libxml2', 'drv_libxml2' ]
+if WITHDLLS:
+    modules.append('libxmlmods.__init__')
+c_files = ['libxml2-py.c', 'libxml.c', 'types.c' ]
+includes= [xml_includes, iconv_includes]
+libs    = [libraryPrefix + "xml2"] + platformLibs
+macros  = []
+if with_threads:
+    macros.append(('_REENTRANT','1'))
+if with_xslt == 1:
+    descr = "libxml2 and libxslt package"
+    if not sys.platform.startswith('win'):
+        #
+        # We are gonna build 2 identical shared libs with merge initializing
+        # both libxml2mod and libxsltmod
+        #
+        c_files = c_files + ['libxslt-py.c', 'libxslt.c']
+        xslt_c_files = c_files
+        macros.append(('MERGED_MODULES', '1'))
+    else:
+        #
+        # On windows the MERGED_MODULE option is not needed
+        # (and does not work)
+        #
+        xslt_c_files = ['libxslt-py.c', 'libxslt.c', 'types.c']
+    libs.insert(0, libraryPrefix + 'exslt')
+    libs.insert(0, libraryPrefix + 'xslt')
+    includes.append(xslt_includes)
+    modules.append('libxslt')
+
+
+extens=[Extension('libxml2mod', c_files, include_dirs=includes,
+                  library_dirs=libdirs, 
+                  libraries=libs, define_macros=macros)] 
+if with_xslt == 1:
+    extens.append(Extension('libxsltmod', xslt_c_files, include_dirs=includes,
+                           library_dirs=libdirs, 
+                            libraries=libs, define_macros=macros))
+
+if missing("MANIFEST"):
+
+    manifest = open("MANIFEST", "w")
+    manifest.write("setup.py\n")
+    for file in xml_files:
+        manifest.write(file + "\n")
+    if with_xslt == 1:
+       for file in xslt_files:
+           manifest.write(file + "\n")
+    manifest.close()
+
+if WITHDLLS:
+    ext_package = "libxmlmods"
+    if sys.version >= "2.2":
+        base = "lib/site-packages/"
+    else:
+        base = ""
+    data_files = [(base+"libxmlmods",dlls)]
+else:
+    ext_package = None
+    data_files = []
+
+setup (name = "libxml2-python",
+       # On *nix, the version number is created from setup.py.in
+       # On windows, it is set by configure.js
+       version = "2.6.20",
+       description = descr,
+       author = "Daniel Veillard",
+       author_email = "veillard@redhat.com",
+       url = "http://xmlsoft.org/python.html",
+       licence="MIT Licence",
+       py_modules=modules,
+       ext_modules=extens,
+       ext_package=ext_package,
+       data_files=data_files,
+       )
+
+sys.exit(0)
+