#
# 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: makeg95.env 20425 2003-05-01 22:36:46Z VZ $
#

# The MINGW32 and MINGW32VERSION variables are preconfigured for
# MinGW gcc version 3.x and must both be changed for any version
# earlier than 3.0 or for cygwin. Editing this file is one way to
# change them. An easier way, at least with GNU make, is to override
# them on the command line, e.g.
#   make MINGW32=0 MINGW32VERSION=2.8 -f makefile.g95

# If using Mingw32 (any version), set this to 1.
# If using Cygwin (any version), set this to 0.
#
# This agrees with the instructions given in docs/msw/install.txt .
# Earlier versions of this makefile suggested setting MINGW32=1 for
# recent versions of cygwin, but that would give the wrong dll entry
# point in src/msw/makefile.g95 .
#
# With cygwin, there are still some problems compiling wxWindows
# this way; './configure && make' may work better.
#
MINGW32=1

# set MIN_SUFFIX to nothing if you use only MinGW compiler, set it to
# something MinGW-specific if you want to build wxWindows with more than one
# compiler
ifeq ($(MINGW32),1)
  MIN_SUFFIX=_min
else
  MIN_SUFFIX=_cyg
endif

# Set to your gcc version. Generally 'gcc --version' tells you
# which version you have. But it cannot distinguish between
# 2.95.2-1 and earlier suffix versions of 2.95 . In that case,
# inspect the dates of bin/gcc.exe and bin/ld.exe ; if they
# are at least
#   2000-01-21 for gcc.exe and
#   2000-02-04 for ld.exe
# then use '2.95-late'.
#
# gcc 2.8.x and earlier require struct-return workaround
#MINGW32VERSION=2.8
#
# gcc 2.95.2 and earlier requires special thunk option
#MINGW32VERSION=2.9-early
#
# mingw gcc-2.95.2-1 supports '-shared'
# windres provided with gcc-2.95.2-1 supports temp file option
#MINGW32VERSION=2.95-late
#
# gcc 3.x provides a win32api.h header
MINGW32VERSION=3.0

# If you want to compile on Wine, simply uncomment this variable
# If you don't want to edit the file, you can simply define it
# on the command line like so: make WINE=1 -f makefile.g95
#WINE=1

# Set this if you are using a cross-compiler, i.e. compiling on one system
# the program for another one
# CROSS=i386-mingw32-

# If we're using MSYS, or other utilities that use forward slashes,
# you need to set this when invoking the makefile from DOS, or the
# wrong separators will be assumed. However, if you're using MSYS,
# you really ought to invoke the makefile from MSYS--or, even better,
# use the './configure && make' technique that MSYS is designed for.
ifndef WINE
#OSTYPE=msys
else
OSTYPE=msys
endif

# If building DLL, the version
include $(WXDIR)/src/version.mak
WXVERSION=$(wxMAJOR_VERSION)$(wxMINOR_VERSION)$(wxRELEASE_NUMBER_IFUNSTABLE)

ifndef UNICODE
  UNICODE=0
endif

ifndef FINAL
  FINAL=0
endif

ifndef wxUSE_GUI
  wxUSE_GUI=1
endif

# 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

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

ifneq (,$(findstring $(MINGW32VERSION),2.8))
# 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 was fixed on 1998-08-14 for
# mingw and cygwin. It is preferable not to use this option where it
# is not required, because it is documented to cause binary API
# incompatibility.
  _STRUCT_RETURN_WORKAROUND=-fno-pcc-struct-return
# Really old versions of cygwin are thought to require extra headers.
  ifneq ($(MINGW32),1)
    GNUWIN32EXTRA=-I$(WXDIR)/include/wx/msw/gnuwin32
  endif
endif

ifneq (,$(findstring $(MINGW32VERSION),2.8 2.9-early))
# Earlier versions of this makefile defined the following macros
# explicitly; mingw versions since at least '2.95-late' define
# them already.
  OBSOLETE_DEFINES = -D_X86_=1 -DWIN32 -D_WIN32 -D__WIN32__
