]> git.lyx.org Git - lyx.git/blobdiff - development/scons/scons_utils.py
Rename files under src/tex2lyx
[lyx.git] / development / scons / scons_utils.py
index 1a200f0186abfd02d81ea783fe63a2c1c43c09a3..bb924cafc86d2c5248871278c0a04b4c020301f6 100644 (file)
@@ -13,7 +13,7 @@
 #
 
 import os, sys, re, shutil, glob
-from SCons.Util import WhereIs
+from SCons.Util import *
 
 
 def getVerFromConfigure(path):
@@ -76,14 +76,64 @@ def env_subst(target, source, env):
     #os.chmod(str(target[0]), stat.S_IMODE(st[stat.ST_MODE]) | stat.S_IWRITE)
 
 
+def env_nsis(source, target, env, for_signature):
+    ''' Get nsis command line '''
+    def quoteIfSpaced(str):
+        if ' ' in str:
+            return '"' + str + '"'
+        else:
+            return str
+    ret = env['NSIS'] + " /V1 "
+    if env.has_key('NSISFLAGS'):
+        for flag in env['NSISFLAGS']:
+            ret += flag
+            ret += ' '
+    if env.has_key('NSISDEFINES'):
+        for d in env['NSISDEFINES']:
+            ret += '/D'+d
+            if env['NSISDEFINES'][d]:
+                ret += '=' + quoteIfSpaced(env['NSISDEFINES'][d])
+            ret += ' '
+    # bundled?
+    if '-bundle.exe' in str(target[0]):
+        ret += '/DSETUPTYPE_BUNDLE=1 '
+    for s in source:
+        ret += quoteIfSpaced(str(s))
+    return ret
+
+
+def env_toc(target, source, env):
+    '''Generate target from source files'''
+    # this is very tricky because we need to use installed lyx2lyx with 
+    # correct lyx2lyx_version.py
+    sys.path.append(env['LYX2LYX_DEST'])
+    sys.path.append(env.Dir('$TOP_SRCDIR/lib/doc').abspath)
+    import doc_toc
+    # build toc
+    doc_toc.build_toc(str(target[0]), [file.abspath for file in source])
+    
+    
+def env_cat(target, source, env):
+    '''Cat source > target. Avoid pipe to increase portability'''
+    output = open(env.File(target[0]).abspath, 'w')
+    for src in source:
+        input = open(env.File(src).abspath)
+        output.write(input.read())
+        input.close()
+    output.close()
+
+
 def createResFromIcon(env, icon_file, rc_file):
     ''' create a rc file with icon, and return res file (windows only) '''
     if os.name == 'nt':
         rc_name = env.File(rc_file).abspath
+        dir = os.path.split(rc_name)[0]
+        if not os.path.isdir(dir):
+            os.makedirs(dir)
         rc = open(rc_name, 'w')
         print >> rc, 'IDI_ICON1  ICON DISCARDABLE "%s"' % \
             os.path.join(env.Dir('$TOP_SRCDIR').abspath, 'development', 'win32',
-                'packaging', 'icons', icon_file)
+                'packaging', 'icons', icon_file).replace('\\', '\\\\')
         rc.close()
         return env.RES(rc_name)
     else:
@@ -130,7 +180,7 @@ int main()
 
 
 def checkCXXGlobalCstd(conf):
-    ''' Check the use of std::tolower or tolower '''
+    ''' Checking the use of std::tolower or tolower '''
     check_global_cstd_source = '''
 #include <cctype>
 using std::tolower;
@@ -139,7 +189,7 @@ int main()
     return 0;
 }
 '''
-    conf.Message('Check for the use of global cstd... ')
+    conf.Message('Checking for the use of global cstd... ')
     ret = conf.TryLink(check_global_cstd_source, '.c')
     conf.Result(ret)
     return ret
@@ -268,6 +318,30 @@ def checkCommand(conf, cmd):
     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 = '''
@@ -277,7 +351,7 @@ int main()
     return LC_MESSAGES;
 }
 '''
-    conf.Message('Check for LC_MESSAGES in locale.h... ')
+    conf.Message('Checking for LC_MESSAGES in locale.h... ')
     ret = conf.TryLink(check_LC_MESSAGES, '.c')
     conf.Result(ret)
     return ret
@@ -294,7 +368,7 @@ int main() {
     return 0; 
 }
 '''
-    conf.Message('Check if the declaration of iconv needs const... ')
+    conf.Message('Checking if the declaration of iconv needs const... ')
     ret = conf.TryLink(check_iconv_const, '.c')
     conf.Result(ret)
     return ret
@@ -309,7 +383,7 @@ int main()
     return 0;
 }
 '''
-    conf.Message('Check the size of wchar_t... ')
+    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'):
@@ -650,7 +724,7 @@ def installCygwinPostinstallScript(path):
     ''' Install lyx.sh '''
     postinstall_script = os.path.join(path, 'lyx.sh')
     script = open(postinstall_script, 'w')
-    script.write('''#!/bin/sh
+    script.write(r'''#!/bin/sh
 
 # Add /usr/share/lyx/fonts to /etc/fonts/local.conf
 # if it is not already there.