#
# makeg95.env
# Common makefile settings for wxWindows programs
# This file is included by all the other makefiles, thus changes
# made here take effect everywhere (except where overriden).
# The settings are for GnuWin32-derived compilers, i.e. Cygwin and Mingw32.
#
# Customize this file to match your own settings.
#
# CVS_ID: $Id$
#

# If using Cygwin beta, set this to 0.
# If using Mingw32 or Cygwin 1.0 or later, set this to 1.
MINGW32=1

# Set to the version you have
MINGW32VERSION=2.95

# If building DLL, the version
WXVERSION=233

ifndef UNICODE
  UNICODE=0
endif

ifndef FINAL
  FINAL=0
endif

ifndef wxUSE_GUI
  wxUSE_GUI=1
endif

# Say yes if you have a "modern" linker that supports --shared option.
# Note that you're probably going to wait forever for dlltool/gcc/etc
# to build the DLL, so you should really use a newer linker that
# supports --shared.
LD_SUPPORTS_SHARED=yes

# Set to the appropriate remove command (must support forward slashes)
# You can get a suitable rm.exe from ports/mingw32/extra.zip on the ftp site.
RM=rm -f

# Set to the appropriate copy command (must support forward slashes)
# You can get a suitable cp.exe from ports/mingw32/extra.zip on the ftp site.
COPY=cp

# Cross compiling? Provide the target prefix (eg., i386-mingw32-)
# CROSS=i386-mingw32-

########################## Compiler ##################################

# C++ compiler
# Put a comment before --pipe for Cygwin, remove comment for Mingw32 2.95

# _GCC295 means GCC is GCC 2.95
# _GCC3 mans GCC is 3.x or better (can actually just be 3.1 or better
#                                  for Cygwin/MinGW)
_GCC295=$(if $(findstring 2.95, $(MINGW32VERSION)), 1,)
_GCC3=$(if $(findstring 3., $(MINGW32VERSION)), 1,)

ifeq ($(MINGW32),1)
  ifneq "$(_GCC295)$(_GCC3)" ""
    CC = $(CROSS)gcc --pipe $(if $(_GCC3), , -fvtable-thunks)
  else
    CC = $(CROSS)gcc
  endif
else
  CC = $(CROSS)gcc
endif

# C compiler for pure C programs
CCC = $(CC)

# Compiler used for LEX generated C
CCLEX=$(CROSS)gcc

# This shouldn't be needed as make is supposed to define this
# variable itself. Uncomment it if your make complains.
#MAKE=make

# LEX (currently unused)
LEX=flex # -t -L

# YACC (currently unused)
YACC=byacc
#YACC=bison

# Settings for Cyginw/Mingw32
# Some versions of windres cannot cope with the --preprocessor
# option. Uncomment the RCPREPROCESSOR line below if yours can.
RESCOMP=$(CROSS)windres
RCINPUTSWITCH=-i
RCOUTPUTSWITCH=-o
RCINCSWITCH=--include-dir
RCDEFSWITCH=--define
# Note that this can cause windres to fail (Win95/98 problem?)
# but commenting out RCPREPROCESSOR then does the trick.
#RCPREPROCESSOR=--preprocessor "$(CC) -c -E -xc-header -DRC_INVOKED"

# Don't make this too long (e.g. by adding contrib/include/wx) because it will
# truncate the command line
# Note: --use-temp-file removed since Mingw32 2.95.2 doesn't recognise it
RESFLAGS=$(RCPREPROCESSOR) $(RCINCSWITCH) $(WXDIR)/include $(RCEXTRAINC) $(RCDEFSWITCH) __WIN32__ $(RCDEFSWITCH) __WIN95__ $(RCDEFSWITCH) __GNUWIN32__

# Needed to build a DLL if your linker does not support --shared option.
AS = $(CROSS)as
DLLTOOL = $(CROSS)dlltool

########################## Compiler flags #############################

