From 087a579450d29553f1a133ef4d06f13026778cf4 Mon Sep 17 00:00:00 2001 From: Christian Dywan Date: Thu, 9 Jul 2009 18:55:41 +0100 Subject: [PATCH] Create Win32 icon and resorce and build it into the executable --- data/midori.rc | 2 ++ midori/wscript_build | 2 ++ wscript | 50 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+) create mode 100644 data/midori.rc diff --git a/data/midori.rc b/data/midori.rc new file mode 100644 index 00000000..b1f1556b --- /dev/null +++ b/data/midori.rc @@ -0,0 +1,2 @@ + +IDR_MAINFRAME ICON DISCARDABLE "../_build_/default/data/midori.ico" diff --git a/midori/wscript_build b/midori/wscript_build index 170ad3b6..6e7836f5 100644 --- a/midori/wscript_build +++ b/midori/wscript_build @@ -27,5 +27,7 @@ obj = bld.new_task_gen ('cc', 'program') obj.target = 'midori' obj.includes = '. .. ../panels' obj.source = 'main.c' +if bld.env['WINRC']: + obj.source += ' ../data/midori.rc' obj.uselib = 'UNIQUE LIBSOUP GMODULE GTHREAD GIO GTK SQLITE WEBKIT LIBXML' obj.uselib_local = 'panels' diff --git a/wscript b/wscript index c7358b99..58cef4fa 100644 --- a/wscript +++ b/wscript @@ -19,6 +19,9 @@ import Utils import pproc as subprocess import os import UnitTest +import Task +from TaskGen import extension +import misc major = 0 minor = 1 @@ -52,6 +55,16 @@ def is_mingw (env): return cc.find ('mingw') != -1# or cc.find ('wine') != -1 return False +# Compile Win32 res files to (resource) object files +@extension ('.rc') +def rc_file(self, node): + rctask = self.create_task ('winrc') + rctask.set_inputs (node) + rctask.set_outputs (node.change_ext ('.rc.o')) + self.compiled_tasks.append (rctask) +Task.simple_task_type ('winrc', '${WINRC} -o${TGT} ${SRC}', color='BLUE', + before='cc cxx', shell=False) + def configure (conf): def option_checkfatal (option, desc): if hasattr (Options.options, 'enable_' + option): @@ -96,10 +109,17 @@ def configure (conf): nls = 'no ' conf.define ('ENABLE_NLS', [0,1][nls == 'yes']) + if is_mingw (conf.env) or Options.platform == 'win32': + if not conf.find_program ('convert', var='CONVERT'): + Utils.pprint ('YELLOW', 'midori.ico won\'t be created') + conf.find_program ('windres', var='WINRC') + # This is specific to cross compiling with mingw if is_mingw (conf.env) and Options.platform != 'win32': if not 'AR' in os.environ and not 'RANLIB' in os.environ: conf.env['AR'] = os.environ['CC'][:-3] + 'ar' + if conf.find_program (os.environ['CC'][:-3] + 'windres', var='WINRC'): + os.environ['WINRC'] = os.environ['CC'][:-3] + 'windres' Options.platform = 'win32' # Make sure we don't have -fPIC in the CCFLAGS conf.env["shlib_CCFLAGS"] = [] @@ -112,6 +132,9 @@ def configure (conf): Utils.pprint ('BLUE', 'Mingw recognized, assuming cross compile.') + if conf.env['CONVERT'] and not conf.env['WINRC']: + Utils.pprint ('YELLOW', 'midori.ico won\'t be created') + dirname_default ('LIBDIR', os.path.join (conf.env['PREFIX'], 'lib')) if conf.env['PREFIX'] == '/usr': dirname_default ('SYSCONFDIR', '/etc') @@ -314,6 +337,33 @@ def set_options (opt): add_enable_option ('hildon', 'Maemo integration', group, disable=not is_maemo ()) def build (bld): + def image_to_win32ico (task): + 'Converts an image to a Win32 ico' + + if not os.path.exists (bld.env['CONVERT']): + return 1 + + infile = task.inputs[0].abspath (task.env) + outfile = task.outputs[0].abspath (task.env) + command = bld.env['CONVERT'] + ' -background transparent \ + -geometry 32x32 -extent 32x32 ' + \ + infile + ' ' + outfile + if Utils.exec_command (command): + return 1 + + if task.chmod: + os.chmod (outfile, task.chmod) + return 0 + + if bld.env['WINRC']: + obj = bld.new_task_gen ('copy', + fun = image_to_win32ico, + source = 'icons/scalable/midori.svg', + target = 'data/midori.ico', + before = 'cc') + + bld.add_group () + bld.add_subdirs ('katze midori icons') if bld.env['addons']: