# NMake Makefile portion for enabling features for Windows builds

# These are the base minimum libraries required for building gtkmm.
!ifndef BASE_INCLUDEDIR
BASE_INCLUDEDIR = $(PREFIX)\include
!endif
!ifndef BASE_LIBDIR
BASE_LIBDIR = $(PREFIX)\lib
!endif
!ifndef BASE_TOOLS_DIR
BASE_TOOLS_DIR = $(PREFIX)\bin
!endif

# Please do not change anything beneath this line unless maintaining the NMake Makefiles
# Debug/Release builds
!if "$(CFG)" == "debug" || "$(CFG)" == "Debug"
DEBUG_SUFFIX = -d
!else
DEBUG_SUFFIX =
!endif

# Dependencies

GTK_API_VERSION = 3
GTKMM_MAJOR_VERSION = 3
GTKMM_MINOR_VERSION = 0
GTKMM_API_VERSION = $(GTKMM_MAJOR_VERSION).$(GTKMM_MINOR_VERSION)

PANGO_API_VERSION = 1.0
PANGOMM_MAJOR_VERSION = 1
PANGOMM_MINOR_VERSION = 4
PANGOMM_API_VERSION = $(PANGOMM_MAJOR_VERSION).$(PANGOMM_MINOR_VERSION)

ATK_API_VERSION = 1.0
ATKMM_MAJOR_VERSION = 1
ATKMM_MINOR_VERSION = 6
ATKMM_API_VERSION = $(ATKMM_MAJOR_VERSION).$(ATKMM_MINOR_VERSION)

GLIB_API_VERSION = 2.0
GLIBMM_MAJOR_VERSION = 2
GLIBMM_MINOR_VERSION = 4
GLIBMM_API_VERSION = $(GLIBMM_MAJOR_VERSION).$(GLIBMM_MINOR_VERSION)

CAIROMM_MAJOR_VERSION = 1
CAIROMM_MINOR_VERSION = 0
CAIROMM_API_VERSION = $(CAIROMM_MAJOR_VERSION).$(CAIROMM_MINOR_VERSION)

SIGC_MAJOR_VERSION = 2
SIGC_MINOR_VERSION = 0
SIGC_SERIES = $(SIGC_MAJOR_VERSION).$(SIGC_MINOR_VERSION)

GDK_PIXBUF_API_VERSION = 2.0
GRAPHENE_API_VERSION = 1.0

OUTDIR = vs$(VSVER)\$(CFG)\$(PLAT)
DEPS_MKFILE = deps-vs$(VSVER)-$(PLAT)-$(CFG).mak
M4_PATH_MKFILE = find-m4-bindir-vs$(VSVER)-$(PLAT)-$(CFG).mak
UNIX_TOOLS_PATH_MKFILE = check-unix-tools-bindir-vs$(VSVER)-$(PLAT)-$(CFG).mak
GENERATE_CHECK_HEADER_BAT = gen-check-header-vs$(VSVER)-$(PLAT)-$(CFG).bat
BUILD_MKFILE_SNIPPET = gtkmm-vs$(VSVER)-$(PLAT)-$(CFG).mak

!if [for %t in (GTK PANGOMM ATKMM GDK_PIXBUF PANGO ATK GLIBMM CAIROMM SIGC CAIRO HARFBUZZ FONTCONFIG FREETYPE GLIB EPOXY) do @(echo !ifndef %t_INCLUDEDIR>>$(DEPS_MKFILE) & echo %t_INCLUDEDIR=^$^(BASE_INCLUDEDIR^)>>$(DEPS_MKFILE) & echo !endif>>$(DEPS_MKFILE))]
!endif
!if [for %t in (GTK PANGOMM ATKMM GDK_PIXBUF PANGO ATK GLIBMM CAIROMM SIGC CAIRO GLIB EPOXY) do @(echo !ifndef %t_LIBDIR>>$(DEPS_MKFILE) & echo %t_LIBDIR=^$^(BASE_LIBDIR^)>>$(DEPS_MKFILE) & echo !endif>>$(DEPS_MKFILE))]
!endif
!if [for %t in (GLIB) do @(echo !ifndef %t_BINDIR>>$(DEPS_MKFILE) & echo %t_BINDIR=^$^(BASE_TOOLS_DIR^)>>$(DEPS_MKFILE) & echo !endif>>$(DEPS_MKFILE))]
!endif

!include $(DEPS_MKFILE)

!if [del /f/q $(DEPS_MKFILE)]
!endif

