Index: branches/sdl2/doc/COMPILING.txt
===================================================================
--- branches/sdl2/doc/COMPILING.txt	(revision 2180)
+++ branches/sdl2/doc/COMPILING.txt	(working copy)
@@ -5,11 +5,11 @@
 
 * gcc C compiler (other compilers may work, but are not officially supported)
 * GNU make (other similar "make" tools may work, but are not supported)
-* SDL library v1.2
-* SDL_image library
+* SDL library v2.0
+* SDL2_image library
 * libpng (not on MacOSX)
 * FreeType library (optional, for truetype fonts)
-* SDL_ttf library (optional, for truetype fonts)
+* SDL2_ttf library (optional, for truetype fonts)
 * Lua library v5.1 or v5.2 (optional, for Lua scripting)
 
 Extra requirements for Windows:
@@ -33,7 +33,7 @@
 If all goes well, it should build grafx2 (the main program) in the "bin"
 directory. Voilà.
 
-If you don't have FreeType and SDL_ttf, type make NOTTF=1 instead. It will
+If you don't have FreeType and SDL2_ttf, type make NOTTF=1 instead. It will
 build a version without TrueType support : the Text tool will be limited to
 bitmap fonts, proportional fonts with .ttf extension won't be available.
 
@@ -93,6 +93,15 @@
 	make GP2XCROSS=1
 This will only work on an UNIXsystem (Linux or FreeBSD).
 
+== macOS ==
+
+By default SDL2 (+image +ttf) will be searched through pkg-config, so if you use
+homebrew, macports or similar you will be fine. If, however, you want to link
+against its framework versions, use NOFW=0
+
+macOS provides libpng already. However, if you want to link against a custom
+libpng use SYSPNG=0. It will be searched through pkg-config.
+
 == Windows ==
 
 It is also possible to compile from linux, with this command :
@@ -111,11 +120,11 @@
   installed in C:\MSYS\mingw
 
 SDL:
-  SDL-devel-1.2.13-mingw32.tar.gz
+  SDL2-devel-2.0.5-mingw.tar.gz
   Uncompress in temporary directory
   make
   make install (no effect?)
-  Headers are in /usr/mingw/include/SDL, copy them to /usr/include/SDL
+  Headers are in /usr/mingw/include/SDL2, copy them to /usr/include/SDL2
 
 Zlib:
   http://gnuwin32.sourceforge.net/downlinks/zlib.php
@@ -148,12 +157,12 @@
   make
   Don't use 'make install', copy tiff.h libtiff.a manually instead.
   
-SDL_image:
+SDL2_image:
   Requires: Libpng
   Requires optionally: libtiff
   Requires optionally: libjpeg
-  http://www.mirrorservice.org/sites/download.sourceforge.net/pub/sourceforge/l/li/libsdl/
-  SDL_image-1.2.8.zip
+  https://www.libsdl.org/projects/SDL_image/release/SDL2_image-devel-2.0.1-VC.zip
+  SDL2_image-devel-2.0.1-VC.zip
   Uncompress in temporary directory
   ./configure
   Check in the messages that png worked
@@ -167,11 +176,10 @@
   mingw-freetype-2.3.7-2
   Uncompress in c:/mwsys/mingw
   
-SDL_ttf:
+SDL2_ttf:
   No mingw package
-  http://www.mirrorservice.org/sites/download.sourceforge.net/pub/sourceforge/l/li/libsdl/
-  SDL_ttf-2.0.9-win32.zip for DLLs: libfreetype-6.dll, SDL_ttf.dll, zlib1.dll
-  SDL_ttf-2.0.9.tar.gz
+  https://www.libsdl.org/projects/SDL_ttf/release/SDL2_ttf-devel-2.0.14-VC.zip
+  SDL2_ttf-devel-2.0.14-VC.zip for DLLs: libfreetype-6.dll, SDL2_ttf.dll, zlib1.dll
 
 Lua:
   (optional)
