python/setup.py now builds all sigar srcs

This commit is contained in:
Doug MacEachern 2009-04-04 19:15:36 -07:00
parent 7f8bfd8195
commit 19d9e00787
1 changed files with 58 additions and 10 deletions

View File

@ -1,17 +1,65 @@
#!/usr/bin/env python #!/usr/bin/env python
from distutils.core import setup, Extension from distutils.core import setup, Extension
from os import system, mkdir, path
import sys, commands
_sigar = Extension( build = 'build'
"_sigar", options = {'perl':'perl'}
["_sigar.c"],
include_dirs = ['../java/sigar-bin/include'], def parse_args():
extra_compile_args = ['-Wall'], global options
libraries=['sigar-universal-macosx'], args = sys.argv[1:]
library_dirs=['../java/sigar-bin/lib'], for arg in args:
extra_link_args=[], if arg.find("--with-sigar") != -1:
define_macros=[], sys.argv.remove(arg)
undef_macros=[]) value = arg.split('=')[1]
options['sigar'] = value
elif arg.find("--with-perl") != -1:
sys.argv.remove(arg)
value = arg.split('=')[1]
options['perl'] = value
def sbuild(cmd):
return commands.getoutput(options['perl'] + ' -Mlib=.. -MSigarBuild -e ' + cmd)
def sargs(cmd):
res = sbuild(cmd)
if len(res) > 0:
return res.split(' ')
else :
return None
parse_args()
if sys.argv[-1] != 'clean':
if not path.exists(build):
mkdir(build)
system(options['perl'] + ' -Mlib=.. -MSigarWrapper -e generate Python ' + build)
if 'sigar' in options:
sigar = options['sigar']
print "Linking againt libsigar in " + sigar
_sigar = Extension(
"_sigar",
["_sigar.c"],
include_dirs = [sigar + '/include', build],
extra_compile_args = ['-Wall'],
libraries=['sigar'],
library_dirs=[sigar + '/lib'])
else :
print "Inlining libsigar sources"
src = sargs('inline_src -- ' + build)
src.append('_sigar.c')
cppflags = sargs('cppflags')
cppflags.append('-Wall')
_sigar = Extension(
"_sigar",
src,
include_dirs = [build],
extra_compile_args = cppflags,
extra_link_args = sargs('ldflags'),
libraries=sargs('libs'))
setup(name="pysigar", version="0.1", setup(name="pysigar", version="0.1",
py_modules = ['sigar'], py_modules = ['sigar'],