Skip to contentSkip to conversation

Make tools cross-friendly

PATCH New Aron Griffis 3 participants 8 messages Jan 19, 2008 – Jan 21, 2008

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Make tools cross-friendly

Hi,

With these patches I'm able to cross-build all of xen-unstable.hg, using the same line that has previously worked only for the hypervisor and kernel:

make -j1 XEN_TARGET_ARCH=ia64 CROSS_COMPILE=ia64-linux-gnu-

In order to make this work, the sys-root containing the include files and libraries should be mounted on, for example, /usr/ia64-linux-gnu/sys-root/

I intend to post a howto on the wiki for building xen/ia64 on fedora8/x86_64, including the rpms and a sys-root image. It should be trivially adaptable to other architectures. I'm hoping that this procedure will make it easier to avoid accidental breakages by making it relatively easy to test builds for alternative architectures.

Thanks,
Aron

17 files changed, 160 insertions(+), 224 deletions(-)
tools/Makefile                  |   15 +++++-
tools/check/check_brctl         |   24 ++---------
tools/check/check_crypto_lib    |   20 +--------
tools/check/check_curl          |   41 +++---------------
tools/check/check_iproute       |   25 +++--------
tools/check/check_openssl_devel |   12 -----
tools/check/check_python        |   11 -----
tools/check/check_python_devel  |   11 -----
tools/check/check_python_xml    |    9 +---
tools/check/check_udev          |   31 +++-----------
tools/check/check_x11_devel     |   15 +-----
tools/check/check_xgettext      |   12 -----
tools/check/check_xml2          |   34 ++-------------
tools/check/check_zlib_devel    |   12 -----
tools/check/check_zlib_lib      |   18 +-------
tools/check/chk                 |    9 +---
tools/check/funcs.sh            |   85 +++++++++++++++++++++++++++++++++++++++
#1 lore raw

PATCH 1/1 Make tools/Makefile cross-friendly

# HG changeset patch
# User Aron Griffis <[email protected]>
# Date 1200715193 18000
# Node ID 79cf8ffbc6678f201d35724bf083ea9749818597 # Parent ff90abf572f2d5aa7d4a7f764b3c343b66a06210 Make tools/Makefile cross-friendly

Pass Xen cross-compilation options through to ioemu. Export CROSS_SYS_ROOT for use by scripts. Unexport IOEMU_DIR since it isn't used outside of the Makefile.

tools/Makefile +13 -2
diff -r ff90abf572f2 -r 79cf8ffbc667 tools/Makefile
@@ -26,6 +26,12 @@ ifeq ($(XEN_COMPILE_ARCH),$(XEN_TARGET_A
 ifeq ($(XEN_COMPILE_ARCH),$(XEN_TARGET_ARCH))
 SUBDIRS-$(PYTHON_TOOLS) += python
 SUBDIRS-$(PYTHON_TOOLS) += pygrub
+endif
+
+# For the sake of linking, set the sys-root
+ifneq ($(CROSS_COMPILE),)
+CROSS_SYS_ROOT ?= /usr/$(CROSS_COMPILE:-=)/sys-root
+export CROSS_SYS_ROOT
 endif
 
 .PHONY: all
@@ -65,10 +71,15 @@ check_clean:
 
 .PHONY: ioemu ioemuinstall ioemuclean
 ifeq ($(CONFIG_IOEMU),y)
-export IOEMU_DIR ?= ioemu
+IOEMU_DIR ?= ioemu
+ifneq ($(XEN_COMPILE_ARCH),$(XEN_TARGET_ARCH))
+IOEMU_CONFIGURE_CROSS ?= --cross-prefix=$(CROSS_COMPILE) \
+			 --interp-prefix=$(CROSS_SYS_ROOT)
+endif
 ioemu ioemuinstall:
 	[ -f $(IOEMU_DIR)/config-host.mak ] || \
-	  (cd $(IOEMU_DIR) && sh configure --prefix=/usr)
+	  ( cd $(IOEMU_DIR) && sh configure --prefix=/usr \
+		$(IOEMU_CONFIGURE_CROSS) )
 	$(MAKE) -C $(IOEMU_DIR) $(patsubst ioemu%,%,$@)
 ioemuclean:
 	$(MAKE) -C $(IOEMU_DIR) distclean
#2 lore raw

Re: [PATCH 1 of 2] Make tools/Makefile cross-friendly

tools/Makefile ifeq ($(XEN_COMPILE_ARCH),$(XEN_TARGET_A · line 35

Quoted 5 lines · Aron Griffis
tools/Makefile +4 -0
+# For the sake of linking, set the sys-root
+ifneq ($(CROSS_COMPILE),)
+CROSS_SYS_ROOT ?= /usr/$(CROSS_COMPILE:-=)/sys-root
+export CROSS_SYS_ROOT
 endif

I suppose this is a completely arbitrary path that happens to work for you? For your example command line
make -j1 XEN_TARGET_ARCH=ia64 CROSS_COMPILE=ia64-linux-gnu- ...this would link against the ugly and bizarre path /usr/ia64linuxgnu/sys-root?

-- Keir

#3 lore raw

Re: [PATCH 1 of 2] Make tools/Makefile cross-friendly

Keir Fraser wrote: [Sat Jan 19 2008, 03:26:30AM EST]

Quoted 9 lines · Aron Griffis

tools/Makefile ifeq ($(XEN_COMPILE_ARCH),$(XEN_TARGET_A · line 35

Quoted 6 lines
tools/Makefile +4 -0
+# For the sake of linking, set the sys-root
+ifneq ($(CROSS_COMPILE),)
+CROSS_SYS_ROOT ?= /usr/$(CROSS_COMPILE:-=)/sys-root
+export CROSS_SYS_ROOT
 endif

I suppose this is a completely arbitrary path that happens to work for you?

No, it appears to be pretty standard. I took my cue on the sys-root from the cross-compilers on arm. My own cross compilers are theirs plus some patches (which I'm preparing to send their direction next)

Quoted 4 lines

For your example command line
make -j1 XEN_TARGET_ARCH=ia64 CROSS_COMPILE=ia64-linux-gnu- ...this would link against the ugly and bizarre path /usr/ia64linuxgnu/sys-root?

No, $(CROSS_COMPILE:-=) only removes the trailing dash. The resulting path is /usr/ia64-linux-gnu/sys-root, so the sys-root lives right next to the rest of the toolchain support:

$ ls /usr/ia64-linux-gnu
bin/  lib/  sys-root/

Aron

#4 lore raw

Re: [PATCH 1 of 2] Make tools/Makefile cross-friendly

To follow up a bit more on the sys-root question, this web page explains it:

http://benoit.papillault.free.fr/notes/cross-gcc.php.en

The sys-root is built into both the compiler and binutils using the --with-sysroot option. That way the compiler can find the include files, and the linker can find the libraries.

The cross-toolchain that I based mine on are from here:

http://www.redhat.com/archives/fedora-devel-list/2007-October/msg00045.html

These assume the sys-root will be in /usr/$target/sys-root, so that's how I set things up too. Lennert suggests using a script repack_cross.pl to install target rpms in the sys-root. I used that for a while but the number of rpms needed was overwhelming, so eventually I realized it would be a lot easier to use an entire root filesystem.

For the rootfs, I started with fedora8/ia64 but it's missing some libs, so I switched to rhel5/ia64. For the howto, I intend to switch to centos4.6 so licensing isn't an issue. In any case, it's not hard to do a simple ia64 installation then bundle up the sys-root from it.

Hope that helps,
Aron

#5 lore raw

PATCH 1/1 Make tools/check scripts cross-friendly

In reply to Aron Griffis

# HG changeset patch
# User Aron Griffis <[email protected]>
# Date 1200715193 18000
# Node ID 735710fbd87c8c3701bb2e33746500793acf14bf # Parent 79cf8ffbc6678f201d35724bf083ea9749818597 Make tools/check scripts cross-friendly

This patch introduces tools/check/funcs.sh with some cross-friendly abstractions, then modifies the check_* scripts to use them.

tools/check/check_brctl +5 -19
diff -r 79cf8ffbc667 -r 735710fbd87c tools/check/check_brctl
@@ -1,27 +1,13 @@
 #!/bin/sh
 # CHECK-INSTALL
 
-RC=0
+. funcs.sh
 
-case ${OS} in
+case $OS in
 OpenBSD|NetBSD|FreeBSD)
-	# These systems have a bridge builtin
-	TOOL="brconfig"
-	which ${TOOL} 1>/dev/null 2>&1 || RC=1 
-	;;
+	has_or_fail brconfig ;;
 Linux)
-	TOOL="brctl"
-	which ${TOOL} 1>/dev/null 2>&1 || RC=1
-	;;
+	has_or_fail brctl ;;
 *)
-	TOOL=""
-	echo "Unknown OS" && RC=1
-	;;
+	fail "unknown OS" ;;
 esac
-
-if test ${RC} -ne 0; then
-	echo
-	echo " *** Check for the bridge control utils (${TOOL}) FAILED"
-fi
-
-exit ${RC} 
tools/check/check_crypto_lib +4 -16
diff -r 79cf8ffbc667 -r 735710fbd87c tools/check/check_crypto_lib
@@ -1,23 +1,11 @@
 #!/bin/sh
 # CHECK-BUILD CHECK-INSTALL
 
-RC=0
+. funcs.sh
 
-case $(uname -s) in
+case $OS in
 FreeBSD|NetBSD|OpenBSD)
-	exit 0
-	;;
-*)
-	;;
+	exit 0 ;;
 esac
 
-PATH=/sbin:$PATH
-set -e
-ldconfig -p 2>&1 | grep -q libcrypto.so || RC=1
-
-if test ${RC} -ne 0; then
-        echo
-        echo " *** Check for crypto library FAILED"
-fi
-
-exit ${RC}
+has_lib libcrypto.so || fail "missing libcrypto.so"
tools/check/check_curl +8 -33

46 lines not on this page · raw message

tools/check/check_iproute +7 -18
diff -r 79cf8ffbc667 -r 735710fbd87c tools/check/check_iproute
@@ -1,26 +1,15 @@
 #!/bin/sh
 # CHECK-INSTALL
 
-RC=0
+. funcs.sh
 
-case ${OS} in
+PATH=/sbin:$PATH
+
+case $OS in
 OpenBSD|NetBSD|FreeBSD)
-	TOOL="ifconfig"
-	eval ${TOOL} -a 1>/dev/null 2>&1 || RC=1 
-	;;
+	has_or_fail ifconfig ;;
 Linux)