# Miscellaneous compiler options
# GRG: the __MINGW32__ option is not needed anymore
# add "-DHAVE_W32API_H" if you have w32api >= 0.5
OPTIONS = -DSTRICT # -D__MINGW32__

# Debugging information
ifeq ($(FINAL),0)
  DEBUGFLAGS = -g -D__WXDEBUG__
endif

WIN95=1

ifeq ($(WIN95),0)
# With 3.50, Win95 will use your existing icons to show smaller ones.
# With 4.0, you'll have to follow Win95 procedures for icons or you'll get the
# default Windows icon.
APPVER=3.50
WINVERSION=-DWINVER=0x0350 -D__GNUWIN32__ -D__WIN32__ # Generic WIN32
else
APPVER=4.0 # 3.50
# This means 'enable Windows 95 features' (in wxWindows and in VC++ 4.0).
WINVERSION=-DWINVER=0x0400 -D__WIN95__ -D__GNUWIN32__ -D__WIN32__
endif

CPU=i386

# Suffixes
OBJSUFF=o
SRCSUFF=cpp
LIBPREFIX=lib
LIBSUFF=a
EXESUFF=.exe
RESSUFF=res
RSCSUFF=rsc

# Warnings
WARN = -Wall

# build wxbase/wxMSW
ifeq ($(wxUSE_GUI),1)
    TOOLKIT=msw
    GUI = -D__WXMSW__ -D__WINDOWS__
else
    TOOLKIT=base
    GUI = -D__WXMSW__ -D__WINDOWS__ -DwxUSE_GUI=0
endif


# According to Guillermo Rodriguez Garcia <guille@iies.es>, the
# -fno-pcc-struct-return option is needed to make the standard div()
# function work - otherwise it returns absolutely incorrect results
# which breaks the wxImage class. This is true at least for
# mingw32-gcc2.8.1, don't know about others.
ifeq ($(FINAL),1)
  OPT = -fno-pcc-struct-return -O2 -fno-rtti -fno-exceptions
else
  OPT = -fno-pcc-struct-return -fno-rtti -fno-exceptions
endif

# Options for ar archiver
# AROPTIONS = crs # For IRIX and Solaris (both SYSVR4).
AR = $(CROSS)ar
AROPTIONS = ruv
RANLIB = $(CROSS)ranlib

# Extra compiler libraries
COMPLIBS=

# Compiler or system-specific include paths
COMPPATHS=

########################## Directories ###############################

OLELIBS=-lole32 -loleaut32 -luuid
BASELIBS=-lstdc++ -lgcc -lodbc32 -lwsock32
ifeq ($(wxUSE_GUI),1)
  WINLIBS= $(BASELIBS) \
	  -lwinspool -lwinmm -lshell32 \
	  -lcomctl32 -lctl3d32 -lodbc32 -ladvapi32 \
	  -lodbc32 -lwsock32 -lopengl32 -lglu32 $(OLELIBS) #  -loldnames
else
  WINLIBS=$(BASELIBS)
endif

#WINLIBS=-lstdc++ -lgcc \
#	-lwinspool -lwinmm -lshell32 \
#    -lcomctl32 -lctl3d32 -lodbc32 -ladvapi32 -lwsock32 # -loldnames

# Shouldn't need to change these...
WXSRC=$(WXDIR)/src/msw
WXINC=$(WXDIR)/include
WXBASESRC=$(WXDIR)/src/common

GNUWIN32EXTRA=-I$(WXDIR)/include/wx/msw/gnuwin32

ifeq ($(MINGW32),1)
  ifneq "$(findstring 2.95, $(MINGW32VERSION))" ""
    GNUWIN32EXTRA=
  endif
endif

