From 22bf3c41720ffe77f0142fb8b2e2ee3ab59bfaa9 Mon Sep 17 00:00:00 2001 From: meep-eep Date: Fri, 13 May 2005 15:10:38 +0000 Subject: [PATCH] Improvements for cross-compiling. git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@1741 8092fc87-c524-0410-9efc-e669fe64eaf9 --- sc2/build.vars.in | 1 + sc2/build/unix/build.config | 2 +- sc2/build/unix/build.docs | 36 +++-- sc2/build/unix/build_functions | 20 ++- sc2/build/unix/config_functions | 104 ++++++++++++-- sc2/build/unix/config_proginfo_build | 132 ++++++++++++++++++ .../{config_proginfo => config_proginfo_host} | 122 +++------------- 7 files changed, 282 insertions(+), 135 deletions(-) create mode 100644 sc2/build/unix/config_proginfo_build rename sc2/build/unix/{config_proginfo => config_proginfo_host} (72%) diff --git a/sc2/build.vars.in b/sc2/build.vars.in index 5dc16558c..93c5c42dc 100644 --- a/sc2/build.vars.in +++ b/sc2/build.vars.in @@ -19,6 +19,7 @@ COMPILE=gcc MKDEPEND='gcc -MM' MAKE='@MAKE@' ECHON='@ECHON@' +SED='@SED@' uqm_CFLAGS='@CFLAGS@' uqm_LDFLAGS='@LDFLAGS@' uqm_INSTALL_BINDIR='@INSTALL_BINDIR@' diff --git a/sc2/build/unix/build.config b/sc2/build/unix/build.config index 39a9cd3a8..dce2e8e3b 100644 --- a/sc2/build/unix/build.config +++ b/sc2/build/unix/build.config @@ -232,7 +232,7 @@ uqm_process_config() { substitute_vars SUBSTITUTE_VARS SUBSTITUTE_FILES src "$BUILD_WORK" # Make build.vars from build.vars.in, substituting variables. - SUBSTITUTE_VARS="CFLAGS LDFLAGS MAKE ECHON DEBUG SOUNDMODULE \ + SUBSTITUTE_VARS="CFLAGS LDFLAGS MAKE ECHON DEBUG SED SOUNDMODULE \ HAVE_OPENGL HAVE_REGEX_H_FLAG USE_ZIP_IO \ INSTALL_LIBDIR INSTALL_BINDIR INSTALL_SHAREDIR \ REZ WINDRES" diff --git a/sc2/build/unix/build.docs b/sc2/build/unix/build.docs index b3b8bcfd8..ba834d78a 100644 --- a/sc2/build/unix/build.docs +++ b/sc2/build/unix/build.docs @@ -22,21 +22,27 @@ For unknown dependencies, additions to config_proginfo might need to be made. The other files should not be modified. Only build.sh is to be called directly. -ansi ansi colour definitions. -build.config configuration options for the program to build. - It contains the description of the configuration - menu, and specifies the dependencies. - The format of the menu description is listed briefly - below. -build.sh the sh script that is to be called for configuration, - building, and installation. -build_functions auxiliary functions to build.sh for building. -config_functions auxiliary functions to build.sh for configuration. -config_proginfo contains descriptions of dependencies. - The information in this file is used in particular for - detecting if those libraries and other external programs - are present. -menu_functions auxiliary functions to build.sh for menus. +ansi ansi colour definitions. +build.config configuration options for the program to build. + It contains the description of the configuration + menu, and specifies the dependencies. + The format of the menu description is listed briefly + below. +build.sh the sh script that is to be called for configuration, + building, and installation. +build_functions auxiliary functions to build.sh for building. +config_functions auxiliary functions to build.sh for configuration. +config_proginfo_build contains descriptions of dependencies for the + system where the code is being built. + The information in this file is used in particular + for detecting if those libraries and other external + programs are present. +config_proginfo_host contains descriptions of dependencies for the + system where the software will eventually be run. + The information in this file is used in particular + for detecting if those libraries and other external + programs are present. +menu_functions auxiliary functions to build.sh for menus. The menu (from build.config) diff --git a/sc2/build/unix/build_functions b/sc2/build/unix/build_functions index d6949292d..480ec4f53 100644 --- a/sc2/build/unix/build_functions +++ b/sc2/build/unix/build_functions @@ -36,7 +36,7 @@ usage() { } escape_string() { - $PROG_sed_FILE -e s,[\\\'\"\`\ \ \$\&\\\*\\\?\#\!],\\\\\&,g << EOF + $SED -e s,[\\\'\"\`\ \ \$\&\\\*\\\?\#\!],\\\\\&,g << EOF $1 EOF } @@ -136,7 +136,12 @@ build_rec_collect_o_files() { # Start the configure program. # $1 = target build_config() { + prepare_build_system config_requirements + prepare_host_system + if [ "$BUILD_SYSTEM" '!=' "$HOST_SYSTEM" ]; then + build_message "Cross-compiling to $HOST_SYSTEM." + fi eval "${TARGET}_requirements" eval "${TARGET}_prepare_config" eval "${TARGET}_load_config" @@ -149,7 +154,12 @@ build_reconfig() { echo "*** Warning: file 'config.state' not found - using defaults." fi + prepare_build_system config_requirements + prepare_host_system + if [ "$BUILD_SYSTEM" '!=' "$HOST_SYSTEM" ]; then + build_message "Cross-compiling to $HOST_SYSTEM." + fi eval "${TARGET}_requirements" eval "${TARGET}_prepare_config" eval "${TARGET}_load_config" @@ -212,10 +222,10 @@ build_distclean() { # Description: check if the config files are present and load them. # If they're not present, remake them. build_check_config() { - [ ! -e "$BUILD_WORK/build.vars" ] || return - - build_config || exit $? - build_process_config + if [ ! -e "$BUILD_WORK/build.vars" ]; then + build_config || exit $? + build_process_config + fi . "$BUILD_WORK/build.vars" . "${BUILD_REC_PATH:=./}Makeinfo" } diff --git a/sc2/build/unix/config_functions b/sc2/build/unix/config_functions index 2bd00bdcf..c84f66470 100644 --- a/sc2/build/unix/config_functions +++ b/sc2/build/unix/config_functions @@ -533,7 +533,30 @@ add_symbol() { } check_endianness() { - try_compile_and_run_c << EOF + local ENDIAN + + if [ "$BUILD_SYSTEM" '!=' "$HOST_SYSTEM" ]; then + case "$BUILD_HOST_ENDIAN" in + "") + build_message "Cross-compiling - assuming little-endian host." + ENDIAN=little + ;; + big) + build_message "Cross-compiling for a big-endian host." + ENDIAN=big + ;; + little) + build_message "Cross-compiling for a little-endian host." + ENDIAN=little + ;; + *) + build_message "Bad endianness specified. Use \"little\" or \"big\"" + exit 1 + ;; + esac + else + # Detect endianness + try_compile_and_run_c << EOF int main() { int i; @@ -541,15 +564,25 @@ int main() { return *((unsigned char *) &i); } EOF - if [ $? -eq 0 ]; then - build_message "Big-endian machine." - add_symbol WORDS_BIGENDIAN "#define WORDS_BIGENDIAN" - add_symbol "WORDS_BIGENDIAN_FLAG" 1 - else - build_message "Little-endian machine." - add_symbol WORDS_BIGENDIAN "#undef WORDS_BIGENDIAN" - add_symbol "WORDS_BIGENDIAN_FLAG" 0 + if [ $? -eq 0 ]; then + build_message "Big-endian machine detected." + ENDIAN=big + else + build_message "Little-endian machine detected." + ENDIAN=little + fi fi + + case "$ENDIAN" in + big) + add_symbol WORDS_BIGENDIAN "#define WORDS_BIGENDIAN" + add_symbol "WORDS_BIGENDIAN_FLAG" 1 + ;; + little) + add_symbol WORDS_BIGENDIAN "#undef WORDS_BIGENDIAN" + add_symbol "WORDS_BIGENDIAN_FLAG" 0 + ;; + esac } @@ -660,10 +693,58 @@ EOF rm -- "${TEMPFILE}.sed" } +# Define the build system type. +set_build_system() { + BUILD_SYSTEM=`uname -s` +} +# Define the host system type. +set_host_system() { + local UHOST -# Include information about programs we can detect -. build/unix/config_proginfo + if [ -z "$BUILD_HOST" ]; then + HOST_SYSTEM=$BUILD_SYSTEM + else + case "$BUILD_HOST" in + *-*-*) + HOST_SYSTEM="${BUILD_HOST#*-}" + HOST_SYSTEM="${OSNAME%-*}" + ;; + esac + + # Use a single capitalization. + # What is used is whatever 'uname -s' would give on such a platform. + UHOST=`$TR "[:lower:]" "[:upper:]" << EOF +$BUILD_HOST +EOF +` + case "$UHOST" in + LINUX) HOST_SYSTEM="Linux" ;; + FREEBSD) HOST_SYSTEM="FreeBSD" ;; + OPENBSD) HOST_SYSTEM="OpenBSD" ;; + MINGW|MINGW32) HOST_SYSTEM="MINGW32" ;; + DARWIN) HOST_SYSTEM="Darwin" ;; + SUNOS) HOST_SYSTEM="SunOS" ;; + QNX) HOST_SYSTEM="QNX" ;; + *) + build_message "Warning: host type '$BUILD_HOST' unknown. Using defaults." + ;; + esac + fi + +} + +prepare_build_system() { + set_build_system + # Include information about programs we can detect for the build system. + . build/unix/config_proginfo_build +} + +prepare_host_system() { + set_host_system + # Include information about programs we can detect for the host system. + . build/unix/config_proginfo_host +} # Some initialisations HAVE_SYMBOLS="" @@ -680,4 +761,3 @@ config_requirements() { MAKE="$PROG_make_FILE" } - diff --git a/sc2/build/unix/config_proginfo_build b/sc2/build/unix/config_proginfo_build new file mode 100644 index 000000000..a17bd85b4 --- /dev/null +++ b/sc2/build/unix/config_proginfo_build @@ -0,0 +1,132 @@ +# Set information on used programs and libraries +# This file contains the information for the programs that test the +# system on which the software is built. +# Copyright (c) 2002 Serge van den Boom +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + +############################################################################## +# Describe the programs (possibly) used: # +############################################################################## + + +### gcc ### +PROG_gcc_NAME="GNU C compiler" +PROG_gcc_FILE="gcc" +PROG_gcc_ACTION="" +PROG_gcc_VERSION='$(gcc --version)' + + +### sed ### +PROG_sed_NAME="Sed stream editor" +PROG_sed_FILE="sed" +PROG_sed_ACTION="" +PROG_sed_VERSION='' + + +### echo -n ### +PROG_echon_NAME="'echo -n' capable echo" +PROG_echon_FILE="" +PROG_echon_ACTION="" +PROG_echon_VERSION='' +PROG_echon_DETECT="echon_detect" +echon_detect() { + local TEST LOCATIONS LOCATION + + # Default echo (probably builtin) + TEST=`echo -n X` + if [ "$TEST" = X ]; then + PROG_echon_FILE="echo -n" + return 0; + fi + + # External echo + LOCATIONS="/bin/ /usr/ucb/" + for LOCATION in $LOCATIONS; do + if [ -x ${LOCATION}echo ]; then + TEST=`${LOCATION}echo -n X` + if [ "$TEST" = X ]; then + PROG_echon_FILE="${LOCATION}echo -n" + return 0; + fi + fi + done + + # Using printf as echo + TEST=`printf %s X` + if [ "$TEST" = X ]; then + PROG_echon_FILE="printf %s" + return 0; + fi + + # No good echo found + return 1 +} + + +### GNU Make ### +PROG_make_NAME="Make" +case "$BUILD_SYSTEM" in + FreeBSD|OpenBSD|SunOS) + PROG_make_FILE="gmake" + ;; + *) + PROG_make_FILE="make" + ;; +esac +PROG_make_ACTION="" +PROG_make_VERSION='' + + +### tr ### +PROG_tr_NAME="tr" +PROG_tr_FILE="tr" +PROG_tr_ACTION="" +PROG_tr_VERSION='' + + +### windres (for Windows) ### +PROG_windres_NAME=windres +PROG_windres_FILE=windres +PROG_windres_ACTION="" +PROG_windres_VERSION='windres --version' + + +### Rez resource compiler (for MacOS X) only ### +PROG_Rez_NAME="Rez resource compiler (Apple Developer Tools)" +PROG_Rez_FILE="/Developer/Tools/Rez" +PROG_Rez_ACTION="" +PROG_Rez_VERSION='' + + +### pkg-config ### +PROG_pkgconfig_NAME="pkg-config" +PROG_pkgconfig_FILE="pkg-config" +PROG_pkgconfig_ACTION="" +PROG_pkgconfig_VERSION='$(pkg-config --version)' + + +############################################################################## +# Describe the libaries (possibly) used: # +############################################################################## + + + +############################################################################## +# Describe the symbols (possibly) used: # +############################################################################## + + diff --git a/sc2/build/unix/config_proginfo b/sc2/build/unix/config_proginfo_host similarity index 72% rename from sc2/build/unix/config_proginfo rename to sc2/build/unix/config_proginfo_host index ffcf702b6..06234310a 100644 --- a/sc2/build/unix/config_proginfo +++ b/sc2/build/unix/config_proginfo_host @@ -1,4 +1,6 @@ # Set information on used programs and libraries +# This file contains the information for the programs that test the +# system on which the software will be run. # Copyright (c) 2002 Serge van den Boom # # This program is free software; you can redistribute it and/or modify @@ -15,108 +17,12 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -OSNAME=`uname -s` ############################################################################## # Describe the programs (possibly) used: # ############################################################################## -### gcc ### -PROG_gcc_NAME="GNU C compiler" -PROG_gcc_FILE="gcc" -PROG_gcc_ACTION="" -PROG_gcc_VERSION='$(gcc --version)' - - -### sed ### -PROG_sed_NAME="Sed stream editor" -PROG_sed_FILE="sed" -PROG_sed_ACTION="" -PROG_sed_VERSION='' - - -### echo -n ### -PROG_echon_NAME="'echo -n' capable echo" -PROG_echon_FILE="" -PROG_echon_ACTION="" -PROG_echon_VERSION='' -PROG_echon_DETECT="echon_detect" -echon_detect() { - local TEST LOCATIONS LOCATION - - # Default echo (probably builtin) - TEST=`echo -n X` - if [ "$TEST" = X ]; then - PROG_echon_FILE="echo -n" - return 0; - fi - - # External echo - LOCATIONS="/bin/ /usr/ucb/" - for LOCATION in $LOCATIONS; do - if [ -x ${LOCATION}echo ]; then - TEST=`${LOCATION}echo -n X` - if [ "$TEST" = X ]; then - PROG_echon_FILE="${LOCATION}echo -n" - return 0; - fi - fi - done - - # Using printf as echo - TEST=`printf %s X` - if [ "$TEST" = X ]; then - PROG_echon_FILE="printf %s" - return 0; - fi - - # No good echo found - return 1 -} - - -### GNU Make ### -PROG_make_NAME="Make" -case "$OSNAME" in - FreeBSD|OpenBSD|SunOS) - PROG_make_FILE="gmake" - ;; - *) - PROG_make_FILE="make" - ;; -esac -PROG_make_ACTION="" -PROG_make_VERSION='' - - -### tr ### -PROG_tr_NAME="tr" -PROG_tr_FILE="tr" -PROG_tr_ACTION="" -PROG_tr_VERSION='' - - -### windres (for Windows) ### -PROG_windres_NAME=windres -PROG_windres_FILE=windres -PROG_windres_ACTION="" -PROG_windres_VERSION='windres --version' - - -### Rez resource compiler (for MacOS X) only ### -PROG_Rez_NAME="Rez resource compiler (Apple Developer Tools)" -PROG_Rez_FILE="/Developer/Tools/Rez" -PROG_Rez_ACTION="" -PROG_Rez_VERSION='' - - -### pkg-config ### -PROG_pkgconfig_NAME="pkg-config" -PROG_pkgconfig_FILE="pkg-config" -PROG_pkgconfig_ACTION="" -PROG_pkgconfig_VERSION='$(pkg-config --version)' - ############################################################################## # Describe the libaries (possibly) used: # @@ -125,7 +31,7 @@ PROG_pkgconfig_VERSION='$(pkg-config --version)' ### SDL ### LIB_SDL_NAME="Simple DirectMedia Layer" -case "$OSNAME" in +case "$TARGET_SYSTEM" in FreeBSD) LIB_SDL_CFLAGS='$(sdl11-config --cflags)' LIB_SDL_LDFLAGS='$(sdl11-config --libs)' @@ -156,7 +62,7 @@ LIB_SDL_mixer_VERSION="" ### SDL_image ### LIB_SDL_image_NAME="SDL_image" -case "$OSNAME" in +case "$TARGET_SYSTEM" in Darwin) LIB_SDL_image_CFLAGS='' LIB_SDL_image_LDFLAGS="-framework SDL_image" @@ -172,7 +78,7 @@ LIB_SDL_image_VERSION="" ### OpenAL ### LIB_openal_NAME="OpenAL" LIB_openal_CFLAGS="" -case "$OSNAME" in +case "$TARGET_SYSTEM" in FreeBSD|OpenBSD) LIB_openal_LDFLAGS="-L/usr/local/lib -pthread -lopenal" ;; @@ -194,7 +100,7 @@ LIB_openal_DEPEND_DETECT_BIN="pkgconfig" ### OpenGL ### LIB_opengl_NAME="OpenGL" -case "$OSNAME" in +case "$TARGET_SYSTEM" in FreeBSD|OpenBSD) LIB_opengl_CFLAGS="-I/usr/X11R6/include -D_THREAD_SAFE" LIB_opengl_LDFLAGS="-L/usr/X11R6/lib -lX11 -lXext -pthread -lGL" @@ -224,11 +130,15 @@ LIB_vorbis_VERSION="" ### Vorbisfile ### LIB_vorbisfile_NAME="vorbisfile" -case "$OSNAME" in +case "$TARGET_SYSTEM" in FreeBSD|OpenBSD) LIB_vorbisfile_CFLAGS="-I/usr/local/include" LIB_vorbisfile_LDFLAGS="-L/usr/local/lib -lvorbisfile -lvorbis" ;; + MINGW32*) + LIB_vorbisfile_CFLAGS="" + LIB_vorbisfile_LDFLAGS="-lvorbisfile -lvorbis -lm -logg" + ;; Darwin) LIB_vorbisfile_CFLAGS="-D__MACOSX__" LIB_vorbisfile_LDFLAGS="-framework Ogg -framework Vorbis" @@ -250,7 +160,14 @@ LIB_vorbisfile_DEPEND_DETECT_BIN="pkgconfig" ### zlib ### LIB_zlib_NAME="zlib" LIB_zlib_CFLAGS="" -LIB_zlib_LDFLAGS="-lz" +case "$TARGET_SYSTEM" in + MINGW32*) + LIB_zlib_LDFLAGS="-lzdll" + ;; + *) + LIB_zlib_LDFLAGS="-lz" + ;; +esac LIB_zlib_VERSION="" LIB_zlib_DETECT="try_pkgconfig_lib zlib zlib" LIB_zlib_DEPEND_DETECT_BIN="pkgconfig" @@ -276,3 +193,4 @@ SYMBOL_wint_t_EXTRA="#include " SYMBOL_iswgraph_EXTRA="#include " +