endif
# But cygwin doesn't define them, at least through its version
# 2.95.3-4 of gcc.
ifneq ($(MINGW32),1)
  OBSOLETE_DEFINES = -D_X86_=1 -DWIN32 -D_WIN32 -D__WIN32__
endif

ifneq (,$(findstring $(MINGW32VERSION),2.8 2.9-early 2.95-late))
# Versions prior to 3.0 require -fvtable-thunks for OLE support.
# All code must be built with this option, even C++ libraries you
# only link to, including system libraries. This option can cause
# subtle problems with multiple inheritance.
  _THUNK_WORKAROUND=-fvtable-thunks
endif

ifeq (,$(findstring $(MINGW32VERSION),2.8 2.9-early))
# Versions since 2.95.2-1 support '-shared', which makes linking
# a dll *much* faster; and the accompanying windres supports
# '--use-temp-file', which is more robust.
  LD_SUPPORTS_SHARED=yes
  _USE_TEMP_FILE_IF_SUPPORTED=--use-temp-file
# Use the WIN32 wxDirDialog only if we have a recent mingw version
  RECENT_MINGW=yes
endif

ifeq (,$(findstring $(MINGW32VERSION),2.8 2.9-early 2.95-late))
# Versions since 3.0 provide win32api.h . An old comment said to
# define this 'if you have w32api >= 0.5', but mingw 2.95.2-1
# has no such header.
ifndef WINE
  _USE_W32API_HEADER_IF_SUPPORTED = -DHAVE_W32API_H
endif
#
# Revision 1.70.2.6 of this file suggested '--pipe' for mingw but
# not for cygwin, and only for version 3.0 or later. Since then,
# the advice given here
#   http://mail.gnu.org/pipermail/autoconf/2000-July/005479.html
# is followed, and '--pipe' is not used unless you specify it on
# the make command line, e.g.
#   make CXXFLAGS=--pipe CFLAGS=--pipe -f makefile.g95
#
endif

# Define the C++ and C compiler respectively
ifndef WINE
CXX = $(CROSS)g++
CC = $(CROSS)gcc
else
CXX = wineg++
CC = winegcc
endif

# Compiler used for LEX generated C
# For now at least, it can be the same as the regular C compiler
CCLEX = $(CROSS)$(CC)

# 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.
ifndef WINE
RESCOMP=$(CROSS)windres $(_USE_TEMP_FILE_IF_SUPPORTED)
else
RESCOMP=wrc
endif
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 "$(CXX) -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
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 #############################

# Unicode defines
ifeq ($(UNICODE),1)
  UNICODE_OPT = -D_UNICODE -DUNICODE -DwxUSE_UNICODE=1
else
  UNICODE_OPT =
endif

# Miscellaneous compiler options
OPTIONS = -DSTRICT $(_USE_W32API_HEADER_IF_SUPPORTED)

# Add "-mthreads" if you want to have threads under mingw32
# Add "-mno-cygwin" if you want to link with msvcrt.dll in Cywin and Wine
#                   Otherwise, you link against the native runtime (cygwin.dll
#                   or libc). Having the flag in mingw32 does not hurt as you
#                   always link against msvcrt.dll By default it should be on,
#                   to minimize dependencies on Cygwin, and have more correct
#                   filename behaviour in Wine.
COMMON_FLAGS = -mno-cygwin  # -mthreads

# 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__ # Generic WIN32
else
APPVER=4.0 # 3.50
# This means 'enable Windows 95 features' (in wxWindows and in the compiler).
WINVERSION=-DWINVER=0x0400 -D__GNUWIN32__
endif

# This is never used and should be expunged.
# 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 =
else
    TOOLKIT=base
    GUI = -DwxUSE_GUI=0
endif

ifeq ($(FINAL),1)
  OPT = -O2 -fno-rtti -fno-exceptions
else
  OPT = -fno-rtti -fno-exceptions
endif

# Options for ar archiver
AROPTIONS = ruv
AR = $(CROSS)ar
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

#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) $(GNUWIN32EXTRA)
#endif

