Commit 0122e850f57bb0cfb16ba28faa5a094590ab6cd9

Ramiro Polla 2009-01-11T21:02:36

Allow cross-compilation with --cross-prefix.

diff --git a/Makefile b/Makefile
index 147df92..223bdaa 100644
--- a/Makefile
+++ b/Makefile
@@ -31,8 +31,8 @@ dlfcn.o:
 	$(CC) -o dlfcn.o -c dlfcn.c -Wall -O3 -fomit-frame-pointer
 
 libdl.a: dlfcn.o
-	ar cru libdl.a dlfcn.o
-	ranlib libdl.a
+	$(AR) cru libdl.a dlfcn.o
+	$(RANLIB) libdl.a
 
 libdl.dll: dlfcn.o
 	$(CC) $(SHFLAGS) -shared -o libdl.dll dlfcn.o
diff --git a/configure b/configure
index 69ce2f3..df2b494 100755
--- a/configure
+++ b/configure
@@ -42,7 +42,8 @@ show_help(){
   echo "  --enable-msvc             create msvc-compatible import lib [auto]"
   echo "  --enable-strip            strip shared library [yes]"
   echo
-  echo "  --cc=CC                   use C compiler CC [$cc]"
+  echo "  --cc=CC                   use C compiler CC [$cc_default]"
+  echo "  --cross-prefix=PREFIX     use PREFIX for compilation tools [$cross_prefix]"
   exit 1
 }
 
@@ -55,7 +56,9 @@ die_unknown(){
 PREFIX="/mingw"
 libdir="${PREFIX}/lib"
 incdir="${PREFIX}/include"
-cc="gcc"
+ar="ar"
+cc_default="gcc"
+ranlib="ranlib"
 
 DEFAULT="msvc
 "
@@ -93,6 +96,9 @@ for opt do
     --cc=*)
         cc="$optval"
     ;;
+    --cross-prefix=*)
+        cross_prefix="$optval"
+    ;;
     --enable-?*|--disable-?*)
         eval `echo "$opt" | sed 's/--/action=/;s/-/ option=/;s/-/_/g'`
         echo "$CMDLINE_SELECT" | grep -q "^ *$option\$" || die_unknown $opt
@@ -104,6 +110,15 @@ for opt do
     esac
 done
 
+ar="${cross_prefix}${ar}"
+cc_default="${cross_prefix}${cc_default}"
+ranlib="${cross_prefix}${ranlib}"
+
+if ! test -z $cc; then
+    cc_default="${cc}"
+fi
+cc="${cc_default}"
+
 disabled shared && disabled static && {
     echo "At least one library type must be set.";
     exit 1;
@@ -115,6 +130,7 @@ cat > /tmp/test.c << EOF
 void function(void)
 { LoadLibrary(NULL); }
 EOF
+echo testing compiler: $cc -shared -o /tmp/test.dll /tmp/test.c
 $cc -shared -o /tmp/test.dll /tmp/test.c
 
 test "$?" != 0 && {
@@ -144,7 +160,9 @@ echo "# Automatically generated by configure" > config.mak
 echo "PREFIX=$PREFIX" >> config.mak
 echo "libdir=$libdir" >> config.mak
 echo "incdir=$incdir" >> config.mak
+echo "AR=$ar" >> config.mak
 echo "CC=$cc" >> config.mak
+echo "RANLIB=$ranlib" >> config.mak
 echo "BUILD_SHARED=$shared" >> config.mak
 echo "BUILD_STATIC=$static" >> config.mak
 echo "BUILD_MSVC=$msvc" >> config.mak
@@ -153,7 +171,9 @@ echo "DO_STRIP=$strip" >> config.mak
 echo "prefix: $PREFIX"
 echo "libdir: $libdir"
 echo "incdir: $incdir"
+echo "ar:     $ar"
 echo "cc:     $cc"
+echo "ranlib: $ranlib"
 echo "static: $static"
 echo "shared: $shared"
 enabled shared && {