Unix build improvement (build tool detection).

git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@2535 8092fc87-c524-0410-9efc-e669fe64eaf9
This commit is contained in:
meep-eep
2006-11-25 01:19:22 +00:00
parent fc2941b60d
commit a5b27582ab
8 changed files with 221 additions and 47 deletions
+3 -1
View File
@@ -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 - Ships in battle can resume normal speed in all circumstances after
the enemy Avatar's tractor beam disengages (bug #860; this is a the enemy Avatar's tractor beam disengages (bug #860; this is a
netplay desynchronizing change) - Alex netplay desynchronizing change) - Alex
+5 -5
View File
@@ -18,11 +18,11 @@ endef
endif endif
define act_mkdep_c define act_mkdep_c
$(MKDEPEND) $(CFLAGS) "$<" -MT "$(@D)/$(<F).o" -MF "$@" $(MKDEP_C) $(CFLAGS) "$<" -MT "$(@D)/$(<F).o" -MF "$@"
endef endef
define act_mkdep_m define act_mkdep_m
$(MKDEPEND) $(CFLAGS) "$<" -MT "$(@D)/$(<F).o" -MF "$@" $(MKDEP_OBJC) $(CFLAGS) "$<" -MT "$(@D)/$(<F).o" -MF "$@"
endef endef
define act_windres define act_windres
@@ -30,15 +30,15 @@ define act_windres
endef endef
define act_cc define act_cc
$(COMPILE) -o "$@" -c $(CFLAGS) "$<" $(COMPILE_C) -o "$@" $(CFLAGS) "$<"
endef endef
define act_objcc define act_objcc
$(COMPILE) -o "$@" -c $(CFLAGS) "$<" $(COMPILE_OBJC) -o "$@" $(CFLAGS) "$<"
endef endef
define act_link define act_link
$(COMPILE) -o "$@" $^ $(LDFLAGS) $(LINK) -o "$@" $^ $(LDFLAGS)
endef endef
+7 -2
View File
@@ -17,8 +17,13 @@
BUILD_SYSTEM='@BUILD_SYSTEM@' BUILD_SYSTEM='@BUILD_SYSTEM@'
HOST_SYSTEM='@HOST_SYSTEM@' HOST_SYSTEM='@HOST_SYSTEM@'
COMPILE='@COMPILE@' PREPROC_C='@PREPROC_C@'
MKDEPEND='@COMPILE@ -MM' MKDEP_C='@MKDEP_C@'
COMPILE_C='@COMPILE_C@'
PREPROC_OBJC='@PREPROC_OBJC@'
MKDEP_OBJC='@MKDEP_OBJC@'
COMPILE_OBJC='@COMPILE_OBJC@'
LINK='@LINK@'
MAKE='@MAKE@' MAKE='@MAKE@'
ECHON='@ECHON@' ECHON='@ECHON@'
SED='@SED@' SED='@SED@'
+10 -10
View File
@@ -9,17 +9,15 @@
uqm_requirements() uqm_requirements()
{ {
# Some requirements: # Some requirements:
have_program gcc || exit 1 have_build_tools_language C || exit 1
COMPILE="$PROG_gcc_FILE" have_build_tool LINK || exit 1
case "$HOST_SYSTEM" in case "$HOST_SYSTEM" in
MINGW32*) MINGW32*)
have_program windres have_build_tool WINDRES || exit 1
WINDRES="$PROG_windres_FILE"
;; ;;
Darwin) Darwin)
have_program Rez || exit 1 have_build_tools_language OBJC || exit 1
REZ="$PROG_Rez_FILE" have_build_tool REZ || exit 1
;; ;;
esac esac
@@ -343,7 +341,9 @@ uqm_process_config() {
substitute_vars SUBSTITUTE_VARS SUBSTITUTE_FILES src "$BUILD_WORK" substitute_vars SUBSTITUTE_VARS SUBSTITUTE_FILES src "$BUILD_WORK"
# Make build.vars from build.vars.in, substituting variables. # Make build.vars from build.vars.in, substituting variables.
SUBSTITUTE_VARS="BUILD_SYSTEM HOST_SYSTEM COMPILE CFLAGS LDFLAGS \ SUBSTITUTE_VARS="BUILD_SYSTEM HOST_SYSTEM CFLAGS LDFLAGS LINK \
PREPROC_C MKDEP_C COMPILE_C \
PREPROC_OBJC MKDEP_OBJC COMPILE_OBJC \
MAKE ECHON SED DEBUG JOYSTICK NETPLAY \ MAKE ECHON SED DEBUG JOYSTICK NETPLAY \
SOUNDMODULE USE_INTERNAL_MIKMOD \ SOUNDMODULE USE_INTERNAL_MIKMOD \
HAVE_OPENGL HAVE_REGEX_H_FLAG USE_ZIP_IO \ HAVE_OPENGL HAVE_REGEX_H_FLAG USE_ZIP_IO \
@@ -389,7 +389,7 @@ uqm_post_build() {
# the resource fork, in fact) # the resource fork, in fact)
case "$HOST_SYSTEM" in case "$HOST_SYSTEM" in
Darwin) Darwin)
${REZ} ${RFORK} -o ${TARGET_FILE} $REZ "$RFORK" -o "$TARGET_FILE"
;; ;;
esac esac
} }
@@ -449,7 +449,7 @@ uqm_install_osx() {
for HEADER in $HEADERS; do for HEADER in $HEADERS; do
HEADER_FILE=`basename $HEADER` HEADER_FILE=`basename $HEADER`
eval FRAMEWORK=`echo '' | \ eval FRAMEWORK=`echo '' | \
$COMPILE -E -D__MACOSX__ -include $HEADER - | \ $PREPROC_C -D__MACOSX__ -include $HEADER - | \
awk '(/'$HEADER_FILE'/ && $2 == 1) { print $3; exit }' | \ awk '(/'$HEADER_FILE'/ && $2 == 1) { print $3; exit }' | \
$SED 's/.Headers.*$/"/'` $SED 's/.Headers.*$/"/'`
cp -r "$FRAMEWORK" "$INSTROOT/Frameworks" cp -r "$FRAMEWORK" "$INSTROOT/Frameworks"
+24 -6
View File
@@ -18,8 +18,9 @@ The files
These are the files in the directory with the build script. These are the files in the directory with the build script.
Of these files only build.config should be modified for a specific build. Of these files only build.config should be modified for a specific build.
For unknown dependencies, additions to config_proginfo might need to be For unknown dependencies, additions to config_proginfo_build or
made. The other files should not be modified. config_proginfo_host might need to be made. The other files should not
be modified.
Only build.sh is to be called directly. Only build.sh is to be called directly.
ansi ansi colour definitions. ansi ansi colour definitions.
@@ -114,8 +115,8 @@ There are three types of menu items.
Program info (from config_proginfo) Program info (from config_proginfo_build)
----------------------------------- -----------------------------------------
Information about programs used should be supplied in the following form: Information about programs used should be supplied in the following form:
- PROG_${PROGRAM}_NAME - PROG_${PROGRAM}_NAME
@@ -148,9 +149,26 @@ Information about programs used should be supplied in the following form:
1 if the program has been verified to be not present 1 if the program has been verified to be not present
<empty> if presence of the program hasn't been verified <empty> 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
<empty> 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: Information about libraries used should be supplied in the following form:
- LIB_${LIB}_NAME - LIB_${LIB}_NAME
+2 -1
View File
@@ -79,7 +79,8 @@ if [ -z "$TARGET" ]; then
exit 1 exit 1
fi fi
BUILD_PROJECT="$TARGET" BUILD_PROJECT="$TARGET"
export TARGET BUILD_PROJECT COMPILE MKDEPEND ECHON 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" export "${BUILD_PROJECT}_CFLAGS" "${BUILD_PROJECT}_LDFLAGS"
# Add trailing / from objs dir # Add trailing / from objs dir
+114 -21
View File
@@ -15,8 +15,9 @@
# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
BUILDLOG=/dev/null BUILDLOG=/tmp/build.log
TEMPFILE="/tmp/build.$$.tmp" TEMPFILE="/tmp/build.$$.tmp"
#KEEPTEMPFILES=keeptempfiles
# Description: perform a command, and set the exit status to the opposite. # Description: perform a command, and set the exit status to the opposite.
@@ -74,29 +75,51 @@ $RESULT
EOF 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 # Description: read text from stdin to use as a c file to compile
# Arguments: $1 - CFLAGS to use for compilation (optional) # Arguments: $1 - CFLAGS to use for compilation (optional)
# $2 - LDFLAGS to use for linking (optional) # $2 - LDFLAGS to use for linking (optional)
# Returns: 0 - if compile successful # Returns: 0 - if compile successful
# something else - if compile failed # something else - if compile failed
try_compile_c() { try_compile_c() {
local SYSTEM_FLAGS local SYSTEM_FLAGS RESULT
if [ -z "$COMPILE" ]; then
echo "Fatal: Program \$COMPILE is not defined!" >&2 if [ -z "$COMPILE_C" ]; then
echo "Fatal: Program \$COMPILE_C is not defined!" >&2
exit 1 exit 1
fi fi
SYSTEM_FLAGS="$SYSTEM_BUILD_CFLAGS $SYSTEM_BUILD_LDFLAGS $SYSTEM_HOST_CFLAGS $SYSTEM_HOST_LDFLAGS" SYSTEM_FLAGS="$SYSTEM_BUILD_CFLAGS $SYSTEM_BUILD_LDFLAGS $SYSTEM_HOST_CFLAGS $SYSTEM_HOST_LDFLAGS"
cat > "$TEMPFILE.c" 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=$? 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 if [ $RESULT -ne 0 ]; then
echo "Failed program was:" >> "$BUILDLOG" echo "Failed program was:" >> "$BUILDLOG"
echo "+++ START $TEMPFILE.c" >> "$BUILDLOG" echo "+++ START $TEMPFILE.c" >> "$BUILDLOG"
cat "$TEMPFILE.c" >> "$BUILDLOG" cat "$TEMPFILE.c" >> "$BUILDLOG"
echo "+++ END $TEMPFILE.c" >> "$BUILDLOG" echo "+++ END $TEMPFILE.c" >> "$BUILDLOG"
fi fi
rm -f "$TEMPFILE.c" "$TEMPFILE.out"
deleteTempFiles "$TEMPFILE.c $TEMPFILE.c.o $TEMPFILE.out"
echo >> "$BUILDLOG" echo >> "$BUILDLOG"
return $RESULT return $RESULT
} }
@@ -104,25 +127,36 @@ try_compile_c() {
# Description: read text from stdin to use as a c file to compile # Description: read text from stdin to use as a c file to compile
# Arguments: $1 - CFLAGS to use for compilation (optional) # Arguments: $1 - CFLAGS to use for compilation (optional)
# $2 - LDFLAGS to use for linking (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 # otherwise - exit status of the program
try_compile_and_run_c() { try_compile_and_run_c() {
local SYSTEM_FLAGS local SYSTEM_FLAGS RESULT
if [ -z "$COMPILE" ]; then
echo "Fatal: Program \$COMPILE is not defined!" >&2 if [ -z "$COMPILE_C" ]; then
echo "Fatal: Program \$COMPILE_C is not defined!" >&2
exit 1 exit 1
fi fi
SYSTEM_FLAGS="$SYSTEM_BUILD_CFLAGS $SYSTEM_BUILD_LDFLAGS $SYSTEM_HOST_CFLAGS $SYSTEM_HOST_LDFLAGS" SYSTEM_FLAGS="$SYSTEM_BUILD_CFLAGS $SYSTEM_BUILD_LDFLAGS $SYSTEM_HOST_CFLAGS $SYSTEM_HOST_LDFLAGS"
cat > "$TEMPFILE.c" 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" \
if [ $? -ne 0 ]; then -o "$TEMPFILE.c.o" >> "$BUILDLOG" 2>&1
return -1
fi
rm -f -- "$TEMPFILE.c"
"$TEMPFILE.out"
RESULT=$? 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" echo >> "$BUILDLOG"
return $RESULT return $RESULT
} }
@@ -268,7 +302,8 @@ detect_dependencies_library() {
} }
# Description: check if a program is present in the path # 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() { have_program() {
local PROG TEMP_NAME TEMP_FILE TEMP_VERSION TEMP_PRESENT TEMP_DETECT local PROG TEMP_NAME TEMP_FILE TEMP_VERSION TEMP_PRESENT TEMP_DETECT
local TEMP_DEPEND_DETECT_PROG TEMP_DEPEND_DETECT_LIB local TEMP_DEPEND_DETECT_PROG TEMP_DEPEND_DETECT_LIB
@@ -347,6 +382,64 @@ but version $2 is required!"
return 0 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 # Description: check if a library is present on the system
# Arguments: $1 - The name of the library as used in config_proginfo after # Arguments: $1 - The name of the library as used in config_proginfo after
# "LIB_" # "LIB_"
@@ -832,7 +925,7 @@ EOF
# The copy is done so that the file modes are equal. # The copy is done so that the file modes are equal.
$SED -f "${TEMPFILE}.sed" < "$SRC_PATH/$FILE".in > "$DST_PATH/$FILE" $SED -f "${TEMPFILE}.sed" < "$SRC_PATH/$FILE".in > "$DST_PATH/$FILE"
done done
rm -- "${TEMPFILE}.sed" deleteTempFiles "${TEMPFILE}.sed"
} }
# Define the build system type. # Define the build system type.
+55
View File
@@ -29,6 +29,61 @@ SYSTEM_BUILD_CFLAGS=""
# LDFLAGS # LDFLAGS
SYSTEM_BUILD_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: # # Describe the programs (possibly) used: #