#ifeq ($(MINGW32),1)
#INC = -I$(WXINC) -I$(WXDIR)/contrib/include -I$(WXDIR)/src/png -I$(WXDIR)/src/jpeg -I$(WXDIR)/src/zlib -I$(WXDIR)/src/tiff $(EXTRAINC) $(COMPPATHS)
#else
INC = -I$(WXDIR)/lib/$(TOOLKIT)$(INCEXT) -I$(WXINC) -I$(WXDIR)/contrib/include -I$(WXDIR)/src/regex -I$(WXDIR)/src/png -I$(WXDIR)/src/jpeg -I$(WXDIR)/src/zlib -I$(WXDIR)/src/tiff $(EXTRAINC) $(COMPPATHS) -I$(WXDIR)/include/wx/msw/gnuwin32
#endif

RCLFLAGS=-cpp "cpp -lang-c++ -DWIN32 -D_WIN32 -DRCL_INVOKED -I$(WXWIN)/include"

ifdef WXUSINGDLL
  # png, jpeg, etc are exported from wx dll, so skip and save on link time.
  LIBS = $(EXTRALIBS) $(WXLIB) $(WINLIBS) $(COMPLIBS)
else
  LIBS = $(EXTRALIBS) $(WXLIB) -lregex -lpng -ljpeg -lzlib -ltiff $(WINLIBS) $(COMPLIBS)
endif

WINFLAGS=-D_X86_=1 -DWIN32 -D_WIN32 $(WINVERSION)

#for windows 95
XINCLUDE=$(WINFLAGS)
XLIB=$(LIBS)
LDLIBS = $(LIBS)

# Directory for object files (don't change)
# OBJDIR = objects$(GUISUFFIX)
OBJDIR = .

ifeq ($(FINAL),1)
    DEBEXT=
else
    DEBEXT=d
endif

ifeq ($(UNICODE),1)
    UNIEXT=u
else
    UNIEXT=
endif

ifeq ($(WXMAKINGDLL)$(WXUSINGDLL),)
    INCEXT=$(UNIEXT)$(DEBEXT)
else
    INCEXT=dll$(UNIEXT)$(DEBEXT)
endif

WXLIB=$(WXDIR)/lib/$(LIBPREFIX)wx$(TOOLKIT)$(UNIEXT)$(DEBEXT).$(LIBSUFF)

ifdef WXMAKINGDLL
  EXTRADLLFLAGS = -DWXMAKINGDLL=1 -D_DLL=1 -D_WINDLL=1
  WXLIB=$(WXDIR)/lib/$(LIBPREFIX)wx$(TOOLKIT)$(WXVERSION)$(UNIEXT)$(DEBEXT).$(LIBSUFF)
endif

ifdef WXUSINGDLL
  EXTRADLLFLAGS = -DWXUSINGDLL=1
  WXLIB=$(WXDIR)/lib/$(LIBPREFIX)wx$(TOOLKIT)$(WXVERSION)$(UNIEXT)$(DEBEXT).$(LIBSUFF)
endif


# You shouldn't need to change these...
CPPFLAGS = $(XINCLUDE) $(INC) $(OPTIONS) $(GUI) $(DEBUGFLAGS) $(WARN) $(OPT) $(EXTRACPPFLAGS) $(EXTRADLLFLAGS)
CFLAGS = $(XINCLUDE) $(INC) $(OPTIONS) $(GUI) $(DEBUGFLAGS) $(WARN) $(OPT) $(EXTRACFLAGS) -DWIN32_LEAN_AND_MEAN
ifeq ($(wxUSE_GUI),1)
    WINDOWSLDFLAGS=-Wl,--subsystem,windows -mwindows
endif
LDFLAGS = $(WINDOWSLDFLAGS) -L$(WXDIR)/lib -L$(WXDIR)/contrib/lib $(EXTRALDFLAGS)

.SUFFIXES: .rc .$(RESSUFF) .$(RSCSUFF) .cpp .cxx .c

.c.o:
	$(CC) -c $(CFLAGS) -o $@ $*.c

.cxx.o:
	$(CC) -c $(CPPFLAGS) -o $@ $*.cxx

.$(SRCSUFF).$(OBJSUFF):
	$(CC) -c $(CPPFLAGS) -o $@ $*.$(SRCSUFF)