Skip to content

Commit 1d8478a

Browse files
author
David Sommerseth
committed
Improved setup.py/setup-dbg.py even more
Get libxml2 compile time info from xml2-config. Retrieve version number from src/version.h
1 parent 15463a7 commit 1d8478a

4 files changed

Lines changed: 128 additions & 11 deletions

File tree

src/setup-dbg.py

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,29 @@
2828

2929
from distutils.core import setup, Extension
3030
from distutils.sysconfig import get_python_lib
31+
from setup_common import *
3132

32-
libdir = get_python_lib(1)
33+
#
34+
# Some default values
35+
#
36+
incdir = []
37+
libdir = [get_python_lib(1)]
38+
libs = []
39+
40+
# Get libxml2 info
41+
libxml2_include(incdir)
42+
libxml2_lib(libdir, libs)
43+
44+
# misc info
45+
dmidec_version = get_version()
46+
47+
#
48+
# Python setup
49+
#
3350

3451
setup(
3552
name = "python-dmidecode-dbg",
36-
version = "3.10.6",
53+
version = dmidec_version,
3754
license='GPL-2',
3855
description = "Python extension module for dmidecode",
3956
author = "Nima Talebi & David Sommerseth",
@@ -52,9 +69,9 @@
5269
"src/dmierror.c",
5370
"src/xmlpythonizer.c"
5471
],
55-
include_dirs = [ "/usr/include/libxml2" ],
56-
library_dirs = [ libdir ],
57-
libraries = [ "xml2", "xml2mod" ],
72+
include_dirs = incdir,
73+
library_dirs = libdir,
74+
libraries = libs,
5875
undef_macros = [ "NDEBUG" ]
5976
)
6077
],

src/setup.py

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,29 @@
2828

2929
from distutils.core import setup, Extension
3030
from distutils.sysconfig import get_python_lib
31+
from setup_common import *
3132

32-
libdir = get_python_lib(1)
33+
#
34+
# Some default values
35+
#
36+
incdir = []
37+
libdir = [get_python_lib(1)]
38+
libs = []
39+
40+
# Get libxml2 info
41+
libxml2_include(incdir)
42+
libxml2_lib(libdir, libs)
43+
44+
# misc info
45+
dmidec_version = get_version()
46+
47+
#
48+
# Python setup
49+
#
3350

3451
setup(
3552
name = "python-dmidecode",
36-
version = "3.10.6",
53+
version = dmidec_version,
3754
license='GPL-2',
3855
description = "Python extension module for dmidecode",
3956
author = "Nima Talebi & David Sommerseth",
@@ -52,9 +69,9 @@
5269
"src/dmierror.c",
5370
"src/xmlpythonizer.c"
5471
],
55-
include_dirs = [ "/usr/include/libxml2" ],
56-
library_dirs = [ libdir ],
57-
libraries = [ "xml2", "xml2mod" ]
72+
include_dirs = incdir,
73+
library_dirs = libdir,
74+
libraries = libs
5875
)
5976
],
6077
py_modules = [ "dmidecode" ]

src/setup_common.py

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
#
2+
# setup-common.py
3+
# Helper functions for retrieving libxml2 arguments needed for compilation
4+
# and other functions which is used in both setup.py and setup-dbg.py
5+
#
6+
# Copyright 2009 David Sommerseth <davids@redhat.com>
7+
#
8+
# This program is free software; you can redistribute it and/or modify
9+
# it under the terms of the GNU General Public License as published by
10+
# the Free Software Foundation; either version 2 of the License, or
11+
# (at your option) any later version.
12+
#
13+
# This program is distributed in the hope that it will be useful,
14+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
# GNU General Public License for more details.
17+
#
18+
# You should have received a copy of the GNU General Public License
19+
# along with this program; if not, write to the Free Software
20+
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21+
#
22+
# For the avoidance of doubt the "preferred form" of this code is one which
23+
# is in an open unpatent encumbered format. Where cryptographic key signing
24+
# forms part of the process of creating an executable the information
25+
# including keys needed to generate an equivalently functional executable
26+
# are deemed to be part of the source code.
27+
#
28+
29+
import commands, sys
30+
31+
# libxml2 - C flags
32+
def libxml2_include(incdir):
33+
(res, libxml2_cflags) = commands.getstatusoutput("xml2-config --cflags")
34+
if res != 0:
35+
print "Could not build python-dmidecode."
36+
print "Could not run xml2-config, is libxml2 installed?"
37+
print "Also the development libraries?"
38+
sys.exit(1)
39+
40+
# Parse the xml2-config --cflags response
41+
for l in libxml2_cflags.split(" "):
42+
if l.find('-I') == 0:
43+
incdir.append(l.replace("-I", "", 1))
44+
45+
46+
47+
# libxml2 - library flags
48+
def libxml2_lib(libdir, libs):
49+
(res, libxml2_libs) = commands.getstatusoutput("xml2-config --libs")
50+
if res != 0:
51+
print "Could not build python-dmidecode."
52+
print "Could not run xml2-config, is libxml2 installed?"
53+
print "Also the development libraries?"
54+
sys.exit(1)
55+
56+
# Parse the xml2-config --libs response
57+
for l in libxml2_libs.split(" "):
58+
if l.find('-L') == 0:
59+
libdir.append(l.replace("-L", "", 1))
60+
elif l.find('-l') == 0:
61+
libs.append(l.replace("-l", "", 1))
62+
63+
# this library is not reported and we need it anyway
64+
libs.append('xml2mod')
65+
66+
67+
68+
# Get version from src/version.h
69+
def get_version():
70+
f = open("src/version.h")
71+
version = "0.0.0"
72+
try:
73+
for line in f:
74+
part = line.split(" ")
75+
if part[0] == "#define":
76+
if part[1] == "VERSION":
77+
version = part[2].strip().strip('"')
78+
break
79+
finally:
80+
f.close()
81+
82+
return version
83+

src/version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
#define VERSION "2.9"
1+
#define VERSION "3.10.6"

0 commit comments

Comments
 (0)