- ret = conf.TryLink(check_select_source, '.c')
- if ret:
- conf.Result(ret)
- return (arg1, arg234, arg5)
- conf.Result('no (use default)')
- return ('int', 'int *', 'struct timeval *')
-
-
-def checkBoostLibraries(conf, lib, pathes):
- ''' look for boost libraries '''
- conf.Message('Checking for boost library %s... ' % lib)
- for path in pathes:
- # direct form: e.g. libboost_iostreams.a
- if os.path.isfile(os.path.join(path, 'lib%s.a' % lib)):
- conf.Result('yes')
- return (path, lib)
- # check things like libboost_iostreams-gcc.a
- files = glob.glob(os.path.join(path, 'lib%s-*.a' % lib))
- # if there are more than one, choose the first one
- # FIXME: choose the best one.
- if len(files) >= 1:
- # get xxx-gcc from /usr/local/lib/libboost_xxx-gcc.a
- conf.Result('yes')
- return (path, files[0].split(os.sep)[-1][3:-2])
- conf.Result('n')
- return ('','')
-
-
-import SCons.Node
-def processLang(env, folder):
- """ Process translations (.po files) in a po/ dir
- This is copied from KDE knetstats-1.5/admin/kde.py
-
- FIXME: imcomplete
- """
- import glob
- dir=SCons.Node.FS.default_fs.Dir(folder).srcnode()
- fld=dir.srcnode()
- tmptransfiles = glob.glob(str(fld)+'/*.po')
-
- transfiles=[]
- if env.has_key('_BUILDDIR_'):
- bdir=env['_BUILDDIR_']
- for dir in env.make_list(tmptransfiles):
- transfiles.append( env.join(bdir, dir) )
- else:
- transfiles=tmptransfiles
-
- env['MSGFMT'] = 'msgfmt'
- env['BUILDERS']['Transfiles']=SCons.Builder.Builder(action='$MSGFMT $SOURCE -o $TARGET',suffix='.gmo',src_suffix='.po')
- languages=None
- # FIXME: KDE has this ARGS thing...
- #if env['ARGS'] and env['ARGS'].has_key('languages'):
- # languages=env.make_list(env['ARGS']['languages'])
- mydir=SCons.Node.FS.default_fs.Dir('.')
- for f in transfiles:
- fname=f.replace(mydir.abspath, '')
- file=SCons.Node.FS.default_fs.File(fname)
- country = SCons.Util.splitext(file.name)[0]
- if not languages or country in languages:
- result = env.Transfiles(file)
- # FIXME
+ ret = conf.TryLink(check_select_source, '.c')
+ if ret:
+ conf.Result(ret)
+ return (arg1, arg234, arg5)
+ conf.Result('no (use default)')
+ return ('int', 'int *', 'struct timeval *')
+
+
+def checkBoostLibraries(conf, libs, lib_paths, inc_paths, versions, isDebug):
+ ''' look for boost libraries
+ libs: library names
+ lib_paths: try these paths for boost libraries
+ inc_paths: try these paths for boost headers
+ versions: supported boost versions
+ isDebug: if true, use debug libraries
+ '''
+ conf.Message('Checking for boost library %s... ' % ', '.join(libs))
+ libprefix = conf.env['LIBPREFIX']
+ libsuffix = '(%s|%s)' % (conf.env['LIBSUFFIX'], conf.env['SHLIBSUFFIX'])
+ found_lib = False
+ found_inc = False
+ lib_names = []
+ lib_path = None
+ inc_path = None
+ for path in lib_paths:
+ conf.Log("Looking into %s\n" % path)
+ for lib in libs:
+ # get all the libs, then filter for the right library
+ files = glob.glob(os.path.join(path, '%sboost_%s-*.*' % (libprefix, lib)))
+ # check things like libboost_iostreams-gcc-mt-d-1_33_1.a
+ if len(files) > 0:
+ conf.Log("Find boost libraries: %s\n" % files)
+ # runtime code includes s,g,y,d,p,n, where we should look for
+ # d,g,y for debug, s,p,n for release
+ lib_files = []
+ if isDebug:
+ for ver in versions:
+ lib_files += filter(lambda x: re.search('%sboost_%s-\w+-mt-[^spn]+-%s%s' % (libprefix, lib, ver, libsuffix), x), files)
+ else:
+ for ver in versions:
+ lib_files += filter(lambda x: re.search('%sboost_%s-\w+-mt-([^dgy]+-)*%s%s' % (libprefix, lib, ver, libsuffix), x), files)
+ if len(lib_files) == 0:
+ # use alternative libraries
+ for ver in versions:
+ lib_files += filter(lambda x: re.search('%sboost_%s-[\w-]+%s%s' % (libprefix, lib, ver, libsuffix), x), files)
+ if len(lib_files) > 0:
+ # get xxx-gcc-1_33_1 from /usr/local/lib/libboost_xxx-gcc-1_33_1.a
+ name = lib_files[0].split(os.sep)[-1][len(libprefix):]
+ lib_names.append(name.split('.')[0])
+ conf.Log("Qualified libraries: %s\n" % lib_names)
+ else:
+ conf.Log("No qualified library is found.\n")
+ break
+ if len(lib_names) == len(libs):
+ found_lib = True
+ lib_path = path
+ break
+ if not found_lib:
+ if len(lib_names) == 0:
+ conf.Log("No boost library is found\n")
+ else:
+ conf.Log("Found boost libraries: %s\n" % lib_names)
+ conf.Result('no')
+ return (None, None, None)
+ # check version number in boost/version.hpp
+ def isValidBoostDir(dir):
+ version_file = os.path.join(dir, 'boost', 'version.hpp')
+ if not os.path.isfile(version_file):
+ return False
+ version_file_content = open(version_file).read()
+ version_strings = ['#define BOOST_LIB_VERSION "%s"' % ver for ver in versions]
+ return True in [x in version_file_content for x in version_strings]
+ # check for boost header file
+ for path in inc_paths:
+ conf.Log("Checking for inc path: %s\n" % path)
+ if isValidBoostDir(path):
+ inc_path = path
+ found_inc = True
+ else: # check path/boost_1_xx_x/boost
+ dirs = glob.glob(os.path.join(path, 'boost-*'))
+ if len(dirs) > 0 and isValidBoostDir(dirs[0]):
+ conf.Log("Checing for sub directory: %s\n" % dirs[0])
+ inc_path = dirs[0]
+ found_inc = True
+ # return result
+ if found_inc:
+ conf.Result('yes')
+ conf.Log('Using boost libraries %s\n' % (', '.join(lib_names)))
+ return (lib_names, lib_path, inc_path)
+ else:
+ conf.Result('no')
+ return (None, None, None)
+
+
+def checkCommand(conf, cmd):
+ ''' check the existence of a command
+ return full path to the command, or none
+ '''
+ conf.Message('Checking for command %s...' % cmd)
+ res = WhereIs(cmd)
+ conf.Result(res is not None)
+ return res
+
+
+def checkNSIS(conf):
+ ''' check the existence of nsis compiler, return the fullpath '''
+ conf.Message('Checking for nsis compiler...')
+ res = None
+ if can_read_reg:
+ # If we can read the registry, get the NSIS command from it
+ try:
+ k = RegOpenKeyEx(hkey_mod.HKEY_LOCAL_MACHINE,
+ 'SOFTWARE\\NSIS')
+ val, tok = RegQueryValueEx(k,None)
+ ret = val + os.path.sep + 'makensis.exe'
+ if os.path.isfile(ret):
+ res = '"' + ret + '"'
+ else:
+ res = None
+ except:
+ pass # Couldn't find the key, just act like we can't read the registry
+ # Hope it's on the path
+ if res is None:
+ res = WhereIs('makensis.exe')
+ conf.Result(res is not None)
+ return res
+
+
+def checkLC_MESSAGES(conf):
+ ''' check the definition of LC_MESSAGES '''
+ check_LC_MESSAGES = '''
+#include <locale.h>
+int main()
+{
+ return LC_MESSAGES;
+}
+'''
+ conf.Message('Checking for LC_MESSAGES in locale.h... ')
+ ret = conf.TryLink(check_LC_MESSAGES, '.c')
+ conf.Result(ret)
+ return ret
+
+
+def checkIconvConst(conf):
+ ''' check the declaration of iconv '''
+ check_iconv_const = '''
+#include <iconv.h>
+// this declaration will fail when there already exists a non const char**
+// version which returns size_t
+double iconv(iconv_t cd, char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft);
+int main() {
+ return 0;
+}
+'''
+ conf.Message('Checking if the declaration of iconv needs const... ')
+ ret = conf.TryLink(check_iconv_const, '.c')
+ conf.Result(ret)
+ return ret
+
+
+def checkSizeOfWChar(conf):
+ ''' check the size of wchar '''
+ check_sizeof_wchar = '''
+int i[ ( sizeof(wchar_t)==%d ? 1 : -1 ) ];
+int main()
+{
+ return 0;
+}
+'''
+ conf.Message('Checking the size of wchar_t... ')
+ if conf.TryLink(check_sizeof_wchar % 2, '.cpp'):
+ ret = 2
+ elif conf.TryLink(check_sizeof_wchar % 4, '.cpp'):
+ ret = 4
+ else:
+ ret = 0
+ conf.Result(str(ret))
+ return ret
+
+
+def createConfigFile(conf, config_file,
+ config_pre = '', config_post = '',
+ headers = [], functions = [], types = [], libs = [],
+ custom_tests = [], extra_items = []):
+ ''' create a configuration file, with options
+ config_file: which file to create
+ config_pre: first part of the config file
+ config_post: last part of the config file
+ headers: header files to check, in the form of a list of
+ ('file', 'HAVE_FILE', 'c'/'c++')
+ functions: functions to check, in the form of a list of
+ ('func', 'HAVE_func', 'include lines'/None)
+ types: types to check, in the form of a list of
+ ('type', 'HAVE_TYPE', 'includelines'/None)
+ libs: libraries to check, in the form of a list of
+ ('lib', 'HAVE_LIB', 'LIB_NAME'). HAVE_LIB will be set if 'lib' exists,
+ or any of the libs exists if 'lib' is a list of libs.
+ Optionally, user can provide another key LIB_NAME, that will
+ be set to the detected lib (or None otherwise).
+ custom_tests: extra tests to perform, in the form of a list of
+ (test (True/False), 'key', 'desc', 'true config line', 'false config line')
+ If the last two are ignored, '#define key 1' '/*#undef key */'
+ will be used.
+ extra_items: extra configuration lines, in the form of a list of
+ ('config', 'description')
+ Return:
+ The result of each test, as a dictioanry of
+ res['XXX'] = True/False
+ XXX are keys defined in each argument.
+ '''
+ cont = config_pre + '\n'
+ result = {}
+ # add to this string, in appropriate format
+ def configString(lines, desc=''):
+ text = ''
+ if lines.strip() != '':
+ if desc != '':
+ text += '/* ' + desc + ' */\n'
+ text += lines + '\n\n'
+ return text
+ #
+ # headers
+ for header in headers:
+ description = "Define to 1 if you have the <%s> header file." % header[0]
+ if (header[2] == 'c' and conf.CheckCHeader(header[0])) or \
+ (header[2] == 'cxx' and conf.CheckCXXHeader(header[0])):
+ result[header[1]] = 1
+ cont += configString('#define %s 1' % header[1], desc = description)
+ else:
+ result[header[1]] = 0
+ cont += configString('/* #undef %s */' % header[1], desc = description)
+ # functions
+ for func in functions:
+ description = "Define to 1 if you have the `%s' function." % func[0]
+ if conf.CheckFunc(func[0], header=func[2]):
+ result[func[1]] = 1
+ cont += configString('#define %s 1' % func[1], desc = description)
+ else:
+ result[func[1]] = 0
+ cont += configString('/* #undef %s */' % func[1], desc = description)
+ # types
+ for t in types:
+ description = "Define to 1 if you have the `%s' type." % t[0]
+ if conf.CheckType(t[0], includes=t[2]):
+ result[t[1]] = 1
+ cont += configString('#define %s 1' % t[1], desc = description)
+ else:
+ result[t[1]] = 0
+ cont += configString('/* #undef %s */' % t[1], desc = description)
+ # libraries
+ for lib in libs:
+ description = "Define to 1 if you have the `%s' library (-l%s)." % (lib[0], lib[0])
+ if type(lib[0]) is type(''):
+ lib_list = [lib[0]]
+ else:
+ lib_list = lib[0]
+ # check if any of the lib exists
+ result[lib[1]] = 0
+ # if user want the name of the lib detected
+ if len(lib) == 3:
+ result[lib[2]] = None
+ for ll in lib_list:
+ if conf.CheckLib(ll):
+ result[lib[1]] = 1
+ if len(lib) == 3:
+ result[lib[2]] = ll
+ cont += configString('#define %s 1' % lib[1], desc = description)
+ break
+ # if not found
+ if not result[lib[1]]:
+ cont += configString('/* #undef %s */' % lib[1], desc = description)
+ # custom tests
+ for test in custom_tests:
+ if test[0]:
+ result[test[1]] = 1
+ if len(test) == 3:
+ cont += configString('#define %s 1' % test[1], desc = test[2])
+ else:
+ cont += configString(test[3], desc = test[2])
+ else:
+ result[test[1]] = 0
+ if len(test) == 3:
+ cont += configString('/* #undef %s */' % test[1], desc = test[2])
+ else:
+ cont += configString(test[4], desc = test[2])
+ # extra items (no key is returned)
+ for item in extra_items:
+ cont += configString(item[0], desc = item[1])
+ # add the last part
+ cont += '\n' + config_post + '\n'
+ # write to file
+ writeToFile(config_file, cont)
+ return result