-	TOOL="ip addr"
-	eval ${TOOL} list 1>/dev/null 2>&1 || RC=1 
-	;;
+	has_or_fail ip ;;
 *)
-	TOOL=""
-	echo "Unknown OS" && RC=1 
-	;;
+	fail "unknown OS" ;;
 esac
-
-if test ${RC} -ne 0; then
-	echo
-	echo " *** Check for iproute (${TOOL}) FAILED"
-fi
-
-exit ${RC} 
tools/check/check_openssl_devel +2 -10
diff -r 79cf8ffbc667 -r 735710fbd87c tools/check/check_openssl_devel
@@ -1,14 +1,6 @@
 #!/bin/sh
 # CHECK-BUILD
 
-RC=0
+. funcs.sh
 
-set -e
-test -r /usr/include/openssl/md5.h || RC=1 
-
-if test ${RC} -ne 0; then
-	echo
-	echo " *** Check for openssl headers FAILED"
-fi
-
-exit ${RC}
+has_header openssl/md5.h || fail "missing openssl headers"
tools/check/check_python +2 -9
diff -r 79cf8ffbc667 -r 735710fbd87c tools/check/check_python
@@ -1,16 +1,9 @@
 #!/bin/sh
 # CHECK-BUILD CHECK-INSTALL
 
-RC=0
+. funcs.sh
 
 python -c '
 import sys
 sys.exit(sys.version_info[0] < 2 or sys.version_info[1] < 2)
-' || RC=1
-
-if test ${RC} -ne 0; then
-	echo
-	echo " *** Check for Python version >= 2.2 FAILED"
-fi
-
-exit ${RC} 
+' || fail "need python version >= 2.2"
tools/check/check_python_devel +2 -9
diff -r 79cf8ffbc667 -r 735710fbd87c tools/check/check_python_devel
@@ -1,7 +1,7 @@
 #!/bin/sh
 # CHECK-BUILD
 
-RC=0
+. funcs.sh
 
 python -c '
 import os.path, sys
@@ -9,11 +9,4 @@ for p in sys.path:
 	if os.path.exists(p + "/config/Makefile"):
 		sys.exit(0)
 sys.exit(1)
-' || RC=1 
-
-if test ${RC} -ne 0; then
-	echo
-	echo " *** Check for python development environment FAILED"
-fi
-
-exit ${RC}
+' || fail "can't find python devel files"
tools/check/check_python_xml +4 -5
diff -r 79cf8ffbc667 -r 735710fbd87c tools/check/check_python_xml
@@ -1,8 +1,7 @@
 #!/bin/sh
 # CHECK-INSTALL
 
