--- include/SDL_config.h
+++ include/SDL_config.h
@@ -1,3 +1,4 @@
+/* include/SDL_config.h.  Generated from SDL_config.h.in by configure.  */
 /*
   Simple DirectMedia Layer
   Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
@@ -22,34 +23,338 @@
 #ifndef _SDL_config_h
 #define _SDL_config_h
 
-#include "SDL_platform.h"
-
 /**
- *  \file SDL_config.h
+ *  \file SDL_config.h.in
+ *
+ *  This is a set of defines to configure the SDL features
  */
 
-/* Add any platform that doesn't build using the configure system. */
-#ifdef USING_PREMAKE_CONFIG_H
-#include "SDL_config_premake.h"
-#elif defined(__WIN32__)
-#include "SDL_config_windows.h"
-#elif defined(__WINRT__)
-#include "SDL_config_winrt.h"
-#elif defined(__MACOSX__)
-#include "SDL_config_macosx.h"
-#elif defined(__IPHONEOS__)
-#include "SDL_config_iphoneos.h"
-#elif defined(__ANDROID__)
-#include "SDL_config_android.h"
-#elif defined(__PSP__)
-#include "SDL_config_psp.h"
+/* General platform specific identifiers */
+#include "SDL_platform.h"
+
+/* Make sure that this isn't included by Visual C++ */
+#ifdef _MSC_VER
+#error You should run hg revert SDL_config.h 
+#endif
+
+/* C language features */
+/* #undef const */
+/* #undef inline */
+/* #undef volatile */
+
+/* C datatypes */
+#ifdef __LP64__
+#define SIZEOF_VOIDP 8
 #else
-/* This is a minimal configuration just to get SDL running on new platforms */
-#include "SDL_config_minimal.h"
-#endif /* platform config */
+#define SIZEOF_VOIDP 4
+#endif
+/* #undef HAVE_GCC_ATOMICS */
+/* #undef HAVE_GCC_SYNC_LOCK_TEST_AND_SET */
+
+/* #undef HAVE_DDRAW_H */
+/* #undef HAVE_DINPUT_H */
+/* #undef HAVE_DSOUND_H */
+/* #undef HAVE_DXGI_H */
+/* #undef HAVE_XINPUT_H */
+
+/* Comment this if you want to build without any C library requirements */
+#define HAVE_LIBC 1
+#if HAVE_LIBC
 
-#ifdef USING_GENERATED_CONFIG_H
-#error Wrong SDL_config.h, check your include path?
+/* Useful headers */
+#define HAVE_ALLOCA_H 1
+#define HAVE_SYS_TYPES_H 1
+#define HAVE_STDIO_H 1
+#define STDC_HEADERS 1
+#define HAVE_STDLIB_H 1
+#define HAVE_STDARG_H 1
+/* #undef HAVE_MALLOC_H */
+#define HAVE_MEMORY_H 1
+#define HAVE_STRING_H 1
+#define HAVE_STRINGS_H 1
+#define HAVE_INTTYPES_H 1
+#define HAVE_STDINT_H 1
+#define HAVE_CTYPE_H 1
+#define HAVE_MATH_H 1
+#define HAVE_ICONV_H 1
+#define HAVE_SIGNAL_H 1
+#define HAVE_ALTIVEC_H 1
+/* #undef HAVE_PTHREAD_NP_H */
+/* #undef HAVE_LIBUDEV_H */
+/* #undef HAVE_DBUS_DBUS_H */
+/* #undef HAVE_IBUS_IBUS_H */
+
+/* C library functions */
+#define HAVE_MALLOC 1
+#define HAVE_CALLOC 1
+#define HAVE_REALLOC 1
+#define HAVE_FREE 1
+#define HAVE_ALLOCA 1
+#ifndef __WIN32__ /* Don't use C runtime versions of these on Windows */
+#define HAVE_GETENV 1
+#define HAVE_SETENV 1
+#define HAVE_PUTENV 1
+#define HAVE_UNSETENV 1
 #endif
