summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGwenolé Beauchesne <gbeauchesne@mandriva.org>2005-01-12 17:22:02 +0000
committerGwenolé Beauchesne <gbeauchesne@mandriva.org>2005-01-12 17:22:02 +0000
commitce5c270d5bce8ef9b9ff280338d577483bff03da (patch)
treee0239736b0ea4d11193de48bc1a94cebcf6f95c7
parent3db240e64d3c941d2dcf6c1bce879922b28777d8 (diff)
downloadmultiarch-utils-topic/first-version.tar
multiarch-utils-topic/first-version.tar.gz
multiarch-utils-topic/first-version.tar.bz2
multiarch-utils-topic/first-version.tar.xz
multiarch-utils-topic/first-version.zip
-rwxr-xr-xmkmultiarch58
-rwxr-xr-xmultiarch-dispatch23
-rw-r--r--multiarch-dispatch.h53
3 files changed, 134 insertions, 0 deletions
diff --git a/mkmultiarch b/mkmultiarch
new file mode 100755
index 0000000..8f25e48
--- /dev/null
+++ b/mkmultiarch
@@ -0,0 +1,58 @@
+#!/bin/bash
+#---------------------------------------------------------------
+# Project : Mandrakelinux
+# Module : multiarch-utils
+# File : mkmultiarch
+# Version : $Id$
+# Author : Gwenole Beauchesne
+# Created On : Wed Jan 12 10:54:10 CET 2005
+#---------------------------------------------------------------
+
+usage="Usage: $0 <binaries|includes> <file1> [<file2> ...]"
+mplat=`multiarch-platform`
+type=$1
+case $type in
+ binaries|includes) shift;;
+ *) echo $usage; exit 1;;
+esac
+
+function error() {
+ echo ${1+"$@"} > /dev/stderr
+ exit 1
+}
+
+function dispatch_binaries() {
+ local file=$1
+ local bindir=`dirname $file`
+ local archbindir=$bindir/$mplat
+ [[ -d $archbindir ]] || mkdir -p $archbindir
+ mv $file $archbindir/
+ ln -s /usr/bin/multiarch-dispatch $file
+}
+
+function dispatch_includes() {
+ local file=$1
+ local incdir=`dirname $file`
+ local prefix=`echo $incdir | sed -n '/\(.*\/include\)\/.*/s//\1/p'`
+ [[ -z "$prefix" ]] && error "Unsupported includedir $incdir"
+ local suffix=`echo $incdir | sed -n '/.*\/include\/\(.*\)/s//\1/p'`
+ [[ -n "$suffix" ]] && suffix="$suffix/"
+ # dispatch nested includes expected in local directory
+ sed -n '/^#[ \t]*include[ \t]*"\([^"][^"]*\)".*/s//\1/p' $file | \
+ while read localfile; do
+ [[ -f "$incdir/$localfile" ]] && dispatch_includes $incdir/$localfile
+ done
+ # dispatch selected include file
+ local archincdir=$prefix/$mplat/$suffix
+ [[ -d $archincdir ]] || mkdir -p $archincdir
+ mv $file $archincdir/
+ cat > $file << EOF
+#define _MULTIARCH_HEADER $suffix${file##*/}
+#include <multiarch-dispatch.h>
+EOF
+}
+
+while [[ $# -gt 0 ]]; do
+ dispatch_$type $1
+ shift
+done
diff --git a/multiarch-dispatch b/multiarch-dispatch
new file mode 100755
index 0000000..db98f1d
--- /dev/null
+++ b/multiarch-dispatch
@@ -0,0 +1,23 @@
+#!/bin/sh
+#---------------------------------------------------------------
+# Project : Mandrakelinux
+# Module : multiarch-utils
+# File : multiarch-dispatch
+# Version : $Id$
+# Author : Gwenole Beauchesne
+# Created On : Wed Jan 12 12:38:53 EST 2005
+#---------------------------------------------------------------
+
+if [[ "$0" = "/usr/bin/multiarch-dispatch" ]]; then
+ echo "Helper script to dispatch a binary under a specific personality"
+ exit 0
+fi
+
+bin=`dirname $0`/`multiarch-platform`/${0##*/}
+
+if [[ -x "$bin" ]]; then
+ echo "Cannot execute $bin" > /dev/stderr
+ exit 1
+fi
+
+exec $bin ${1+"$@"}
diff --git a/multiarch-dispatch.h b/multiarch-dispatch.h
new file mode 100644
index 0000000..75f6a50
--- /dev/null
+++ b/multiarch-dispatch.h
@@ -0,0 +1,53 @@
+/* Undefine some built-ins */
+#ifdef linux
+#undef linux
+#define _multiarch_defined_linux
+#endif
+#ifdef i386
+#undef i386
+#define _multiarch_defined_i386
+#endif
+#ifdef sparc
+#undef sparc
+#define _multiarch_defined_sparc
+#endif
+
+/* Dispatch arch dependent header */
+#define _MULTIARCH_MAKE_HEADER(arch,header) <multiarch-arch-linux/header>
+#if defined(__x86_64__)
+#include _MULTIARCH_MAKE_HEADER(x86_64,_MULTIARCH_HEADER)
+#elif defined(__i386__)
+#include _MULTIARCH_MAKE_HEADER(i386,_MULTIARCH_HEADER)
+#elif defined(__powerpc64__)
+#include _MULTIARCH_MAKE_HEADER(ppc64,_MULTIARCH_HEADER)
+#elif defined(__powerpc__)
+#include _MULTIARCH_MAKE_HEADER(ppc,_MULTIARCH_HEADER)
+#elif defined(__sparc_v9__)
+#include _MULTIARCH_MAKE_HEADER(sparc64,_MULTIARCH_HEADER)
+#elif defined(__sparc__)
+#include _MULTIARCH_MAKE_HEADER(sparc,_MULTIARCH_HEADER)
+#elif defined(__s390x__)
+#include _MULTIARCH_MAKE_HEADER(s390x,_MULTIARCH_HEADER)
+#elif defined(__s390__)
+#include _MULTIARCH_MAKE_HEADER(s390,_MULTIARCH_HEADER)
+#elif defined(__ia64__)
+#include _MULTIARCH_MAKE_HEADER(ia64,_MULTIARCH_HEADER)
+#elif defined(__alpha__)
+#include _MULTIARCH_MAKE_HEADER(alpha,_MULTIARCH_HEADER)
+#endif
+#undef _MULTIARCH_MAKE_HEADER
+#undef _MULTIARCH_HEADER
+
+/* Redefine built-ins */
+#ifdef _multiarch_defined_linux
+#undef _multiarch_defined_linux
+#define linux 1
+#endif
+#ifdef _multiarch_defined_i386
+#undef _multiarch_defined_i386
+#define i386 1
+#endif
+#ifdef _multiarch_defined_sparc
+#undef _multiarch_defined_sparc
+#define sparc 1
+#endif