#!/usr/bin/env python from __future__ import generators import user import config.autoconf import os import config.package class Configure(config.package.Package,config.autoconf.Configure): def __init__(self, framework): config.autoconf.Configure.__init__(self, framework) config.package.Package.__init__(self, framework) self.headerPrefix = '' self.substPrefix = '' self.foundlibxml2 = 0 return def __str__(self): if self.foundlibxml2: desc = ['libxml2:'] desc.append(' Includes: '+str(self.include)) desc.append(' Library: '+str(self.lib)) return '\n'.join(desc)+'\n' return '' def setupHelp(self, help): import nargs help.addArgument('libxml2', '-with-libxml2-include=', nargs.ArgDir(None, None, 'Specify an include directory for libxml2')) help.addArgument('libxml2', '-with-libxml2-libdir=', nargs.Arg(None, None, 'Specify libxml2 library directory')) return def setupDependencies(self, framework): config.package.Package.setupDependencies(self, framework) return def configureLibrary(self): '''Checks for libxml2 and defines LIBXML2_CPPPATH, LIBXML2_LIBPATH, and LIBXML2_LIBS''' foundInclude = 0 includeDirs = ['/usr/include/libxml2', '/usr/include', '/usr/local/include', '/usr/local/libxml2/include'] includeDir = '' foundLibrary = 0 libraryDirs = map(lambda s: s.replace('include', 'lib'), includeDirs) libraryDir = '' # Check for libxml2 includes if self.framework.argDB.has_key('with-libxml2-include'): if not os.path.isdir(self.framework.argDB['with-libxml2-include']): raise RuntimeError('Invalid libxml2 include directory specified by --with-libxml2-include='+os.path.abspath(self.framework.argDB['with-libxml2-include'])) includeDir = self.framework.argDB['with-libxml2-include'] foundInclude = 1 else: testInclude = 'libxml/tree.h' if self.checkPreprocess('#include <'+testInclude+'>\n'): foundInclude = 1 # Check standard paths if not foundInclude: for dir in includeDirs: if os.path.isfile(os.path.join(dir, testInclude)): foundInclude = 1 includeDir = dir # Check for libxml2 libraries if self.framework.argDB.has_key('with-libxml2-libdir'): if not os.path.isdir(self.framework.argDB['with-libxml2-libdir']): raise RuntimeError('Invalid libxml2 library specified by --with-libxml2-libdir='+os.path.abspath(self.framework.argDB['with-libxml2-libdir'])) libraryDir = self.framework.argDB['with-libxml2-libdir'] foundLibrary = 1 else: testLibrary = 'xml2' testFunction = 'xmlCleanupParser' # Check default compiler libraries if not foundLibrary: oldLibs = self.compilers.LIBS self.compilers.LIBS += ' -l'+testLibrary self.pushLanguage(self.language[-1]) if self.checkLink('', testFunction+'();\n'): foundLibrary = 1 self.compilers.LIBS = oldLibs self.popLanguage() # Check standard paths if not foundLibrary: for dir in libraryDirs: for ext in ['.a', '.so', '.sl']: if os.path.isfile(os.path.join(dir, 'lib'+testLibrary+ext)): foundLibrary = 1 libraryDir = dir # Verify that library can be linked with if foundLibrary: oldLibs = self.compilers.LIBS if libraryDir: self.compilers.LIBS += ' -L'+libraryDir self.compilers.LIBS += ' -l'+testLibrary self.pushLanguage(self.language[-1]) if not self.checkLink('', testFunction+'();\n'): foundLibrary = 0 self.compilers.LIBS = oldLibs self.popLanguage() if foundInclude and foundLibrary: self.logPrint('Found libxml2 includes and libraries') self.foundlibxml2 = 1 cpppath = '' if includeDir: cpppath = includeDir libpath='' if libraryDir: libpath = libraryDir libs='xml2' self.lib = '-lxml2' self.addSubstitution('LIBXML2_CPPPATH', cpppath) self.addSubstitution('LIBXML2_LIBPATH', libpath) self.addSubstitution('LIBXML2_LIBS', libs) if hasattr(self.framework, 'packages'): self.framework.packages.append(self) else: if not foundInclude: msg='Could not find libxml2 includes. Tried\n' for d in includeDirs: msg+=d + "\n" msg+='Try using the --with-libxml2-include option.' raise RuntimeError(msg) if not foundLibrary: msg='Could not find libxml2 libraries. Tried\n' for d in libraryDirs: msg+=d + "\n" msg+='Try using the --with-libxml2-libdir option.' raise RuntimeError(msg) return def configure(self): self.executeTest(self.configureLibrary) return if __name__ == '__main__': import config.framework import sys framework = config.framework.Framework(sys.argv[1:]) framework.setup() framework.addChild(Configure(framework)) framework.configure() framework.dumpSubstitutions()