@@ -182,7 +190,7 @@
   (make install doesn't work, even with prefix)
   Copy luaconf.h, lualib.h, lua.h, lauxlib.h to c:\msys\mingw\include
   Copy liblua.a to c:\msys\mingw\lib
-  Copy lua51.dll to c:\msys\mingw\bin
+  Copy lua52.dll to c:\msys\mingw\bin
 
 == Atari TOS machines ==
 The Atari build is very similar to the Linux one. The build might work on native machine with gcc 4.3> compiler, 
Index: branches/sdl2/src/.DS_Store
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Index: branches/sdl2/src/Makefile
===================================================================
--- branches/sdl2/src/Makefile	(revision 2180)
+++ branches/sdl2/src/Makefile	(working copy)
@@ -32,19 +32,6 @@
 # Compile with OPTIM=0 to disable gcc optimizations, to enable debug.
   STRIP = strip
 
-### Specific to build MAC OS X universal binaries on Tiger or Lion ###
-### (may need to be changed or removed depending on the OSX version) ###
-
-#MACOSX_LION = 1
-
-ifdef MACOSX_LION
-MACOSX_SYSROOT = /Developer/SDKs/MacOSX10.6.sdk
-MACOSX_ARCH = -arch x86_64 -arch i386
-else
-MACOSX_SYSROOT = /Developer/SDKs/MacOSX10.4u.sdk
-MACOSX_ARCH = -arch ppc -arch i386
-endif
-
 ### PLATFORM DETECTION AND CONFIGURATION ###
 
 PLATFORMOBJ =
@@ -91,10 +78,11 @@
 
   else
   ifeq ($(PLATFORM),Darwin) # 2
+    MACOSX_ARCH = -arch x86_64 -arch i386
     #Mac OS X specific
     DELCOMMAND = rm -rf
     MKDIR = mkdir -p
-    RMDIR = rmdir --ignore-fail-on-non-empty
+    RMDIR = rm -rf
     # Force it
     OPTIM = 3
     CP = cp
@@ -105,38 +93,60 @@
     BIN = ../bin/grafx2
     SVN_REVISION = $(shell svnversion | cut -f2 -d ":" - | tr -d "M")
 
-    # these are for use with macports
-    #SDLCOPT = $(shell sdl2-config --cflags)
-    #SDLLOPT = $(shell sdl2-config --libs) $(shell pkg-config --libs SDL2_image)
-    #LUACOPT = $(shell pkg-config lua --cflags --silence-errors ||pkg-config lua5.1 --cflags --silence-errors ||pkg-config lua-5.1 --cflags)
-    #LUALOPT = $(shell pkg-config lua --libs --silence-errors ||pkg-config lua5.1 --libs --silence-errors ||pkg-config lua-5.1 --libs)
+    # frameworks OFF by default
+    ifndef NOFW
+        NOFW = 1
+    endif
+    ifeq ($(NOFW),0)
+        SDLCOPT = -F$(FWDIR) -D_THREAD_SAFE -DPREFIX_SDL
+	# @rpath is introduced in 10.5 Leopard
+        SDLLOPT = -framework Cocoa -framework SDL2 -framework SDL2_image -rpath @executable_path/../Frameworks
+    else
+        SDLCOPT = $(shell sdl2-config --cflags) $(shell pkg-config SDL2_image --cflags --silence-errors)
+        SDLLOPT = $(shell sdl2-config --libs) $(shell pkg-config SDL2_image --libs --silence-errors)
+    endif
 
-    # these are for use with Mac OS X native frameworks
-    #-framework SDL_ttf 
-    SDLLOPT = -isysroot $(MACOSX_SYSROOT) $(MACOSX_ARCH) -L/usr/lib -framework SDL -framework SDL2_image -framework Cocoa -framework Carbon -framework OpenGL
-    SDLCOPT = $(MACOSX_ARCH) -I$(FWDIR)/SDL.framework/Headers -I$(FWDIR)/SDL2_image.framework/Headers -I$(FWDIR)/SDL_ttf.framework/Headers -D_THREAD_SAFE
-    LUACOPT = -I$(FWDIR)/Lua.framework/Headers
-ifdef MACOSX_LION
-    LUALOPT = -framework lua
-else
-    LUALOPT = -llua 
-endif
+    ifndef SYSPNG
+        SYSPNG = 1
+    endif
+    ifeq ($(SYSPNG),1)
+        PNGCOPT =
+        PNGLOPT = -lpng
+    else
+        PNGCOPT = $(shell pkg-config libpng --cflags --silence-errors)
+        PNGLOPT = $(pkg-config libpng --libs --silence-errors)
+    endif
 
+    # lua ON by default
+    ifndef NOLUA
+        NOLUA = 0
+    endif
+    ifeq ($(NOLUA),0)
+        LUACOPT = $(shell pkg-config lua --cflags --silence-errors)
+        LUALOPT = $(shell pkg-config lua --libs --silence-errors)
+    endif
+
+    # ttf OFF by default
+    ifndef NOTTF
+        NOTTF = 1
+    endif
+    ifeq ($(NOTTF),0)
+        ifeq ($(NOFW),0)
+            TTFCOPT = $(shell pkg-config SDL2_ttf --cflags --silence-errors)
+            TTFLOPT = $(shell pkg-config SDL2_ttf --libs --silence-errors)
+        else
+	    TTFCOPT =
+	    TTFLOPT = -framework SDL2_ttf
+        endif
+    endif	
+
     # these are for everyone
-    COPT = -D_DARWIN_C_SOURCE -D__macosx__ -D__linux__ -W -Wall -Wdeclaration-after-statement -O$(OPTIM) -std=c99 -c -g $(LUACOPT) $(SDLCOPT) $(TTFCOPT) -I/usr/include
-ifdef MACOSX_LION
-    LOPT = $(SDLLOPT) $(LUALOPT) -framework libpng14 -lz
-else
-    LOPT = $(SDLLOPT) $(LUALOPT) -lpng -lz
-endif
-    # Use gcc for compiling. Use ncc to build a callgraph and analyze the code.
-    CC = gcc
-    #CC = nccgen -ncgcc -ncld -ncfabs
+    COPT = $(MACOSX_ARCH) -D_DARWIN_C_SOURCE -D__macosx__ -W -Wall -Wdeclaration-after-statement -O$(OPTIM) -std=c99 -c -g $(PNGCOPT) $(LUACOPT) $(SDLCOPT) $(TTFCOPT) -I/usr/include
+    LOPT = -F$(FWDIR) $(PNGLOPT) $(LUALOPT) $(SDLLOPT) $(TTFLOPT)
+    CC = clang
     OBJDIR = ../obj/macosx
-    PLATFORMOBJ = $(OBJDIR)/SDLMain.o
     FCLOPT = 
     MACAPPEXE = Grafx2.app/Contents/MacOS/Grafx2
-    NOTTF = 1
   else
   ifeq ($(PLATFORM),AROS) # 3
     #AROS specific
@@ -433,59 +443,65 @@
 
 FONT_FILES = ../share/grafx2/fonts/8pxfont.png ../share/grafx2/fonts/Tuffy.ttf ../share/grafx2/fonts/PF_Arma_5__.png ../share/grafx2/fonts/PF_Easta_7_.png ../share/grafx2/fonts/PF_Easta_7__.png ../share/grafx2/fonts/PF_Ronda_7__.png ../share/grafx2/fonts/PF_Tempesta_5.png ../share/grafx2/fonts/PF_Tempesta_5_.png ../share/grafx2/fonts/PF_Tempesta_5__.png ../share/grafx2/fonts/PF_Tempesta_5___.png ../share/grafx2/fonts/PF_Tempesta_7.png ../share/grafx2/fonts/PF_Tempesta_7_.png ../share/grafx2/fonts/PF_Tempesta_7__.png ../share/grafx2/fonts/PF_Tempesta_7___.png ../share/grafx2/fonts/PF_Westa_7_.png ../share/grafx2/fonts/PF_Westa_7__.png
 
-
 ifeq ($(PLATFORM),Darwin)
 all : $(MACAPPEXE)
 $(MACAPPEXE) : $(BIN)
-	rm -rf Grafx2.app
-	mkdir -p Grafx2.app Grafx2.app/Contents Grafx2.app/Contents/Frameworks Grafx2.app/Contents/MacOS Grafx2.app/Contents/Resources Grafx2.app/Contents/Resources/scripts
-	mkdir -p Grafx2.app/Contents/Resources/scripts/samples_2.4
-	mkdir -p Grafx2.app/Contents/Resources/scripts/samples_2.4/brush
-	mkdir -p Grafx2.app/Contents/Resources/scripts/samples_2.4/demo
-	mkdir -p Grafx2.app/Contents/Resources/scripts/samples_2.4/libs
-	mkdir -p Grafx2.app/Contents/Resources/scripts/samples_2.4/palette
-	mkdir -p Grafx2.app/Contents/Resources/scripts/samples_2.4/picture
+	$(RMDIR) Grafx2.app
+	$(MKDIR) Grafx2.app Grafx2.app/Contents Grafx2.app/Contents/Frameworks Grafx2.app/Contents/MacOS Grafx2.app/Contents/Resources Grafx2.app/Contents/Resources/scripts
+	$(MKDIR) Grafx2.app/Contents/Resources/scripts/samples_2.4
+	$(MKDIR) Grafx2.app/Contents/Resources/scripts/samples_2.4/brush
+	$(MKDIR) Grafx2.app/Contents/Resources/scripts/samples_2.4/demo
+	$(MKDIR) Grafx2.app/Contents/Resources/scripts/samples_2.4/libs
+	$(MKDIR) Grafx2.app/Contents/Resources/scripts/samples_2.4/palette
+	$(MKDIR) Grafx2.app/Contents/Resources/scripts/samples_2.4/picture
 	echo 'APPL????' > Grafx2.app/Contents/PkgInfo
-	cp ../Info.plist Grafx2.app/Contents
-	cp -r Grafx2.icns Grafx2.app/Contents/Resources
-	cp -r English.lproj Grafx2.app/Contents/Resources
-	cp -r ../share/grafx2/fonts Grafx2.app/Contents/Resources
-	cp -r ../share/grafx2/skins Grafx2.app/Contents/Resources
-	cp -r ../share/grafx2/gfx2def.ini Grafx2.app/Contents/Resources
-	cp -r ../share/grafx2/scripts/samples_2.4/brush Grafx2.app/Contents/Resources/scripts/samples_2.4
-	cp -r ../share/grafx2/scripts/samples_2.4/demo Grafx2.app/Contents/Resources/scripts/samples_2.4
-	cp -r ../share/grafx2/scripts/samples_2.4/libs Grafx2.app/Contents/Resources/scripts/samples_2.4
-	cp -r ../share/grafx2/scripts/samples_2.4/palette Grafx2.app/Contents/Resources/scripts/samples_2.4
-	cp -r ../share/grafx2/scripts/samples_2.4/picture Grafx2.app/Contents/Resources/scripts/samples_2.4
-ifdef MACOSX_LION
-	mkdir -p Grafx2.app/Contents/Frameworks/Lua.framework/Versions
-	mkdir -p Grafx2.app/Contents/Frameworks/libpng14.framework/Versions
-endif
-	mkdir -p Grafx2.app/Contents/Frameworks/SDL.framework/Versions
-	mkdir -p Grafx2.app/Contents/Frameworks/SDL2_image.framework/Versions
-#	mkdir -p Grafx2.app/Contents/Frameworks/SDL_ttf.framework/Versions
-ifdef MACOSX_LION
-	cp -Rp $(FWDIR)/Lua.framework/Versions/A Grafx2.app/Contents/Frameworks/Lua.framework/Versions
-	cp -Rp $(FWDIR)/libpng14.framework/Versions/1.4.8 Grafx2.app/Contents/Frameworks/libpng14.framework/Versions
-endif
-	cp -Rp $(FWDIR)/SDL.framework/Versions/A Grafx2.app/Contents/Frameworks/SDL.framework/Versions
-	cp -Rp $(FWDIR)/SDL2_image.framework/Versions/A Grafx2.app/Contents/Frameworks/SDL2_image.framework/Versions
-#	cp -Rp $(FWDIR)/SDL_ttf.framework/Versions/A Grafx2.app/Contents/Frameworks/SDL_ttf.framework/Versions
-    # remove those
-	rm -fr Grafx2.app/Contents/Frameworks/SDL.framework/Versions/A/Headers
-	rm -fr Grafx2.app/Contents/Frameworks/SDL.framework/Versions/A/Resources
-	rm -fr Grafx2.app/Contents/Frameworks/SDL2_image.framework/Versions/A/Headers
-	rm -fr Grafx2.app/Contents/Frameworks/SDL2_image.framework/Versions/A/Resources
-ifdef MACOSX_LION
-	rm -fr Grafx2.app/Contents/Frameworks/Lua.framework/Versions/A/Resources
-	rm -fr Grafx2.app/Contents/Frameworks/Lua.framework/Versions/A/Headers
-	rm -fr Grafx2.app/Contents/Frameworks/libpng14.framework/Versions/1.4.8/Resources
-	rm -fr Grafx2.app/Contents/Frameworks/libpng14.framework/Versions/1.4.8/Headers
-	rm -fr Grafx2.app/Contents/Frameworks/SDL_ttf.framework/Versions
-endif
+	$(CP) ../Info.plist Grafx2.app/Contents
+	$(CP) -r Grafx2.icns Grafx2.app/Contents/Resources
+	$(CP) -r English.lproj Grafx2.app/Contents/Resources
+	$(CP) -r ../share/grafx2/fonts Grafx2.app/Contents/Resources
+	$(CP) -r ../share/grafx2/skins Grafx2.app/Contents/Resources
+	$(CP) -r ../share/grafx2/gfx2def.ini Grafx2.app/Contents/Resources
+	$(CP) -r ../share/grafx2/scripts/samples_2.4/brush Grafx2.app/Contents/Resources/scripts/samples_2.4
+	$(CP) -r ../share/grafx2/scripts/samples_2.4/demo Grafx2.app/Contents/Resources/scripts/samples_2.4
+	$(CP) -r ../share/grafx2/scripts/samples_2.4/libs Grafx2.app/Contents/Resources/scripts/samples_2.4
+	$(CP) -r ../share/grafx2/scripts/samples_2.4/palette Grafx2.app/Contents/Resources/scripts/samples_2.4
+	$(CP) -r ../share/grafx2/scripts/samples_2.4/picture Grafx2.app/Contents/Resources/scripts/samples_2.4
+
 	cp $(BIN) $(MACAPPEXE)
 	$(STRIP) -x -X -S $(MACAPPEXE)
 	chmod +x $(MACAPPEXE)
+
+ifeq ($(NOFW),0)
+	# copy frameworks
+	$(MKDIR) Grafx2.app/Contents/Frameworks/SDL2.framework/Versions
+	$(MKDIR) Grafx2.app/Contents/Frameworks/SDL2_image.framework/Versions
+	$(MKDIR) Grafx2.app/Contents/Frameworks/SDL2_ttf.framework/Versions
+	$(CP) -Rp $(FWDIR)/SDL2.framework/Versions/A Grafx2.app/Contents/Frameworks/SDL2.framework/Versions
+	$(CP) -Rp $(FWDIR)/SDL2_image.framework/Versions/A Grafx2.app/Contents/Frameworks/SDL2_image.framework/Versions
+	$(CP) -Rp $(FWDIR)/SDL2_ttf.framework/Versions/A Grafx2.app/Contents/Frameworks/SDL2_ttf.framework/Versions
+
+	# resign SDL
+	codesign -f -s - Grafx2.app/Contents/Frameworks/SDL2.framework/Versions/A/SDL2
+	codesign -f -s - Grafx2.app/Contents/Frameworks/SDL2_image.framework/Versions/A/SDL2_image
+ifeq ($(NOTTF),0)
+	codesign -f -s - Grafx2.app/Contents/Frameworks/SDL2_ttf.framework/Versions/A/SDL2_ttf
+endif
+
+	# remove unneeded resources and headers
+	$(RMDIR) Grafx2.app/Contents/Frameworks/SDL2.framework/Versions/A/Headers
+	$(RMDIR) Grafx2.app/Contents/Frameworks/SDL2.framework/Versions/A/Resources
+	$(RMDIR) Grafx2.app/Contents/Frameworks/SDL2_image.framework/Versions/A/Headers
+	$(RMDIR) Grafx2.app/Contents/Frameworks/SDL2_image.framework/Versions/A/Resources
+	$(RMDIR) Grafx2.app/Contents/Frameworks/SDL2_image.framework/Versions/A/Frameworks/webp.framework/Versions/A/Headers
+	$(RMDIR) Grafx2.app/Contents/Frameworks/SDL2_image.framework/Versions/A/Frameworks/webp.framework/Versions/A/Resources
+	$(RMDIR) Grafx2.app/Contents/Frameworks/SDL2_ttf.framework/Versions/A/Headers
+	$(RMDIR) Grafx2.app/Contents/Frameworks/SDL2_ttf.framework/Versions/A/Resources
+	$(RMDIR) Grafx2.app/Contents/Frameworks/SDL2_ttf.framework/Versions/A/Frameworks/FreeType.framework/Versions/A/Resources
+	$(RMDIR) Grafx2.app/Contents/Frameworks/SDL2_ttf.framework/Versions/A/Frameworks/FreeType.framework/Versions/A/Headers
+else
+	# TODO copy dylibs
+endif
+	# dist files
 	tar cvzf grafx2-svn$(SVN_REVISION)-macosx.tgz --exclude '*svn*' --exclude '*DS_Store*' Grafx2.app/*
 else
 all : $(BIN)
@@ -520,15 +536,15 @@
 # Create a zip archive ready for upload to the website, including binaries and sourcecode
 ziprelease: version $(BIN) release
 	echo `sed "s/.*=\"\(.*\)\";/\1/" pversion.c`.`svnversion` | tr " :" "_-" | sed -e "s/\(wip\)\\./\1/I" > $(OBJDIR)/versiontag
-	tar cvzf "../src-`cat $(OBJDIR)/versiontag`.tgz" --strip=1 ../src/*.c ../src/*.cpp ../src/*.h ../src/Makefile ../src/Makefile.dep ../src/gfx2.ico ../src/Grafx2_Prefix.pch ../src/SDLMain.m
+	tar cvzf "../src-`cat $(OBJDIR)/versiontag`.tgz" --strip=1 ../src/*.c ../src/*.cpp ../src/*.h ../src/Makefile ../src/Makefile.dep ../src/gfx2.ico ../src/Grafx2_Prefix.pch
 	cd .. && $(ZIP) $(ZIPOPT) "grafx2-`cat $(OBJDIR:../%=%)/versiontag`$(TTFLABEL)-$(PLATFORM).$(ZIP)" $(BIN:../%=%) share/grafx2/gfx2def.ini $(SCRIPT_FILES:../%=%) $(SKIN_FILES:../%=%) share/grafx2/gfx2.gif share/icons/grafx2.svg doc/README.txt doc/COMPILING.txt doc/gpl-2.0.txt doc/PF_fonts.txt $(FONT_FILES:../%=%) doc/README-zlib1.txt doc/README-SDL.txt doc/README-SDL_image.txt doc/README-SDL_ttf.txt doc/README-lua.txt src-`cat $(OBJDIR:../%=%)/versiontag`.tgz $(PLATFORMFILES:../%=%)
 	$(DELCOMMAND) "../src-`cat $(OBJDIR)/versiontag`.tgz"
-	tar cvzf "../grafx2-`cat $(OBJDIR)/versiontag`$(TTFLABEL)-src.tgz" --strip=1 --transform 's,^,grafx2/,g' ../src/*.c ../src/*.cpp ../src/*.h ../src/Makefile ../src/Makefile.dep ../share/grafx2/gfx2def.ini $(SCRIPT_FILES) $(SKIN_FILES) ../src/gfx2.ico ../share/grafx2/gfx2.gif ../share/icons/grafx2.svg ../doc/README.txt ../doc/COMPILING.txt ../doc/gpl-2.0.txt ../doc/PF_fonts.txt ../misc/unix/grafx2.1 ../misc/unix/grafx2.xpm ../misc/unix/grafx2.desktop ../misc/morphos/grafx2.info $(FONT_FILES) ../src/Grafx2_Prefix.pch ../src/SDLMain.m
+	tar cvzf "../grafx2-`cat $(OBJDIR)/versiontag`$(TTFLABEL)-src.tgz" --strip=1 --transform 's,^,grafx2/,g' ../src/*.c ../src/*.cpp ../src/*.h ../src/Makefile ../src/Makefile.dep ../share/grafx2/gfx2def.ini $(SCRIPT_FILES) $(SKIN_FILES) ../src/gfx2.ico ../share/grafx2/gfx2.gif ../share/icons/grafx2.svg ../doc/README.txt ../doc/COMPILING.txt ../doc/gpl-2.0.txt ../doc/PF_fonts.txt ../misc/unix/grafx2.1 ../misc/unix/grafx2.xpm ../misc/unix/grafx2.desktop ../misc/morphos/grafx2.info $(FONT_FILES) ../src/Grafx2_Prefix.pch
 	$(DELCOMMAND) "$(OBJDIR)/versiontag"
 
 $(BIN) : $(OBJ)
 	test -d ../bin || $(MKDIR) ../bin
-	$(CC) $(OBJ) -o $(BIN) $(LOPT) $(LFLAGS)
+	$(CC) $(LOPT) $(LFLAGS) -o $(BIN) $(OBJ)
 
 # SVN revision number
 version.c :
@@ -572,6 +588,9 @@
 clean :
 	$(DELCOMMAND) $(OBJ)
 	$(DELCOMMAND) $(BIN)
+ifeq ($(PLATFORM),Darwin)
+	$(DELCOMMAND) Grafx2.app
+endif
 
 ifneq ($(PLATFORM),amiga-vbcc)
 # Linux installation of the program
Index: branches/sdl2/src/SFont.c
===================================================================
--- branches/sdl2/src/SFont.c	(revision 2180)
+++ branches/sdl2/src/SFont.c	(working copy)
@@ -25,8 +25,13 @@
     GERMANY
     karlb@gmx.net                                                      
 */                                                                            
+#if defined(PREFIX_SDL)
 #include <SDL2/SDL.h>
+#include <SDL2/SDL_video.h>
+#else
+#include <SDL.h>
 #include <SDL_video.h>
+#endif
 
 #include <assert.h>
 #include <stdlib.h>
Index: branches/sdl2/src/SFont.h
===================================================================
--- branches/sdl2/src/SFont.h	(revision 2180)
+++ branches/sdl2/src/SFont.h	(working copy)
@@ -44,7 +44,11 @@
 #ifndef _SFONT_H_
 #define _SFONT_H_
 
+#if defined(PREFIX_SDL)
 #include <SDL2/SDL.h>
+#else
+#include <SDL.h>
+#endif
 
 #ifdef __cplusplus 
 extern "C" {
Index: branches/sdl2/src/buttons.c
===================================================================
--- branches/sdl2/src/buttons.c	(revision 2180)
+++ branches/sdl2/src/buttons.c	(working copy)
@@ -46,7 +46,12 @@
 #include <unistd.h>
 #include <ctype.h>
 #include <sys/stat.h>
+
+#if defined(PREFIX_SDL)
 #include <SDL2/SDL.h>
+#else
+#include <SDL.h>
+#endif
 
 #include "const.h"
 #include "struct.h"
Index: branches/sdl2/src/buttons_effects.c
===================================================================
--- branches/sdl2/src/buttons_effects.c	(revision 2180)
+++ branches/sdl2/src/buttons_effects.c	(working copy)
@@ -25,7 +25,12 @@
 /// Handles all the effects buttons and setup windows in the effects menu.
 ////////////////////////////////////////////////////////////////////////////
 
+#if defined(PREFIX_SDL)
+#include <SDL2/SDL.h>
+#else
 #include <SDL.h>
+#endif
+
 #include <stdlib.h>
 #include <string.h>
 
Index: branches/sdl2/src/filesel.c
===================================================================
--- branches/sdl2/src/filesel.c	(revision 2180)
+++ branches/sdl2/src/filesel.c	(working copy)
@@ -24,7 +24,14 @@
     along with Grafx2; if not, see <http://www.gnu.org/licenses/>
 */
 
-#include <SDL_syswm.h>
+// There is no WM on the GP2X...
+#if !defined(__GP2X__) && !defined(__WIZ__) && !defined(__CAANOO__)
+    #if defined(PREFIX_SDL)
+        #include <SDL2/SDL_syswm.h>
+    #else
+        #include <SDL_syswm.h>
+    #endif
+#endif
 
 #if defined(__amigaos4__) || defined(__AROS__) || defined(__MORPHOS__) || defined(__amigaos__)
     #include <proto/dos.h>
Index: branches/sdl2/src/global.h
===================================================================
--- branches/sdl2/src/global.h	(revision 2180)
+++ branches/sdl2/src/global.h	(working copy)
@@ -30,7 +30,12 @@
 #ifndef _GLOBAL_H_
 #define _GLOBAL_H_
 
+#if defined(PREFIX_SDL)
 #include <SDL2/SDL.h>
+#else
+#include <SDL.h>
+#endif
+
 #include "struct.h"
 
 // MAIN declares the variables,
Index: branches/sdl2/src/hotkeys.h
===================================================================
--- branches/sdl2/src/hotkeys.h	(revision 2180)
+++ branches/sdl2/src/hotkeys.h	(working copy)
@@ -31,7 +31,12 @@
 #else
     #define bool char
 #endif
+
+#if defined(PREFIX_SDL)
 #include <SDL2/SDL.h>
+#else
+#include <SDL.h>
+#endif
 
 #define NB_SHORTCUTS 209   ///< Number of actions that can have a key combination associated to it.
 
Index: branches/sdl2/src/init.c
===================================================================
--- branches/sdl2/src/init.c	(revision 2180)
+++ branches/sdl2/src/init.c	(working copy)
@@ -44,8 +44,15 @@
 
 #include <stdlib.h>
 #include <errno.h>
+
+#if defined(PREFIX_SDL)
 #include <SDL2/SDL.h>
+#include <SDL2_image/SDL_image.h>
+#else
+#include <SDL.h>
 #include <SDL_image.h>
+#endif
+
 #if defined(__WIN32__)
   #include <windows.h> // GetLogicalDrives(), GetDriveType(), DRIVE_*
 #endif
Index: branches/sdl2/src/input.c
===================================================================
--- branches/sdl2/src/input.c	(revision 2180)
+++ branches/sdl2/src/input.c	(working copy)
@@ -21,9 +21,22 @@
 */
 
 #include <stdlib.h>
+
+#if defined(PREFIX_SDL)
 #include <SDL2/SDL.h>
-#include <SDL_syswm.h>
+#else
+#include <SDL.h>
+#endif
 
+// There is no WM on the GP2X...
+#if !defined(__GP2X__) && !defined(__WIZ__) && !defined(__CAANOO__)
+    #if defined(PREFIX_SDL)
+        #include <SDL2/SDL_syswm.h>
+    #else
+        #include <SDL_syswm.h>
+    #endif
+#endif
+
 #include "global.h"
 #include "keyboard.h"
 #include "sdlscreen.h"
Index: branches/sdl2/src/io.c
===================================================================
--- branches/sdl2/src/io.c	(revision 2180)
+++ branches/sdl2/src/io.c	(working copy)
@@ -24,7 +24,11 @@
 // Fonctions de lecture/ecriture file, gèrent les systèmes big-endian et
 // little-endian.
 
+#if defined(PREFIX_SDL)
+#include <SDL2/SDL_endian.h>
+#else
 #include <SDL_endian.h>
+#endif
 #include <string.h>
 #include <sys/stat.h>
 #include <errno.h>
Index: branches/sdl2/src/loadsave.c
===================================================================
--- branches/sdl2/src/loadsave.c	(revision 2180)
+++ branches/sdl2/src/loadsave.c	(working copy)
@@ -31,8 +31,14 @@
 #include <string.h>
 #include <unistd.h>
 #include <limits.h>
+
+#if defined(PREFIX_SDL)
+#include <SDL2/SDL_endian.h>
+#include <SDL2_image/SDL_image.h>
+#else
+#include <SDL_endian.h>
 #include <SDL_image.h>
-#include <SDL_endian.h>
+#endif
 
 #include "buttons.h"
 #include "const.h"
Index: branches/sdl2/src/loadsave.h
===================================================================
--- branches/sdl2/src/loadsave.h	(revision 2180)
+++ branches/sdl2/src/loadsave.h	(working copy)
@@ -28,7 +28,12 @@
 #define __LOADSAVE_H__
 
 #include <stdio.h>
+
+#if defined(PREFIX_SDL)
+#include <SDL2_image/SDL_image.h>
+#else
 #include <SDL_image.h>
+#endif
 
 enum CONTEXT_TYPE {
   CONTEXT_MAIN_IMAGE,
Index: branches/sdl2/src/main.c
===================================================================
--- branches/sdl2/src/main.c	(revision 2180)
+++ branches/sdl2/src/main.c	(working copy)
@@ -36,13 +36,21 @@
 #include <string.h>
 #include <signal.h>
 #include <unistd.h>
+#if defined(PREFIX_SDL)
 #include <SDL2/SDL.h>
+#include <SDL2_image/SDL_image.h>
+#else
+#include <SDL.h>
 #include <SDL_image.h>
+#endif
 
-
 // There is no WM on the GP2X...
 #if !defined(__GP2X__) && !defined(__WIZ__) && !defined(__CAANOO__)
-    #include <SDL_syswm.h>
+    #if defined(PREFIX_SDL)
+        #include <SDL2/SDL_syswm.h>
+    #else
+        #include <SDL_syswm.h>
+    #endif
 #endif
 
 #include "const.h"
Index: branches/sdl2/src/misc.c
===================================================================
--- branches/sdl2/src/misc.c	(revision 2180)
+++ branches/sdl2/src/misc.c	(working copy)
@@ -21,7 +21,12 @@
     You should have received a copy of the GNU General Public License
     along with Grafx2; if not, see <http://www.gnu.org/licenses/>
 */
+#if defined(PREFIX_SDL)
 #include <SDL2/SDL.h>
+#else
+#include <SDL.h>
+#endif
+
 #include <string.h>
 #include <strings.h>
 #include <stdlib.h>
Index: branches/sdl2/src/oldies.c
===================================================================
--- branches/sdl2/src/oldies.c	(revision 2180)
+++ branches/sdl2/src/oldies.c	(working copy)
@@ -20,7 +20,12 @@
     You should have received a copy of the GNU General Public License
     along with Grafx2; if not, see <http://www.gnu.org/licenses/>
 */
+#if defined(PREFIX_SDL)
+#include <SDL2/SDL.h>
+#else
 #include <SDL.h>
+#endif
+
 #include <string.h>
 #include <strings.h>
 #include <stdlib.h>
Index: branches/sdl2/src/pxsimple.c
===================================================================
--- branches/sdl2/src/pxsimple.c	(revision 2180)
+++ branches/sdl2/src/pxsimple.c	(working copy)
@@ -23,7 +23,13 @@
 
 #include <string.h>
 #include <stdlib.h>
+
+#if defined(PREFIX_SDL)
+#include <SDL2/SDL.h>
+#else
 #include <SDL.h>
+#endif
+
 #include "global.h"
 #include "sdlscreen.h"
 #include "misc.h"
Index: branches/sdl2/src/readini.c
===================================================================
--- branches/sdl2/src/readini.c	(revision 2180)
+++ branches/sdl2/src/readini.c	(working copy)
@@ -841,13 +841,13 @@
     conf->Skin_file = strdup(value_label);
   }
   else
-    conf->Skin_file = strdup("skin_DPaint.png");
+    conf->Skin_file = strdup("skin_modern.png");
 
   // Optional, name of font file. (>2.0)
   if(!Load_INI_get_string(file,buffer,"Font_file",value_label,1))
     conf->Font_file = strdup(value_label);
   else
-    conf->Font_file = strdup("font_Dpaint.png");
+    conf->Font_file = strdup("font_Classic.png");
 
   // Optional, "fake hardware zoom" factor (>2.1)
   if (!Load_INI_get_values (file, buffer,"Pixel_ratio",1,values))
Index: branches/sdl2/src/realpath.c
===================================================================
--- branches/sdl2/src/realpath.c	(revision 2180)
+++ branches/sdl2/src/realpath.c	(working copy)
@@ -6,7 +6,7 @@
 #include <fcntl.h>
 #include <string.h>
 #include <unistd.h>
-#if defined(__AROS__) || defined(__linux__) || defined(__GLIBC__)|| defined(__MINT__) || defined(__FreeBSD__)
+#if defined(__AROS__) || defined(__linux__) || defined(__GLIBC__)|| defined(__MINT__) || defined(__FreeBSD__) || defined(__macosx__)
 #include <limits.h>
 #endif
 
Index: branches/sdl2/src/sdlscreen.c
===================================================================
--- branches/sdl2/src/sdlscreen.c	(revision 2180)
+++ branches/sdl2/src/sdlscreen.c	(working copy)
@@ -25,10 +25,26 @@
 #include <string.h>
 #include <stdlib.h>
 #include <stdio.h>
+
+#if defined(PREFIX_SDL)
 #include <SDL2/SDL.h>
+#include <SDL2/SDL_endian.h>
+#include <SDL2_image/SDL_image.h>
+#else
+#include <SDL.h>
+#include <SDL_endian.h>
 #include <SDL_image.h>
-#include <SDL_endian.h>
-#include <SDL2/SDL_syswm.h>
+#endif
+
+// There is no WM on the GP2X...
+#if !defined(__GP2X__) && !defined(__WIZ__) && !defined(__CAANOO__)
+    #if defined(PREFIX_SDL)
+        #include <SDL2/SDL_syswm.h>
+    #else
+        #include <SDL_syswm.h>
+    #endif
+#endif
+
 #if defined(__WIN32__)
     #include <windows.h>
 #endif
Index: branches/sdl2/src/sdlscreen.h
===================================================================
--- branches/sdl2/src/sdlscreen.h	(revision 2180)
+++ branches/sdl2/src/sdlscreen.h	(working copy)
@@ -28,7 +28,12 @@
 #ifndef SDLSCREEN_H_INCLUDED
 #define SDLSCREEN_H_INCLUDED
 
+#if defined(PREFIX_SDL)
 #include <SDL2/SDL.h>
+#else
+#include <SDL.h>
+#endif
+
 #include "struct.h"
 
 ///
Index: branches/sdl2/src/setup.h
===================================================================
--- branches/sdl2/src/setup.h	(revision 2180)
+++ branches/sdl2/src/setup.h	(working copy)
@@ -139,7 +139,7 @@
 #if defined (__MINT__)
   #define DEFAULT_SKIN_FILENAME "SDPAINT.PNG"
 #else
-  #define DEFAULT_SKIN_FILENAME "skin_DPaint.png"
+  #define DEFAULT_SKIN_FILENAME "skin_modern.png"
 #endif
 
 /// Name of the image file for the default (and fallback) 8x8 font.
@@ -146,7 +146,7 @@
 #if defined (__MINT__)
   #define DEFAULT_FONT_FILENAME "FDPAINT.PNG"
 #else
-  #define DEFAULT_FONT_FILENAME "font_DPaint.png"
+  #define DEFAULT_FONT_FILENAME "font_Dpaint.png"
 #endif
 
 /// File extension for safety backups
Index: branches/sdl2/src/struct.h
===================================================================
--- branches/sdl2/src/struct.h	(revision 2180)
+++ branches/sdl2/src/struct.h	(working copy)
@@ -29,7 +29,11 @@
 #ifndef _STRUCT_H_
 #define _STRUCT_H_
 
+#if defined(PREFIX_SDL)
+#include <SDL2/SDL.h>
+#else
 #include <SDL.h>
+#endif
 
 #if defined(__BEOS__) || defined(__TRU64__)
     #include <inttypes.h>
Index: branches/sdl2/src/text.c
===================================================================
--- branches/sdl2/src/text.c	(revision 2180)
+++ branches/sdl2/src/text.c	(working copy)
@@ -32,10 +32,10 @@
 
 // TrueType
 #ifndef NOTTF
-#if defined(__macosx__)
-  #include <SDL_ttf/SDL_ttf.h>
+#if defined(PREFIX_SDL)
+#include <SDL2_ttf/SDL_ttf.h>
 #else
-  #include <SDL2/SDL_ttf.h>
+#include <SDL_ttf.h>
 #endif
 
 #if defined(__CAANOO__) || defined(__WIZ__) || defined(__GP2X__)
@@ -50,7 +50,12 @@
   #import <sys/param.h>
 #endif
 
+#if defined(PREFIX_SDL)
+#include <SDL2_image/SDL_image.h>
+#else
 #include <SDL_image.h>
+#endif
+
 #include "SFont.h"
 
 #include "struct.h"
@@ -316,7 +321,7 @@
       number = 3;
       // Make sure we also search into the user's fonts directory
       CFURLRef url = (CFURLRef) CFCopyHomeDirectoryURLForUser(NULL);
-      CFURLGetFileSystemRepresentation(url, true, (UInt8 *) home_dir, MAXPATHLEN);
+      CFURLGetFileSystemRepresentation(url, true, (UInt8 *)&home_dir, MAXPATHLEN);
       strcat(home_dir, "/Library/Fonts");
       font_path_list[2] = home_dir;
 
Index: branches/sdl2/src/windows.h
===================================================================
--- branches/sdl2/src/windows.h	(revision 2180)
+++ branches/sdl2/src/windows.h	(working copy)
@@ -28,7 +28,12 @@
 #define __WINDOWS_H_
 
 #include "struct.h"
+
+#if defined(PREFIX_SDL)
+#include <SDL2/SDL.h>
+#else
 #include <SDL.h>
+#endif
 
 
 #ifdef MULTI_WINDOW
