diff --git a/sc2/build/build.config b/sc2/build/build.config index 1d1987871..7acba40d5 100644 --- a/sc2/build/build.config +++ b/sc2/build/build.config @@ -26,6 +26,9 @@ have_library vorbisfile || exit 1 define_have_symbol strupr define_have_symbol stricmp +# Check for getopt.h +define_have_header getopt.h + # Describe the menu: MENU_main_ITEMS="debug graphics sound link install_path" diff --git a/sc2/build/config_functions b/sc2/build/config_functions index b936afa95..835d370c2 100644 --- a/sc2/build/config_functions +++ b/sc2/build/config_functions @@ -253,6 +253,43 @@ EOF fi } +# Description: check if a header is available. +# Arguments: $1 - the name of the header file +have_header() { + local HEADER + HEADER="$1" + + try_compile_c "$TEMP_CFLAGS" "$TEMP_LDFLAGS" << EOF 2>&1 > /dev/null +#include <$HEADER> +int main() { + return 0; +} +EOF + if [ $? -gt 0 ]; then + build_message "Header '$HEADER' not found." + return 1 + fi + build_message "Header '$HEADER' found." + return 0 +} + +# Description: check if a header is available. +# set HAVE_ accordingly, where is the capitalized +# name of the header file. "sys/time.h" becomes "SYS_TIME_H". +# Arguments: $1 - the name of the symbol +define_have_header() { + local NAME VALUE + NAME=`$TR /.a-z __A-Z << EOF +$1 +EOF +` + if have_header "$1"; then + add_symbol "HAVE_$NAME" "#define HAVE_$NAME" + else + add_symbol "HAVE_$NAME" "#undef HAVE_$NAME" + fi +} + # Description: Add a symbol to be replaced by substitute_vars # $HAVE_SYMBOLS will contain the variable names of all # symbols added by define_have_symbol and should be passed to @@ -303,14 +340,11 @@ substitute_vars() { eval FILES=\"\$$2\" for VAR in $VARS; do - # Using CR as a seperator, as it's unlikely that's used in - # $VAR itself. + # Escape all / in VAR so that we can use / as seperator char for sed eval VALUE=\"\$$VAR\" + VALUE=$(echo "$VALUE" | sed 's,\([\&/]\),\\\1,g') cat << EOF -s -@${VAR}@ -${VALUE} -g +s/@${VAR}@/${VALUE}/g EOF done > "${TEMPFILE}.sed" diff --git a/sc2/src/Makeinfo b/sc2/src/Makeinfo index 4e10985ef..2fb879817 100644 --- a/sc2/src/Makeinfo +++ b/sc2/src/Makeinfo @@ -1,4 +1,4 @@ -uqm_SUBDIRS=sc2code +uqm_SUBDIRS="sc2code getopt" uqm_CFILES="options.c port.c starcon2.c" test_CFILES=test.c diff --git a/sc2/src/config.h.in b/sc2/src/config.h.in index 4c004d838..9181c6f39 100644 --- a/sc2/src/config.h.in +++ b/sc2/src/config.h.in @@ -10,3 +10,6 @@ /* Defined if your system has stricmp of its own */ @HAVE_STRICMP@ +/* Defined if your system has getopt.h */ +@HAVE_GETOPT_H@ + diff --git a/sc2/src/getopt/Makeinfo b/sc2/src/getopt/Makeinfo new file mode 100644 index 000000000..60e91d9f8 --- /dev/null +++ b/sc2/src/getopt/Makeinfo @@ -0,0 +1 @@ +uqm_CFILES="getopt.c getopt1.c" diff --git a/sc2/src/getopt/getopt.c b/sc2/src/getopt/getopt.c index 9a98f8b2b..6d57ba533 100644 --- a/sc2/src/getopt/getopt.c +++ b/sc2/src/getopt/getopt.c @@ -31,6 +31,7 @@ # include #endif +#ifndef HAVE_GETOPT_H #if !defined __STDC__ || !__STDC__ /* This is a separate conditional since some stdc systems reject `defined (const)'. */ @@ -1057,3 +1058,5 @@ main (argc, argv) } #endif /* TEST */ + +#endif /* HAVE_GETOPT_H */ diff --git a/sc2/src/getopt/getopt1.c b/sc2/src/getopt/getopt1.c index 22a7efbdd..6a3db824b 100644 --- a/sc2/src/getopt/getopt1.c +++ b/sc2/src/getopt/getopt1.c @@ -22,6 +22,7 @@ #include #endif +#ifndef HAVE_GETOPT_H #include "getopt.h" #if !defined __STDC__ || !__STDC__ @@ -186,3 +187,5 @@ main (argc, argv) } #endif /* TEST */ + +#endif /* HAVE_GETOPT_H */ diff --git a/sc2/src/starcon2.c b/sc2/src/starcon2.c index 3f3efc284..eddad2fbe 100644 --- a/sc2/src/starcon2.c +++ b/sc2/src/starcon2.c @@ -18,10 +18,14 @@ #ifndef WIN32 #include -#include #include "config.h" #else #include +#endif + +#ifdef HAVE_GETOPT_H +#include +#else #include "getopt/getopt.h" #endif