-python -c 'import xml.dom.minidom' 2>/dev/null || {
-    echo
-    echo "  *** Check for python-xml package FAILED"
-    exit 1
-}
+. funcs.sh
+
+python -c 'import xml.dom.minidom' 2>/dev/null || \
+fail "can't import xml.dom.minidom"
tools/check/check_udev +8 -23
diff -r 79cf8ffbc667 -r 735710fbd87c tools/check/check_udev
@@ -1,34 +1,19 @@
 #!/bin/sh
 # CHECK-INSTALL
 
-RC=0
+. funcs.sh
 
-case ${OS} in
+case $OS in
 OpenBSD|NetBSD|FreeBSD)
-	TOOL="vnconfig"
-	which ${TOOL} 1>/dev/null 2>&1 || RC=1
+	has_or_fail vncconfig
 	;;
 Linux)
-	TOOL="udevinfo"
-	UDEV_VERSION="0"
-	test -x "$(which ${TOOL} 2>/dev/null)" && \
-		UDEV_VERSION=$(${TOOL} -V | sed -e 's/^[^0-9]* \([0-9]\{1,\}\)[^0-9]\{0,\}/\1/')
-	if test "${UDEV_VERSION}" -ge 059; then
-		RC=0
-	else
-		TOOL="hotplug"
-		which ${TOOL} 1>/dev/null 2>&1 || RC=1
-	fi
+	has_or_fail udevinfo
+	[ "`udevinfo -V | awk '{print $NF}'`" -ge 59 ] 2>/dev/null || \
+		has hotplug || \
+		fail "udev is too old, upgrade to version 59 or later"
 	;;
 *)
-	TOOL=""
-	echo "Unknown OS" && RC=1
+	fail "unknown OS"
 	;;
 esac
-
-if test ${RC} -ne 0; then
-	echo
-	echo " *** Check for ${TOOL} FAILED"
-fi
-
-exit ${RC}
tools/check/check_x11_devel +4 -11
diff -r 79cf8ffbc667 -r 735710fbd87c tools/check/check_x11_devel
@@ -1,15 +1,8 @@
 #!/bin/sh
 # CHECK-BUILD
 
-RC=0
+. funcs.sh
 
-set -e
-test -r /usr/include/X11/keysymdef.h || \
-test -r /usr/X11R6/include/X11/keysymdef.h || RC=1
-
-if test ${RC} -ne 0; then
-	echo
-	echo " *** Check for x11 headers FAILED"
-fi
-
-exit ${RC}
+has_header X11/keysymdef.h || \
+has_header /usr/X11R6/include/X11/keysymdef.h || \
+fail "can't find X11 headers"
tools/check/check_xgettext +2 -10
diff -r 79cf8ffbc667 -r 735710fbd87c tools/check/check_xgettext
@@ -1,14 +1,6 @@
 #!/bin/sh
 # CHECK-BUILD
 
-RC=0
+. funcs.sh
 
-TOOL="xgettext"
-which ${TOOL} 1>/dev/null 2>&1 || RC=1 
-
-if test ${RC} -ne 0; then
-	echo
-	echo " *** Check for the gettext utility (${TOOL}) FAILED"
-fi
-
-exit ${RC} 
+has_or_fail xgettext
tools/check/check_xml2 +5 -29
diff -r 79cf8ffbc667 -r 735710fbd87c tools/check/check_xml2
@@ -1,5 +1,7 @@
 #!/bin/sh
 # CHECK-BUILD CHECK-INSTALL
+
+. funcs.sh
 
 if [ ! "$LIBXENAPI_BINDINGS" = "y" -a ! "$ACM_SECURITY" = "y" ]
 then
@@ -7,32 +9,6 @@ then
     exit 0
 fi
 
