6
from commonPkgConfigUtils import *
8
def getHypreDir(sconsEnv=None):
9
default = os.path.join(os.path.sep,"usr","local")
10
hypre_dir = getPackageDir("hypre", sconsEnv=sconsEnv, default=default)
13
def pkgVersion(compiler=None, linker=None, cflags=None, sconsEnv=None):
14
# A test for checking the hypre version
15
cpp_version_str = r"""
18
#include <HYPRE_config.h>
21
#ifdef HYPRE_PACKAGE_VERSION
22
printf("%s",HYPRE_PACKAGE_VERSION);
27
write_cppfile(cpp_version_str, "hypre_config_test_version.c")
30
# FIXME: get_compiler() returns a C++ compiler. Should be a C compiler.
31
compiler = get_compiler(sconsEnv)
33
linker = get_linker(sconsEnv)
36
cmdstr = "%s -o a.out %s hypre_config_test_version.c" % (compiler, cflags)
37
compileFailed, cmdoutput = getstatusoutput(cmdstr)
39
remove_cfile("hypre_config_test_version.c")
40
raise UnableToCompileException("Hypre", cmd=cmdstr,
41
program=cpp_version_str, errormsg=cmdoutput)
42
cmdstr = os.path.join(os.getcwd(), "a.out")
43
runFailed, cmdoutput = getstatusoutput(cmdstr)
45
remove_cfile("hypre_config_test_version.c", execfile=True)
46
raise UnableToRunException("Hypre", errormsg=cmdoutput)
47
hypre_version = cmdoutput
49
remove_cfile("hypre_config_test_version.c", execfile=True)
53
def pkgLibs(compiler=None, cflags=None, sconsEnv=None):
54
# A test to see if we need to link with blas and lapack
58
#include <HYPRE_config.h>
70
write_cppfile(cpp_libs_str, "hypre_config_test_libs.c")
73
# FIXME: get_compiler() returns a C++ compiler. Do we need a C compiler?
74
compiler = get_compiler(sconsEnv)
77
cmdstr = "%s -o a.out %s hypre_config_test_libs.c" % (compiler,cflags)
78
compileFailed, cmdoutput = getstatusoutput(cmdstr)
80
remove_cfile("hypre_config_test_libs.c")
81
raise UnableToCompileException("Hypre", cmd=cmdstr,
82
program=cpp_libs_str, errormsg=cmdoutput)
84
cmdstr = os.path.join(os.getcwd(), "a.out")
85
runFailed, cmdoutput = getstatusoutput(cmdstr)
87
remove_cfile("hypre_config_test_libs.c", execfile=True)
88
raise UnableToRunException("Hypre", errormsg=cmdoutput)
89
blaslapack_str = string.join(string.split(cmdoutput, '\n'))
91
remove_cfile("hypre_config_test_libs.c", execfile=True)
93
if get_architecture() == "darwin":
94
libs_str = "-framework vecLib"
96
libs_str = "-L%s %s" % (getAtlasDir(sconsEnv=sconsEnv),blaslapack_str)
98
libs_dir = os.path.join(getHypreDir(sconsEnv=sconsEnv),"lib")
99
libs_str += " -L%s -lHYPRE" % libs_dir
103
def pkgCflags(sconsEnv=None):
104
include_dir = os.path.join(getHypreDir(sconsEnv=sconsEnv),"include")
105
cflags = "-I%s -fPIC" % include_dir
106
if get_architecture() == "darwin":
107
# Additional cflags required on Mac
108
cflags += " -fno_common"
111
def pkgTests(forceCompiler=None, sconsEnv=None,
112
version=None, libs=None, cflags=None, **kwargs):
113
"""Run the tests for this package.
115
If Ok, return various variables, if not we will end with an exception.
116
forceCompiler, if set, should be a tuple containing (compiler, linker)
117
or just a string, which in that case will be used as both
119
# Set architecture up front.
120
arch = get_architecture()
122
if not forceCompiler:
123
compiler = get_compiler(sconsEnv)
124
linker = get_linker(sconsEnv)
126
compiler, linker = set_forced_compiler(forceCompiler)
129
cflags = pkgCflags(sconsEnv=sconsEnv)
131
version = pkgVersion(compiler=compiler, cflags=cflags, sconsEnv=sconsEnv)
133
libs = pkgLibs(compiler=compiler, cflags=cflags, sconsEnv=sconsEnv)
135
# A test to see if we can actually use the libHYPRE
136
cpp_testlib_str = r"""
139
#include <HYPRE_config.h>
140
#include <_hypre_IJ_mv.h>
142
int main(int argc, char *argv[])
144
#ifdef HYPRE_SEQUENTIAL
145
MPI_Comm comm = MPI_COMM_NULL;
147
HYPRE_IJMatrixCreate(comm, 0, 10, 0, 10, &A);
151
MPI_Init(&argc,&argv);
152
MPI_Comm_size(MPI_COMM_WORLD,&nprocs);
153
MPI_Comm_rank(MPI_COMM_WORLD,&rank);
155
HYPRE_IJMatrixCreate(MPI_COMM_WORLD, 0, 10, 0, 10, &A);
161
write_cppfile(cpp_testlib_str, "hypre_config_test_libstest.c")
163
cmdstr = "%s %s -c hypre_config_test_libstest.c" % (compiler,cflags)
164
compileFailed, cmdoutput = getstatusoutput(cmdstr)
166
remove_cfile("hypre_config_test_libstest.c")
167
raise UnableToCompileException("Hypre", cmd=cmdstr,
168
program=cpp_testlib_str, errormsg=cmdoutput)
170
cmdstr = "%s -o a.out %s hypre_config_test_libstest.o" % (linker,libs)
171
linkFailed, cmdoutput = getstatusoutput(cmdstr)
173
remove_cfile("hypre_config_test_libstest.c", ofile=True)
174
raise UnableToLinkException("Hypre", cmd=cmdstr,
175
program=cpp_testlib_str, errormsg=cmdoutput)
177
cmdstr = os.path.join(os.getcwd(), "a.out")
178
runFailed, cmdoutput = getstatusoutput(cmdstr)
180
remove_cfile("hypre_config_test_libstest.c", execfile=True, ofile=True)
181
raise UnableToRunException("Hypre", errormsg=cmdoutput)
183
remove_cfile("hypre_config_test_libstest.c", execfile=True, ofile=True)
185
return version, libs, cflags
187
def generatePkgConf(directory=suitablePkgConfDir(), sconsEnv=None, **kwargs):
188
"""Generate a pkg-config file for Hypre."""
190
version, libs, cflags = pkgTests(sconsEnv=sconsEnv)
192
pkg_file_str = r"""Name: Hypre
194
Description: The Hypre project - http://www.llnl.gov/casc/hypre/software.html
197
""" % (version, libs, cflags)
199
pkg_file = open(os.path.join(directory,"hypre.pc"), 'w')
200
pkg_file.write(pkg_file_str)
202
print "done\n Found Hypre and generated pkg-config file in \n '%s'" % directory
204
if __name__ == "__main__":
205
generatePkgConf(directory=".")