From a5b27582abffe4cedd99837ab524f59dd5e4d5ed Mon Sep 17 00:00:00 2001 From: meep-eep Date: Sat, 25 Nov 2006 01:19:22 +0000 Subject: [PATCH] Unix build improvement (build tool detection). git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@2535 8092fc87-c524-0410-9efc-e669fe64eaf9 --- sc2/ChangeLog | 4 +- sc2/Makefile.build | 10 +- sc2/build.vars.in | 9 +- sc2/build/unix/build.config | 20 ++-- sc2/build/unix/build.docs | 30 ++++-- sc2/build/unix/build.sh | 5 +- sc2/build/unix/config_functions | 135 ++++++++++++++++++++++----- sc2/build/unix/config_proginfo_build | 55 +++++++++++ 8 files changed, 221 insertions(+), 47 deletions(-) diff --git a/sc2/ChangeLog b/sc2/ChangeLog index e97401913..4499da9ed 100644 --- a/sc2/ChangeLog +++ b/sc2/ChangeLog @@ -1,4 +1,6 @@ -Changes towards version 0.6: +- Unix build scripts improvements. - SvdB +- Build fixes for MacOS X (with thanks to Nic) - SvdB +======= - Ships in battle can resume normal speed in all circumstances after the enemy Avatar's tractor beam disengages (bug #860; this is a netplay desynchronizing change) - Alex diff --git a/sc2/Makefile.build b/sc2/Makefile.build index 5b0d6ff6e..d91a5ad75 100644 --- a/sc2/Makefile.build +++ b/sc2/Makefile.build @@ -18,11 +18,11 @@ endef endif define act_mkdep_c - $(MKDEPEND) $(CFLAGS) "$<" -MT "$(@D)/$( if presence of the program hasn't been verified +Information about build tools in general (say "a C compiler"), where you're +not interested in what program is actually called, should be supplied in +the following corm: + - BUILDTOOL_${TOOL}_NAME + A string describing the build tool. + - BUILDTOOL_${TOOL}_COMMAND + The command, with arguments, that is to be executed to run this tool. + - BUILDTOOL_${TOOL}_DEPEND + A whitespace separated list of programs (as described above) + that this tool depends on. + - BUILDTOOL_${TOOL}_PRESENT (set by the configuration program) + 0 if the tool has been verified to be present + 1 if the tool has been verified to be not present + if presence of the tool hasn't been verified +Each tool described, once detected, will be available through the environment +variable with the name as specified in $TOOL. -Library info (from config_proginfo) ------------------------------------ + +Library info (from config_proginfo_host) +----------------------------------------- Information about libraries used should be supplied in the following form: - LIB_${LIB}_NAME diff --git a/sc2/build/unix/build.sh b/sc2/build/unix/build.sh index 4d19798b6..a9472cf95 100644 --- a/sc2/build/unix/build.sh +++ b/sc2/build/unix/build.sh @@ -79,8 +79,9 @@ if [ -z "$TARGET" ]; then exit 1 fi BUILD_PROJECT="$TARGET" -export TARGET BUILD_PROJECT COMPILE MKDEPEND ECHON -export "${BUILD_PROJECT}_CFLAGS" "${BUILD_PROJECT}_LDFLAGS" +export TARGET BUILD_PROJECT ECHON +export PREPROC_C MKDEP_C COMPILE_C PREPROC_OBJC MKDEP_OBJC COMPILE_OBJC LINK +export "${BUILD_PROJECT}_CFLAGS" "${BUILD_PROJECT}_LDFLAGS" # Add trailing / from objs dir eval ${BUILD_PROJECT}_OBJS=\${${BUILD_PROJECT}_OBJS%/}/ diff --git a/sc2/build/unix/config_functions b/sc2/build/unix/config_functions index e065973b6..704c9d774 100644 --- a/sc2/build/unix/config_functions +++ b/sc2/build/unix/config_functions @@ -15,8 +15,9 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -BUILDLOG=/dev/null +BUILDLOG=/tmp/build.log TEMPFILE="/tmp/build.$$.tmp" +#KEEPTEMPFILES=keeptempfiles # Description: perform a command, and set the exit status to the opposite. @@ -74,29 +75,51 @@ $RESULT EOF } +# Description: delete the files passed as arguments, unless +# $KEEPTEMPFILES is set. +deleteTempFiles() { + if [ -n "$KEEPTEMPFILES" ]; then + return + fi + + rm -f -- "$@" +} + # Description: read text from stdin to use as a c file to compile # Arguments: $1 - CFLAGS to use for compilation (optional) # $2 - LDFLAGS to use for linking (optional) # Returns: 0 - if compile successful # something else - if compile failed try_compile_c() { - local SYSTEM_FLAGS - if [ -z "$COMPILE" ]; then - echo "Fatal: Program \$COMPILE is not defined!" >&2 + local SYSTEM_FLAGS RESULT + + if [ -z "$COMPILE_C" ]; then + echo "Fatal: Program \$COMPILE_C is not defined!" >&2 exit 1 fi + SYSTEM_FLAGS="$SYSTEM_BUILD_CFLAGS $SYSTEM_BUILD_LDFLAGS $SYSTEM_HOST_CFLAGS $SYSTEM_HOST_LDFLAGS" cat > "$TEMPFILE.c" - echo_and_perform $COMPILE $SYSTEM_FLAGS $1 $2 "$TEMPFILE.c" \ - -o "$TEMPFILE.out" >> "$BUILDLOG" 2>&1 + + echo_and_perform $COMPILE_C $SYSTEM_FLAGS $1 "$TEMPFILE.c" \ + -o "$TEMPFILE.c.o" >> "$BUILDLOG" 2>&1 RESULT=$? + + if [ $RESULT -eq 0 ]; then + echo_and_perform $LINK $SYSTEM_FLAGS $2 "$TEMPFILE.c.o" \ + -o "$TEMPFILE.out" >> "$BUILDLOG" 2>&1 + RESULT=$? + fi + if [ $RESULT -ne 0 ]; then echo "Failed program was:" >> "$BUILDLOG" echo "+++ START $TEMPFILE.c" >> "$BUILDLOG" cat "$TEMPFILE.c" >> "$BUILDLOG" echo "+++ END $TEMPFILE.c" >> "$BUILDLOG" fi - rm -f "$TEMPFILE.c" "$TEMPFILE.out" + + deleteTempFiles "$TEMPFILE.c $TEMPFILE.c.o $TEMPFILE.out" + echo >> "$BUILDLOG" return $RESULT } @@ -104,25 +127,36 @@ try_compile_c() { # Description: read text from stdin to use as a c file to compile # Arguments: $1 - CFLAGS to use for compilation (optional) # $2 - LDFLAGS to use for linking (optional) -# Returns: -1 - if compile failed +# Returns: 128 - if compiling or linking failed # otherwise - exit status of the program try_compile_and_run_c() { - local SYSTEM_FLAGS - if [ -z "$COMPILE" ]; then - echo "Fatal: Program \$COMPILE is not defined!" >&2 + local SYSTEM_FLAGS RESULT + + if [ -z "$COMPILE_C" ]; then + echo "Fatal: Program \$COMPILE_C is not defined!" >&2 exit 1 fi + SYSTEM_FLAGS="$SYSTEM_BUILD_CFLAGS $SYSTEM_BUILD_LDFLAGS $SYSTEM_HOST_CFLAGS $SYSTEM_HOST_LDFLAGS" cat > "$TEMPFILE.c" - echo_and_perform $COMPILE $SYSTEM_FLAGS $1 $2 "$TEMPFILE.c" \ - -o "$TEMPFILE.out" >> "$BUILDLOG" 2>&1 - if [ $? -ne 0 ]; then - return -1 - fi - rm -f -- "$TEMPFILE.c" - "$TEMPFILE.out" + + echo_and_perform $COMPILE_C $SYSTEM_FLAGS $1 "$TEMPFILE.c" \ + -o "$TEMPFILE.c.o" >> "$BUILDLOG" 2>&1 RESULT=$? - rm -f -- "$TEMPFILE.out" + + if [ $RESULT -eq 0 ]; then + echo_and_perform $LINK $SYSTEM_FLAGS $2 "$TEMPFILE.c.o" \ + -o "$TEMPFILE.out" >> "$BUILDLOG" 2>&1 + RESULT=$? + fi + + if [ $RESULT -eq 0 ]; then + "$TEMPFILE.out" + RESULT=$? + fi + + deleteTempFiles "$TEMPFILE.c $TEMPFILE.c.o $TEMPFILE.out" + echo >> "$BUILDLOG" return $RESULT } @@ -268,7 +302,8 @@ detect_dependencies_library() { } # Description: check if a program is present in the path -# Arguments: +# Arguments: $1 - The name of the program as used in config_proginfo after +# "BIN_" have_program() { local PROG TEMP_NAME TEMP_FILE TEMP_VERSION TEMP_PRESENT TEMP_DETECT local TEMP_DEPEND_DETECT_PROG TEMP_DEPEND_DETECT_LIB @@ -347,6 +382,64 @@ but version $2 is required!" return 0 } +# Description: check if a build tool is present, and define the appropriate +# environment variable for it. +# Arguments: $1 - The type of compile tool. One of PREPROC_C, MKDEP_C, +# COMPILE_C, PREPROC_OBJC, MKDEP_OBJC, COMPILE_OBJC, +# and LINK. +have_build_tool() { + local TOOL TEMP_NAME TEMP_PRESENT DEPENDS DEPEND SUCCESS COMMAND + + TOOL=$1 + + TEMP_NAME=`evalVar BUILDTOOL_${TOOL}_NAME` + if [ -z "$TEMP_NAME" ]; then + echo "Fatal: Program '$TOOL' is not defined!" >&2 + exit 1 + fi + + eval TEMP_PRESENT="\$BUILDTOOL_${TOOL}_PRESENT" + if [ -n "$TEMP_PRESENT" ]; then + return "$TEMP_PRESENT" + fi + + SUCCESS=0 + eval DEPENDS="\$BUILDTOOL_${TOOL}_DEPEND" + for DEPEND in $DEPENDS; do + if not have_program "$DEPEND"; then + SUCCESS=1 + fi + done + + eval "BUILDTOOL_${TOOL}_PRESENT"="\$SUCCESS" + + eval COMMAND="\$BUILDTOOL_${TOOL}_COMMAND" + # Expand environment variables in $COMMAND: + eval COMMAND=\"$COMMAND\" + + if [ $SUCCESS -eq 0 ]; then + build_message "We have a $TEMP_NAME." + eval "${TOOL}"="\$COMMAND" + else + build_message "No $TEMP_NAME found." + fi + + return $SUCCESS +} + +have_build_tools_language() { + local LANGUAGE + + LANGUAGE=$1 + + have_build_tool "PREPROC_$LANGUAGE" || return 1 + have_build_tool "MKDEP_$LANGUAGE" || return 1 + have_build_tool "COMPILE_$LANGUAGE" || return 1 + + return 0 +} + + # Description: check if a library is present on the system # Arguments: $1 - The name of the library as used in config_proginfo after # "LIB_" @@ -832,7 +925,7 @@ EOF # The copy is done so that the file modes are equal. $SED -f "${TEMPFILE}.sed" < "$SRC_PATH/$FILE".in > "$DST_PATH/$FILE" done - rm -- "${TEMPFILE}.sed" + deleteTempFiles "${TEMPFILE}.sed" } # Define the build system type. diff --git a/sc2/build/unix/config_proginfo_build b/sc2/build/unix/config_proginfo_build index d36b3f889..9e7efad14 100644 --- a/sc2/build/unix/config_proginfo_build +++ b/sc2/build/unix/config_proginfo_build @@ -29,6 +29,61 @@ SYSTEM_BUILD_CFLAGS="" # LDFLAGS SYSTEM_BUILD_LDFLAGS="" +# Compilers etc. +BUILDTOOL_PREPROC_C_NAME="C preprocessor" +BUILDTOOL_MKDEP_C_NAME="C dependency generator" +BUILDTOOL_COMPILE_C_NAME="C compiler" +BUILDTOOL_PREPROC_OBJC_NAME="Objective-C preprocessor" +BUILDTOOL_MKDEP_OBJC_NAME="Objective-C dependency generator" +BUILDTOOL_COMPILE_OBJC_NAME="Objective-C compiler" +BUILDTOOL_LINK_NAME="linker" +useGccBuildTools() { + # These strings will be evaluated later. + BUILDTOOL_PREPROC_C_COMMAND="\$PROG_gcc_FILE -E $EXTRA_PLATFORM_GCC_FLAGS_PREPROC_C" + BUILDTOOL_PREPROC_C_DEPEND='gcc' + + BUILDTOOL_MKDEP_C_COMMAND="\$PROG_gcc_FILE -MM $EXTRA_PLATFORM_GCC_FLAGS_MKDEP_C" + BUILDTOOL_MKDEP_C_DEPEND='gcc' + + BUILDTOOL_COMPILE_C_COMMAND="\$PROG_gcc_FILE -c $EXTRA_PLATFORM_GCC_FLAGS_COMPILE_C" + BUILDTOOL_COMPILE_C_DEPEND='gcc' + + BUILDTOOL_PREPROC_OBJC_COMMAND="\$PROG_gcc_FILE -E $EXTRA_PLATFORM_GCC_FLAGS_PREPROC_OBJC" + BUILDTOOL_PREPROC_OBJC_DEPEND='gcc' + + BUILDTOOL_MKDEP_OBJC_COMMAND="\$PROG_gcc_FILE -MF $EXTRA_PLATFORM_GCC_FLAGS_MKDEP_OBJC" + BUILDTOOL_MKDEP_OBJC_DEPEND='gcc' + + BUILDTOOL_COMPILE_OBJC_COMMAND="\$PROG_gcc_FILE -c $EXTRA_PLATFORM_GCC_FLAGS_COMPILE_OBJC" + BUILDTOOL_COMPILE_OBJC_DEPEND='gcc' + + BUILDTOOL_LINK_COMMAND="\$PROG_gcc_FILE $EXTRA_PLATFORM_GCC_LINK_FLAGS" + BUILDTOOL_LINK_DEPEND='gcc' +} +case "$BUILD_SYSTEM" in + Darwin) + EXTRA_PLATFORM_GCC_FLAGS_COMPILE_C='-arch ppc -arch i386' + EXTRA_PLATFORM_GCC_FLAGS_COMPILE_OBJC='-arch ppc -arch i386' + EXTRA_PLATFORM_GCC_FLAGS_LINK='-arch ppc -arch i386' + useGccBuildTools + ;; + *) + useGccBuildTools + ;; +esac +case "$BUILD_SYSTEM" in + Darwin) + BUILDTOOL_REZ_NAME="MacOS X resource compiler (Rez)" + BUILDTOOL_REZ='$PROG_Rez_FILE' + BUILDTOOL_REZ_DEPEND='Rez' + ;; + MINGW32*|CYGWIN*) + BUILDTOOL_WINDRES_NAME="Windows resource linker (windres)" + BUILDTOOL_WINDRES='$PROG_windres_FILE' + BUILDTOOL_WINDRES_DEPEND='windres' + ;; +esac + ############################################################################## # Describe the programs (possibly) used: #