-RC=0
-
-XML2_CONFIG="$(which xml2-config)"
-tmpfile=$(mktemp)
-
-if test -z ${XML2_CONFIG}; then
-    RC=1
-else
-    ${XML2_CONFIG} --libs 2>&1 > /dev/null
-    RC=$?
-fi
-
-if test $RC -ne 0; then
-    echo "FAILED"
-	echo " *** xml2-config is missing. "
-    echo " *** Please install libxml2-devel."
-elif ! ld $($XML2_CONFIG --libs) -o $tmpfile >/dev/null 2>&1; then
-    echo "FAILED"
-    echo " *** dependency libraries for xml2 are missing: "
-    RC=1
-    for i in $(ld $($XML2_CONFIG --libs) -o $tmpfile 2>&1 >/dev/null); do
-        case $i in
-        -l*) echo lib${i#-l}
-        esac
-    done
-fi
-rm -f $tmpfile
-
-exit $RC
+has_or_fail xml2-config
+xml2_libs=`xml2-config --libs` || fail "xml2-config --libs failed"
+test_link $xml2_libs || fail "dependency libraries for xml2 are missing"
tools/check/check_zlib_devel +2 -10
diff -r 79cf8ffbc667 -r 735710fbd87c tools/check/check_zlib_devel
@@ -1,14 +1,6 @@
 #!/bin/sh
 # CHECK-BUILD
 
-RC=0
+. funcs.sh
 
-set -e
-test -r /usr/include/zlib.h || RC=1
-
-if test ${RC} -ne 0; then
-	echo
-	echo " *** Check for zlib headers FAILED"
-fi 
-
-exit ${RC}
+has_header zlib.h || fail "can't find zlib headers"
tools/check/check_zlib_lib +3 -15
diff -r 79cf8ffbc667 -r 735710fbd87c tools/check/check_zlib_lib
@@ -1,24 +1,12 @@
 #!/bin/sh
 # CHECK-BUILD CHECK-INSTALL
 
-RC=0
+. funcs.sh
 
-case $(uname -s) in
+case $OS in
 FreeBSD|NetBSD|OpenBSD)
 	exit 0
 	;;
-*)
-	;;
 esac
 
-PATH=/sbin:$PATH
-
-set -e
-ldconfig -p 2>&1 | grep -q libz.so || RC=1
-
-if test ${RC} -ne 0; then
-	echo
-	echo " *** Check for zlib library FAILED"
-fi
-
-exit ${RC} 
+has_lib libz.so || fail "can't find zlib"
tools/check/chk +4 -5
diff -r 79cf8ffbc667 -r 735710fbd87c tools/check/chk
@@ -7,17 +7,16 @@ func_usage ()
     echo
     echo "Check suitability for Xen build or install."
     echo "Exit with 0 if OK, 1 if not."
-    echo "Prints only failed tests."
     echo
     echo "Calling with 'clean' removes generated files."
     exit 1
 }
 
-PATH=${PATH}:/sbin:/usr/sbin
+PATH=$PATH:/sbin:/usr/sbin
 OS=`uname -s`
 export PATH OS
 
-if test "${OS}" = "SunOS"; then
+if [ "$OS" = "SunOS" ]; then
 	exit 0
 fi
 
@@ -38,7 +37,7 @@ esac
 
 failed=0
 
-echo "Xen ${check} " $(date)
+echo "Xen ${check} " `date`
 for f in check_* ; do
     case $f in
         *~)
@@ -50,7 +49,7 @@ for f in check_* ; do
     if ! [ -x $f ] ; then
         continue
     fi
-    if ! grep -q ${check} $f ; then
+    if ! grep -Fq "$check" $f ; then
         continue
     fi
     echo -n "Checking $f: "
tools/check/funcs.sh new file +85 -0

85 lines not on this page · raw message

#6 lore raw

Re: [PATCH 2 of 2] Make tools/check scripts cross-friendly

check_udev fails due to a typo in the patch.
See inline for other comments.

Christoph

Quoted 13 lines · On Saturday 19 January 2008 05:02:31 Aron Griffis wrote:

# HG changeset patch
# User Aron Griffis <[email protected]>
# Date 1200715193 18000
# Node ID 735710fbd87c8c3701bb2e33746500793acf14bf # Parent 79cf8ffbc6678f201d35724bf083ea9749818597 Make tools/check scripts cross-friendly

This patch introduces tools/check/funcs.sh with some cross-friendly abstractions, then modifies the check_* scripts to use them.

[snip]

Quoted 6 lines

diff -r 79cf8ffbc667 -r 735710fbd87c tools/check/check_udev

tools/check/check_udev +0 -0
@@ -1,34 +1,19 @@
 #!/bin/sh
 # CHECK-INSTALL

tools/check/check_udev line 8

Quoted 10 lines
tools/check/check_udev +3 -4
 
-RC=0
+. funcs.sh
 