+#define HAVE_QSORT 1
+#define HAVE_ABS 1
+#define HAVE_BCOPY 1
+#define HAVE_MEMSET 1
+#define HAVE_MEMCPY 1
+#define HAVE_MEMMOVE 1
+#define HAVE_MEMCMP 1
+#define HAVE_STRLEN 1
+#define HAVE_STRLCPY 1
+#define HAVE_STRLCAT 1
+#define HAVE_STRDUP 1
+/* #undef HAVE__STRREV */
+/* #undef HAVE__STRUPR */
+/* #undef HAVE__STRLWR */
+/* #undef HAVE_INDEX */
+/* #undef HAVE_RINDEX */
+#define HAVE_STRCHR 1
+#define HAVE_STRRCHR 1
+#define HAVE_STRSTR 1
+/* #undef HAVE_ITOA */
+/* #undef HAVE__LTOA */
+/* #undef HAVE__UITOA */
+/* #undef HAVE__ULTOA */
+#define HAVE_STRTOL 1
+#define HAVE_STRTOUL 1
+/* #undef HAVE__I64TOA */
+/* #undef HAVE__UI64TOA */
+#define HAVE_STRTOLL 1
+#define HAVE_STRTOULL 1
+#define HAVE_STRTOD 1
+#define HAVE_ATOI 1
+#define HAVE_ATOF 1
+#define HAVE_STRCMP 1
+#define HAVE_STRNCMP 1
+/* #undef HAVE__STRICMP */
+#define HAVE_STRCASECMP 1
+/* #undef HAVE__STRNICMP */
+#define HAVE_STRNCASECMP 1
+/* #undef HAVE_SSCANF */
+#define HAVE_VSSCANF 1
+/* #undef HAVE_SNPRINTF */
+#define HAVE_VSNPRINTF 1
+#define HAVE_M_PI /**/
+#define HAVE_ATAN 1
+#define HAVE_ATAN2 1
+#define HAVE_ACOS 1
+#define HAVE_ASIN 1
+#define HAVE_CEIL 1
+#define HAVE_COPYSIGN 1
+#define HAVE_COS 1
+#define HAVE_COSF 1
+#define HAVE_FABS 1
+#define HAVE_FLOOR 1
+#define HAVE_LOG 1
+#define HAVE_POW 1
+#define HAVE_SCALBN 1
+#define HAVE_SIN 1
+#define HAVE_SINF 1
+#define HAVE_SQRT 1
+#define HAVE_SQRTF 1
+#define HAVE_TAN 1
+#define HAVE_TANF 1
+#define HAVE_FSEEKO 1
+/* #undef HAVE_FSEEKO64 */
+#define HAVE_SIGACTION 1
+#define HAVE_SA_SIGACTION 1
+#define HAVE_SETJMP 1
+#define HAVE_NANOSLEEP 1
+#define HAVE_SYSCONF 1
+#define HAVE_SYSCTLBYNAME 1
+/* #undef HAVE_CLOCK_GETTIME */
+/* #undef HAVE_GETPAGESIZE */
+#define HAVE_MPROTECT 1
+#define HAVE_ICONV 1
+/* #undef HAVE_PTHREAD_SETNAME_NP */
+/* #undef HAVE_PTHREAD_SET_NAME_NP */
+/* #undef HAVE_SEM_TIMEDWAIT */
+
+#else
+#define HAVE_STDARG_H 1
+#define HAVE_STDDEF_H 1
+#define HAVE_STDINT_H 1
+#endif /* HAVE_LIBC */
+
+/* SDL internal assertion support */
+/* #undef SDL_DEFAULT_ASSERT_LEVEL */
+
+/* Allow disabling of core subsystems */
+/* #undef SDL_ATOMIC_DISABLED */
+/* #undef SDL_AUDIO_DISABLED */
+/* #undef SDL_CPUINFO_DISABLED */
+/* #undef SDL_EVENTS_DISABLED */
+/* #undef SDL_FILE_DISABLED */
+/* #undef SDL_JOYSTICK_DISABLED */
+/* #undef SDL_HAPTIC_DISABLED */
+/* #undef SDL_LOADSO_DISABLED */
+/* #undef SDL_RENDER_DISABLED */
+/* #undef SDL_THREADS_DISABLED */
+/* #undef SDL_TIMERS_DISABLED */
+/* #undef SDL_VIDEO_DISABLED */
+/* #undef SDL_POWER_DISABLED */
+/* #undef SDL_FILESYSTEM_DISABLED */
+
+/* Enable various audio drivers */
+/* #undef SDL_AUDIO_DRIVER_ALSA */
+/* #undef SDL_AUDIO_DRIVER_ALSA_DYNAMIC */
+/* #undef SDL_AUDIO_DRIVER_ARTS */
+/* #undef SDL_AUDIO_DRIVER_ARTS_DYNAMIC */
+/* #undef SDL_AUDIO_DRIVER_PULSEAUDIO */
+/* #undef SDL_AUDIO_DRIVER_PULSEAUDIO_DYNAMIC */
+/* #undef SDL_AUDIO_DRIVER_HAIKU */
+/* #undef SDL_AUDIO_DRIVER_BSD */
+#define SDL_AUDIO_DRIVER_COREAUDIO 1
+#define SDL_AUDIO_DRIVER_DISK 1
+#define SDL_AUDIO_DRIVER_DUMMY 1
+/* #undef SDL_AUDIO_DRIVER_ANDROID */
+/* #undef SDL_AUDIO_DRIVER_XAUDIO2 */
+/* #undef SDL_AUDIO_DRIVER_DSOUND */
+/* #undef SDL_AUDIO_DRIVER_ESD */
+/* #undef SDL_AUDIO_DRIVER_ESD_DYNAMIC */
+/* #undef SDL_AUDIO_DRIVER_NACL */
+/* #undef SDL_AUDIO_DRIVER_NAS */
+/* #undef SDL_AUDIO_DRIVER_NAS_DYNAMIC */
+/* #undef SDL_AUDIO_DRIVER_SNDIO */
+/* #undef SDL_AUDIO_DRIVER_SNDIO_DYNAMIC */
+/* #undef SDL_AUDIO_DRIVER_OSS */
+/* #undef SDL_AUDIO_DRIVER_OSS_SOUNDCARD_H */
+/* #undef SDL_AUDIO_DRIVER_PAUDIO */
+/* #undef SDL_AUDIO_DRIVER_QSA */
+/* #undef SDL_AUDIO_DRIVER_SUNAUDIO */
+/* #undef SDL_AUDIO_DRIVER_WINMM */
+/* #undef SDL_AUDIO_DRIVER_FUSIONSOUND */
+/* #undef SDL_AUDIO_DRIVER_FUSIONSOUND_DYNAMIC */
+/* #undef SDL_AUDIO_DRIVER_EMSCRIPTEN */
+
+/* Enable various input drivers */
+/* #undef SDL_INPUT_LINUXEV */
+/* #undef SDL_INPUT_LINUXKD */
+/* #undef SDL_INPUT_TSLIB */
+/* #undef SDL_JOYSTICK_HAIKU */
+/* #undef SDL_JOYSTICK_DINPUT */
+/* #undef SDL_JOYSTICK_XINPUT */
+/* #undef SDL_JOYSTICK_DUMMY */
+#define SDL_JOYSTICK_IOKIT 1
+/* #undef SDL_JOYSTICK_LINUX */
+/* #undef SDL_JOYSTICK_ANDROID */
+/* #undef SDL_JOYSTICK_WINMM */
+/* #undef SDL_JOYSTICK_USBHID */
+/* #undef SDL_JOYSTICK_USBHID_MACHINE_JOYSTICK_H */
+/* #undef SDL_JOYSTICK_EMSCRIPTEN */
+/* #undef SDL_HAPTIC_DUMMY */
+/* #undef SDL_HAPTIC_LINUX */
+#define SDL_HAPTIC_IOKIT 1
+/* #undef SDL_HAPTIC_DINPUT */
+/* #undef SDL_HAPTIC_XINPUT */
+
+/* Enable various shared object loading systems */
+/* #undef SDL_LOADSO_HAIKU */
+#define SDL_LOADSO_DLOPEN 1
+/* #undef SDL_LOADSO_DUMMY */
+/* #undef SDL_LOADSO_LDG */
+/* #undef SDL_LOADSO_WINDOWS */
+
+/* Enable various threading systems */
+#define SDL_THREAD_PTHREAD 1
+#define SDL_THREAD_PTHREAD_RECURSIVE_MUTEX 1
+/* #undef SDL_THREAD_PTHREAD_RECURSIVE_MUTEX_NP */
+/* #undef SDL_THREAD_WINDOWS */
+
+/* Enable various timer systems */
+/* #undef SDL_TIMER_HAIKU */
+/* #undef SDL_TIMER_DUMMY */
+#define SDL_TIMER_UNIX 1
+/* #undef SDL_TIMER_WINDOWS */
+
+/* Enable various video drivers */
+/* #undef SDL_VIDEO_DRIVER_HAIKU */
+#define SDL_VIDEO_DRIVER_COCOA 1
+/* #undef SDL_VIDEO_DRIVER_DIRECTFB */
+/* #undef SDL_VIDEO_DRIVER_DIRECTFB_DYNAMIC */
+#define SDL_VIDEO_DRIVER_DUMMY 1
+/* #undef SDL_VIDEO_DRIVER_WINDOWS */
+/* #undef SDL_VIDEO_DRIVER_WAYLAND */
+/* #undef SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH */
+/* #undef SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC */
+/* #undef SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_EGL */
+/* #undef SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_CURSOR */
+/* #undef SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_XKBCOMMON */
+/* #undef SDL_VIDEO_DRIVER_MIR */
+/* #undef SDL_VIDEO_DRIVER_MIR_DYNAMIC */
+/* #undef SDL_VIDEO_DRIVER_MIR_DYNAMIC_XKBCOMMON */
+#define SDL_VIDEO_DRIVER_X11 1
+/* #undef SDL_VIDEO_DRIVER_RPI */
+/* #undef SDL_VIDEO_DRIVER_ANDROID */
+/* #undef SDL_VIDEO_DRIVER_EMSCRIPTEN */
+#define SDL_VIDEO_DRIVER_X11_DYNAMIC "/usr/X11R6/lib/libX11.6.dylib"
+#define SDL_VIDEO_DRIVER_X11_DYNAMIC_XEXT "/usr/X11R6/lib/libXext.6.dylib"
+#define SDL_VIDEO_DRIVER_X11_DYNAMIC_XCURSOR "/usr/X11R6/lib/libXcursor.1.dylib"
+#define SDL_VIDEO_DRIVER_X11_DYNAMIC_XINERAMA "/usr/X11R6/lib/libXinerama.1.dylib"
+/* #undef SDL_VIDEO_DRIVER_X11_DYNAMIC_XINPUT2 */
+/* #undef SDL_VIDEO_DRIVER_X11_DYNAMIC_XRANDR */
+#define SDL_VIDEO_DRIVER_X11_DYNAMIC_XSS "/usr/X11R6/lib/libXss.1.dylib"
+#define SDL_VIDEO_DRIVER_X11_DYNAMIC_XVIDMODE "/usr/X11R6/lib/libXxf86vm.1.dylib"
+#define SDL_VIDEO_DRIVER_X11_XCURSOR 1
+#define SDL_VIDEO_DRIVER_X11_XDBE 1
+#define SDL_VIDEO_DRIVER_X11_XINERAMA 1
+/* #undef SDL_VIDEO_DRIVER_X11_XINPUT2 */
+/* #undef SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_MULTITOUCH */
+/* #undef SDL_VIDEO_DRIVER_X11_XRANDR */
+#define SDL_VIDEO_DRIVER_X11_XSCRNSAVER 1
+#define SDL_VIDEO_DRIVER_X11_XSHAPE 1
+#define SDL_VIDEO_DRIVER_X11_XVIDMODE 1
+/* #undef SDL_VIDEO_DRIVER_X11_SUPPORTS_GENERIC_EVENTS */
+/* #undef SDL_VIDEO_DRIVER_X11_CONST_PARAM_XEXTADDDISPLAY */
+#define SDL_VIDEO_DRIVER_X11_HAS_XKBKEYCODETOKEYSYM 1
+/* #undef SDL_VIDEO_DRIVER_NACL */
+/* #undef SDL_VIDEO_DRIVER_VIVANTE */
+/* #undef SDL_VIDEO_DRIVER_VIVANTE_VDK */
+
+/* #undef SDL_VIDEO_RENDER_D3D */
+/* #undef SDL_VIDEO_RENDER_D3D11 */
+#define SDL_VIDEO_RENDER_OGL 1
+/* #undef SDL_VIDEO_RENDER_OGL_ES */
+/* #undef SDL_VIDEO_RENDER_OGL_ES2 */
+/* #undef SDL_VIDEO_RENDER_DIRECTFB */
+
+/* Enable OpenGL support */
+#define SDL_VIDEO_OPENGL 1
+/* #undef SDL_VIDEO_OPENGL_ES */
+/* #undef SDL_VIDEO_OPENGL_ES2 */
+/* #undef SDL_VIDEO_OPENGL_BGL */
+#define SDL_VIDEO_OPENGL_CGL 1
+/* #undef SDL_VIDEO_OPENGL_EGL */
+#define SDL_VIDEO_OPENGL_GLX 1
+/* #undef SDL_VIDEO_OPENGL_WGL */
+/* #undef SDL_VIDEO_OPENGL_OSMESA */
+/* #undef SDL_VIDEO_OPENGL_OSMESA_DYNAMIC */
+
+/* Enable system power support */
+/* #undef SDL_POWER_LINUX */
+/* #undef SDL_POWER_WINDOWS */
+#define SDL_POWER_MACOSX 1
+/* #undef SDL_POWER_HAIKU */
+/* #undef SDL_POWER_ANDROID */
+/* #undef SDL_POWER_EMSCRIPTEN */
+/* #undef SDL_POWER_HARDWIRED */
+
+/* Enable system filesystem support */
+/* #undef SDL_FILESYSTEM_HAIKU */
+#define SDL_FILESYSTEM_COCOA 1
+/* #undef SDL_FILESYSTEM_DUMMY */
+/* #undef SDL_FILESYSTEM_UNIX */
+/* #undef SDL_FILESYSTEM_WINDOWS */
+/* #undef SDL_FILESYSTEM_NACL */
+/* #undef SDL_FILESYSTEM_ANDROID */
+/* #undef SDL_FILESYSTEM_EMSCRIPTEN */
+
+/* Enable assembly routines */
+#define SDL_ASSEMBLY_ROUTINES 1
+#define SDL_ALTIVEC_BLITTERS 1
 
 #endif /* _SDL_config_h */
--- include/SDL_platform.h
+++ include/SDL_platform.h
@@ -70,7 +70,7 @@
 /* lets us know what version of Mac OS X we're compiling on */
 #include "AvailabilityMacros.h"
 #include "TargetConditionals.h"
-#if TARGET_OS_IPHONE
+#if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
 /* if compiling for iPhone */
 #undef __IPHONEOS__
 #define __IPHONEOS__ 1
@@ -80,7 +80,9 @@
 #undef __MACOSX__
 #define __MACOSX__  1
 #if MAC_OS_X_VERSION_MIN_REQUIRED < 1050
+#if 0
 # error SDL for Mac OS X only supports deploying on 10.5 and above.
+#endif
 #endif /* MAC_OS_X_VERSION_MIN_REQUIRED < 1050 */
 #endif /* TARGET_OS_IPHONE */
 #endif /* defined(__APPLE__) */
--- include/SDL_syswm.h
+++ include/SDL_syswm.h
@@ -215,21 +215,29 @@
 #if defined(SDL_VIDEO_DRIVER_COCOA)
         struct
         {
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
 #if defined(__OBJC__) && defined(__has_feature) && __has_feature(objc_arc)
             NSWindow __unsafe_unretained *window; /* The Cocoa window */
 #else
             NSWindow *window;                     /* The Cocoa window */
 #endif
+#else
+            NSWindow *window;                     /* The Cocoa window */
+#endif
         } cocoa;
 #endif
 #if defined(SDL_VIDEO_DRIVER_UIKIT)
         struct
         {
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
 #if defined(__OBJC__) && defined(__has_feature) && __has_feature(objc_arc)
             UIWindow __unsafe_unretained *window; /* The UIKit window */
 #else
             UIWindow *window;                     /* The UIKit window */
 #endif
+#else
+            UIWindow *window;                     /* The UIKit window */
+#endif
             GLuint framebuffer; /* The GL view's Framebuffer Object. It must be bound when rendering to the screen using GL. */
             GLuint colorbuffer; /* The GL view's color Renderbuffer Object. It must be bound when SDL_GL_SwapWindow is called. */
             GLuint resolveFramebuffer; /* The Framebuffer Object which holds the resolve color Renderbuffer, when MSAA is used. */
--- src/atomic/SDL_spinlock.c
+++ src/atomic/SDL_spinlock.c
@@ -28,6 +28,10 @@
 #include "SDL_mutex.h"
 #include "SDL_timer.h"
 
+#if defined(__MACOSX__) || defined(__IPHONEOS__)
+#include <libkern/OSAtomic.h>
+#endif
+
 #if !defined(HAVE_GCC_ATOMICS) && defined(__SOLARIS__)
 #include <atomic.h>
 #endif
--- src/file/cocoa/SDL_rwopsbundlesupport.m
+++ src/file/cocoa/SDL_rwopsbundlesupport.m
@@ -33,7 +33,9 @@
  Also, note the bundle layouts are different for iPhone and Mac.
 */
 FILE* SDL_OpenFPFromBundleOrFallback(const char *file, const char *mode)
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
 { @autoreleasepool
+#endif
 {
     FILE* fp = NULL;
 
@@ -42,6 +44,9 @@
         return fopen(file, mode);
     }
 
+#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070
+    NSAutoreleasePool* autorelease_pool = [[NSAutoreleasePool alloc] init];
+#endif
     NSFileManager* file_manager = [NSFileManager defaultManager];
     NSString* resource_path = [[NSBundle mainBundle] resourcePath];
 
@@ -54,8 +59,15 @@
         fp = fopen(file, mode);
     }
 
+#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070
+    [autorelease_pool drain];
+#endif
     return fp;
+#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070
+}
+#else
 }}
+#endif
 
 #endif /* __APPLE__ */
 
--- src/filesystem/cocoa/SDL_sysfilesystem.m
+++ src/filesystem/cocoa/SDL_sysfilesystem.m
@@ -35,8 +35,13 @@
 
 char *
 SDL_GetBasePath(void)
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
 { @autoreleasepool
 {
+#else
+{
+    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+#endif
     NSBundle *bundle = [NSBundle mainBundle];
     const char* baseType = [[[bundle infoDictionary] objectForKey:@"SDL_FILESYSTEM_BASE_DIR_TYPE"] UTF8String];
     const char *base = NULL;
@@ -64,13 +69,24 @@
         }
     }
 
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
     return retval;
 }}
+#else
+    [pool release];
+    return retval;
+}
+#endif
 
 char *
 SDL_GetPrefPath(const char *org, const char *app)
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
 { @autoreleasepool
 {
+#else
+{
+    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+#endif
     char *retval = NULL;
 
     NSArray *array = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES);
@@ -98,8 +114,14 @@
         }
     }
 
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
     return retval;
 }}
+#else
+    [pool release];
+    return retval;
+}
+#endif
 
 #endif /* SDL_FILESYSTEM_COCOA */
 
--- src/joystick/darwin/SDL_sysjoystick.c
+++ src/joystick/darwin/SDL_sysjoystick.c
@@ -452,9 +452,8 @@
 
     /* We have to do some storage of the io_service_t for SDL_HapticOpenFromJoystick */
 
-#if MAC_OS_X_VERSION_MIN_REQUIRED < 1060
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
     if (IOHIDDeviceGetService != NULL) {  /* weak reference: available in 10.6 and later. */
-#endif
 
         const io_service_t ioservice = IOHIDDeviceGetService(ioHIDDeviceObject);
 #if SDL_HAPTIC_IOKIT
@@ -464,7 +463,6 @@
         }
 #endif
 
-#if MAC_OS_X_VERSION_MIN_REQUIRED < 1060
     }
 #endif
 
--- src/video/cocoa/SDL_cocoaclipboard.m
+++ src/video/cocoa/SDL_cocoaclipboard.m
@@ -28,17 +28,25 @@
 static NSString *
 GetTextFormat(_THIS)
 {
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
     if (floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_5) {
         return NSPasteboardTypeString;
     } else {
+#endif
         return NSStringPboardType;
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
     }
+#endif
 }
 
 int
 Cocoa_SetClipboardText(_THIS, const char *text)
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
 { @autoreleasepool
 {
+#else
+{   NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
+#endif
     SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
     NSPasteboard *pasteboard;
     NSString *format = GetTextFormat(_this);
@@ -47,13 +55,24 @@
     data->clipboard_count = [pasteboard declareTypes:[NSArray arrayWithObject:format] owner:nil];
     [pasteboard setString:[NSString stringWithUTF8String:text] forType:format];
 
+#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070
+    [pool release];
+#endif
     return 0;
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
 }}
+#else
+}
+#endif
 
 char *
 Cocoa_GetClipboardText(_THIS)
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
 { @autoreleasepool
 {
+#else
+{   NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
+#endif
     NSPasteboard *pasteboard;
     NSString *format = GetTextFormat(_this);
     NSString *available;
@@ -76,8 +95,15 @@
         text = SDL_strdup("");
     }
 
+#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070
+    [pool release];
+#endif
     return text;
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
 }}
+#else
+}
+#endif
 
 SDL_bool
 Cocoa_HasClipboardText(_THIS)
@@ -93,8 +119,12 @@
 
 void
 Cocoa_CheckClipboardUpdate(struct SDL_VideoData * data)
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
 { @autoreleasepool
 {
+#else
+{   NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
+#endif
     NSPasteboard *pasteboard;
     NSInteger count;
 
@@ -106,7 +136,12 @@
         }
         data->clipboard_count = count;
     }
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
 }}
+#else
+    [pool release];
+}
+#endif
 
 #endif /* SDL_VIDEO_DRIVER_COCOA */
 
--- src/video/cocoa/SDL_cocoaevents.m
+++ src/video/cocoa/SDL_cocoaevents.m
@@ -54,7 +54,11 @@
 - (void)setAppleMenu:(NSMenu *)menu;
 @end
 
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
 @interface SDLAppDelegate : NSObject <NSApplicationDelegate> {
+#else
+@interface SDLAppDelegate : NSObject {
+#endif
 @public
     BOOL seenFirstActivate;
 }
@@ -311,16 +315,22 @@
 
 void
 Cocoa_RegisterApp(void)
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
 { @autoreleasepool
+#endif
 {
     /* This can get called more than once! Be careful what you initialize! */
-
+#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070
+    NSAutoreleasePool *pool;
+    pool = [[NSAutoreleasePool alloc] init];
+#endif
     if (NSApp == nil) {
         [SDLApplication sharedApplication];
         SDL_assert(NSApp != nil);
 
         const char *hint = SDL_GetHint(SDL_HINT_MAC_BACKGROUND_APP);
         if (!hint || *hint == '0') {
+#if defined(MAC_OS_X_VERSION_10_6)
 #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_6
 			if ([NSApp respondsToSelector:@selector(setActivationPolicy:)]) {
 #endif
@@ -331,6 +341,7 @@
 				TransformProcessType(&psn, kProcessTransformToForegroundApplication);
 			}
 #endif
+#endif
             [NSApp activateIgnoringOtherApps:YES];
 		}
 		
@@ -358,12 +369,22 @@
             appDelegate->seenFirstActivate = YES;
         }
     }
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
 }}
+#else
+    [pool release];
+}
+#endif
 
 void
 Cocoa_PumpEvents(_THIS)
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
 { @autoreleasepool
 {
+#else
+{
+    NSAutoreleasePool *pool;
+#endif
     /* Update activity every 30 seconds to prevent screensaver */
     SDL_VideoData *data = (SDL_VideoData *)_this->driverdata;
     if (_this->suspend_screensaver && !data->screensaver_use_iopm) {
@@ -375,6 +396,9 @@
         }
     }
 
+#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070
+    pool = [[NSAutoreleasePool alloc] init];
+#endif
     for ( ; ; ) {
         NSEvent *event = [NSApp nextEventMatchingMask:NSAnyEventMask untilDate:[NSDate distantPast] inMode:NSDefaultRunLoopMode dequeue:YES ];
         if ( event == nil ) {
@@ -406,10 +430,16 @@
         /* Pass through to NSApp to make sure everything stays in sync */
         [NSApp sendEvent:event];
     }
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
 }}
+#else
+    [pool release];
+}
+#endif
 
 void
 Cocoa_SuspendScreenSaver(_THIS)
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
 { @autoreleasepool
 {
     SDL_VideoData *data = (SDL_VideoData *)_this->driverdata;
@@ -436,6 +466,10 @@
                                            &data->screensaver_assertion);
     }
 }}
+#else
+{
+}
+#endif
 
 #endif /* SDL_VIDEO_DRIVER_COCOA */
 
--- src/video/cocoa/SDL_cocoakeyboard.m
+++ src/video/cocoa/SDL_cocoakeyboard.m
@@ -150,11 +150,15 @@
             aRange.location, aRange.length, windowHeight,
             NSStringFromRect(rect));
 
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
     if ([[self window] respondsToSelector:@selector(convertRectToScreen:)]) {
         rect = [[self window] convertRectToScreen:rect];
     } else {
+#endif
         rect.origin = [[self window] convertBaseToScreen:rect.origin];
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
     }
+#endif
 
     return rect;
 }
@@ -498,18 +502,25 @@
     SDL_SetScancodeName(SDL_SCANCODE_RALT, "Right Option");
     SDL_SetScancodeName(SDL_SCANCODE_RGUI, "Right Command");
 
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
     /* On pre-10.6, you might have the initial capslock key state wrong. */
     if (floor(NSAppKitVersionNumber) >= NSAppKitVersionNumber10_6) {
         data->modifierFlags = [NSEvent modifierFlags];
         SDL_ToggleModState(KMOD_CAPS, (data->modifierFlags & NSAlphaShiftKeyMask) != 0);
     }
+#endif
 }
 
 void
 Cocoa_StartTextInput(_THIS)
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
 { @autoreleasepool
+#endif
 {
     SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
+#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070
+    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+#endif
     SDL_Window *window = SDL_GetKeyboardFocus();
     NSWindow *nswindow = nil;
     if (window) {
@@ -534,20 +545,37 @@
         [parentView addSubview: data->fieldEdit];
         [nswindow makeFirstResponder: data->fieldEdit];
     }
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
 }}
+#else
+    [pool release];
+}
+#endif
 
 void
 Cocoa_StopTextInput(_THIS)
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
 { @autoreleasepool
+#endif
 {
     SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
 
     if (data && data->fieldEdit) {
+#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070
+        NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+#endif
         [data->fieldEdit removeFromSuperview];
         [data->fieldEdit release];
         data->fieldEdit = nil;
+#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070
+        [pool release];
+#endif
     }
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
 }}
+#else
+}
+#endif
 
 void
 Cocoa_SetTextInputRect(_THIS, SDL_Rect *rect)
--- src/video/cocoa/SDL_cocoamessagebox.m
+++ src/video/cocoa/SDL_cocoamessagebox.m
@@ -79,10 +79,15 @@
 /* Display a Cocoa message box */
 int
 Cocoa_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid)
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
 { @autoreleasepool
+#endif
 {
     Cocoa_RegisterApp();
 
+#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070
+    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+#endif
     NSAlert* alert = [[[NSAlert alloc] init] autorelease];
 
     if (messageboxdata->flags & SDL_MESSAGEBOX_ERROR) {
@@ -124,8 +129,15 @@
         returnValue = SDL_SetError("Did not get a valid `clicked button' id: %ld", (long)clicked);
     }
 
+#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070
+    [pool release];
+#endif
     return returnValue;
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
 }}
+#else
+}
+#endif
 
 #endif /* SDL_VIDEO_DRIVER_COCOA */
 
--- src/video/cocoa/SDL_cocoamodes.m
+++ src/video/cocoa/SDL_cocoamodes.m
@@ -70,7 +70,11 @@
 #if FORCE_OLD_API
     return NO;
 #else
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
     return floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_5;
+#else
+    return NO;
+#endif
 #endif
 }
 
@@ -132,6 +136,7 @@
     }
     data->moderef = moderef;
 
+    #if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
     if (IS_SNOW_LEOPARD_OR_LATER()) {
         CGDisplayModeRef vidmode = (CGDisplayModeRef) moderef;
         CFStringRef fmt = CGDisplayModeCopyPixelEncoding(vidmode);
@@ -154,6 +159,7 @@
 
         CFRelease(fmt);
     }
+    #endif
 
     #if MAC_OS_X_VERSION_MIN_REQUIRED < 1060
     if (!IS_SNOW_LEOPARD_OR_LATER()) {
@@ -206,17 +212,21 @@
 static void
 Cocoa_ReleaseDisplayMode(_THIS, const void *moderef)
 {
+    #if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
     if (IS_SNOW_LEOPARD_OR_LATER()) {
         CGDisplayModeRelease((CGDisplayModeRef) moderef);  /* NULL is ok */
     }
+    #endif
 }
 
 static void
 Cocoa_ReleaseDisplayModeList(_THIS, CFArrayRef modelist)
 {
+    #if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
     if (IS_SNOW_LEOPARD_OR_LATER()) {
         CFRelease(modelist);  /* NULL is ok */
     }
+    #endif
 }
 
 static const char *
@@ -235,8 +245,13 @@
 
 void
 Cocoa_InitModes(_THIS)
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
 { @autoreleasepool
 {
+#else
+{
+    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+#endif
     CGDisplayErr result;
     CGDirectDisplayID *displays;
     CGDisplayCount numDisplays;
@@ -245,6 +260,9 @@
     result = CGGetOnlineDisplayList(0, NULL, &numDisplays);
     if (result != kCGErrorSuccess) {
         CG_SetError("CGGetOnlineDisplayList()", result);
+#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070
+        [pool release];
+#endif
         return;
     }
     displays = SDL_stack_alloc(CGDirectDisplayID, numDisplays);
@@ -252,6 +270,9 @@
     if (result != kCGErrorSuccess) {
         CG_SetError("CGGetOnlineDisplayList()", result);
         SDL_stack_free(displays);
+#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070
+        [pool release];
+#endif
         return;
     }
 
@@ -278,9 +299,11 @@
                 continue;
             }
 
+            #if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
             if (IS_SNOW_LEOPARD_OR_LATER()) {
                 moderef = CGDisplayCopyDisplayMode(displays[i]);
             }
+            #endif
 
             #if MAC_OS_X_VERSION_MIN_REQUIRED < 1060
             if (!IS_SNOW_LEOPARD_OR_LATER()) {
@@ -322,7 +345,12 @@
         }
     }
     SDL_stack_free(displays);
+#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070
+    [pool release];
+}
+#else
 }}
+#endif
 
 int
 Cocoa_GetDisplayBounds(_THIS, SDL_VideoDisplay * display, SDL_Rect * rect)
@@ -344,9 +372,11 @@
     SDL_DisplayData *data = (SDL_DisplayData *) display->driverdata;
     CFArrayRef modes = NULL;
 
+    #if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
     if (IS_SNOW_LEOPARD_OR_LATER()) {
         modes = CGDisplayCopyAllDisplayModes(data->display, NULL);
     }
+    #endif
 
     #if MAC_OS_X_VERSION_MIN_REQUIRED < 1060
     if (!IS_SNOW_LEOPARD_OR_LATER()) {
@@ -365,9 +395,11 @@
             const void *moderef = CFArrayGetValueAtIndex(modes, i);
             SDL_DisplayMode mode;
             if (GetDisplayMode(_this, moderef, link, &mode)) {
+                #if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
                 if (IS_SNOW_LEOPARD_OR_LATER()) {
                     CGDisplayModeRetain((CGDisplayModeRef) moderef);
                 }
+                #endif
                 SDL_AddDisplayMode(display, &mode);
             }
         }
@@ -380,9 +412,11 @@
 static CGError
 Cocoa_SwitchMode(_THIS, CGDirectDisplayID display, const void *mode)
 {
+    #if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
     if (IS_SNOW_LEOPARD_OR_LATER()) {
         return CGDisplaySetDisplayMode(display, (CGDisplayModeRef) mode, NULL);
     }
+    #endif
  
     #if MAC_OS_X_VERSION_MIN_REQUIRED < 1060
     if (!IS_SNOW_LEOPARD_OR_LATER()) {
--- src/video/cocoa/SDL_cocoamouse.m
+++ src/video/cocoa/SDL_cocoamouse.m
@@ -66,8 +66,13 @@
 
 static SDL_Cursor *
 Cocoa_CreateDefaultCursor()
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
 { @autoreleasepool
 {
+#else
+{
+    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+#endif
     NSCursor *nscursor;
     SDL_Cursor *cursor = NULL;
 
@@ -81,13 +86,25 @@
         }
     }
 
+#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070
+    [pool release];
+#endif
     return cursor;
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
 }}
+#else
+}
+#endif
 
 static SDL_Cursor *
 Cocoa_CreateCursor(SDL_Surface * surface, int hot_x, int hot_y)
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
 { @autoreleasepool
 {
+#else
+{
+    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+#endif
     NSImage *nsimage;
     NSCursor *nscursor = NULL;
     SDL_Cursor *cursor = NULL;
@@ -106,13 +123,25 @@
         }
     }
 
+#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070
+    [pool release];
+#endif
     return cursor;
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
 }}
+#else
+}
+#endif
 
 static SDL_Cursor *
 Cocoa_CreateSystemCursor(SDL_SystemCursor id)
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
 { @autoreleasepool
 {
+#else
+{
+    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+#endif
     NSCursor *nscursor = NULL;
     SDL_Cursor *cursor = NULL;
 
@@ -165,23 +194,45 @@
         }
     }
 
+#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070
+    [pool release];
+#endif
     return cursor;
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
 }}
+#else
+}
+#endif
 
 static void
 Cocoa_FreeCursor(SDL_Cursor * cursor)
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
 { @autoreleasepool
 {
+#else
+{
+    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+#endif
     NSCursor *nscursor = (NSCursor *)cursor->driverdata;
 
     [nscursor release];
     SDL_free(cursor);
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
 }}
+#else
+    [pool release];
+}
+#endif
 
 static int
 Cocoa_ShowCursor(SDL_Cursor * cursor)
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
 { @autoreleasepool
 {
+#else
+{
+    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+#endif
     SDL_VideoDevice *device = SDL_GetVideoDevice();
     SDL_Window *window = (device ? device->windows : NULL);
     for (; window != NULL; window = window->next) {
@@ -192,8 +243,15 @@
                                                 waitUntilDone:NO];
         }
     }
+#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070
+    [pool release];
+#endif
     return 0;
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
 }}
+#else
+}
+#endif
 
 static SDL_Window *
 SDL_FindWindowAtPoint(const int x, const int y)
--- src/video/cocoa/SDL_cocoaopengl.m
+++ src/video/cocoa/SDL_cocoaopengl.m
@@ -150,11 +150,20 @@
 
 SDL_GLContext
 Cocoa_GL_CreateContext(_THIS, SDL_Window * window)
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
 { @autoreleasepool
 {
+#else
+{
+    NSAutoreleasePool *pool;
+#endif
     SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
     SDL_DisplayData *displaydata = (SDL_DisplayData *)display->driverdata;
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1670
     SDL_bool lion_or_later = floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_6;
+#else
+    SDL_bool lion_or_later = SDL_FALSE;
+#endif
     NSOpenGLPixelFormatAttribute attr[32];
     NSOpenGLPixelFormat *fmt;
     SDLOpenGLContext *context;
@@ -173,7 +182,11 @@
         return NULL;
     }
 
+#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070
+    pool = [[NSAutoreleasePool alloc] init];
+#endif
     /* specify a profile if we're on Lion (10.7) or later. */
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
     if (lion_or_later) {
         NSOpenGLPixelFormatAttribute profile = NSOpenGLProfileVersionLegacy;
         if (_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_CORE) {
@@ -182,6 +195,7 @@
         attr[i++] = NSOpenGLPFAOpenGLProfile;
         attr[i++] = profile;
     }
+#endif
 
     attr[i++] = NSOpenGLPFAColorSize;
     attr[i++] = SDL_BYTESPERPIXEL(display->current_mode.format)*8;
@@ -237,6 +251,9 @@
     fmt = [[NSOpenGLPixelFormat alloc] initWithAttributes:attr];
     if (fmt == nil) {
         SDL_SetError("Failed creating OpenGL pixel format");
+#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070
+        [pool release];
+#endif
         return NULL;
     }
 
@@ -250,12 +267,18 @@
 
     if (context == nil) {
         SDL_SetError("Failed creating OpenGL context");
+#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070
+        [pool release];
+#endif
         return NULL;
     }
 
     if ( Cocoa_GL_MakeCurrent(_this, window, context) < 0 ) {
         Cocoa_GL_DeleteContext(_this, context);
         SDL_SetError("Failed making OpenGL context current");
+#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070
+        [pool release];
+#endif
         return NULL;
     }
 
@@ -270,6 +293,9 @@
         if (!glGetStringFunc) {
             Cocoa_GL_DeleteContext(_this, context);
             SDL_SetError ("Failed getting OpenGL glGetString entry point");
+#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070
+            [pool release];
+#endif
             return NULL;
         }
 
@@ -277,12 +303,18 @@
         if (glversion == NULL) {
             Cocoa_GL_DeleteContext(_this, context);
             SDL_SetError ("Failed getting OpenGL context version");
+#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070
+            [pool release];
+#endif
             return NULL;
         }
 
         if (SDL_sscanf(glversion, "%d.%d", &glversion_major, &glversion_minor) != 2) {
             Cocoa_GL_DeleteContext(_this, context);
             SDL_SetError ("Failed parsing OpenGL context version");
+#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070
+            [pool release];
+#endif
             return NULL;
         }
 
@@ -290,6 +322,9 @@
            ((glversion_major == _this->gl_config.major_version) && (glversion_minor < _this->gl_config.minor_version))) {
             Cocoa_GL_DeleteContext(_this, context);
             SDL_SetError ("Failed creating OpenGL context at version requested");
+#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070
+            [pool release];
+#endif
             return NULL;
         }
 
@@ -299,13 +334,25 @@
         /*_this->gl_config.major_version = glversion_major;*/
         /*_this->gl_config.minor_version = glversion_minor;*/
     }
+#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070
+    [pool release];
+#endif
     return context;
+#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070
+}
+#else
 }}
+#endif
 
 int
 Cocoa_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context)
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
 { @autoreleasepool
 {
+#else
+{
+    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+#endif
     if (context) {
         SDLOpenGLContext *nscontext = (SDLOpenGLContext *)context;
         [nscontext setWindow:window];
@@ -315,8 +362,15 @@
         [NSOpenGLContext clearCurrentContext];
     }
 
+#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070
+    [pool release];
+#endif
     return 0;
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
 }}
+#else
+}
+#endif
 
 void
 Cocoa_GL_GetDrawableSize(_THIS, SDL_Window * window, int * w, int * h)
@@ -327,9 +381,11 @@
 
     /* This gives us the correct viewport for a Retina-enabled view, only
      * supported on 10.7+. */
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
     if ([contentView respondsToSelector:@selector(convertRectToBacking:)]) {
         viewport = [contentView convertRectToBacking:viewport];
     }
+#endif
 
     if (w) {
         *w = viewport.size.width;
@@ -342,7 +398,9 @@
 
 int
 Cocoa_GL_SetSwapInterval(_THIS, int interval)
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
 { @autoreleasepool
+#endif
 {
     NSOpenGLContext *nscontext;
     GLint value;
@@ -351,6 +409,9 @@
     if (interval < 0) {  /* no extension for this on Mac OS X at the moment. */
         return SDL_SetError("Late swap tearing currently unsupported");
     }
+#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070
+    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+#endif
 
     nscontext = (NSOpenGLContext*)SDL_GL_GetCurrentContext();
     if (nscontext != nil) {
@@ -361,13 +422,25 @@
         status = SDL_SetError("No current OpenGL context");
     }
 
+#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070
+    [pool release];
+#endif
     return status;
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
 }}
+#else
+}
+#endif
 
 int
 Cocoa_GL_GetSwapInterval(_THIS)
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
 { @autoreleasepool
 {
+#else
+{
+    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+#endif
     NSOpenGLContext *nscontext;
     GLint value;
     int status = 0;
@@ -378,27 +451,54 @@
         status = (int)value;
     }
 
+#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070
+    [pool release];
+#endif
     return status;
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
 }}
+#else
+}
+#endif
 
 void
 Cocoa_GL_SwapWindow(_THIS, SDL_Window * window)
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
 { @autoreleasepool
 {
+#else
+{
+    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+#endif
     SDLOpenGLContext* nscontext = (SDLOpenGLContext*)SDL_GL_GetCurrentContext();
     [nscontext flushBuffer];
     [nscontext updateIfNeeded];
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
 }}
+#else
+    [pool release];
+}
+#endif
 
 void
 Cocoa_GL_DeleteContext(_THIS, SDL_GLContext context)
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
 { @autoreleasepool
 {
+#else
+{
+    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+#endif
     SDLOpenGLContext *nscontext = (SDLOpenGLContext *)context;
 
     [nscontext setWindow:NULL];
     [nscontext release];
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
 }}
+#else
+    [pool release];
+}
+#endif
 
 #endif /* SDL_VIDEO_OPENGL_CGL */
 
--- src/video/cocoa/SDL_cocoashape.m
+++ src/video/cocoa/SDL_cocoashape.m
@@ -75,8 +75,13 @@
 
 int
 Cocoa_SetWindowShape(SDL_WindowShaper *shaper, SDL_Surface *shape, SDL_WindowShapeMode *shape_mode)
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
 { @autoreleasepool
 {
+#else
+{
+    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+#endif
     SDL_ShapeData* data = (SDL_ShapeData*)shaper->driverdata;
     SDL_WindowData* windata = (SDL_WindowData*)shaper->window->driverdata;
     SDL_CocoaClosure closure;
@@ -99,8 +104,15 @@
     SDL_TraverseShapeTree(data->shape,&ConvertRects,&closure);
     [closure.path addClip];
 
+#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070
+    [pool release];
+#endif
     return 0;
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
 }}
+#else
+}
+#endif
 
 int
 Cocoa_ResizeWindowShape(SDL_Window *window)
--- src/video/cocoa/SDL_cocoavideo.m
+++ src/video/cocoa/SDL_cocoavideo.m
@@ -22,6 +22,13 @@
 
 #if SDL_VIDEO_DRIVER_COCOA
 
+#if defined(__APPLE__) && defined(__POWERPC__) && !defined(__APPLE_ALTIVEC__)
+#include <altivec.h>
+#undef bool
+#undef vector
+#undef pixel
+#endif
+
 #include "SDL.h"
 #include "SDL_endian.h"
 #include "SDL_cocoavideo.h"
@@ -147,10 +154,15 @@
     Cocoa_InitMouse(_this);
 
     const char *hint = SDL_GetHint(SDL_HINT_VIDEO_MAC_FULLSCREEN_SPACES);
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
     data->allow_spaces = ( (floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_6) && (!hint || (*hint != '0')) );
 
     /* The IOPM assertion API can disable the screensaver as of 10.7. */
     data->screensaver_use_iopm = floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_6;
+#else
+    data->allow_spaces = 0;
+    data->screensaver_use_iopm = 0;
+#endif
 
     return 0;
 }
--- src/video/cocoa/SDL_cocoawindow.h
+++ src/video/cocoa/SDL_cocoawindow.h
@@ -35,7 +35,11 @@
     PENDING_OPERATION_MINIMIZE
 } PendingWindowOperation;
 
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
 @interface Cocoa_WindowListener : NSResponder <NSWindowDelegate> {
+#else
+@interface Cocoa_WindowListener : NSResponder {
+#endif
     SDL_WindowData *_data;
     BOOL observingVisible;
     BOOL wasCtrlLeft;
@@ -75,7 +79,9 @@
 -(void) windowDidEnterFullScreen:(NSNotification *) aNotification;
 -(void) windowWillExitFullScreen:(NSNotification *) aNotification;
 -(void) windowDidExitFullScreen:(NSNotification *) aNotification;
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
 -(NSApplicationPresentationOptions)window:(NSWindow *)window willUseFullScreenPresentationOptions:(NSApplicationPresentationOptions)proposedOptions;
+#endif
 
 /* See if event is in a drag area, toggle on window dragging. */
 -(BOOL) processHitTest:(NSEvent *)theEvent;
@@ -98,7 +104,17 @@
 -(void) touchesCancelledWithEvent:(NSEvent *) theEvent;
 
 /* Touch event handling */
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
 -(void) handleTouches:(NSTouchPhase) phase withEvent:(NSEvent*) theEvent;
+#else
+typedef enum {
+    COCOA_TOUCH_DOWN,
+    COCOA_TOUCH_UP,
+    COCOA_TOUCH_MOVE,
+    COCOA_TOUCH_CANCELLED
+} cocoaTouchType;
+-(void) handleTouches:(cocoaTouchType)type withEvent:(NSEvent*) event;
+#endif
 
 @end
 /* *INDENT-ON* */
--- src/video/cocoa/SDL_cocoawindow.m
+++ src/video/cocoa/SDL_cocoawindow.m
@@ -23,7 +23,9 @@
 #if SDL_VIDEO_DRIVER_COCOA
 
 #if MAC_OS_X_VERSION_MAX_ALLOWED < 1070
+#if 0
 # error SDL for Mac OS X must be built with a 10.7 SDK or above.
+#endif
 #endif /* MAC_OS_X_VERSION_MAX_ALLOWED < 1070 */
 
 #include "SDL_syswm.h"
@@ -53,7 +55,11 @@
 #define FULLSCREEN_MASK (SDL_WINDOW_FULLSCREEN_DESKTOP | SDL_WINDOW_FULLSCREEN)
 
 
+#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070
+@interface SDLWindow : NSWindow
+#else
 @interface SDLWindow : NSWindow <NSDraggingDestination>
+#endif
 /* These are needed for borderless/fullscreen windows */
 - (BOOL)canBecomeKeyWindow;
 - (BOOL)canBecomeMainWindow;
@@ -114,8 +120,13 @@
 }
 
 - (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
 { @autoreleasepool
 {
+#else
+{
+    NSAutoreleasePool *pool;
+#endif
     NSPasteboard *pasteboard = [sender draggingPasteboard];
     NSArray *types = [NSArray arrayWithObject:NSFilenamesPboardType];
     NSString *desiredType = [pasteboard availableTypeFromArray:types];
@@ -128,11 +139,15 @@
         return NO;
     }
 
+#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070
+    pool = [[NSAutoreleasePool alloc] init];
+#endif
     SDL_assert([desiredType isEqualToString:NSFilenamesPboardType]);
     NSArray *array = [pasteboard propertyListForType:@"NSFilenamesPboardType"];
 
     for (NSString *path in array) {
         NSURL *fileURL = [[NSURL fileURLWithPath:path] autorelease];
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
         NSNumber *isAlias = nil;
 
         /* Functionality for resolving URL aliases was added with OS X 10.6. */
@@ -156,14 +171,25 @@
                 }
             }
         }
+#endif
 
         if (!SDL_SendDropFile([[fileURL path] UTF8String])) {
+#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070
+            [pool release];
+#endif
             return NO;
         }
     }
 
+#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070
+    [pool release];
+#endif
     return YES;
+#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070
+}
+#else
 }}
+#endif
 
 - (BOOL)wantsPeriodicDraggingUpdates
 {
@@ -277,11 +303,13 @@
         [center addObserver:self selector:@selector(windowDidDeminiaturize:) name:NSWindowDidDeminiaturizeNotification object:window];
         [center addObserver:self selector:@selector(windowDidBecomeKey:) name:NSWindowDidBecomeKeyNotification object:window];
         [center addObserver:self selector:@selector(windowDidResignKey:) name:NSWindowDidResignKeyNotification object:window];
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
         [center addObserver:self selector:@selector(windowDidChangeBackingProperties:) name:NSWindowDidChangeBackingPropertiesNotification object:window];
         [center addObserver:self selector:@selector(windowWillEnterFullScreen:) name:NSWindowWillEnterFullScreenNotification object:window];
         [center addObserver:self selector:@selector(windowDidEnterFullScreen:) name:NSWindowDidEnterFullScreenNotification object:window];
         [center addObserver:self selector:@selector(windowWillExitFullScreen:) name:NSWindowWillExitFullScreenNotification object:window];
         [center addObserver:self selector:@selector(windowDidExitFullScreen:) name:NSWindowDidExitFullScreenNotification object:window];
+#endif
         [center addObserver:self selector:@selector(windowDidFailToEnterFullScreen:) name:@"NSWindowDidFailToEnterFullScreenNotification" object:window];
         [center addObserver:self selector:@selector(windowDidFailToExitFullScreen:) name:@"NSWindowDidFailToExitFullScreenNotification" object:window];
     } else {
@@ -302,9 +330,11 @@
 
     [view setNextResponder:self];
 
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
     if ([view respondsToSelector:@selector(setAcceptsTouchEvents:)]) {
         [view setAcceptsTouchEvents:YES];
     }
+#endif
 }
 
 - (void)observeValueForKeyPath:(NSString *)keyPath
@@ -374,7 +404,9 @@
     inFullscreenTransition = YES;
 
     /* you need to be FullScreenPrimary, or toggleFullScreen doesn't work. Unset it again in windowDidExitFullScreen. */
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
     [nswindow setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary];
+#endif
     [nswindow performSelectorOnMainThread: @selector(toggleFullScreen:) withObject:nswindow waitUntilDone:NO];
     return YES;
 }
@@ -410,11 +442,13 @@
         [center removeObserver:self name:NSWindowDidDeminiaturizeNotification object:window];
         [center removeObserver:self name:NSWindowDidBecomeKeyNotification object:window];
         [center removeObserver:self name:NSWindowDidResignKeyNotification object:window];
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
         [center removeObserver:self name:NSWindowDidChangeBackingPropertiesNotification object:window];
         [center removeObserver:self name:NSWindowWillEnterFullScreenNotification object:window];
         [center removeObserver:self name:NSWindowDidEnterFullScreenNotification object:window];
         [center removeObserver:self name:NSWindowWillExitFullScreenNotification object:window];
         [center removeObserver:self name:NSWindowDidExitFullScreenNotification object:window];
+#endif
         [center removeObserver:self name:@"NSWindowDidFailToEnterFullScreenNotification" object:window];
         [center removeObserver:self name:@"NSWindowDidFailToExitFullScreenNotification" object:window];
     } else {
@@ -589,12 +623,14 @@
         [NSMenu setMenuBarVisible:NO];
     }
 
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
     /* On pre-10.6, you might have the capslock key state wrong now because we can't check here. */
     if (floor(NSAppKitVersionNumber) >= NSAppKitVersionNumber10_6) {
         const unsigned int newflags = [NSEvent modifierFlags] & NSAlphaShiftKeyMask;
         _data->videodata->modifierFlags = (_data->videodata->modifierFlags & ~NSAlphaShiftKeyMask) | newflags;
         SDL_ToggleModState(KMOD_CAPS, newflags != 0);
     }
+#endif
 }
 
 - (void)windowDidResignKey:(NSNotification *)aNotification
@@ -621,6 +657,7 @@
 
 - (void)windowDidChangeBackingProperties:(NSNotification *)aNotification
 {
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
     NSNumber *oldscale = [[aNotification userInfo] objectForKey:NSBackingPropertyOldScaleFactorKey];
 
     if (inFullscreenTransition) {
@@ -633,6 +670,7 @@
         _data->window->h = 0;
         [self windowDidResize:aNotification];
     }
+#endif
 }
 
 - (void)windowWillEnterFullScreen:(NSNotification *)aNotification
@@ -733,12 +771,14 @@
         [nswindow miniaturize:nil];
     } else {
         /* Adjust the fullscreen toggle button and readd menu now that we're here. */
+#if MAC_OS_X_VERSION_MIN_REQUIRED > 1070
         if (window->flags & SDL_WINDOW_RESIZABLE) {
             /* resizable windows are Spaces-friendly: they get the "go fullscreen" toggle button on their titlebar. */
             [nswindow setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary];
         } else {
             [nswindow setCollectionBehavior:NSWindowCollectionBehaviorManaged];
         }
+#endif
         [NSMenu setMenuBarVisible:YES];
 
         pendingWindowOperation = PENDING_OPERATION_NONE;
@@ -756,6 +796,7 @@
     }
 }
 
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
 -(NSApplicationPresentationOptions)window:(NSWindow *)window willUseFullScreenPresentationOptions:(NSApplicationPresentationOptions)proposedOptions
 {
     if ((_data->window->flags & SDL_WINDOW_FULLSCREEN_DESKTOP) == SDL_WINDOW_FULLSCREEN_DESKTOP) {
@@ -764,6 +805,7 @@
         return proposedOptions;
     }
 }
+#endif
 
 
 /* We'll respond to key events by doing nothing so we don't beep.
@@ -993,6 +1035,7 @@
 
 - (void)touchesBeganWithEvent:(NSEvent *) theEvent
 {
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
     NSSet *touches = [theEvent touchesMatchingPhase:NSTouchPhaseAny inView:nil];
     int existingTouchCount = 0;
 
@@ -1013,25 +1056,89 @@
 
     DLog("Began Fingers: %lu .. existing: %d", (unsigned long)[touches count], existingTouchCount);
     [self handleTouches:NSTouchPhaseBegan withEvent:theEvent];
+#endif
 }
 
 - (void)touchesMovedWithEvent:(NSEvent *) theEvent
 {
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
     [self handleTouches:NSTouchPhaseMoved withEvent:theEvent];
+#endif
 }
 
 - (void)touchesEndedWithEvent:(NSEvent *) theEvent
 {
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
     [self handleTouches:NSTouchPhaseEnded withEvent:theEvent];
+#endif
 }
 
 - (void)touchesCancelledWithEvent:(NSEvent *) theEvent
 {
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
     [self handleTouches:NSTouchPhaseCancelled withEvent:theEvent];
+#endif
 }
 
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
+#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070
 - (void)handleTouches:(NSTouchPhase) phase withEvent:(NSEvent *) theEvent
+#else
+- (void)handleTouches:(cocoaTouchType)type withEvent:(NSEvent *)event
+#endif
 {
+#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070
+    NSSet *touches = 0;
+    NSEnumerator *enumerator;
+    NSTouch *touch;
+
+    switch (type) {
+        case COCOA_TOUCH_DOWN:
+            touches = [event touchesMatchingPhase:NSTouchPhaseBegan inView:nil];
+            break;
+        case COCOA_TOUCH_UP:
+            touches = [event touchesMatchingPhase:NSTouchPhaseEnded inView:nil];
+            break;
+        case COCOA_TOUCH_CANCELLED:
+            touches = [event touchesMatchingPhase:NSTouchPhaseCancelled inView:nil];
+            break;
+        case COCOA_TOUCH_MOVE:
+            touches = [event touchesMatchingPhase:NSTouchPhaseMoved inView:nil];
+            break;
+    }
+
+    enumerator = [touches objectEnumerator];
+    touch = (NSTouch*)[enumerator nextObject];
+    while (touch) {
+        const SDL_TouchID touchId = (SDL_TouchID)(intptr_t)[touch device];
+        if (!SDL_GetTouch(touchId)) {
+            if (SDL_AddTouch(touchId, "") < 0) {
+                return;
+            }
+        }
+
+        const SDL_FingerID fingerId = (SDL_FingerID)(intptr_t)[touch identity];
+        float x = [touch normalizedPosition].x;
+        float y = [touch normalizedPosition].y;
+        /* Make the origin the upper left instead of the lower left */
+        y = 1.0f - y;
+
+        switch (type) {
+        case COCOA_TOUCH_DOWN:
+            SDL_SendTouch(touchId, fingerId, SDL_TRUE, x, y, 1.0f);
+            break;
+        case COCOA_TOUCH_UP:
+        case COCOA_TOUCH_CANCELLED:
+            SDL_SendTouch(touchId, fingerId, SDL_FALSE, x, y, 1.0f);
+            break;
+        case COCOA_TOUCH_MOVE:
+            SDL_SendTouchMotion(touchId, fingerId, x, y, 1.0f);
+            break;
+        }
+
+        touch = (NSTouch*)[enumerator nextObject];
+     }
+#else
     NSSet *touches = [theEvent touchesMatchingPhase:phase inView:nil];
 
     for (NSTouch *touch in touches) {
@@ -1061,7 +1168,9 @@
             break;
         }
     }
+#endif
 }
+#endif
 
 @end
 
@@ -1118,8 +1227,13 @@
 
 static int
 SetupWindowData(_THIS, SDL_Window * window, NSWindow *nswindow, SDL_bool created)
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
 { @autoreleasepool
 {
+#else
+{
+    NSAutoreleasePool *pool;
+#endif
     SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata;
     SDL_WindowData *data;
 
@@ -1134,6 +1248,9 @@
     data->videodata = videodata;
     data->nscontexts = [[NSMutableArray alloc] init];
 
+#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070
+    pool = [[NSAutoreleasePool alloc] init];
+#endif
     /* Create an event listener for the window */
     data->listener = [[Cocoa_WindowListener alloc] init];
 
@@ -1194,15 +1311,27 @@
      */
     [nswindow setOneShot:NO];
 
+#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070
+    [pool release];
+#endif
     /* All done! */
     window->driverdata = data;
     return 0;
+#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070
+}
+#else
 }}