!ifndef M4
!ifdef UNIX_TOOLS_BINDIR
M4 = $(UNIX_TOOLS_BINDIR)\m4.exe
!else
M4 = m4
!endif
!endif

# Try to deduce full path to m4.exe, as needed
!if [if not exist $(M4)\ if exist $(M4) echo M4_FULL_PATH = $(M4)>$(M4_PATH_MKFILE)]
!endif
!if [if exist $(M4).exe echo M4_FULL_PATH = $(M4).exe>$(M4_PATH_MKFILE)]
!endif
!if [if not exist $(M4_PATH_MKFILE) ((echo M4_FULL_PATH = \>$(M4_PATH_MKFILE)) & where $(M4)>>$(M4_PATH_MKFILE) 2>NUL)]
!endif

!include $(M4_PATH_MKFILE)

!if [del /f/q $(M4_PATH_MKFILE)]
!endif

!if [if not "$(UNIX_TOOLS_BINDIR)" == "" if not "$(M4_FULL_PATH)" == "" echo UNIX_TOOLS_BINDIR_CHECKED = $(UNIX_TOOLS_BINDIR)>$(UNIX_TOOLS_PATH_MKFILE)]
!endif

!if [if "$(UNIX_TOOLS_BINDIR)" == "" if not "$(M4_FULL_PATH)" == "" (for %f in ($(M4_FULL_PATH)) do @echo UNIX_TOOLS_BINDIR_CHECKED = %~dpf>$(UNIX_TOOLS_PATH_MKFILE))]
!endif

!if [if not exist $(UNIX_TOOLS_PATH_MKFILE) (echo UNIX_TOOLS_BINDIR_CHECKED = >$(UNIX_TOOLS_PATH_MKFILE))]
!endif

!include $(UNIX_TOOLS_PATH_MKFILE)

!if [del /f/q $(UNIX_TOOLS_PATH_MKFILE)]
!endif

!ifndef GMMPROC_DIR
GMMPROC_DIR=$(GLIBMM_LIBDIR)\glibmm-$(GLIBMM_API_VERSION)\proc
!endif

!ifndef GMMPROC_PANGO_DIR
GMMPROC_PANGO_DIR=$(PANGOMM_LIBDIR)\pangomm-$(PANGOMM_API_VERSION)\proc\m4
!endif

!ifndef GMMPROC_ATK_DIR
GMMPROC_ATK_DIR=$(ATKMM_LIBDIR)\atkmm-$(ATKMM_API_VERSION)\proc\m4
!endif

DEP_INCLUDES =	\
	/I$(GTK_INCLUDEDIR)\gtk-$(GTK_API_VERSION).0	\
	/I$(GDK_PIXBUF_INCLUDEDIR)\gdk-pixbuf-$(GDK_PIXBUF_API_VERSION)	\
	/I$(PANGOMM_INCLUDEDIR)\pangomm-$(PANGOMM_API_VERSION)	\
	/I$(PANGOMM_LIBDIR)\pangomm-$(PANGOMM_API_VERSION)\include	\
	/I$(PANGO_INCLUDEDIR)\pango-$(PANGO_API_VERSION)	\
	/I$(CAIROMM_INCLUDEDIR)\cairomm-$(CAIROMM_API_VERSION)	\
	/I$(CAIROMM_LIBDIR)\cairomm-$(CAIROMM_API_VERSION)\include	\
	/I$(CAIRO_INCLUDEDIR)\cairo	\
	/I$(ATKMM_INCLUDEDIR)\atkmm-$(ATKMM_API_VERSION)	\
	/I$(ATKMM_LIBDIR)\atkmm-$(ATKMM_API_VERSION)\include	\
	/I$(ATK_INCLUDEDIR)\atk-$(ATK_API_VERSION)	\
	/I$(GLIBMM_INCLUDEDIR)\giomm-$(GLIBMM_API_VERSION)	\
	/I$(GLIBMM_LIBDIR)\giomm-$(GLIBMM_API_VERSION)\include	\
	/I$(GLIBMM_INCLUDEDIR)\glibmm-$(GLIBMM_API_VERSION)	\
	/I$(GLIBMM_LIBDIR)\glibmm-$(GLIBMM_API_VERSION)\include	\
	/I$(GLIB_INCLUDEDIR)\glib-$(GLIB_API_VERSION)	\
	/I$(GLIB_LIBDIR)\glib-$(GLIB_API_VERSION)\include	\
	/I$(SIGC_INCLUDEDIR)\sigc++-$(SIGC_SERIES)	\
	/I$(SIGC_LIBDIR)\sigc++-$(SIGC_SERIES)\include	\
	/I$(HARFBUZZ_INCLUDEDIR)\harfbuzz