-case ${OS} in
+case $OS in
 OpenBSD|NetBSD|FreeBSD)
-	TOOL="vnconfig"
-	which ${TOOL} 1>/dev/null 2>&1 || RC=1
+	has_or_fail vncconfig
                            ^^^^^^

Typo!!

Quoted 181 lines
tools/check/check_udev +0 -4
 	;;
 Linux)
-	TOOL="udevinfo"
-	UDEV_VERSION="0"
-	test -x "$(which ${TOOL} 2>/dev/null)" && \
-		UDEV_VERSION=$(${TOOL} -V | sed -e 's/^[^0-9]*

\([0-9]\{1,\}\)[^0-9]\{0,\}/\1/') - if test "${UDEV_VERSION}" -ge 059; then

tools/check/check_udev +5 -14
-		RC=0
-	else
-		TOOL="hotplug"
-		which ${TOOL} 1>/dev/null 2>&1 || RC=1
-	fi
+	has_or_fail udevinfo
+	[ "`udevinfo -V | awk '{print $NF}'`" -ge 59 ] 2>/dev/null || \
+		has hotplug || \
+		fail "udev is too old, upgrade to version 59 or later"
 	;;
 *)
-	TOOL=""
-	echo "Unknown OS" && RC=1
+	fail "unknown OS"
 	;;
 esac
-
-if test ${RC} -ne 0; then
-	echo
-	echo " *** Check for ${TOOL} FAILED"
-fi
-
-exit ${RC}

diff -r 79cf8ffbc667 -r 735710fbd87c tools/check/check_x11_devel

tools/check/check_x11_devel +4 -11
@@ -1,15 +1,8 @@
 #!/bin/sh
 # CHECK-BUILD
 
-RC=0
+. funcs.sh
 
-set -e
-test -r /usr/include/X11/keysymdef.h || \
-test -r /usr/X11R6/include/X11/keysymdef.h || RC=1
-
-if test ${RC} -ne 0; then
-	echo
-	echo " *** Check for x11 headers FAILED"
-fi
-
-exit ${RC}
+has_header X11/keysymdef.h || \
+has_header /usr/X11R6/include/X11/keysymdef.h || \
+fail "can't find X11 headers"

diff -r 79cf8ffbc667 -r 735710fbd87c tools/check/check_xgettext

tools/check/check_xgettext +2 -10
@@ -1,14 +1,6 @@
 #!/bin/sh
 # CHECK-BUILD
 
-RC=0
+. funcs.sh
 
-TOOL="xgettext"
-which ${TOOL} 1>/dev/null 2>&1 || RC=1
-
-if test ${RC} -ne 0; then
-	echo
-	echo " *** Check for the gettext utility (${TOOL}) FAILED"
-fi
-
-exit ${RC}
+has_or_fail xgettext

diff -r 79cf8ffbc667 -r 735710fbd87c tools/check/check_xml2

tools/check/check_xml2 +5 -29
@@ -1,5 +1,7 @@
 #!/bin/sh
 # CHECK-BUILD CHECK-INSTALL
+
+. funcs.sh
 
 if [ ! "$LIBXENAPI_BINDINGS" = "y" -a ! "$ACM_SECURITY" = "y" ]
 then
@@ -7,32 +9,6 @@ then
     exit 0
 fi
 
-RC=0
-
-XML2_CONFIG="$(which xml2-config)"
-tmpfile=$(mktemp)
-
-if test -z ${XML2_CONFIG}; then
-    RC=1
-else
-    ${XML2_CONFIG} --libs 2>&1 > /dev/null
-    RC=$?
-fi
-
-if test $RC -ne 0; then
-    echo "FAILED"
-	echo " *** xml2-config is missing. "
-    echo " *** Please install libxml2-devel."
-elif ! ld $($XML2_CONFIG --libs) -o $tmpfile >/dev/null 2>&1; then
-    echo "FAILED"
-    echo " *** dependency libraries for xml2 are missing: "
-    RC=1
-    for i in $(ld $($XML2_CONFIG --libs) -o $tmpfile 2>&1 >/dev/null); do
-        case $i in
-        -l*) echo lib${i#-l}
-        esac
-    done
-fi
-rm -f $tmpfile
-
-exit $RC
+has_or_fail xml2-config
+xml2_libs=`xml2-config --libs` || fail "xml2-config --libs failed"
+test_link $xml2_libs || fail "dependency libraries for xml2 are missing"

diff -r 79cf8ffbc667 -r 735710fbd87c tools/check/check_zlib_devel

tools/check/check_zlib_devel +2 -10
@@ -1,14 +1,6 @@
 #!/bin/sh
 # CHECK-BUILD
 
-RC=0
+. funcs.sh
 
-set -e
-test -r /usr/include/zlib.h || RC=1
-
-if test ${RC} -ne 0; then
-	echo
-	echo " *** Check for zlib headers FAILED"
-fi
-
-exit ${RC}
+has_header zlib.h || fail "can't find zlib headers"

diff -r 79cf8ffbc667 -r 735710fbd87c tools/check/check_zlib_lib

tools/check/check_zlib_lib +3 -15
@@ -1,24 +1,12 @@
 #!/bin/sh
 # CHECK-BUILD CHECK-INSTALL
 
-RC=0
+. funcs.sh
 
-case $(uname -s) in
+case $OS in
 FreeBSD|NetBSD|OpenBSD)
 	exit 0
 	;;
