public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Jerone Young <jyoung5-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
To: kvm-devel <kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org>
Subject: [PATCH] [v4] add cross compile capability to top level configure	script
Date: Tue, 16 Oct 2007 15:11:34 -0500	[thread overview]
Message-ID: <1192565494.6079.28.camel@thinkpad> (raw)

Based on comments I've added the ability to separately add a compiler
for qemu. CFLAGS & LDFLAGS for qemu now have an option. I've also added
information back to the help screen. 

I had not thought much about how the kernel/ directory takes in the
config.mak that is created. Currently I am not using the kernel/
directory .. sorry. Everything works for me though compiling on my
laptop. 


Signed-off-by: Jerone Young <jyoung5-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>

diff --git a/configure b/configure
--- a/configure
+++ b/configure
@@ -3,32 +3,37 @@ prefix=/usr/local
 prefix=/usr/local
 kerneldir=/lib/modules/$(uname -r)/build
 want_module=1
-qemu_cc=$(ls /usr/bin/gcc3* /usr/bin/gcc-3* 2>/dev/null | tail -n1)
+cc=gcc
+qemu_cc=
+qemu_cflags=
+qemu_ldflags=
 disable_gcc_check=
+cross_prefix=
+arch=`uname -m`
+target_exec=
 
 usage() {
     cat <<-EOF
 	Usage: $0 [options]
 
 	Options include:
-
+	    --arch=ARCH            architecture to compile for ($arch)
+	    --cross-prefix=PREFIX  prefix for cross compile
+	    --cc=CC		   specify c compiler to compile
+	                           not valid if used with --cross-prefix
 	    --prefix=PREFIX        where to install things ($prefix)
 	    --with-patched-kernel  don't use external module
 	    --kerneldir=DIR        kernel build directory ($kerneldir)
-	    --qemu-cc="$qemu_cc"   compiler for qemu (needs gcc3.x) ($qemu_cc)
+	    --qemu-cc=CC           override compiler for qemu (must be gcc-3.x)
+	                           will override --cc for qemu configuration
+	                           not valid if used with --cross-prefix
+	    --qemu-cflags=CFLAGS   CFLAGS to add to qemu configuration
+	    --qemu-ldflags=LDFLAGS LDFLAGS to add to qemu configuration
 	    --disable-gcc-check    don't insist on gcc-3.x
-                                   - this will break running without kvm
+	                           CAUTION: this will break running without kvm
 EOF
     exit 1
 }
-
-
-# prefer gcc if its version is 3.* ( over a compat-gcc )
-# do it before parsing command line arguments to enable the user
-#    to specify a specific gcc he/she likes.
-if gcc -v 2>&1 | grep -q 'gcc *version *3\.[2-4]\.[0-9]'; then
-	qemu_cc=gcc
-fi
 
 while [[ "$1" = -* ]]; do
     opt="$1"; shift
@@ -47,12 +52,27 @@ while [[ "$1" = -* ]]; do
 	--with-patched-kernel)
 	    want_module=
 	    ;;
+	--cc)
+	    cc="$arg"
+	    ;;
 	--qemu-cc)
 	    qemu_cc="$arg"
+	    ;;
+	--qemu-cflags)
+	    qemu_cflags="$arg"
+	    ;;
+	--qemu-ldflags)
+	    qemu_ldflags="$arg"
 	    ;;
 	--disable-gcc-check)
 	    disable_gcc_check=1
 	    ;;
+	--arch)
+	    arch="$arg"
+	    ;;
+	--cross-prefix)
+	    cross_prefix="$arg"
+            ;;
 	--help)
 	    usage
 	    ;;
@@ -62,39 +82,58 @@ while [[ "$1" = -* ]]; do
     esac
 done
 
-if [[ -z "$qemu_cc" ]]; then
-    echo "$0: cannot locate gcc 3.x. please install it or specify with --qemu-cc"
-    exit 1
-fi
 
+#set kenel directory
 libkvm_kerneldir="$kerneldir"
 if (( want_module )); then
     libkvm_kerneldir=$(readlink -f kernel)
 fi
 
-target_cpu() {
-    if [[ $(uname -m) = i?86 ]]; then
-	echo x86_64
+#if arch is an x86 arch set to i386
+if [[ $arch = i?86 ]]; then
+  arch="i386"
+fi
+
+#see if using a cross compiler or not
+qemu_opts=
+user_opts=
+if [[ -z $cross_prefix ]]; then
+    if [[ -n $qemu_cc ]]; then
+       qemu_opts+=" --cc=$qemu_cc"
     else
-	uname -m
+       qemu_opts+=" --cc=$cc"
     fi
-}
+    user_opts+=" --cc=$cc"
+else
+    qemu_opts+=" --cross-prefix=$cross_prefix"
+    user_opts+=" --cross-prefix=$cross_prefix"
+fi
 
-(cd user; ./configure --prefix="$prefix" --kerneldir="$libkvm_kerneldir")
-(cd qemu; ./configure --target-list=$(target_cpu)-softmmu --cc="$qemu_cc" \
-    --disable-kqemu --extra-cflags="-I $PWD/../user" \
-    --extra-ldflags="-L $PWD/../user" \
+#set parameters compiling
+if [ "$arch" = "i386" -o "$arch" = "x86_64" ]; then
+    target_exec="x86_64-softmmu"
+    qemu_opts+=" --enable-alsa"
+fi
+
+#configure user dir
+(cd user; ./configure --prefix="$prefix" --kerneldir="$libkvm_kerneldir" \
+          $user_opts --arch="$arch")
+
+#configure qemu
+(cd qemu; ./configure --target-list=$target_exec \
+    --disable-kqemu --extra-cflags="-I $PWD/../user $qemu_cflags" \
+    --extra-ldflags="-L $PWD/../user $qemu_ldflags" \
     --enable-kvm --kernel-path="$libkvm_kerneldir" \
-    --enable-alsa \
     ${disable_gcc_check:+"--disable-gcc-check"} \
-    --prefix="$prefix"
+    --prefix="$prefix" \
+    $qemu_opts --cpu=$arch
 )
 
 
-
 cat <<EOF > config.mak
+ARCH=$arch
 PREFIX=$prefix
 KERNELDIR=$kerneldir
 WANT_MODULE=$want_module
+CROSS_COMPILE=$cross_prefix
 EOF
-



-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/

                 reply	other threads:[~2007-10-16 20:11 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1192565494.6079.28.camel@thinkpad \
    --to=jyoung5-r/jw6+rmf7hqt0dzr+alfa@public.gmane.org \
    --cc=kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox