#!/usr/bin/env python # $Id: setup.py,v 1.12 2007/07/28 06:10:35 marcusva Exp $ # setup script for papi import distutils.sysconfig from distutils.core import setup, Extension import os, sys, glob # Minimum requirements. ATK_MINIMUM = "1.18.0" PYTHON_MINIMUM = (2, 3) PAPI_VERSION = "0.0.5" PAPI_DEBUG = "1" ## # General configuration stuff. ## def check_pkgconfig (): """Checks for the pkg-config utility.""" # TODO: unchecked code, verify it using a Win32 environment. if sys.platform == "win32": return os.system ("pkg-config > NUL") == 0 else: return os.system ("pkg-config 2> /dev/null") == 256 def pkg_get_flags (package, flags, repl=None): """Gets the general compiler flags for a specific package using the pkg-config utility.""" pipe = os.popen ("pkg-config %s %s" % (flags, package), "r") data = pipe.readline ().strip () pipe.close () if repl: return data.replace (repl, "").split () return data.split () def pkg_get_all_cflags (name): """Gets all necessary flags for a compiler using the pkg-config utility.""" return pkg_get_flags (name, "--cflags-only-I", "-I"), \ pkg_get_flags (name, "--libs-only-L", "-L"), \ pkg_get_flags (name, "--libs-only-l", "-l") def get_papi_defines (): """Builds the defines list for the C Compiler.""" val = [("VERSION", "\"" + PAPI_VERSION + "\"")] if PAPI_DEBUG != "0": val.append(("DEBUG", PAPI_DEBUG)) if sys.platform == "win32": val.append (("IS_WIN32", "1")) return val def get_papi_files (): """Gets the list of file to use for building the papi accessibility module.""" files = glob.glob (os.path.join ("src", "*.c")) return files def get_directory_list (base): """Gets a list of subdirectories for the given base path.""" # Get the needed ocempgui directory. realpath = os.path.split (os.path.abspath (sys.argv[0]))[0] # First get all the directories. paths = glob.glob (os.path.join (realpath, base, "*")) dirpaths = [] for x in paths: if os.path.isdir (x): dirpaths += get_directory_list (os.path.join (base, x)) # Although this should not happen, guarantee, that there is no CVS # target. dirpaths = [x for x in dirpaths if x.find ("CVS") == -1] # Do not forget the main directory. dirpaths = [os.path.join (realpath, base)] + dirpaths return dirpaths def get_installation_files (base, installpath, filedict): """Create a nice list from it suitable for the data_files section of the distutils setup.""" # Get the needed ocempgui directory. realpath = os.path.split (os.path.abspath (sys.argv[0]))[0] filelist = [] for key in filedict: # We also need to get rid of the current directory prefix and # set it it to the correct installation prefix. try: path = key.split (os.path.join (realpath, base, ""))[1] except IndexError: # We got the main directory. path = "" path = os.path.join (installpath, path) # Add the files. files = [] for installfile in filedict[key]: installfile = installfile.split (os.path.join (realpath, ""), 1)[1] files.append (installfile) filelist.append ((path, files)) return filelist def get_documentation_files (): """Gets a list of files to install as documentation.""" installpath = os.path.join ("share", "doc", "papi") docpaths = get_directory_list ("doc") # Traverse all the directories in the docpath an get the needed files. # Every file installed from the docs will have a suffix. filedict = {} for path in docpaths: files = glob.glob (os.path.join (path, "*.*")) if files: filedict[path] = files return get_installation_files ("doc", installpath, filedict) def run_checks (): # Python version check. if sys.version_info < PYTHON_MINIMUM: # major, minor check raise Exception ("You should have at least Python >= %d.%d.x " "installed." % PYTHON_MINIMUM) # Environment checks for the PAPI interfaces. atk_version = None if not check_pkgconfig (): raise Exception ("pkg-config not found") val = pkg_get_flags ("atk", "--modversion") if val: atk_version = val[0] if not val or (atk_version < ATK_MINIMUM): raise Exception ("You should have at least ATK >= %s installed" % ATK_MINIMUM) print "\nThe following information will be used to build papi:" print "\t Python: %d.%d.%d" % sys.version_info[0:3] print "\t ATK: %s" % atk_version if __name__ == "__main__": run_checks () includes, libdirs, libs = pkg_get_all_cflags ("atk") gmodflags = pkg_get_all_cflags ("gmodule-2.0") includes += gmodflags[0] libdirs += gmodflags[1] libs += gmodflags[2] includes += distutils.sysconfig.get_python_inc () defines = get_papi_defines () docfiles = get_documentation_files () if PAPI_DEBUG != "0": warn_flags = ["-W", "-Wall", "-Wpointer-arith", "-Wcast-qual", "-Winline", "-Wcast-align", "-Wconversion", "-Wstrict-prototypes", "-Wmissing-prototypes", "-Wmissing-declarations", "-Wnested-externs", "-Wshadow", "-Wredundant-decls" ] else: warn_flags = [] compile_args = warn_flags + ["-std=c99", "-g"] papi = Extension ("papi", sources=get_papi_files (), include_dirs=includes, library_dirs=libdirs, libraries=libs, language="c", define_macros=defines, extra_compile_args=compile_args) setupdata = { "name" : "papi", "version" : PAPI_VERSION, "description": "Python accessibility programming interface", "author": "Marcus von Appen", "author_email": "marcus@sysfault.org", "license": "BSD license", "url": "http://ocemp.sourceforge.net/papi.html", "ext_modules" : [papi], "data_files" : [] } setup (**setupdata)