TOP = ..\..
PRJ_TOP = ..
PACKAGE = gdk_pixbuf
PKG_VER = $(GDK_PIXBUF_VER)

!INCLUDE $(TOP)/glib/build/win32/make.msc

!IFNDEF PERL
PERL = perl
!ENDIF

GDK_PIXBUF_VER = 2.0

# -DINCLUDE_gdiplus _replaces_ -DINCLUDE_bmp -DINCLUDE_gif -DINCLUDE_ico -DINCLUDE_jpeg  -DINCLUDE_tiff
# but not yet -DINCLUDE_png 
##USEGDIP=1
# to get _working_ include modules we need respective defines ...
#   
BUILT_IN_FORMATS = \
!IFDEF USEGDIP
	-DINCLUDE_gdiplus \
!ELSE
	-DINCLUDE_bmp -DINCLUDE_gif -DINCLUDE_ico -DINCLUDE_jpeg -DINCLUDE_tiff \
!ENDIF
	-DINCLUDE_png \
	-DINCLUDE_xpm -DINCLUDE_wbmp \
	-DINCLUDE_pnm -DINCLUDE_ras

PKG_CFLAGS = -FImsvc_recommended_pragmas.h \
!IFNDEF USEGDIP
 	$(JPEG_CFLAGS) $(TIFF_CFLAGS) \
!ENDIF
	-I. -I.. $(GLIB_CFLAGS) \
	$(BUILT_IN_FORMATS) \
	$(PNG_CFLAGS) $(INTL_CFLAGS) \
	$(G_DEBUGGING) \
	-DGDK_PIXBUF_ENABLE_BACKEND \
	-DGTK_PREFIX=\"/just/some/non/existing/path/\" \
	-UUSE_GMODULE # use built-in
#	-DUSE_GMODULE -DPIXBUF_LIBDIR=\".\"

PKG_LINK = $(GLIB_LIBS) \
!IFNDEF USEGDIP
	$(TIFF_LIBS) $(JPEG_LIBS) \
!ENDIF
	$(PNG_LIBS) $(INTL_LIBS) \
	pixops\pixops.lib \
 
OBJECTS_NON_NATIVE = \
	io-bmp.obj \
	io-gif.obj \
	io-ico.obj \
	io-tiff.obj \
	io-jpeg.obj \

OBJECTS_NATIVE = \
	io-gdip-animation.obj \
	io-gdip-bmp.obj \
	io-gdip-emf.obj \
	io-gdip-gif.obj \
	io-gdip-ico.obj \
	io-gdip-jpeg.obj \
	io-gdip-tiff.obj \
	io-gdip-utils.obj \
	io-gdip-wmf.obj

OBJECTS = \
	gdk-pixbuf-enum-types.obj \
	gdk-pixbuf-animation.obj \
	gdk-pixbuf-data.obj \
	gdk-pixbuf-io.obj \
	gdk-pixbuf-loader.obj \
	gdk-pixbuf-scale.obj \
	gdk-pixbuf-scaled-anim.obj \
	gdk-pixbuf-util.obj \
	gdk-pixbuf.obj \
	gdk-pixbuf-simple-anim.obj \
	gdk-pixdata.obj \
	io-wbmp.obj \
	io-gif-animation.obj \
	io-png.obj \
	io-pnm.obj \
	io-ras.obj \
	io-xpm.obj \
!IFDEF USEGDIP
	$(OBJECTS_NATIVE)
!ELSE
	$(OBJECTS_NON_NATIVE)
!ENDIF

gdk_pixbuf_headers = 	\
	gdk-pixbuf.h	\
	gdk-pixbuf-core.h	\
	gdk-pixbuf-loader.h	\
	gdk-pixbuf-transform.h

gdk-pixbuf-marshal.h: gdk-pixbuf-marshal.list
	..\..\glib\gobject\glib-genmarshal --prefix=_gdk_pixbuf_marshal gdk-pixbuf-marshal.list --header >gdk-pixbuf-marshal.h

gdk-pixbuf-marshal.c: gdk-pixbuf-marshal.h gdk-pixbuf-marshal.list
	..\..\glib\gobject\glib-genmarshal --prefix=_gdk_pixbuf_marshal gdk-pixbuf-marshal.list --body >gdk-pixbuf-marshal.c

gdk-pixbuf-alias.h: gdk-pixbuf.symbols
	perl makegdkpixbufalias.pl < gdk-pixbuf.symbols > gdk-pixbuf-alias.h

gdk_pixbuf.def: gdk-pixbuf.symbols makefile.msc
	echo EXPORTS > gdk_pixbuf.def
	cl /EP -DINCLUDE_VARIABLES -DG_OS_WIN32 -DALL_FILES \
	-DG_GNUC_MALLOC= -DG_GNUC_CONST= -DG_GNUC_NULL_TERMINATED= -DG_GNUC_NORETURN= -DG_GNUC_PRINTF=;G_GNUC_PRINTF \
	gdk-pixbuf.symbols >> gdk_pixbuf.def

