root/swish-python/setup.py

Revision 1677, 2.8 kB (checked in by augur, 3 years ago)

Initial revision

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1  
2 #!/usr/bin/env python
3
4 # this file is automatically generated as a part of the build
5 # procedure.  All edits will be lost!
6
7
8 from distutils.core import *
9 from string import split
10 import re
11
12 def ReadSetup(filename):
13       """ReadSetup goes through filename (default, setup.txt), and parses
14       out the values stored in the file.  Values need to be stored in a
15       \"key=value format\""""
16
17       #return val
18       opts = {}
19      
20       fh = open(filename, 'r')
21       reobj = re.compile(r"([a-z]+)=(.+)")
22       for line in (fh.readlines()):
23             matchobj = reobj.search(line)
24            
25             if(matchobj == None):
26                   raise "Error:  syntaxt error in setup.txt line: %s"%line
27
28             lab,val = (matchobj.groups())
29             opts[lab] = val
30       return opts
31
32          
33 def ParseCPPFlags(str):
34       """parse the CPPFlags macro"""
35       incl_dir = []
36       cppflags = []
37      
38       tokens = split(str)
39       # go through the list of compile flags.  treat search path args
40       # specially; otherwise just add to "extra_compile_args"
41       for tok in (tokens):
42             if(tok[0:2] == "-I"):
43                   incl_dir.append(tok[2:])
44                   continue
45             else:
46                   cppflags.append(tok)
47      
48       return(incl_dir, cppflags)
49
50 def ParseLDFlags(str):
51       """parse the global LDFlags macro"""
52       lib_dir = []
53
54       tokens = split(str)
55       # go through the list of link flags.  treat search path args
56       # specially; discard the rest
57       for tok in (tokens):
58             if(tok[0:2] == "-L"):
59                   lib_dir.append(tok[2:])
60                   continue
61      
62       return(lib_dir)
63
64
65 def ParseLibs(str):
66       """parse the list of extra libraries"""
67       libs = []
68      
69       tokens = split(str)
70       # go through the list of libs
71       for tok in (tokens):
72             if(tok[0:2] == "-l"):
73                   libs.append(tok[2:])
74                   continue
75      
76       return(libs)
77
78 def RunSetup(incldir, cppflags, ldflags, libdir):
79       setup(name="uff",
80             version="1.0",
81             author="David L Norris",
82             author_email="dave@webaugur.com",
83             description="SWISH-E Search Library",
84             py_modules=["swish"],
85             ext_modules=[
86                   Extension("_swish",
87                             ["swish_wrap.c",
88                              ],
89                             extra_compile_args=cppflags,
90                             include_dirs=incldir,
91                             libraries=libs,
92                             library_dirs=ldflags
93                            )
94                   ]
95             )
96
97 if __name__ == "__main__":
98       opts = ReadSetup("setup.txt")
99       incldir, cppflags = ParseCPPFlags(opts["includes"])
100       ldflags = ParseLDFlags(opts["ldflags"])
101       libs = ParseLibs(opts["libs"])
102       RunSetup(incldir, cppflags, ldflags, libs)
103
104
Note: See TracBrowser for help on using the browser.