Add basic cross-compilation support.

Supports both autotools-like --host=... switch and Linux kernel-style
CROSS_COMPILE env var.
This commit is contained in:
notaz 2012-12-09 01:20:55 +02:00
parent 3e9bedd4c7
commit 7d283ab48d
3 changed files with 6 additions and 4 deletions

View File

@ -4,9 +4,9 @@ check_switch_c NOUNUSED -Wno-unused-result
add_define_make NOUNUSED "$HAVE_NOUNUSED" add_define_make NOUNUSED "$HAVE_NOUNUSED"
# There are still broken 64-bit Linux distros out there. :) # There are still broken 64-bit Linux distros out there. :)
[ -d /usr/lib64 ] && add_library_dirs /usr/lib64 [ -z "$CROSS_COMPILE" ] && [ -d /usr/lib64 ] && add_library_dirs /usr/lib64
[ -d /opt/local/lib ] && add_library_dirs /opt/local/lib [ -z "$CROSS_COMPILE" ] && [ -d /opt/local/lib ] && add_library_dirs /opt/local/lib
if [ "$OS" = 'BSD' ]; then DYLIB=-lc; else DYLIB=-ldl; fi if [ "$OS" = 'BSD' ]; then DYLIB=-lc; else DYLIB=-ldl; fi
[ "$OS" = 'Darwin' ] && HAVE_X11=no # X11 breaks on recent OSXes even if present. [ "$OS" = 'Darwin' ] && HAVE_X11=no # X11 breaks on recent OSXes even if present.

View File

@ -24,7 +24,7 @@ if [ "$USE_LANG_C" = 'yes' ]; then
#include <stdio.h> #include <stdio.h>
int main(void) { puts("Hai world!"); return 0; } int main(void) { puts("Hai world!"); return 0; }
EOF EOF
for CC in ${CC:=$(which gcc cc)} ''; do for CC in ${CC:=$(which ${CROSS_COMPILE}gcc ${CROSS_COMPILE}cc)} ''; do
"$CC" -o "$TEMP_EXE" "$TEMP_C" >/dev/null 2>&1 && break "$CC" -o "$TEMP_EXE" "$TEMP_C" >/dev/null 2>&1 && break
done done
[ "$CC" ] || { echo "$ECHOBUF ... Not found. Exiting."; exit 1;} [ "$CC" ] || { echo "$ECHOBUF ... Not found. Exiting."; exit 1;}
@ -40,7 +40,7 @@ if [ "$USE_LANG_CXX" = 'yes' ]; then
#include <iostream> #include <iostream>
int main() { std::cout << "Hai guise" << std::endl; return 0; } int main() { std::cout << "Hai guise" << std::endl; return 0; }
EOF EOF
for CXX in ${CXX:=$(which g++ c++)} ''; do for CXX in ${CXX:=$(which ${CROSS_COMPILE}g++ ${CROSS_COMPILE}c++)} ''; do
"$CXX" -o "$TEMP_EXE" "$TEMP_CXX" >/dev/null 2>&1 && break "$CXX" -o "$TEMP_EXE" "$TEMP_CXX" >/dev/null 2>&1 && break
done done
[ "$CXX" ] || { echo "$ECHOBUF ... Not found. Exiting."; exit 1;} [ "$CXX" ] || { echo "$ECHOBUF ... Not found. Exiting."; exit 1;}

View File

@ -16,6 +16,7 @@ LDFLAGS: Linker flags
General options: General options:
--prefix=\$path: Install path prefix --prefix=\$path: Install path prefix
--host=HOST: cross-compile to build programs to run on HOST
--help: Show this help --help: Show this help
Custom options: Custom options:
@ -50,6 +51,7 @@ parse_input() # Parse stuff :V
while [ "$1" ]; do while [ "$1" ]; do
case "$1" in case "$1" in
--prefix=*) PREFIX=${1##--prefix=};; --prefix=*) PREFIX=${1##--prefix=};;
--host=*) CROSS_COMPILE=${1##--host=}-;;
--enable-*) --enable-*)
opt_exists "${1##--enable-}" opt_exists "${1##--enable-}"
eval "HAVE_$opt=yes" eval "HAVE_$opt=yes"