+#endif
 
 int
 Cocoa_CreateWindow(_THIS, SDL_Window * window)
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
 { @autoreleasepool
 {
+#else
+{
+    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+#endif
     SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata;
     NSWindow *nswindow;
     SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
@@ -1243,6 +1372,7 @@
     [nswindow setBackgroundColor:[NSColor blackColor]];
 
     if (videodata->allow_spaces) {
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
         SDL_assert(floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_6);
         SDL_assert([nswindow respondsToSelector:@selector(toggleFullScreen:)]);
         /* we put FULLSCREEN_DESKTOP windows in their own Space, without a toggle button or menubar, later */
@@ -1250,6 +1380,7 @@
             /* resizable windows are Spaces-friendly: they get the "go fullscreen" toggle button on their titlebar. */
             [nswindow setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary];
         }
+#endif
     }
 
     /* Create a default view for this window */
@@ -1268,18 +1399,30 @@
 
     /* Allow files and folders to be dragged onto the window by users */
     [nswindow registerForDraggedTypes:[NSArray arrayWithObject:(NSString *)kUTTypeFileURL]];
+#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070
+    [pool release];
+#endif
 
     if (SetupWindowData(_this, window, nswindow, SDL_TRUE) < 0) {
         [nswindow release];
         return -1;
     }
     return 0;
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
 }}
+#else
+}
+#endif
 
 int
 Cocoa_CreateWindowFrom(_THIS, SDL_Window * window, const void *data)
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
 { @autoreleasepool
 {
+#else
+{
+    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+#endif
     NSWindow *nswindow = (NSWindow *) data;
     NSString *title;
 
@@ -1290,34 +1433,64 @@
     }
 
     return SetupWindowData(_this, window, nswindow, SDL_FALSE);
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
 }}
+#else
+    [pool release];
+}
+#endif
 
 void
 Cocoa_SetWindowTitle(_THIS, SDL_Window * window)
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
 { @autoreleasepool
 {
+#else
+{
+    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+#endif
     const char *title = window->title ? window->title : "";
     NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
     NSString *string = [[NSString alloc] initWithUTF8String:title];
     [nswindow setTitle:string];
     [string release];
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
 }}
+#else
+    [pool release];
+}
+#endif
 
 void
 Cocoa_SetWindowIcon(_THIS, SDL_Window * window, SDL_Surface * icon)
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
 { @autoreleasepool
 {
+#else
+{
+    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+#endif
     NSImage *nsimage = Cocoa_CreateImage(icon);
 
     if (nsimage) {
         [NSApp setApplicationIconImage:nsimage];
     }
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
 }}
+#else
+    [pool release];
+}
+#endif
 
 void
 Cocoa_SetWindowPosition(_THIS, SDL_Window * window)
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
 { @autoreleasepool
 {
+#else
+{
+    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+#endif
     SDL_WindowData *windata = (SDL_WindowData *) window->driverdata;
     NSWindow *nswindow = windata->nswindow;
     NSRect rect;
@@ -1335,12 +1508,22 @@
     s_moveHack = moveHack;
 
     ScheduleContextUpdates(windata);
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
 }}
+#else
+    [pool release];
+}
+#endif
 
 void
 Cocoa_SetWindowSize(_THIS, SDL_Window * window)
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
 { @autoreleasepool
 {
+#else
+{
+    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+#endif
     SDL_WindowData *windata = (SDL_WindowData *) window->driverdata;
     NSWindow *nswindow = windata->nswindow;
     NSRect rect;
@@ -1362,12 +1545,22 @@
     s_moveHack = moveHack;
 
     ScheduleContextUpdates(windata);
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
 }}
+#else
+    [pool release];
+}
+#endif
 
 void
 Cocoa_SetWindowMinimumSize(_THIS, SDL_Window * window)
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
 { @autoreleasepool
 {
+#else
+{
+    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+#endif
     SDL_WindowData *windata = (SDL_WindowData *) window->driverdata;
 
     NSSize minSize;
@@ -1375,12 +1568,22 @@
     minSize.height = window->min_h;
 
     [windata->nswindow setContentMinSize:minSize];
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
 }}
+#else
+    [pool release];
+}
+#endif
 
 void
 Cocoa_SetWindowMaximumSize(_THIS, SDL_Window * window)
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
 { @autoreleasepool
 {
+#else
+{
+    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+#endif
     SDL_WindowData *windata = (SDL_WindowData *) window->driverdata;
 
     NSSize maxSize;
@@ -1388,12 +1591,22 @@
     maxSize.height = window->max_h;
 
     [windata->nswindow setContentMaxSize:maxSize];
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
 }}
+#else
+    [pool release];
+}
+#endif
 
 void
 Cocoa_ShowWindow(_THIS, SDL_Window * window)
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
 { @autoreleasepool
 {
+#else
+{
+    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+#endif
     SDL_WindowData *windowData = ((SDL_WindowData *) window->driverdata);
     NSWindow *nswindow = windowData->nswindow;
 
@@ -1402,21 +1615,41 @@
         [nswindow makeKeyAndOrderFront:nil];
         [windowData->listener resumeVisibleObservation];
     }
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
 }}
+#else
+    [pool release];
+}
+#endif
 
 void
 Cocoa_HideWindow(_THIS, SDL_Window * window)
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
 { @autoreleasepool
 {
+#else
+{
+    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+#endif
     NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
 
     [nswindow orderOut:nil];
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
 }}
+#else
+    [pool release];
+}
+#endif
 
 void
 Cocoa_RaiseWindow(_THIS, SDL_Window * window)
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
 { @autoreleasepool
 {
+#else
+{
+    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+#endif
     SDL_WindowData *windowData = ((SDL_WindowData *) window->driverdata);
     NSWindow *nswindow = windowData->nswindow;
 
@@ -1429,24 +1662,44 @@
         [nswindow makeKeyAndOrderFront:nil];
     }
     [windowData->listener resumeVisibleObservation];
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
 }}
+#else
+    [pool release];
+}
+#endif
 
 void
 Cocoa_MaximizeWindow(_THIS, SDL_Window * window)
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
 { @autoreleasepool
 {
+#else
+{
+    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+#endif
     SDL_WindowData *windata = (SDL_WindowData *) window->driverdata;
     NSWindow *nswindow = windata->nswindow;
 
     [nswindow zoom:nil];
 
     ScheduleContextUpdates(windata);
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
 }}
+#else
+    [pool release];
+}
+#endif
 
 void
 Cocoa_MinimizeWindow(_THIS, SDL_Window * window)
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
 { @autoreleasepool
 {
+#else
+{
+    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+#endif
     SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
     NSWindow *nswindow = data->nswindow;
 
@@ -1455,12 +1708,22 @@
     } else {
         [nswindow miniaturize:nil];
     }
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
 }}
+#else
+    [pool release];
+}
+#endif
 
 void
 Cocoa_RestoreWindow(_THIS, SDL_Window * window)
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
 { @autoreleasepool
 {
+#else
+{
+    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+#endif
     NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
 
     if ([nswindow isMiniaturized]) {
@@ -1468,7 +1731,12 @@
     } else if ((window->flags & SDL_WINDOW_RESIZABLE) && [nswindow isZoomed]) {
         [nswindow zoom:nil];
     }
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
 }}
+#else
+    [pool release];
+}
+#endif
 
 static NSWindow *
 Cocoa_RebuildWindow(SDL_WindowData * data, NSWindow * nswindow, unsigned style)
@@ -1493,20 +1761,35 @@
 
 void
 Cocoa_SetWindowBordered(_THIS, SDL_Window * window, SDL_bool bordered)
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
 { @autoreleasepool
 {
+#else
+{
+    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+#endif
     if (SetWindowStyle(window, GetWindowStyle(window))) {
         if (bordered) {
             Cocoa_SetWindowTitle(_this, window);  /* this got blanked out. */
         }
     }
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
 }}
+#else
+    [pool release];
+}
+#endif
 
 
 void
 Cocoa_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen)
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
 { @autoreleasepool
 {
+#else
+{
+    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+#endif
     SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
     NSWindow *nswindow = data->nswindow;
     NSRect rect;
@@ -1585,7 +1868,12 @@
     }
 
     ScheduleContextUpdates(data);
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
 }}
+#else
+    [pool release];
+}
+#endif
 
 int
 Cocoa_SetWindowGammaRamp(_THIS, SDL_Window * window, const Uint16 * ramp)
@@ -1670,8 +1958,13 @@
 
 void
 Cocoa_DestroyWindow(_THIS, SDL_Window * window)
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
 { @autoreleasepool
 {
+#else
+{
+    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+#endif
     SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
 
     if (data) {
@@ -1694,7 +1987,12 @@
         SDL_free(data);
     }
     window->driverdata = NULL;
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
 }}
+#else
+    [pool release];
+}
+#endif
 
 SDL_bool
 Cocoa_GetWindowWMInfo(_THIS, SDL_Window * window, SDL_SysWMinfo * info)
@@ -1726,8 +2024,13 @@
 
 SDL_bool
 Cocoa_SetWindowFullscreenSpace(SDL_Window * window, SDL_bool state)
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
 { @autoreleasepool
 {
+#else
+{
+    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+#endif
     SDL_bool succeeded = SDL_FALSE;
     SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
 
@@ -1758,8 +2061,15 @@
         succeeded = SDL_TRUE;
     }
 
+#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070
+    [pool release];
+#endif
     return succeeded;
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
 }}
+#else
+}
+#endif
 
 int
 Cocoa_SetWindowHitTest(SDL_Window * window, SDL_bool enabled)
