+ifeq ($(PLATFORM),cross-win32) # cross-compiling to Windows
+PROGNAME = ../$(PROGBASE).exe
+EXTRA_LDFLAGS = -lshfolder -lwsock32
+endif
+
+
+# -----------------------------------------------------------------------------
+# configuring target
+# -----------------------------------------------------------------------------
+
+ifndef TARGET # auto-detect compiling for SDL or SDL2
+ SDL_VERSION := $(shell sdl2-config --version 2> /dev/null)
+ ifdef SDL_VERSION
+ TARGET = sdl2
+ else
+ SDL_VERSION := $(shell sdl-config --version 2> /dev/null)
+ ifdef SDL_VERSION
+ TARGET = sdl
+ else
+ $(error SDL/SDL2 library not found)
+ endif
+ endif
+endif
+
+ifeq ($(STATIC),true) # check for static linking
+override TARGET := $(TARGET)-static
+endif
+
+# $(info Using SDL version $(SDL_VERSION) [TARGET == $(TARGET)])
+
+ifeq ($(TARGET),sdl) # compiling for SDL target
+SYS_CFLAGS = -DTARGET_SDL $(shell sdl-config --cflags)
+SDL_LIBS = -lSDL_image -lSDL_mixer -lSDL_net -lsmpeg
+SYS_LDFLAGS = $(SDL_LIBS) $(shell sdl-config --libs)
+endif
+
+ifeq ($(TARGET),sdl2) # compiling for SDL2 target
+SYS_CFLAGS = -DTARGET_SDL2 $(shell sdl2-config --cflags)
+SDL_LIBS = -lSDL2_image -lSDL2_mixer -lSDL2_net -lsmpeg2
+SYS_LDFLAGS = $(SDL_LIBS) $(shell sdl2-config --libs)
+endif
+
+ifeq ($(TARGET),sdl-static) # compiling for SDL target (static)
+SYS_CFLAGS = -DTARGET_SDL $(shell sdl-config --cflags)
+SDL_LIBS = -lSDL_image -lSDL_mixer -lSDL_net -lsmpeg -lmikmod
+SYS_LDFLAGS = $(SDL_LIBS) $(shell sdl-config --static-libs)
+endif
+
+ifeq ($(TARGET),sdl2-static) # compiling for SDL2 target (static)
+SYS_CFLAGS = -DTARGET_SDL2 $(shell sdl2-config --cflags)
+SDL_LIBS = -lSDL2_image -lSDL2_mixer -lSDL2_net -lsmpeg2 -lmikmod
+SYS_LDFLAGS = $(SDL_LIBS) $(shell sdl2-config --static-libs)
+endif
+
+
+# -----------------------------------------------------------------------------
+# configuring compile-time definitions
+# -----------------------------------------------------------------------------
+
+ifdef RO_GAME_DIR # path to read-only game data specified
+CONFIG_RO_GAME_DIR = -DRO_GAME_DIR="\"$(RO_GAME_DIR)\""
+endif
+
+ifdef RW_GAME_DIR # path to writable game data specified
+CONFIG_RW_GAME_DIR = -DRW_GAME_DIR="\"$(RW_GAME_DIR)\""
+endif
+
+ifdef SCORE_ENTRIES # number of score entries per player