Building Dynamic LAPACKE With SCons
Posted on March 13, 2012
I wanted a shared library of LAPACKE on my linux box. I did this so that I can work with Jalla in GHCi, but it might be useful in other cases too. Since LAPACKE comes with a plain makefile, and I had to also leave out some files depending amongst others on XBLAS, I wrote a SConstruct file (for the great SCons build system) to build a dynamic as well as a static LAPACKE:
# This file is part of Jalla <http://github.com/cgo/jalla>.
# Copyright 2012 Christian Gosch.
#
# 1. You may have to modify the library paths and/or names below to suit your system.
# 2. Copy this SConstruct file to the top level directory of LAPACKE
# 3. Call "scons" on the command line, possibly "scons -jN" where N is the
# number of processors to use.
# 4. Copy the built libraries where you need them.
#
# This worked for the LAPACKE which was delivered with LAPACK 3.4.0.
#
# Builds a shared and a static library.
#
# Dependencies: LAPACK, BLAS, CBLAS
#
import re, sys, glob
= Environment ()
env = Glob ('utils/*.c')
utils_sources
# XBLAS dependent functions
= re.compile ('xx\.c$|sx\.c$|xx_work\.c$|sx_work\.c$') # |^cla_|^sla_')
x_regex # Test generation functions
= re.compile ('.*lapacke_[sdcz]la')
testing_regex # Functions apparently not available in stock Ubuntu 11.10 LAPACK, only in LAPACK 3.4.0
= re.compile ('qrt\.c$|qrt2\.c$|qrt3\.c|rfb\.c$|qrt_work\.c$|qrt2_work\.c$|qrt3_work\.c|rfb_work\.c$')
other_regex
# Filtering out XBLAS dependencies
= filter (lambda fn: x_regex.search(fn) == None, glob.glob ('src/*.c'))
lapacke_sources # Filtering out testing dependencies
= filter (lambda fn: testing_regex.search(fn) == None, lapacke_sources)
lapacke_sources # Filtering out other (new 3.4.0 functions??) dependencies
= filter (lambda fn: other_regex.search(fn) == None, lapacke_sources)
lapacke_sources
= '-DHAVE_LAPACK_CONFIG_H -DLAPACK_COMPLEX_STRUCTURE')
env.Append (CCFLAGS = ['lapack', 'f77blas', 'cblas', 'm'])
env.Append (LIBS = ['../include', './include'])
env.Append (CPPPATH = ['/usr/lib/atlas-base/'])
env.Append (LIBPATH
'lapacke', lapacke_sources + utils_sources)
env.SharedLibrary ('lapacke', lapacke_sources + utils_sources) env.StaticLibrary (