[rtems-tools commit] Add support to cross-compile. Use --hosti=.

Chris Johns chrisj at rtems.org
Sun Jan 18 07:14:03 UTC 2015


Module:    rtems-tools
Branch:    master
Commit:    3badbb06227a0f42bb2b23b2f287bd8d403ad2d7
Changeset: http://git.rtems.org/rtems-tools/commit/?id=3badbb06227a0f42bb2b23b2f287bd8d403ad2d7

Author:    Chris Johns <chrisj at rtems.org>
Date:      Sun Jan 18 18:12:18 2015 +1100

Add support to cross-compile. Use --hosti=.

On FreeBSD use --host=mingw32 for Windows. If you use another
OS you might need to add the specific windows host to the
top level wscript file.

---

 linkers/wscript                             |  2 ++
 {linkers => rtemstoolkit}/win32/ar.h        |  0
 {linkers => rtemstoolkit}/win32/sys/cdefs.h |  0
 {linkers => rtemstoolkit}/win32/sys/errno.h |  0
 {linkers => rtemstoolkit}/win32/sys/mman.h  |  0
 {linkers => rtemstoolkit}/win32/sys/queue.h |  0
 rtemstoolkit/wscript                        | 15 +++++++++------
 wscript                                     | 27 +++++++++++++++++++++++++++
 8 files changed, 38 insertions(+), 6 deletions(-)

diff --git a/linkers/wscript b/linkers/wscript
index 6cfbedb..d48ce47 100644
--- a/linkers/wscript
+++ b/linkers/wscript
@@ -41,6 +41,8 @@ def build(bld):
                         rtemstoolkit + '/elftoolchain/libelf',
                         rtemstoolkit + '/elftoolchain/common',
                         rtemstoolkit + '/libiberty']
+    if bld.env.DEST_OS == 'win32':
+        conf['includes'] += [rtemstoolkit + '/win32']
     conf['warningflags'] = ['-Wall', '-Wextra', '-pedantic']
     conf['optflags'] = bld.env.C_OPTS
     conf['cflags'] = ['-pipe', '-g'] + conf['optflags']
diff --git a/linkers/win32/ar.h b/rtemstoolkit/win32/ar.h
similarity index 100%
rename from linkers/win32/ar.h
rename to rtemstoolkit/win32/ar.h
diff --git a/linkers/win32/sys/cdefs.h b/rtemstoolkit/win32/sys/cdefs.h
similarity index 100%
rename from linkers/win32/sys/cdefs.h
rename to rtemstoolkit/win32/sys/cdefs.h
diff --git a/linkers/win32/sys/errno.h b/rtemstoolkit/win32/sys/errno.h
similarity index 100%
rename from linkers/win32/sys/errno.h
rename to rtemstoolkit/win32/sys/errno.h
diff --git a/linkers/win32/sys/mman.h b/rtemstoolkit/win32/sys/mman.h
similarity index 100%
rename from linkers/win32/sys/mman.h
rename to rtemstoolkit/win32/sys/mman.h
diff --git a/linkers/win32/sys/queue.h b/rtemstoolkit/win32/sys/queue.h
similarity index 100%
rename from linkers/win32/sys/queue.h
rename to rtemstoolkit/win32/sys/queue.h
diff --git a/rtemstoolkit/wscript b/rtemstoolkit/wscript
index 544321a..5658dc5 100644
--- a/rtemstoolkit/wscript
+++ b/rtemstoolkit/wscript
@@ -38,7 +38,7 @@ def build(bld):
     # The include paths.
     #
     conf['includes'] = ['elftoolchain/libelf', 'elftoolchain/common', 'libiberty']
-    if sys.platform == 'win32':
+    if bld.env.DEST_OS == 'win32':
         conf['includes'] += ['win32']
 
     #