-*)
-	;;
 esac
 
-PATH=/sbin:$PATH
-
-set -e
-ldconfig -p 2>&1 | grep -q libz.so || RC=1
-
-if test ${RC} -ne 0; then
-	echo
-	echo " *** Check for zlib library FAILED"
-fi
-
-exit ${RC}
+has_lib libz.so || fail "can't find zlib"

diff -r 79cf8ffbc667 -r 735710fbd87c tools/check/chk

tools/check/chk +0 -1
@@ -7,17 +7,16 @@ func_usage ()
     echo
     echo "Check suitability for Xen build or install."
     echo "Exit with 0 if OK, 1 if not."
-    echo "Prints only failed tests."
     echo
     echo "Calling with 'clean' removes generated files."

tools/check/chk func_usage () · line 19

Quoted 10 lines
tools/check/chk +2 -2
     exit 1
 }
 
-PATH=${PATH}:/sbin:/usr/sbin
+PATH=$PATH:/sbin:/usr/sbin
 OS=`uname -s`
 export PATH OS
 
-if test "${OS}" = "SunOS"; then
+if [ "$OS" = "SunOS" ]; then

What does this fix? Don't change this if you can't test on Solaris.

Quoted 70 lines
tools/check/chk +2 -2
 	exit 0
 fi
 
@@ -38,7 +37,7 @@ esac
 
 failed=0
 
-echo "Xen ${check} " $(date)
+echo "Xen ${check} " `date`
 for f in check_* ; do
     case $f in
         *~)
@@ -50,7 +49,7 @@ for f in check_* ; do
     if ! [ -x $f ] ; then
         continue
     fi
-    if ! grep -q ${check} $f ; then
+    if ! grep -Fq "$check" $f ; then
         continue
     fi
     echo -n "Checking $f: "

diff -r 79cf8ffbc667 -r 735710fbd87c tools/check/funcs.sh