# Just in case one built Pango with FontConfig support
!if "$(FONTCONFIG_INCLUDEDIR)" != "$(BASE_INCLUDEDIR)"
DEP_INCLUDES = $(DEP_INCLUDES) /I$(FONTCONFIG_INCLUDEDIR)
!endif
DEP_INCLUDES = $(DEP_INCLUDES) /I$(FREETYPE_INCLUDEDIR)\freetype2

!if "$(EPOXY_INCLUDEDIR)" != "$(BASE_INCLUDEDIR)"
DEP_INCLUDES = $(DEP_INCLUDES) /I$(EPOXY_INCLUDEDIR)
!endif
DEP_INCLUDES = $(DEP_INCLUDES) /I$(BASE_INCLUDEDIR)

# Compiler CXXFLAGS and In-source include directories
GTKMM_BASE_CFLAGS = /FImsvc_recommended_pragmas.h
GTKMM_BUILD_INCLUDES = /I$(OUTDIR)
GTKMM_INCLUDES = /I..\untracked\gtk /I..\untracked\gtk\gtkmm /I..\gtk /I.\gtkmm
GDKMM_INCLUDES = $(GTKMM_INCLUDES:gtk=gdk)

# Now gather up the CXXFLAGS and include flags

LIBGDKMM_CXXFLAGS = /DGDKMM_BUILD $(GTKMM_BASE_CFLAGS)
LIBGTKMM_CXXFLAGS = $(LIBGDKMM_CXXFLAGS:/DGDKMM_=/DGTKMM_) /wd4250
GTKMM_DEMO_CFLAGS = $(CFLAGS) $(GTKMM_BASE_CFLAGS) /wd4250
LIBGDKMM_INCLUDES = $(GTKMM_BUILD_INCLUDES) $(GDKMM_INCLUDES) $(DEP_INCLUDES)
LIBGTKMM_INCLUDES = $(GTKMM_BUILD_INCLUDES) $(GTKMM_INCLUDES) $(GDKMM_INCLUDES) $(DEP_INCLUDES)

# We build gtkmm-vc$(VSVER_LIB)-$(GTKMM_MAJOR_VERSION)_$(GTKMM_MINOR_VERSION).dll or
#          gtkmm-vc$(VSVER_LIB)-d-$(GTKMM_MAJOR_VERSION)_$(GTKMM_MINOR_VERSION).dll at least

# With /GL, gtkmm4-demo fails on VS 2017 32 bit with an internal compiler error...
!if $(VSVER) < 16 && "$(PLAT)" == "Win32"
GTKMM_DEMO_CFLAGS = $(GTKMM_DEMO_CFLAGS: /GL=)
GTKMM_DEMO_LDFLAGS = $(LDFLAGS: /LTCG=)
!else
GTKMM_DEMO_LDFLAGS = $(LDFLAGS)
!endif

!if "$(USE_COMPAT_LIBS)" != ""
MESON_VERVER_LIB =
VSVER_LIB = 140
!else
VSVER_LIB = $(PDBVER)$(VSVER_SUFFIX)
MESON_VERVER_LIB = -vc$(VSVER_LIB)
!endif

GIO_LIBS = gio-$(GLIB_API_VERSION).lib gobject-$(GLIB_API_VERSION).lib gmodule-$(GLIB_API_VERSION).lib glib-$(GLIB_API_VERSION).lib

ATK_LIB = atk-$(ATK_API_VERSION).lib
CAIRO_LIBS = cairo-gobject.lib cairo.lib
EPOXY_LIB = epoxy.lib
GDK_PIXBUF_LIB = gdk_pixbuf-$(GDK_PIXBUF_API_VERSION).lib
GTK_LIBS = gtk-$(GTK_API_VERSION).0.lib gdk-$(GTK_API_VERSION).0.lib
PANGO_LIBS = pangocairo-$(PANGO_API_VERSION).lib pango-$(PANGO_API_VERSION).lib

