]> git.lyx.org Git - lyx.git/blobdiff - development/scons/scons_utils.py
Scons: msvc command line support.
[lyx.git] / development / scons / scons_utils.py
index 6cb37c670e8c33b69bb23a254c975a5cadf0a019..164b8f30cfea80af1927237ccd74675346fce541 100644 (file)
 # 
 
 import os, sys, re, shutil, glob
+from SCons.Util import WhereIs
 
 config_h = os.path.join('src', 'config.h')
+config_content = ''
 
 def writeToFile(filename, lines, append = False):
   " utility function: write or append lines to filename "
@@ -26,14 +28,6 @@ def writeToFile(filename, lines, append = False):
   file.close()
 
 
-def addToConfig(lines, top_src_dir):
-  ''' utility function: shortcut for appending lines to outfile
-    add newline at the end of lines.
-  '''
-  if lines.strip() != '':
-    writeToFile(os.path.join(top_src_dir, config_h), lines + '\n\n', append = True)
-
-
 def printEnvironment(env, keys=[]):
   ''' used to check profile settings '''
   dict = env.Dictionary()
@@ -60,21 +54,32 @@ def env_subst(target, source, env):
   source_file = file(str(source[0]), "r")
   
   contents = source_file.read()
-  for k in env.get('SUBST_KEYS', []):
-    if not env.has_key(k):
-      print "Failed to subst key ", k, " from file", str(source[0])
-      raise
-    contents = re.sub('@'+k+'@', env.subst('$'+k).replace('\n',r'\\n\\\n'), contents)
+  for k, v in env.items():
+    try:
+      val = env.subst('$'+k)
+      # temporary fix for the \Resource backslash problem
+      val = val.replace('\\', '/')
+      # multi-line replacement
+      val = val.replace('\n',r'\\n\\\n')
+      contents = re.sub('@'+k+'@', val, contents)
+      contents = re.sub('%'+k+'%', val, contents)
+    except:
+      pass
   target_file.write(contents + "\n")
   target_file.close()
   #st = os.stat(str(source[0]))
   #os.chmod(str(target[0]), stat.S_IMODE(st[stat.ST_MODE]) | stat.S_IWRITE)
 
-
-def env_filecopy(target, source, env):
-  ''' target can be a directory '''
-  shutil.copy(str(source[0]), str(target[0]))
-
+#
+# glob filenames
+#
+def globSource(dir, pattern, build_dir=None, exclude=[], include=[]):
+  ''' glob files, in dir and use build_dir as returned path name '''
+  files = filter(lambda x: x not in exclude, glob.glob1(dir, pattern)) + include
+  if build_dir is None:
+    return files
+  else:
+    return ['%s/%s' % (build_dir, x) for x in files]
 
 #
 # autoconf tests
@@ -96,10 +101,10 @@ def checkPackage(conf, pkg):
   return ret
 
 
-def startConfigH(top_src_dir):
+def startConfigH():
   ''' Write the first part of config.h '''
-  writeToFile(os.path.join(top_src_dir, config_h), 
-'''/* src/config.h.  Generated by scon.  */
+  global config_content
+  config_content = '''/* src/config.h.  Generated by scon.  */
 
 /* -*- C++ -*- */
 /*
@@ -115,13 +120,23 @@ def startConfigH(top_src_dir):
 
 #ifndef _CONFIG_H
 #define _CONFIG_H
-''')
+'''
+
+
+def addToConfig(lines, newline=2):
+  ''' utility function: shortcut for appending lines to outfile
+    add newline at the end of lines.
+  '''
+  global config_content
+  if lines.strip() != '':
+    config_content += lines + '\n'*newline
 
 
 def endConfigH(top_src_dir):
   ''' Write the last part of config.h '''
-  writeToFile(os.path.join(top_src_dir, config_h), '''
-/************************************************************
+  global config_content
+  writeToFile(os.path.join(top_src_dir, config_h), config_content + 
+'''/************************************************************
  ** You should not need to change anything beyond this point */
 
 #ifndef HAVE_STRERROR
@@ -166,40 +181,7 @@ int mkstemp(char*);
 #endif
 
 #endif
-''', append=True)
-
-
-#HAVE_PUTENV
-def checkPutenv(conf):
-  check_putenv_source = """
-#include <stdlib.h>
-int main()
-{
-  putenv("");
-  return(0);
-}
-"""
-  conf.Message('Checking for putenv... ')
-  ret = conf.TryLink(check_putenv_source, '.c')
-  conf.Result(ret)
-  return ret
-
-
-#HAVE_DECL_ISTREAMBUF_ITERATOR
-def checkIstreambufIterator(conf):
-  check_istreambuf_iterator_source = """
-#include <streambuf> 
-#include <istream>
-int main()
-{
-  std::istreambuf_iterator<std::istream> iter;
-  return 0;
-}
-"""
-  conf.Message('Checking for iostreambuf::iterator... ')
-  ret = conf.TryLink(check_istreambuf_iterator_source, '.cpp')
-  conf.Result(ret)
-  return ret
+''')
 
 
 #MKDIR_TAKES_ONE_ARG
@@ -212,7 +194,9 @@ int main()
 }
 """
   conf.Message('Checking for the number of args for mkdir... ')
-  ret = conf.TryLink(check_mkdir_one_arg_source, '.c')
+  ret = conf.TryLink(check_mkdir_one_arg_source, '.c') or \
+    conf.TryLink('#include <unistd.h>' + check_mkdir_one_arg_source, '.c') or \
+    conf.TryLink('#include <direct.h>' + check_mkdir_one_arg_source, '.c')
   if ret:
     conf.Result('one')
   else:
@@ -220,24 +204,19 @@ int main()
   return ret
 
 
-#HAVE_STD_COUNT
-def checkStdCount(conf):
-  check_std_count_source = """
-#include <algorithm>
-using std::count;
-int countChar(char * b, char * e, char const c)
-{
-  return count(b, e, c);
-}
-
+# CXX_GLOBAL_CSTD
+def checkCXXGlobalCstd(conf):
+  ''' Check the use of std::tolower or tolower '''
+  check_global_cstd_source = '''
+#include <cctype>
+using std::tolower;
 int main()
 {
-  char a[] = "hello";
-  int i = countChar(a, a + 5, 'l');
+  return 0;
 }
-"""
-  conf.Message('Checking for std::count... ')
-  ret = conf.TryLink(check_std_count_source, '.cpp')
+'''
+  conf.Message('Check for the use of global cstd... ')
+  ret = conf.TryLink(check_global_cstd_source, '.c')
   conf.Result(ret)
   return ret
 
@@ -292,15 +271,14 @@ def checkBoostLibraries(conf, lib, pathes):
   return ('','')
 
 
-def checkMsgFmt(conf):
-  ''' check the existence of command msgfmt '''
-  conf.Message('Checking for gettext command msgfmt...')
-  res = conf.TryAction('msgfmt --help')
-  conf.Result(res[0])
-  if res[0]:
-    return 'msgfmt'
-  else:
-    return 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 installCygwinLDScript(path):