tools/check/funcs.sh new file +45 -0
@@ -0,0 +1,85 @@
+# has is the same as which, except it handles cross environments
+has() {
+	if [ -z "$CROSS_COMPILE" ]; then
+		command which "$@"
+		return $?
+	fi
+
+	check_sys_root || return 1
+
+	# subshell to prevent pollution of caller's IFS
+	(
+	IFS=:
+	for p in $PATH; do
+		if [ -x "$CROSS_SYS_ROOT/$p/$1" ]; then
+			echo "$CROSS_SYS_ROOT/$p/$1"
+			return 0
+		fi
+	done
+	return 1
+	)
+}
+
+has_or_fail() {
+	has "$1" >/dev/null || fail "can't find $1"
+}
+
+has_header() {
+	case $1 in
+		/*) ;;
+		*) set -- "/usr/include/$1" ;;
+	esac
+
+	check_sys_root || return 1
+
+	test -r "$CROSS_SYS_ROOT$1"
+	return $?
+}
+
+has_lib() {
+	check_sys_root || return 1
+
+	# subshell to prevent pollution of caller's environment
+	(
+	PATH=/sbin:$PATH        # for ldconfig
+

tools/check/funcs.sh line 55

Quoted 10 lines
tools/check/funcs.sh new file +10 -0
+	# This relatively common in a sys-root; libs are installed but
+	# ldconfig hasn't run there, so ldconfig -p won't work.  We can
+	# only fix it if it's writeable.
+	[ "$OS" != Linux ] || \
+	[ -f "$CROSS_SYS_ROOT/etc/ld.so.cache" ] || \
+	ldconfig -r "$CROSS_SYS_ROOT" && \
+	ldconfig -p ${CROSS_SYS_ROOT+-r "$CROSS_SYS_ROOT"} | grep -Fq "$1"
+	return $?
+	)
+}

This can be more readable with "if test" constructs.

Quoted 37 lines
tools/check/funcs.sh new file +30 -0
+
+test_link() {
+	# subshell to trap removal of tmpfile
+	(
+	unset tmpfile
+	trap 'rm -f "$tmpfile"; exit' 0 1 2 15
+	tmpfile=`mktemp` || return 1
+	ld "$@" -o "$tmpfile" >/dev/null 2>&1
+	return $?
+	)
+}
+
+# this function is used commonly above
+check_sys_root() {
+	[ -z "$CROSS_COMPILE" ] && return 0
+	if [ -z "$CROSS_SYS_ROOT" ]; then
+		echo "please set CROSS_SYS_ROOT in the environment"
+		return 1
+	fi
+	if [ ! -d "$CROSS_SYS_ROOT" ]; then
+		echo "no sys-root found at $CROSS_SYS_ROOT"
+		return 1
+	fi
+}
+
+fail() {
+	echo
+	echo " *** `basename "$0"` FAILED${*+: $*}"
+	exit 1
+}

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

Signature · 12 lines
AMD Saxony, Dresden, Germany
Operating System Research Center

Legal Information:
AMD Saxony Limited Liability Company & Co. KG
Sitz (Geschäftsanschrift):
   Wilschdorfer Landstr. 101, 01109 Dresden, Deutschland
Registergericht Dresden: HRA 4896
vertretungsberechtigter Komplementär:
   AMD Saxony LLC (Sitz Wilmington, Delaware, USA)
Geschäftsführer der AMD Saxony LLC:
   Dr. Hans-R. Deppe, Thomas McCoy
#7 lore raw

Re: [PATCH 2 of 2] Make tools/check scripts cross-friendly

Christoph Egger wrote: [Mon Jan 21 2008, 06:05:42AM EST]

Quoted 10 lines
Quoted 10 lines

diff -r 79cf8ffbc667 -r 735710fbd87c tools/check/check_udev

tools/check/check_udev +1 -1
@@ -1,34 +1,19 @@
 #!/bin/sh
 # CHECK-INSTALL
 
-RC=0
+. funcs.sh
 
Quoted 8 lines

tools/check/check_udev line 8

Quoted 6 lines
tools/check/check_udev +2 -3
-case ${OS} in
+case $OS in
 OpenBSD|NetBSD|FreeBSD)
-	TOOL="vnconfig"
-	which ${TOOL} 1>/dev/null 2>&1 || RC=1
+	has_or_fail vncconfig
                            ^^^^^^

Typo!!

Thanks, will fix and repost.

Quoted 4 lines

tools/check/check_udev line 9

Quoted 2 lines
tools/check/check_udev +1 -1
-if test "${OS}" = "SunOS"; then
+if [ "$OS" = "SunOS" ]; then

What does this fix?

I tried to make the scripts more consistently written while working on them.

Quoted 1 line

Don't change this if you can't test on Solaris.

*shrug*

This works on every Bourne shell on every Solaris. I'll change it back if you want, but it's pointless.

Quoted 11 lines
Quoted 11 lines
tools/check/check_udev +11 -0
+has_lib() {
+	check_sys_root || return 1
+
+	# subshell to prevent pollution of caller's environment
+	(
+	PATH=/sbin:$PATH        # for ldconfig
+
+	# This relatively common in a sys-root; libs are installed but
+	# ldconfig hasn't run there, so ldconfig -p won't work.  We can
+	# only fix it if it's writeable.
+	[ "$OS" != Linux ] || \
Quoted 8 lines

tools/check/check_udev

Quoted 6 lines
tools/check/check_udev +6 -0
+	[ -f "$CROSS_SYS_ROOT/etc/ld.so.cache" ] || \
+	ldconfig -r "$CROSS_SYS_ROOT" && \
+	ldconfig -p ${CROSS_SYS_ROOT+-r "$CROSS_SYS_ROOT"} | grep -Fq "$1"
+	return $?
+	)
+}

This can be more readable with "if test" constructs.

Yeah, I wasn't very happy with that either. I'll make it better, thanks.

Aron