]> git.lyx.org Git - lyx.git/blobdiff - development/scons/SConstruct
fix bug 3154
[lyx.git] / development / scons / SConstruct
index d1f9d5a16bf5f7a3b1dc65736d9913d1e42c468f..e6dc0ce7535bf22e85bda94dabb18ca710bc8fd5 100644 (file)
@@ -189,6 +189,8 @@ opts.AddOptions(
         comp1,comp2,...: rebuild specified targets''', None),
     # can be set to a non-existing directory
     ('prefix', 'install architecture-independent files in PREFIX', default_prefix),
+    # replace the default name and location of the windows installer
+    ('win_installer', 'name or full path to the windows installer', None),
     # build directory, will use $mode if not set
     ('build_dir', 'Build directory', None),
     # version suffix
@@ -419,6 +421,10 @@ if platform_name == 'win32':
     else:
         env.Tool('mingw')
         env.AppendUnique(CPPPATH = ['#c:/MinGW/include'])
+        # fix a scons winres bug (there is a missing space between ${RCINCPREFIX} and ${SOURCE.dir}
+        # in version 0.96.93
+        env['RCCOM'] = '$RC $_CPPDEFFLAGS $RCINCFLAGS ${RCINCPREFIX} ${SOURCE.dir} $RCFLAGS -i $SOURCE -o $TARGET'
+    
 
 # we differentiate between hard-coded options and default options
 # hard-coded options are required and will always be there
@@ -586,6 +592,7 @@ conf = Configure(env,
         'CheckSelectArgType' : utils.checkSelectArgType,
         'CheckBoostLibraries' : utils.checkBoostLibraries,
         'CheckCommand' : utils.checkCommand,
+        'CheckNSIS' : utils.checkNSIS,
         'CheckCXXGlobalCstd' : utils.checkCXXGlobalCstd,
         'CheckLC_MESSAGES' : utils.checkLC_MESSAGES,
         'CheckIconvConst' : utils.checkIconvConst,
@@ -704,6 +711,10 @@ else:
 # check for msgfmt command
 env['MSGFMT'] = conf.CheckCommand('msgfmt')
 
+# if under windows, check the nsis compiler
+if platform_name == 'win32':
+    env['NSIS'] = conf.CheckNSIS()
+
 # cygwin packaging requires the binaries to be stripped
 if platform_name == 'cygwin':
     env['STRIP'] = conf.CheckCommand('strip')
@@ -1319,7 +1330,7 @@ if frontend == 'qt4':
     if not succ:
         # Under linux, I can test the following perfectly
         # Under windows, lib names need to passed as libXXX4.a ...
-        if platform_name == 'win32' and use_vc:
+        if platform_name == 'win32':
             succ = conf.CheckLibWithHeader('QtCore4', 'QtGui/QApplication', 'c++', 'QApplication qapp();')
         else:
             succ = conf.CheckLibWithHeader('QtCore', 'QtGui/QApplication', 'c++', 'QApplication qapp();')
@@ -1371,18 +1382,6 @@ if frontend == 'qt4':
 
     frontend_env = conf.Finish()
 
-if os.name == 'nt':
-    # if under windows, create an rc file
-    rc_file = frontend_env.File('$BUILDDIR/lyx.rc').abspath
-    rc = open(rc_file, 'w')
-    print >> rc, 'IDI_ICON1  ICON DISCARDABLE "%s"' % \
-        os.path.join(frontend_env.Dir('$TOP_SRCDIR').abspath, 'development', 'win32',
-            'packaging', 'icons', 'lyx_32x32.ico')
-    rc.close()
-    frontend_env['ICON_RES'] = frontend_env.RES(rc_file)
-else:
-    frontend_end['ICON_RES'] = []
-
 #
 # Report results
 #
@@ -1487,8 +1486,9 @@ def appExists(apppath, appname):
     return os.path.isfile(File(env.subst('$BUILDDIR/common/%s/${PROGPREFIX}%s$PROGSUFFIX' % (apppath, appname))).abspath)
 
 targets = BUILD_TARGETS
+build_installer = 'installer' in targets
 # msvc need to pass full target name, so I have to look for path/lyx etc
-build_lyx = targets == [] or True in ['lyx' in x for x in targets] \
+build_lyx = build_installer or targets == [] or True in ['lyx' in x for x in targets] \
     or 'install' in targets or 'all' in targets
 build_boost = (included_boost and not libExists('boost_regex')) or 'boost' in targets
 build_intl = (included_gettext and not libExists('included_intl')) or 'intl' in targets
@@ -1499,9 +1499,9 @@ build_frontends = build_lyx or 'frontends' in targets
 build_graphics = build_lyx or 'graphics' in targets
 build_controllers = build_lyx or 'controllers' in targets
 build_client = True in ['client' in x for x in targets] \
-    or 'install' in targets or 'all' in targets
+    or 'install' in targets or 'all' in targets or build_installer
 build_tex2lyx = True in ['tex2lyx' in x for x in targets] \
-    or 'install' in targets or 'all' in targets
+    or 'install' in targets or 'all' in targets or build_installer
 build_lyxbase = build_lyx or 'lyxbase' in targets
 build_po = 'po' in targets or 'install' in targets or 'all' in targets
 build_qt4 = (build_lyx and frontend == 'qt4') or 'qt4' in targets
@@ -1759,7 +1759,7 @@ if build_client:
             LIBS = ['support'] + intl_libs + system_libs +
                 socket_libs + boost_libraries + qtcore_lib,
             source = ['$BUILDDIR/common/client/%s' % x for x in src_client_files] + \
-                frontend_env['ICON_RES']
+                utils.createResFromIcon(frontend_env, 'lyx_32x32.ico', '$LOCALLIBPATH/client.rc')
         )
         Alias('client', frontend_env.Command(os.path.join('$BUILDDIR', os.path.split(str(client[0]))[1]),
             client, [Copy('$TARGET', '$SOURCE')]))
@@ -1790,7 +1790,7 @@ if build_tex2lyx:
         target = '$BUILDDIR/common/tex2lyx/tex2lyx',
         LIBS = ['support'] + boost_libraries + intl_libs + system_libs + qtcore_lib,
         source = ['$BUILDDIR/common/tex2lyx/%s' % x for x in src_tex2lyx_files] + \
-            frontend_env['ICON_RES'],
+            utils.createResFromIcon(frontend_env, 'lyx_32x32.ico', '$LOCALLIBPATH/tex2lyx.rc'),
         CPPPATH = ['$BUILDDIR/common/tex2lyx', '$CPPPATH'],
         LIBPATH = ['#$LOCALLIBPATH', '$LIBPATH'],
     )
@@ -1838,7 +1838,8 @@ if build_lyx:
     #
     lyx = frontend_env.Program(
         target = '$BUILDDIR/lyx',
-        source = ['$BUILDDIR/common/main.C'] + frontend_env['ICON_RES'],
+        source = ['$BUILDDIR/common/main.C'] + \
+            utils.createResFromIcon(frontend_env, 'lyx_32x32.ico', '$LOCALLIBPATH/lyx.rc'),
         LIBS = [
             'lyxbase_pre',
             'mathed',
@@ -1996,6 +1997,49 @@ if build_po:
                 gmo_files.extend(env.Transfiles(f))
 
 
+if build_installer:
+    #
+    # build windows installer using NSIS
+    #
+    # NOTE:
+    # There is a nsis builder on scons wiki but it does not work with
+    # our lyx.nsi because it does not dig through all the include directives
+    # and find the dependencies automatically. Also, it can not parse
+    # OutFile in lyx.nsi since it is defined as SETUP_EXE which is in turn
+    # something rely on date.
+    # Because of this, I am doing a simple nsis builder here.
+    if platform_name != 'win32':
+        print 'installer target is only available for windows platform'
+        Exit(1)
+    if env.has_key('NSIS') and env['NSIS'] is not None:
+        # create a builder to strip and install
+        env['BUILDERS']['installer'] = Builder(generator=utils.env_nsis)
+    else:
+        print 'No nsis compiler is found. Existing...'
+        Exit(2)
+    if not env.has_key('win_installer') or env['win_installer'] is None:
+        if devel_version:
+            env['win_installer'] = '%s-%s-%s-Installer.exe' % (package_name, package_version, time.strftime('%Y-%m-%d'))
+        else:
+            env['win_installer'] = '%s-%s-Installer.exe' % (package_name, package_version)
+    # if absolute path is given, use it, otherwise, write to current directory
+    if not (':' in env['win_installer'] or '/' in env['win_installer'] or '\\' in env['win_installer']):
+        env['win_installer'] = os.path.join(env.Dir('$BUILDDIR').abspath, env['win_installer'])
+    env.Append(NSISDEFINES={'ExeFile':env['win_installer']})
+    installer = env.installer(env['win_installer'],
+        '$TOP_SRCDIR/development/Win32/packaging/installer/lyx.nsi')
+    # since I can not use a scanner, explicit dependent is required
+    env.Depends(installer, [lyx, tex2lyx] + \
+        ['$TOP_SRCDIR/development/Win32/packaging/installer/%s' % x for x in win32_packaging_installer_files] + \
+        ['$TOP_SRCDIR/development/Win32/packaging/installer/components/%s' % x for x in win32_packaging_installer_components_files] + \
+        ['$TOP_SRCDIR/development/Win32/packaging/installer/dialogs/%s' % x for x in win32_packaging_installer_dialogs_files] + \
+        ['$TOP_SRCDIR/development/Win32/packaging/installer/graphics/%s' % x for x in win32_packaging_installer_graphics_files] + \
+        ['$TOP_SRCDIR/development/Win32/packaging/installer/include/%s' % x for x in win32_packaging_installer_include_files] + \
+        ['$TOP_SRCDIR/development/Win32/packaging/installer/lang/%s' % x for x in win32_packaging_installer_lang_files ]
+    )
+    frontend_env.Alias('installer', installer)
+
+
 if 'install' in targets:
     #
     # this part is a bit messy right now. Since scons will provide