RCLFLAGS=-cpp "cpp -lang-c++ $(OBSOLETE_DEFINES) -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$(MIN_SUFFIX) -lpng$(MIN_SUFFIX) -ljpeg$(MIN_SUFFIX) -lzlib$(MIN_SUFFIX) -ltiff$(MIN_SUFFIX) $(WINLIBS) $(COMPLIBS)
endif

WINFLAGS = $(OBSOLETE_DEFINES) $(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)$(MIN_SUFFIX).$(LIBSUFF)
endif

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


ifeq ($(wxUSE_GUI),1)
    WINDOWSLDFLAGS=-Wl,--subsystem,windows
    WINDOWSLDLIBS=-mwindows
endif

# Note: WIN32_LEAN_AND_MEAN is defined only for C and not for C++ compiles.
# Defining this macro means that a great deal of less commonly used stuff
# is ignored in the windows headers, resulting in faster compiles. It can't
# be used with some C++ source files. It just so happens that it can be
# used with all C source files.

CFLAGS = -DWIN32_LEAN_AND_MEAN

WXLIBDIRS = -L$(WXDIR)/lib -L$(WXDIR)/contrib/lib

# You shouldn't need to change these flags, which are merely composed of
# the options selected above. You can add more flags by specifying them on
# the make command line, e.g.
#   make CXXFLAGS='-O3 -march=i686' -f makefile.g95
# The gnu make manual says
#   'Users expect to be able to specify CFLAGS freely themselves'
# That was unsafe with older versions of this makefile, but now it works.
#
# C preprocessor flags
# Some makefiles pass extra flags in $(EXTRACPPFLAGS); although earlier
# versions of this file used CPPFLAGS as C++ compiler flags (instead of
# as C preprocessor flags), it is OK to add them to the preprocessor
# flags, which are always used for C++ compiles. Because other makefiles
# use this method to override these flags, they are added after $(CPPFLAGS),
# which would normally come last.
ALL_CPPFLAGS = $(XINCLUDE) $(INC) $(CPPFLAGS) $(EXTRACPPFLAGS)
# C and C++ compiler flags for compatibility with old gcc versions
REQUIRED_GCC_FLAGS = $(_STRUCT_RETURN_WORKAROUND) $(_THUNK_WORKAROUND)
# C++ compiler flags
ALL_CXXFLAGS = $(COMMON_FLAGS) $(REQUIRED_GCC_FLAGS) $(UNICODE_OPT) $(OPTIONS) $(GUI) $(DEBUGFLAGS) $(WARN) $(OPT) $(EXTRADLLFLAGS) $(CXXFLAGS)
# C compiler flags
ALL_CFLAGS   = $(COMMON_FLAGS) $(REQUIRED_GCC_FLAGS) $(UNICODE_OPT) $(OPTIONS) $(GUI) $(DEBUGFLAGS) $(WARN) $(OPT) $(EXTRADLLFLAGS) $(CFLAGS)
# Linker flags
ALL_LDFLAGS  = $(COMMON_FLAGS) $(WINDOWSLDFLAGS) $(WINDOWSLDLIBS) $(WXLIBDIRS) $(EXTRALDFLAGS) $(LDFLAGS)
# under Cygwin, Dlls must not be linked with subsystem=windows
ALL_LDFLAGS_DLL  = $(COMMON_FLAGS) $(WINDOWSLDLIBS) $(WXLIBDIRS) $(EXTRALDFLAGS) $(LDFLAGS)
  
.SUFFIXES: .rc .$(RESSUFF) .$(RSCSUFF) .cpp .cxx .cc .c

.c.o:
	$(CC)  -c $(ALL_CPPFLAGS) $(ALL_CFLAGS) -o $@ $*.c

.cc.o:
	$(CXX) -c $(ALL_CPPFLAGS) $(ALL_CXXFLAGS) -o $@ $*.cc

.cxx.o:
	$(CXX) -c $(ALL_CPPFLAGS) $(ALL_CXXFLAGS) -o $@ $*.cxx

# This '.cpp.o' rule is apparently written this way because
# the 'tmake' file g95.t expects it.
.$(SRCSUFF).$(OBJSUFF):
	$(CXX) -c $(ALL_CPPFLAGS) $(ALL_CXXFLAGS) -o $@ $*.$(SRCSUFF)
