diff --git a/sc2/build/unix/build.docs b/sc2/build/unix/build.docs index 7290ee735..b3b8bcfd8 100644 --- a/sc2/build/unix/build.docs +++ b/sc2/build/unix/build.docs @@ -122,7 +122,8 @@ Information about programs used should be supplied in the following form: done configuring. - PROG_${PROGRAM}_DETECT (optional) A command to be executed which should return 0 if the program is present - on the system, or 1 otherwise. If not supplied, 'type' is + on the system, 1 if it is not present, or 2 to fallback to the default + detection. If no detect function was set, or it returned 2, 'type' is used to check for the program in the path. This command may include a shell command that modifies any of the variables PROG_${PROGRAM}_FILE, PROG_${PROGRAM}_ACTION, or @@ -156,9 +157,10 @@ Information about libraries used should be supplied in the following form: is used. - PROG_${LIB}_DETECT (optional) A command to be executed which should return 0 if the library is present - on the system, or 1 otherwise. If not supplied, an attempt is - made to compile and link an empty C program with the flags as in - LIB_${LIB}_CFLAGS and LIB_${LIB}_LDFLAGS. + on the system, 1 if it is not present, or 2 to fallback to the default + detection. If no detect function was set, or it returned 2, + an attempt is made to compile and link an empty C program with + the flags as in LIB_${LIB}_CFLAGS and LIB_${LIB}_LDFLAGS. This command may include a shell command that modifies any of the variables PROG_${LIB}_CFLAGS, PROG_${LIB}_LDFLAGS, or PROG_${LIB}_VERSION. diff --git a/sc2/build/unix/config_functions b/sc2/build/unix/config_functions index e5a96fa85..5e6a29240 100644 --- a/sc2/build/unix/config_functions +++ b/sc2/build/unix/config_functions @@ -194,17 +194,30 @@ have_program() { $TEMP_DETECT # NB. TEMP_DETECT should make sure PROG_${PROG}_VERSION and # PROG_${PROG}_FILE are set. - if [ $? -ne 0 ]; then - eval "PROG_${PROG}_PRESENT"=1 - build_message "$TEMP_NAME not found." - return 1 - fi + case $? in + 0) # Program found + eval "PROG_${PROG}_PRESENT"=0 + ;; + 1) # Lib not found + eval "PROG_${PROG}_PRESENT"=1 + ;; + 2) # Use default detection + ;; + esac fi - TEMP_FILE=`evalVar PROG_${PROG}_FILE` - - type "${TEMP_FILE%% *}" > /dev/null 2>&1 - if [ $? -ne 0 ]; then + eval TEMP_PRESENT="\$PROG_${PROG}_PRESENT" + if [ -z "$TEMP_PRESENT" ]; then + TEMP_FILE=`evalVar PROG_${PROG}_FILE` + type "${TEMP_FILE%% *}" > /dev/null 2>&1 + if [ $? -eq 0 ]; then + # Program found + eval "PROG_${PROG}_PRESENT"=0 + fi + fi + + eval TEMP_PRESENT="\$PROG_${PROG}_PRESENT" + if [ -z "$TEMP_PRESENT" ]; then eval "PROG_${PROG}_PRESENT"=1 build_message "$TEMP_NAME not found." return 1 @@ -262,14 +275,27 @@ have_library() { TEMP_DETECT=`evalVar LIB_${LIB}_DETECT` if [ -n "$TEMP_DETECT" ]; then - $TEMP_DETECT TEMP_DEPEND_PROG=`evalVar LIB_${LIB}_DEPEND_DETECT_PROG` TEMP_DEPEND_LIB=`evalVar LIB_${LIB}_DEPEND_DETECT_LIB` detect_dependencies_program "$TEMP_DEPEND_PROG" detect_dependencies_library "$TEMP_DEPEND_LIB" + $TEMP_DETECT # NB. TEMP_DETECT should make sure PROG_$LIB_VERSION is set. # return value of $TEMP_DETECT is used below. - else + case $? in + 0) # Lib found + eval "LIB_${LIB}_PRESENT"=0 + ;; + 1) # Lib not found + eval "LIB_${LIB}_PRESENT"=1 + ;; + 2) # Use default detection + ;; + esac + fi + + eval TEMP_PRESENT="\$LIB_${LIB}_PRESENT" + if [ -z "$TEMP_PRESENT" ]; then TEMP_CFLAGS=`evalVar LIB_${LIB}_CFLAGS` TEMP_LDFLAGS=`evalVar LIB_${LIB}_LDFLAGS` @@ -280,9 +306,14 @@ int main(int argc, char *argv[]) { return 0; } EOF - fi # TEMP_DETECT not defined + if [ $? -eq 0 ]; then + # Build successful + eval "LIB_${LIB}_PRESENT"=0 + fi + fi - if [ $? -ne 0 ]; then + eval TEMP_PRESENT="\$LIB_${LIB}_PRESENT" + if [ -z "$TEMP_PRESENT" ]; then eval "LIB_${LIB}_PRESENT"=1 build_message "$TEMP_NAME not found." return 1 @@ -548,7 +579,7 @@ try_pkgconfig_prog() { eval PROG_${PROG}_VERSION=\$TEMP_VERSION return 0 else - return 1 + return 2 fi } @@ -582,9 +613,10 @@ try_pkgconfig_lib() { eval LIB_${LIB}_VERSION=\$TEMP_VERSION eval LIB_${LIB}_CFLAGS=\$TEMP_CFLAGS eval LIB_${LIB}_LDFLAGS=\$TEMP_LDFLAGS - return 0 + return 2 # Force testing using the new CFLAGS and LDFLAGS + #return 0 else - return 1 + return 2 fi } diff --git a/sc2/build/unix/config_proginfo b/sc2/build/unix/config_proginfo index 0cdb4e91d..a1a7b1351 100644 --- a/sc2/build/unix/config_proginfo +++ b/sc2/build/unix/config_proginfo @@ -132,7 +132,7 @@ case "$OSNAME" in LIB_SDL_VERSION='$(sdl11-config --version)' ;; Darwin) - LIB_SDL_CFLAGS='-I/System/Library/Frameworks/SDL.framework/Headers -I/Library/Frameworks/SDL.framework/Headers -I$HOME/Library/Frameworks/SDL.framework/Headers' + LIB_SDL_CFLAGS='' LIB_SDL_LDFLAGS='-framework SDL -framework Cocoa -lobjc' LIB_SDL_VERSION=$(echo \ "SDL_MAJOR_VERSION.SDL_MINOR_VERSION.SDL_PATCHLEVEL" | \ @@ -158,7 +158,7 @@ LIB_SDL_mixer_VERSION="" LIB_SDL_image_NAME="SDL_image" case "$OSNAME" in Darwin) - LIB_SDL_image_CFLAGS='-I/System/Library/Frameworks/SDL_image.framework/Headers -I/Library/Frameworks/SDL_image.framework/Headers -I$HOME/Library/Frameworks/SDL_image.framework/Headers' + LIB_SDL_image_CFLAGS='' LIB_SDL_image_LDFLAGS="-framework SDL_image" ;; *) @@ -176,9 +176,13 @@ case "$OSNAME" in FreeBSD|OpenBSD) LIB_openal_LDFLAGS="-L/usr/local/lib -pthread -lopenal" ;; - MINGW32*) + MINGW32*) LIB_openal_LDFLAGS="-lopenal32" ;; + Darwin) + LIB_openal_CFLAGS='' + LIB_openal_LDFLAGS="-framework OpenAL" + ;; *) LIB_openal_LDFLAGS="-lopenal" ;; diff --git a/sc2/src/port.h b/sc2/src/port.h index de88bb862..65808510d 100644 --- a/sc2/src/port.h +++ b/sc2/src/port.h @@ -137,6 +137,20 @@ iswgraph(wint_t wc) } #endif +// Use SDL_INCLUDE to portably include the SDL files from the right +// location. TODO: Where SDL_H is located could be detected from the build +// script. +#ifdef APPLE +# define HAVE_SDL_SDL_H +#else +# define HAVE_SDL_H +#endif +#ifdef HAVE_SDL_H +# define SDL_INCLUDE(file) +#elif defined(HAVE_SDL_SDL_H) +# define SDL_INCLUDE(file) +#endif + #endif /* _PORT_H */ diff --git a/sc2/src/sc2code/libs/graphics/sdl/bbox.c b/sc2/src/sc2code/libs/graphics/sdl/bbox.c index b1904728a..62cf62abe 100644 --- a/sc2/src/sc2code/libs/graphics/sdl/bbox.c +++ b/sc2/src/sc2code/libs/graphics/sdl/bbox.c @@ -1,4 +1,5 @@ -#include "SDL.h" +#include "port.h" +#include SDL_INCLUDE(SDL.h) #include "bbox.h" TFB_BoundingBox TFB_BBox; diff --git a/sc2/src/sc2code/libs/graphics/sdl/canvas.c b/sc2/src/sc2code/libs/graphics/sdl/canvas.c index 08e7fad7e..3d6746154 100644 --- a/sc2/src/sc2code/libs/graphics/sdl/canvas.c +++ b/sc2/src/sc2code/libs/graphics/sdl/canvas.c @@ -1,4 +1,5 @@ -#include "SDL.h" +#include "port.h" +#include SDL_INCLUDE(SDL.h) #include "sdl_common.h" #include "libs/graphics/gfx_common.h" #include "libs/graphics/sdl/primitives.h" diff --git a/sc2/src/sc2code/libs/graphics/sdl/rotozoom.h b/sc2/src/sc2code/libs/graphics/sdl/rotozoom.h index ceedb7731..728fd429b 100644 --- a/sc2/src/sc2code/libs/graphics/sdl/rotozoom.h +++ b/sc2/src/sc2code/libs/graphics/sdl/rotozoom.h @@ -18,7 +18,8 @@ #define M_PI 3.141592654 #endif -#include "SDL.h" +#include "port.h" +#include SDL_INCLUDE(SDL.h) /* ---- Defines */ diff --git a/sc2/src/sc2code/libs/graphics/sdl/sdl_common.h b/sc2/src/sc2code/libs/graphics/sdl/sdl_common.h index 2b7ab02d7..7b18cc6f8 100644 --- a/sc2/src/sc2code/libs/graphics/sdl/sdl_common.h +++ b/sc2/src/sc2code/libs/graphics/sdl/sdl_common.h @@ -19,9 +19,10 @@ #ifndef SDL_COMMON_H #define SDL_COMMON_H -#include "SDL.h" -#include "SDL_image.h" -#include "SDL_byteorder.h" +#include "port.h" +#include SDL_INCLUDE(SDL.h) +#include SDL_INCLUDE(SDL_image.h) +#include SDL_INCLUDE(SDL_byteorder.h) #include "libs/graphics/gfxintrn.h" #include "libs/graphics/tfb_draw.h" diff --git a/sc2/src/sc2code/libs/graphics/sdl/sdluio.c b/sc2/src/sc2code/libs/graphics/sdl/sdluio.c index 9e21d8857..7f3f66f60 100644 --- a/sc2/src/sc2code/libs/graphics/sdl/sdluio.c +++ b/sc2/src/sc2code/libs/graphics/sdl/sdluio.c @@ -2,10 +2,10 @@ #include "port.h" #include "libs/uio.h" -#include "SDL.h" -#include "SDL_image.h" -#include "SDL_error.h" -#include "SDL_rwops.h" +#include SDL_INCLUDE(SDL.h) +#include SDL_INCLUDE(SDL_image.h) +#include SDL_INCLUDE(SDL_error.h) +#include SDL_INCLUDE(SDL_rwops.h) #include "libs/misc.h" #include #include diff --git a/sc2/src/sc2code/libs/graphics/sdl/sdluio.h b/sc2/src/sc2code/libs/graphics/sdl/sdluio.h index ab97b2e33..c3178894d 100644 --- a/sc2/src/sc2code/libs/graphics/sdl/sdluio.h +++ b/sc2/src/sc2code/libs/graphics/sdl/sdluio.h @@ -3,8 +3,8 @@ #include "port.h" #include "libs/uio.h" -#include "SDL.h" -#include "SDL_rwops.h" +#include SDL_INCLUDE(SDL.h) +#include SDL_INCLUDE(SDL_rwops.h) SDL_Surface *sdluio_loadImage (uio_DirHandle *dir, const char *fileName); int sdluio_seek (SDL_RWops *context, int offset, int whence); diff --git a/sc2/src/sc2code/libs/input/sdl/keynames.c b/sc2/src/sc2code/libs/input/sdl/keynames.c index 4acf56e67..234b2d34e 100644 --- a/sc2/src/sc2code/libs/input/sdl/keynames.c +++ b/sc2/src/sc2code/libs/input/sdl/keynames.c @@ -1,7 +1,7 @@ -#include +#include "port.h" +#include SDL_INCLUDE(SDL.h) #include #include "keynames.h" -#include "port.h" /* This code is adapted from the code in SDL_keysym.h. Though this * would almost certainly be fast if we were to use a direct char * diff --git a/sc2/src/sc2code/libs/input/sdl/vcontrol.c b/sc2/src/sc2code/libs/input/sdl/vcontrol.c index d650605b2..68e8f443f 100644 --- a/sc2/src/sc2code/libs/input/sdl/vcontrol.c +++ b/sc2/src/sc2code/libs/input/sdl/vcontrol.c @@ -1,11 +1,11 @@ -#include +#include "port.h" +#include SDL_INCLUDE(SDL.h) #include #include #include #include "vcontrol.h" #include "vcontrol_malloc.h" #include "keynames.h" -#include "port.h" /* How many binding slots are allocated at once. */ #define POOL_CHUNK_SIZE 64 diff --git a/sc2/src/sc2code/libs/input/sdl/vcontrol.h b/sc2/src/sc2code/libs/input/sdl/vcontrol.h index 07a8bd0f3..11f831484 100644 --- a/sc2/src/sc2code/libs/input/sdl/vcontrol.h +++ b/sc2/src/sc2code/libs/input/sdl/vcontrol.h @@ -1,10 +1,9 @@ -#include - #ifndef _VCONTROL_H_ #define _VCONTROL_H_ #include "port.h" #include "libs/uio.h" +#include SDL_INCLUDE(SDL.h) /* Initialization routines */ void VControl_Init (void); diff --git a/sc2/src/sc2code/libs/sound/mixer/sdl/audiodrv_sdl.h b/sc2/src/sc2code/libs/sound/mixer/sdl/audiodrv_sdl.h index 2a7e3c341..a9cb490f4 100644 --- a/sc2/src/sc2code/libs/sound/mixer/sdl/audiodrv_sdl.h +++ b/sc2/src/sc2code/libs/sound/mixer/sdl/audiodrv_sdl.h @@ -20,10 +20,10 @@ #ifndef _AUDIODRV_SDL_H #define _AUDIODRV_SDL_H -#include "config.h" +#include "port.h" #include "libs/sound/sound.h" #include "libs/sound/mixer/mixer.h" -#include +#include SDL_INCLUDE(SDL.h) /* General */ sint32 mixSDL_Init (audio_Driver *driver, sint32 flags); diff --git a/sc2/src/sc2code/libs/threads/sdl/sdlthreads.h b/sc2/src/sc2code/libs/threads/sdl/sdlthreads.h index 19b17a805..76887ad9c 100644 --- a/sc2/src/sc2code/libs/threads/sdl/sdlthreads.h +++ b/sc2/src/sc2code/libs/threads/sdl/sdlthreads.h @@ -20,8 +20,9 @@ #ifndef _SDLTHREAD_H #define _SDLTHREAD_H -#include "SDL.h" -#include "SDL_thread.h" +#include "port.h" +#include SDL_INCLUDE(SDL.h) +#include SDL_INCLUDE(SDL_thread.h) #include "libs/threadlib.h" #include "libs/timelib.h" diff --git a/sc2/src/sc2code/libs/time/sdl/sdltime.h b/sc2/src/sc2code/libs/time/sdl/sdltime.h index b73e5cf5b..2e498aabe 100644 --- a/sc2/src/sc2code/libs/time/sdl/sdltime.h +++ b/sc2/src/sc2code/libs/time/sdl/sdltime.h @@ -20,7 +20,8 @@ #ifndef _SDLTIME_H #define _SDLTIME_H -#include "SDL.h" +#include "port.h" +#include SDL_INCLUDE(SDL.h) #include "../timecommon.h" #define NativeInitTimeSystem() diff --git a/sc2/src/starcon2.c b/sc2/src/starcon2.c index ad0c4d157..9d35f5ccf 100644 --- a/sc2/src/starcon2.c +++ b/sc2/src/starcon2.c @@ -43,7 +43,7 @@ #if defined(GFXMODULE_SDL) -# include +# include SDL_INCLUDE(SDL.h) // Including this is actually necessary on OSX. #endif