# -*- makefile -*-
# $Id$
# Include file for GNU C++ build

ifndef PLATFORM

ifeq ($(TERM),cygwin)
MINGW=true
PLATFORM=cyg
else
ifeq ($(OSTYPE),msys)
MINGW=true
PLATFORM=cyg
endif
endif

ifeq ($(findstring EMX, $(PATH)), EMX)
PLATFORM=emx
endif

ifneq ($(DJGPP),)     # DJGPP build (enviroment variable 'DJGPP' is defined)
PLATFORM=djg
endif

ifeq ($(OSTYPE),beos) # BeOS build
PLATFORM=be
endif

ifeq ($(findstring solaris, $(OSTYPE)), solaris)
PLATFORM=sun
endif

ifeq ($(findstring darwin, $(OSTYPE)), darwin)
PLATFORM=osx
endif

endif  # ifndef PLATFORM

ifeq ($(PLATFORM),cyg)
CAT=cat
SED=sed
GREP=grep
CC=gcc -mno-cygwin
CXX=g++ -mno-cygwin
AR=ar
RANLIB=ranlib
WINDRES=windres
EXEEXT=.exe
OBJEXT=.o
LIBEXT=.a
CFLAGS+=-DHAVE_SNPRINTF -DHAVE_VSNPRINTF -DHAVE_STDARG_H
else
ifeq ($(PLATFORM),emx)
CAT=cat
SED=sed
GREP=grep
CC=gcc
AR=ar
RANLIB=ar s
SHELL=bash
EXEEXT=.exe
OBJEXT=.o
LIBEXT=.a
#CC=gcc -Zomf
#AR=emxomfar
#RANLIB=emxomfar s
#PLATFORM=emx
#SHELL=bash
#EXEEXT=.exe
#OBJEXT=.obj
#LIBEXT=.lib
CXX=$(CC)
CFLAGS+=-DHAVE_SNPRINTF -DHAVE_VSNPRINTF -DHAVE_STDARG_H
else
ifeq ($(PLATFORM),djg)
CAT=command.com /c type
SED=sed
GREP=grep
CC=gcc
CXX=gxx
AR=ar
RANLIB=ranlib
SHELL=sh
EXEEXT=.exe
OBJEXT=.o
LIBEXT=.a
else
ifeq ($(PLATFORM),be)
CAT=cat
SED=sed
GREP=grep
CC=gcc
CXX=g++
AR=ar
RANLIB=ranlib
EXEEXT=
OBJEXT=.o
LIBEXT=.a
LNKFLAGS+=-lbe -ltextencoding
CFLAGS+=-DHAVE_SNPRINTF -DHAVE_VSNPRINTF -DHAVE_STDARG_H
else
ifeq ($(PLATFORM),sun) # SUN Solaris
CAT=cat
SED=gsed
GREP=ggrep
CC=gcc
CXX=g++
AR=ar
RANLIB=ranlib
EXEEXT=
OBJEXT=.o
LIBEXT=.a
CFLAGS+=-D__SUNOS__ -D__UNIX__ -DUNIX
CFLAGS+=-DHAVE_SNPRINTF -DHAVE_VSNPRINTF -DHAVE_STDARG_H
ifeq ($(WIDE_NCURSES),1)
LIBCURSES=-L/opt/csw/lib -lncursesw
else
LIBCURSES=-L/opt/csw/lib -lncurses
endif
else
ifeq ($(PLATFORM),osx) # Mac OSX
CAT=cat
SED=sed
GREP=grep
CC=gcc
CXX=g++
AR=ar
RANLIB=ranlib
PLATFORM=osx
EXEEXT=
OBJEXT=.o
LIBEXT=.a
ifeq ($(WIDE_NCURSES),1)
LIBCURSES=-lncursesw
else
LIBCURSES=-lncurses
endif
CFLAGS+=-DHAVE_SNPRINTF -DHAVE_VSNPRINTF -DHAVE_STDARG_H
else                   # Linux, *BSD or another unix-like OS
CAT=cat
SED=sed
GREP=grep
CC=gcc
CXX=g++
AR=ar
RANLIB=ranlib
PLATFORM=lnx
EXEEXT=
OBJEXT=.o
LIBEXT=.a
ifeq ($(WIDE_NCURSES),1)
CFLAGS+=-I/usr/include/ncursesw/
LIBCURSES=-lncursesw
else
LIBCURSES=-lncurses
endif
endif
endif
endif
endif
endif
endif
CFLAGS+=-funsigned-char -g $(INCS) -Wall -Wno-sign-compare -pedantic -O2 -DPRAGMA_PACK # -fomit-frame-pointer
LNKFLAGS+=-g
CPPFLAGS+=$(CFLAGS) -fno-rtti # -fno-exceptions

# Run `make USE_NCURSES=0` if you dislike ncurses
# Run `make BUGGY_NCURSES=1` if your build requires additional keypresses to
# pass areascan
# NOTE: lnx is active for any *NIX system and only ncurses mode is portable
USE_NCURSES?=1
BUGGY_NCURSES?=0

ifeq ($(PLATFORM),lnx)
ifeq ($(USE_NCURSES),1)
CPPFLAGS+=-D__USE_NCURSES__
ifeq ($(BUGGY_NCURSES),1)
CPPFLAGS+=-DBUGGY_NCURSES
endif
endif
endif

ifeq ($(PLATFORM),sun)
ifeq ($(USE_NCURSES),1)
CPPFLAGS+=-D__USE_NCURSES__
endif
endif

ifeq ($(PLATFORM),osx)
ifeq ($(USE_NCURSES),1)
CPPFLAGS+=-D__USE_NCURSES__
endif
endif

# uncomment the next line for better koi-8 support. do not do it for
# international builds since latin-1 support will be broken.
ifeq ($(PLATFORM),lnx)
ifeq ($(KOI8),1)
CPPFLAGS+=-DKOI8
endif
endif
ifeq "$(ICONV)" "1"
CFLAGS+=-DHAS_ICONV
endif

#uncomment the following line if you build version to be used
#on BONE-powered systems(Dan0 etc.) This improves some operations ...
ifeq ($(PLATFORM),be)
CPPFLAGS+=#-DBEOS_BONE_BUILD
endif

# force not to use coprocessor features in DOS, if you have one you may remove this
ifeq ($(PLATFORM),djg)
#CFLAGS+=-mcpu=i386  # GCC v2.x.x
CFLAGS+=-march=i386 #-mtune=i686 # GCC v3.x.x
STDLIBS+=-llocal
endif

# force not to use coprocessor features in DOS, if you have one you may remove this
ifeq ($(PLATFORM),djg)
#STDLIBS+= -lwmemu
endif

BIN=bin
OBJPATH=obj
LIBPATH=lib