gdk-pixbuf-aliasdef.c: gdk-pixbuf.symbols
	 perl makegdkpixbufalias.pl -def < gdk-pixbuf.symbols > gdk-pixbuf-aliasdef.c

## common stuff

INSTALL = copy

CFLAGS = -I. -DHAVE_CONFIG_H

sub-pixops :
	cd pixops
	nmake -f makefile.msc
	cd ..

## targets
all : \
	$(PRJ_TOP)\config.h \
	gdk-pixbuf-alias.h \
	gdk-pixbuf-aliasdef.c \
	gdk-pixbuf-marshal.h \
	gdk-pixbuf-marshal.c \
	sub-pixops \
	lib$(PACKAGE)-$(PKG_VER)-0.dll \
	$(PACKAGE)-$(PKG_VER)s.lib \
#	make-inline-pixbuf.exe \
	gdk-pixbuf-csource.exe \
	test-gdk-pixbuf.exe

$(PACKAGE).res : $(PACKAGE).rc
	rc -DBUILDNUMBER=0 -r -fo $(PACKAGE).res $(PACKAGE).rc

$(PACKAGE)-$(PKG_VER)s.lib : $(OBJECTS)
	lib /out:$(PACKAGE)-$(PKG_VER)s.lib $(OBJECTS) pixops\pixops.lib

lib$(PACKAGE)-$(PKG_VER)-0.dll : $(OBJECTS) $(PACKAGE).def $(PACKAGE).res
	$(CC) $(CFLAGS) -LD -Fe$@ $(OBJECTS) $(PKG_LINK) user32.lib advapi32.lib ole32.lib wsock32.lib $(PACKAGE).res \
	$(LDFLAGS) /implib:$(PACKAGE)-$(PKG_VER).lib /def:$(PACKAGE).def

make-inline-pixbuf.exe : make-inline-pixbuf.c
	$(CC) $(PKG_CFLAGS) -Femake-inline-pixbuf.exe make-inline-pixbuf.c $(PKG_LINK) $(PACKAGE)-$(PKG_VER).lib

gdk-pixbuf-csource.exe : gdk-pixbuf-csource.c
	$(CC) $(PKG_CFLAGS) -Fegdk-pixbuf-csource.exe gdk-pixbuf-csource.c $(PKG_LINK) $(PACKAGE)-$(PKG_VER).lib

test-gdk-pixbuf.exe : test-gdk-pixbuf.c
	$(CC) $(PKG_CFLAGS) -Fetest-gdk-pixbuf.exe test-gdk-pixbuf.c $(PKG_LINK) $(PACKAGE)-$(PKG_VER).lib

#
# gdk-pixbuf-enum-types.h
#
gdk-pixbuf-enum-types.h : $(gdk_pixbuf_headers) makefile.msc
	$(PERL) $(GLIB)\gobject\glib-mkenums \
		--fhead "#ifndef __GDK_PIXBUF__ENUM_TYPES_H__\n#define __GDK_PIXBUF_ENUM_TYPES_H__\n" \
		--fprod "/* enumerations from \"@filename@\" */\n" \
		--vhead "GType @enum_name@_get_type (void);\n#define GDK_TYPE_@ENUMSHORT@ (@enum_name@_get_type())\n"         \
		--ftail "#endif /* __GDK_PIXBUF_ENUM_TYPES_H__ */" \
		$(gdk_pixbuf_headers) ) > gdk-pixbuf-enum-types.h

#
# gdk-pixbuf-enum-types.c
#
gdk-pixbuf-enum-types.c: $(gdk_pixbuf_headers) makefile.msc
	$(PERL) $(GLIB)\gobject\glib-mkenums \
		--fhead "#include <gdk-pixbuf/gdk-pixbuf.h>" \
		--fprod "\n/* enumerations from \"@filename@\" */" \
		--vhead "GType\n@enum_name@_get_type (void)\n{\n  static GType etype = 0;\n  if (etype == 0) {\n    static const G@Type@Value values[] = {"       \
		--vprod "      { @VALUENAME@, \"@VALUENAME@\", \"@valuenick@\" }," \
		--vtail "      { 0, NULL, NULL }\n    };\n    etype = g_@type@_register_static (\"@EnumName@\", values);\n  }\n  return etype;\n}\n" \
		  $(gdk_pixbuf_headers) > gdk-pixbuf-enum-types.c

gdk-pixbuf-enum-types.obj : gdk-pixbuf-enum-types.c gdk-pixbuf-enum-types.h

$(PRJ_TOP)\config.h: $(PRJ_TOP)\config.h.win32
	copy $(PRJ_TOP)\config.h.win32 $(PRJ_TOP)\config.h

.c.obj :
	$(CC) $(CFLAGS) -GD -c $(PKG_CFLAGS) $<

clean::
	del config.h
	del gdk-pixbuf-marshal.h
	del gdk-pixbuf-marshal.c
	del gdk-pixbuf-alaias.h