@@ -122,9 +122,11 @@ def bld_libelf(bld, conf):
     #
     if sys.platform == 'win32':
         m4_rule = 'type ${SRC} | m4 -D SRCDIR=../rtemstoolkit/' + libelf[:-1] + '> ${TGT}"'
-        includes = ['win32']
     else:
         m4_rule = 'm4 -D SRCDIR=../rtemstoolkit/' + libelf[:-1] + ' ${SRC} > ${TGT}'
+    if bld.env.DEST_OS == 'win32':
+        includes = ['win32']
+    else:
         includes = []
 
     bld(target = 'libelf_convert.c', source = libelf + 'libelf_convert.m4', rule = m4_rule)
@@ -133,21 +135,22 @@ def bld_libelf(bld, conf):
 
     host_source = []
 
-    if sys.platform == 'linux2':
+    if bld.env.DEST_OS == 'linux2':
         common = 'elftoolchain/common/'
         bld(target = common + 'native-elf-format.h',
             source = common + 'native-elf-format',
             name = 'native-elf-format',
             rule   = './${SRC} > ${TGT}')
         bld.add_group ()
-    elif sys.platform == 'win32':
+    elif bld.env.DEST_OS == 'win32':
         host_source += [libelf + 'mmap_win32.c']
 
     bld.stlib(target = 'elf',
               features = 'c',
               install_path = None,
               uses = ['native-elf-format'],
-              includes = [bld.bldnode.abspath(), 'elftoolchain/libelf', 'elftoolchain/common'] + includes,
+              includes = [bld.bldnode.abspath(),
+                          'elftoolchain/libelf', 'elftoolchain/common'] + includes,
               cflags = conf['cflags'],
               source =[libelf + 'elf.c',
                        libelf + 'elf_begin.c',
@@ -230,7 +233,7 @@ def conf_libiberty(conf):
     conf.write_config_header('libiberty/config.h')
 
 def bld_libiberty(bld, conf):
-    if sys.platform == 'win32':
+    if bld.env.DEST_OS == 'win32':
         pex_host = 'libiberty/pex-win32.c'
     else:
         pex_host = 'libiberty/pex-unix.c'
diff --git a/wscript b/wscript
index edfa91f..e289858 100644
--- a/wscript
+++ b/wscript
@@ -46,8 +46,24 @@ def options(ctx):
                    default = '-O2',
                    dest='c_opts',
                    help = 'Set build options, default: -O2.')
+    ctx.add_option('--host',
+                   default = 'native',
+                   dest='host',
+                   help = 'Set host to build for, default: none.')
     recurse(ctx)
 
+def init(ctx):
+    try:
+        import waflib.Options
+        import waflib.ConfigSet
+        env = waflib.ConfigSet.ConfigSet()
+        env.load(waflib.Options.lockfile)
+        check_options(ctx, env.options['host'])
+        for sd in subdirs:
+            ctx.recurse(sd)
+    except:
+        pass
+
 def configure(ctx):
     try:
         ctx.load("doxygen", tooldir = 'waf-tools')
@@ -55,6 +71,7 @@ def configure(ctx):
         pass
     ctx.env.C_OPTS = ctx.options.c_opts.split(',')
     ctx.env.RTEMS_VERSION = ctx.options.rtems_version
+    check_options(ctx, ctx.options.host)
     recurse(ctx)
 
 def build(ctx):
@@ -70,6 +87,16 @@ def rebuild(ctx):
     import waflib.Options
     waflib.Options.commands.extend(['clean', 'build'])
 
+def check_options(ctx, host):
+    if host in ['mingw32']:
+        ctx.env.HOST = host
+        ctx.env.CC = '%s-gcc' % (host)
+        ctx.env.CXX = '%s-g++' % (host)
+        ctx.env.AR = '%s-ar' % (host)
+        ctx.env.PYTHON = 'python'
+    elif host is not 'native':
+        ctx.fatal('unknown host: %s' % (host));
+
 #
 # The doxy command.
 #




More information about the vc mailing list