!ifdef USE_MESON_LIBS
SIGC_LIBNAME = sigc-$(SIGC_SERIES)
GLIBMM_LIBNAME = glibmm$(MESON_VERVER_LIB)-$(GLIBMM_API_VERSION)
GIOMM_LIBNAME = giomm$(MESON_VERVER_LIB)-$(GLIBMM_API_VERSION)
CAIROMM_LIBNAME = cairomm$(MESON_VERVER_LIB)-$(CAIROMM_API_VERSION)
ATKMM_LIBNAME = atkmm$(MESON_VERVER_LIB)-$(ATKMM_API_VERSION)
PANGOMM_LIBNAME = pangomm$(MESON_VERVER_LIB)-$(PANGOMM_API_VERSION)
GTKMM_LIBNAME = gtkmm$(MESON_VERVER_LIB)-$(GTKMM_API_VERSION)
GTKMM_DLLNAME = $(GTKMM_LIBNAME)-1
!else
SIGC_LIBNAME = sigc-vc$(PDBVER)0$(DEBUG_SUFFIX)-$(SIGC_SERIES:.=_)
GLIBMM_LIBNAME = glibmm-vc$(VSVER_LIB)$(DEBUG_SUFFIX)-$(GLIBMM_API_VERSION:.=_)
GIOMM_LIBNAME = giomm-vc$(VSVER_LIB)$(DEBUG_SUFFIX)-$(GLIBMM_API_VERSION:.=_)
CAIROMM_LIBNAME = cairomm-vc$(VSVER_LIB)$(DEBUG_SUFFIX)-$(CAIROMM_API_VERSION:.=_)
ATKMM_LIBNAME = atkmm-vc$(VSVER_LIB)$(DEBUG_SUFFIX)-$(ATKMM_API_VERSION:.=_)
PANGOMM_LIBNAME = pangomm-vc$(VSVER_LIB)$(DEBUG_SUFFIX)-$(PANGOMM_API_VERSION:.=_)
GTKMM_LIBNAME = gtkmm-vc$(VSVER_LIB)$(DEBUG_SUFFIX)-$(GTKMM_API_VERSION:.=_)
GTKMM_DLLNAME = $(GTKMM_LIBNAME)
!endif
GDKMM_LIBNAME = $(GTKMM_LIBNAME:gtkmm=gdkmm)
GDKMM_DLLNAME = $(GTKMM_DLLNAME:gtkmm=gdkmm)

SIGC_LIB = $(SIGC_LIBNAME).lib
GLIBMM_LIB = $(GLIBMM_LIBNAME).lib
GIOMM_LIB = $(GIOMM_LIBNAME).lib
CAIROMM_LIB = $(CAIROMM_LIBNAME).lib
PANGOMM_LIB = $(PANGOMM_LIBNAME).lib
ATKMM_LIB = $(ATKMM_LIBNAME).lib

GDKMM_DLL = $(OUTDIR)\$(GDKMM_DLLNAME).dll
GDKMM_LIB = $(OUTDIR)\$(GDKMM_LIBNAME).lib
GTKMM_DLL = $(OUTDIR)\$(GTKMM_DLLNAME).dll
GTKMM_LIB = $(OUTDIR)\$(GTKMM_LIBNAME).lib

GTKMM3_DEMO = $(OUTDIR)\gtkmm3-demo$(DEBUG_SUFFIX).exe

TARGETS = $(GTKMM_LIB) $(GTKMM3_DEMO)

GENDEF = $(OUTDIR)\gendef.exe

