#ifeq ($(os),sunos)
# CIOLIB-MT_LIBS		+=	$(UL_PRE)curses$(UL_SUF)
#else
# CIOLIB-MT_LIBS		+=	$(UL_PRE)ncurses$(UL_SUF)
#endif

# OSs with vasprintf...
ifeq ($(os),darwin)
 CFLAGS += -DHAVE_VASPRINTF
endif
ifeq ($(os),linux)
 CFLAGS += -DHAVE_VASPRINTF
endif
ifeq ($(os),freebsd)
 CFLAGS += -DHAVE_VASPRINTF
endif
ifeq ($(os),netbsd)
 CFLAGS += -DHAVE_VASPRINTF
endif
ifeq ($(os),openbsd)
 CFLAGS += -DHAVE_VASPRINTF
endif

ifdef USE_SYSTEM_CURSES
 CIOLIB-MT_LIBS		+=	$(UL_PRE)curses$(UL_SUF)
else
 CIOLIB-MT_LIBS		+=	$(UL_PRE)ncurses$(UL_SUF)
endif
ifndef NO_X
 ifdef STATIC
  CIOLIB-MT_LIBS		+=	-L$(X_PATH)$(DIRSEP)lib -lX11
 else
  ifeq ($(os),darwin)
   ifeq ($(shell uname -r),6.8)
    CIOLIB-MT_LIBS		+=  $(UL_PRE)dl$(UL_SUF)
   endif
  endif
  ifeq ($(os),linux)
   CIOLIB-MT_LIBS		+=  $(UL_PRE)dl$(UL_SUF)
  endif
  ifeq ($(os),sunos)
   CIOLIB-MT_LIBS		+=  $(UL_PRE)dl$(UL_SUF)
  endif
 endif
else
  ifeq ($(os),darwin)
   CIOLIB-MT_CFLAGS		+=  -DDISABLE_X11=1
  endif
endif

# Find SDL headers!
ifdef USE_SDL
 ifndef WITH_SDL_AUDIO
  ifdef SDL_CONFIG
   ifeq ($(shell ${SDL_CONFIG} --cflags > /dev/null 2>&1 && echo YES),YES)
	WITH_SDL	:=	1
   endif
  else
   ifeq ($(os),darwin)
	ifeq ($(shell if [ -d /Library/Frameworks/SDL.framework ] ; then echo YES ; fi),YES)
     SDL_FRAMEWORK_PATH ?= /Library/Frameworks
	endif
    ifdef SDL_FRAMEWORK_PATH
     WITH_SDL	:=	1
    endif
   else
	ifeq ($(shell sdl-config --cflags > /dev/null 2>&1 && echo YES),YES)
     SDL_CONFIG := sdl-config
     WITH_SDL	:=	1
	else
     ifeq ($(shell sdl13-config --cflags > /dev/null 2>&1 && echo YES),YES)
      SDL_CONFIG := sdl13-config
      WITH_SDL	:=	1
     else
      ifeq ($(shell sdl12-config --cflags > /dev/null 2>&1 && echo YES),YES)
       SDL_CONFIG := sdl12-config
       WITH_SDL	:=	1
      else
       ifeq ($(shell sdl11-config --cflags > /dev/null 2>&1 && echo YES),YES)
    	SDL_CONFIG := sdl11-config
    	WITH_SDL	:=	1
       endif
      endif
     endif
	endif
   endif
  endif
 endif
endif

ifdef WITH_SDL
 ifndef WITH_SDL_AUDIO
  # Prefer local include over system includes.
  #CFLAGS += -I$(SRC_ROOT)/../include/sdl
  ifdef SDL_CONFIG
   ifeq ($(shell ${SDL_CONFIG} --cflags > /dev/null 2>&1 && echo YES),YES)
	CIOLIB-MT_CFLAGS	+=	-DWITH_SDL
	CIOLIB-MT_CFLAGS	+=	$(shell $(SDL_CONFIG) --cflags)
	CIOLIB_CFLAGS	+=	-DWITH_SDL
	CIOLIB_CFLAGS	+=	$(shell $(SDL_CONFIG) --cflags)
	ifdef STATIC_SDL
     CIOLIB-MT_LIBS	+=	$(shell $(SDL_CONFIG) --static-libs)
     CIOLIB-MT_CFLAGS	+=	-DSTATIC_SDL
     CIOLIB-LIBS	+=	$(shell $(SDL_CONFIG) --static-libs)
     CIOLIB-CFLAGS	+=	-DSTATIC_SDL
	else
     ifeq ($(os),darwin)
      ifeq ($(shell uname -r),6.8)
       CIOLIB-MT_LIBS		+=  $(UL_PRE)dl$(UL_SUF)
       CIOLIB_LIBS		+=  $(UL_PRE)dl$(UL_SUF)
      endif
     endif
     ifeq ($(os),linux)
      CIOLIB-MT_LIBS		+=  $(UL_PRE)dl$(UL_SUF)
      CIOLIB_LIBS		+=  $(UL_PRE)dl$(UL_SUF)
     endif
     ifeq ($(os),sunos)
      CIOLIB-MT_LIBS		+=  $(UL_PRE)dl$(UL_SUF)
      CIOLIB_LIBS		+=  $(UL_PRE)dl$(UL_SUF)
     endif
	endif
   endif
  else
   ifeq ($(os),darwin)
	CIOLIB-MT_CFLAGS	+=	-DWITH_SDL -DSTATIC_SDL
	WITH_SDL	:=	1
	STATIC_SDL	:=	1
	CIOLIB-MT_CFLAGS	+=	-I${SDL_FRAMEWORK_PATH}/SDL.framework/Headers
	CIOLIB-MT_LIBS	+=	-F${SDL_FRAMEWORK_PATH} -framework SDL -framework Cocoa -framework Carbon -I${SDL_FRAMEWORK_PATH}/SDL.framework/Headers
	CIOLIB_CFLAGS	+=	-DWITH_SDL -DSTATIC_SDL
	CIOLIB_CFLAGS	+=	-I${SDL_FRAMEWORK_PATH}/SDL.framework/Headers
	CIOLIB_LIBS	+=	-F${SDL_FRAMEWORK_PATH} -framework SDL -framework Cocoa -framework Carbon -I${SDL_FRAMEWORK_PATH}/SDL.framework/Headers
   endif
  endif
 endif
endif

ifdef NO_X
 ifndef WITH_SDL
  ifndef WITH_SDL_AUDIO
   CIOLIB-MT_CFLAGS		+=	-DNO_FONTS
   CIOLIB_CFLAGS			+=	-DNO_FONTS
  endif
 endif
endif
