#!/usr/bin/env python # this file is automatically generated as a part of the build # procedure. All edits will be lost! from distutils.core import * from string import split import re def ReadSetup(filename): """ReadSetup goes through filename (default, setup.txt), and parses out the values stored in the file. Values need to be stored in a \"key=value format\"""" #return val opts = {} fh = open(filename, 'r') reobj = re.compile(r"([a-z]+)=(.+)") for line in (fh.readlines()): matchobj = reobj.search(line) if(matchobj == None): raise "Error: syntaxt error in setup.txt line: %s"%line lab,val = (matchobj.groups()) opts[lab] = val return opts def ParseCPPFlags(str): """parse the CPPFlags macro""" incl_dir = [] cppflags = [] tokens = split(str) # go through the list of compile flags. treat search path args # specially; otherwise just add to "extra_compile_args" for tok in (tokens): if(tok[0:2] == "-I"): incl_dir.append(tok[2:]) continue else: cppflags.append(tok) return(incl_dir, cppflags) def ParseLDFlags(str): """parse the global LDFlags macro""" lib_dir = [] tokens = split(str) # go through the list of link flags. treat search path args # specially; discard the rest for tok in (tokens): if(tok[0:2] == "-L"): lib_dir.append(tok[2:]) continue return(lib_dir) def ParseLibs(str): """parse the list of extra libraries""" libs = [] tokens = split(str) # go through the list of libs for tok in (tokens): if(tok[0:2] == "-l"): libs.append(tok[2:]) continue return(libs) def RunSetup(incldir, cppflags, ldflags, libdir): setup(name="uff", version="1.0", author="David L Norris", author_email="dave@webaugur.com", description="SWISH-E Search Library", py_modules=["swish"], ext_modules=[ Extension("_swish", ["swish_wrap.c", ], extra_compile_args=cppflags, include_dirs=incldir, libraries=libs, library_dirs=ldflags ) ] ) if __name__ == "__main__": opts = ReadSetup("setup.txt") incldir, cppflags = ParseCPPFlags(opts["includes"]) ldflags = ParseLDFlags(opts["ldflags"]) libs = ParseLibs(opts["libs"]) RunSetup(incldir, cppflags, ldflags, libs)