# Gather up the .lib's that we need to link to
DEP_LDFLAGS = $(EPOXY_LIB) /libpath:$(BASE_LIBDIR)
!if "$(EPOXY_LIBDIR)" != "$(BASE_LIBDIR)"
DEP_LDFLAGS = /libpath:$(EPOXY_LIBDIR) $(DEP_LDFLAGS)
!endif
DEP_LDFLAGS = $(GIO_LIBS) $(DEP_LDFLAGS)
!if "$(GLIB_LIBDIR)" != "$(BASE_LIBDIR)"
DEP_LDFLAGS = /libpath:$(GLIB_LIBDIR) $(DEP_LDFLAGS)
!endif
DEP_LDFLAGS = $(CAIRO_LIBS) $(DEP_LDFLAGS)
!if "$(CAIRO_LIBDIR)" != "$(BASE_LIBDIR)"
DEP_LDFLAGS = /libpath:$(CAIRO_LIBDIR) $(DEP_LDFLAGS)
!endif
DEP_LDFLAGS = $(ATK_LIB) $(DEP_LDFLAGS)
!if "$(ATK_LIBDIR)" != "$(BASE_LIBDIR)"
DEP_LDFLAGS = /libpath:$(ATK_LIBDIR) $(DEP_LDFLAGS)
!endif
DEP_LDFLAGS = $(GDK_PIXBUF_LIB) $(DEP_LDFLAGS)
!if "$(GDK_PIXBUF_LIBDIR)" != "$(BASE_LIBDIR)"
DEP_LDFLAGS = /libpath:$(GDK_PIXBUF_LIBDIR) $(DEP_LDFLAGS)
!endif
DEP_LDFLAGS = $(GTK_LIBS) $(DEP_LDFLAGS)
!if "$(GTK_LIBDIR)" != "$(BASE_LIBDIR)"
DEP_LDFLAGS = /libpath:$(GTK_LIBDIR) $(DEP_LDFLAGS)
!endif
DEP_LDFLAGS = $(SIGC_LIB) $(DEP_LDFLAGS)
!if "$(SIGC_LIBDIR)" != "$(BASE_LIBDIR)"
DEP_LDFLAGS = /libpath:$(SIGC_LIBDIR) $(DEP_LDFLAGS)
!endif
DEP_LDFLAGS = $(GIOMM_LIB) $(GLIBMM_LIB) $(DEP_LDFLAGS)
!if "$(GLIBMM_LIBDIR)" != "$(BASE_LIBDIR)"
DEP_LDFLAGS = /libpath:$(GLIBMM_LIBDIR) $(DEP_LDFLAGS)
!endif
DEP_LDFLAGS = $(CAIROMM_LIB) $(DEP_LDFLAGS)
!if "$(CAIROMM_LIBDIR)" != "$(BASE_LIBDIR)"
DEP_LDFLAGS = /libpath:$(CAIROMM_LIBDIR) $(DEP_LDFLAGS)
!endif
DEP_LDFLAGS = $(ATKMM_LIB) $(DEP_LDFLAGS)
!if "$(ATKMM_LIBDIR)" != "$(BASE_LIBDIR)"
DEP_LDFLAGS = /libpath:$(ATKMM_LIBDIR) $(DEP_LDFLAGS)
!endif
DEP_LDFLAGS = $(PANGOMM_LIB) $(DEP_LDFLAGS)
!if "$(PANGOMM_LIBDIR)" != "$(BASE_LIBDIR)"
DEP_LDFLAGS = /libpath:$(PANGOMM_LIBDIR) $(DEP_LDFLAGS)
!endif


GTKMM_DLL = $(OUTDIR)\$(GTKMM_DLLNAME).dll
GTKMM_LIB = $(OUTDIR)\$(GTKMM_LIBNAME).lib

GTKMM4_DEMO = $(OUTDIR)\gtkmm4-demo$(DEBUG_SUFFIX).exe

GTKMM_INT_EXTRA_SOURCES = $(gtkmm_files_extra_any_cc)
GTKMM_INT_EXTRA_HEADERS_P = $(gtkmm_files_extra_ph:/=\)
GTKMM_INT_EXTRA_HEADERS = $(gtkmm_files_extra_any_h)

GDKMM_HG_FILES = $(gdkmm_files_any_hg)
GTKMM_HG_FILES = $(gtkmm_files_any_hg)

ENABLED_DEPRECATED = no

!ifndef DISABLE_DEPRECATED
GTKMM_INT_EXTRA_SOURCES = $(GTKMM_INT_EXTRA_SOURCES) $(gtkmm_files_extra_deprecated_cc)
GTKMM_INT_EXTRA_HEADERS = $(GTKMM_INT_EXTRA_HEADERS) $(gtkmm_files_extra_deprecated_h)
GDKMM_HG_FILES = $(GDKMM_HG_FILES) $(gdkmm_files_deprecated_hg)
GTKMM_HG_FILES = $(GTKMM_HG_FILES) $(gtkmm_files_deprecated_hg)
ENABLED_DEPRECATED = yes
!endif

GDKMM_INT_GENERATED_HEADERS = $(GDKMM_HG_FILES:.hg=.h)
GDKMM_INT_GENERATED_HEADERS_P = $(GDKMM_HG_FILES:.hg=_p.h)
GTKMM_INT_GENERATED_HEADERS = $(GTKMM_HG_FILES:.hg=.h)
GDKMM_INT_GENERATED_SOURCES = $(GDKMM_HG_FILES:.hg=.cc) wrap_init.cc
GTKMM_INT_GENERATED_SOURCES = $(GTKMM_HG_FILES:.hg=.cc) wrap_init.cc

# Path to glib-compile-resources.exe
!ifndef GLIB_COMPILE_RESOURCES
GLIB_COMPILE_RESOURCES = $(GLIB_BINDIR)\glib-compile-resources.exe
!endif
