# Makefile form Microsoft C++ nmake.exe
# $Id$
!IFNDEF WITH_DEVEL
WITH_DEVEL          = ../../deps
!ENDIF

!IFNDEF WITH_BUILD
WITH_BUILD = ..\..\gdbuild
!ENDIF

!IFDEF WITH_PNG
!IF "$(WITH_PNG)"=="dll"
PNG_LIBS     = libpng.lib
USE_LIBPNG      = true
PNG          = dll
!ELSEIF "$(WITH_PNG)"=="static"
PNG_LIBS     = libpng_a.lib
USE_LIBPNG   = true
PNG          = static
!ELSE
USE_LIBPNG   = false
!ENDIF
!ENDIF

!IFDEF WITH_JPEG
!IF "$(WITH_JPEG)"=="dll"
JPEG_LIBS     = libjpeg.lib
USE_LIBJPEG      = true
PNG          = dll
!ELSEIF "$(WITH_JPEG)"=="static"
JPEG_LIBS     = libjpeg_a.lib
USE_LIBJPEG   = true
PNG          = static
!ELSE
USE_LIBJPEG   = false
!ENDIF
!ENDIF

EXTRA_INCLUDE=$(WITH_DEVEL)/include
EXTRA_LIBS=/libpath:$(WITH_DEVEL)/lib

CC=cl.exe
LD=link.exe
BUILD=Release
#BUILD=Debug

LIBGD_SRC_DIR=..\src
LIBGD_OBJ_DIR=$(WITH_BUILD)
LIBGD_BIN_DIR=$(WITH_BUILD)\bin

!MESSAGE library source:  $(LIBGD_SRC_DIR)
!MESSAGE library objects: $(LIBGD_OBJ_DIR)

LIBGDCFLAGS= \
   /D PATHSEPARATOR="\";\"" \
   /D DEFAULT_FONTPATH="\"C:\\WINDOWS\\FONTS;C:\\WINNT\\FONTS\"" \

#LIBS=libjpeg.lib freetype2.lib libpng.lib zlib.lib kernel32.lib user32.lib advapi32.lib
LIBS=kernel32.lib user32.lib advapi32.lib

!IF "$(USE_LIBPNG)" == "true"
LIBPNG_CFLAGS   = $(LIBPNG_CFLAGS) /I"$(WITH_DEVEL)/include/libpng15"  /D HAVE_LIBPNG
LIBS= $(LIBS) libpng_a.lib
!ENDIF

CFLAGS=/c -I. -I.. -I../src -I$(EXTRA_INCLUDE) -nologo -DWIN32 -D_WIN32 -DMSWIN32 -DBGDWIN32 $(LIBGDCFLAGS)
#LIBS=libjpeg.lib freetype2.lib libpng.lib zlib.lib kernel32.lib user32.lib advapi32.lib

!if "$(BUILD)" == "Debug"
CFLAGS=$(CFLAGS) /Od /Zi /MTd /D_DEBUG /LDd
LDFLAGS=/DEBUG $(LDFLAGS) /nodefaultlib:msvcrt.lib  $(EXTRA_LIBS)
LIBS=$(LIBS) msvcrtd.lib
!else
CFLAGS=$(CFLAGS) /Oi /O2 /Oy /GF /MT /DNDEBUG /LD
LDFLAGS=/nodefaultlib:msvcrtd.lib $(EXTRA_LIBS)
LIBS=$(LIBS) msvcrt.lib
!endif

CPPFLAGS=$(CFLAGS)

!if "$(DLLNAME)" == ""
DLLNAME=libgd.dll
!endif

DYNAMICLIB=$(DLLNAME:.dll=.lib)

!if "$(STATICLIB)" == ""
STATICLIB=libgd_a.lib
!endif

LIB_OBJS= \
  $(LIBGD_OBJ_DIR)\gd.obj \
  $(LIBGD_OBJ_DIR)\gdcache.obj \
  $(LIBGD_OBJ_DIR)\gdfontg.obj \
  $(LIBGD_OBJ_DIR)\gdfontl.obj \
  $(LIBGD_OBJ_DIR)\gdfontmb.obj \
  $(LIBGD_OBJ_DIR)\gdfonts.obj \
  $(LIBGD_OBJ_DIR)\gdfontt.obj \
  $(LIBGD_OBJ_DIR)\gdft.obj \
  $(LIBGD_OBJ_DIR)\gdfx.obj \
  $(LIBGD_OBJ_DIR)\gd_gd2.obj \
  $(LIBGD_OBJ_DIR)\gd_gd.obj \
  $(LIBGD_OBJ_DIR)\gd_gif_in.obj \
  $(LIBGD_OBJ_DIR)\gd_gif_out.obj \
  $(LIBGD_OBJ_DIR)\gdhelpers.obj \
  $(LIBGD_OBJ_DIR)\gd_io.obj \
  $(LIBGD_OBJ_DIR)\gd_io_dp.obj \
  $(LIBGD_OBJ_DIR)\gd_io_file.obj \
  $(LIBGD_OBJ_DIR)\gd_io_ss.obj \
  $(LIBGD_OBJ_DIR)\gd_jpeg.obj \
  $(LIBGD_OBJ_DIR)\gd_security.obj \
  $(LIBGD_OBJ_DIR)\gdkanji.obj \
  $(LIBGD_OBJ_DIR)\gd_png.obj \
  $(LIBGD_OBJ_DIR)\gd_ss.obj \
  $(LIBGD_OBJ_DIR)\gdtables.obj \
  $(LIBGD_OBJ_DIR)\gd_topal.obj \
  $(LIBGD_OBJ_DIR)\gd_transform.obj \
  $(LIBGD_OBJ_DIR)\gd_wbmp.obj \
  $(LIBGD_OBJ_DIR)\gdxpm.obj \
  $(LIBGD_OBJ_DIR)\wbmp.obj \
  $(LIBGD_OBJ_DIR)\gd_interpolation.obj \
  $(LIBGD_OBJ_DIR)\gd_matrix.obj \
  $(LIBGD_OBJ_DIR)\gd_rotate.obj

EXE_OBJS= \
  annotate.obj \
  circletexttest.obj \
  fontconfigtest.obj \
  fontsizetest.obj \
  fontwheeltest.obj \
	gd2copypal.obj \
	gd2togif.obj \
	gd2topng.obj \
	gdcmpgif.obj \
	gdparttopng.obj \
	gdtopng.obj \
	giftogd2.obj \
	gdtest.obj \
	gdtestft.obj \
	gifanimtest.obj \
	pngtogd.obj \
	pngtogd2.obj \
	testac.obj \
	testtr.obj \
	webpng.obj

$(LIBGD_OBJ_DIR):
	@if not exist $(LIBGD_OBJ_DIR) mkdir $(LIBGD_OBJ_DIR)

$(LIBGD_BIN_DIR):
	@if not exist $(LIBGD_BIN_DIR) mkdir $(LIBGD_BIN_DIR)

all: $(LIBGD_OBJ_DIR) $(LIBGD_BIN_DIR) $(LIB_OBJS) $(STATICLIB)

.SUFFIXES: .c .obj .res

{$(LIBGD_SRC_DIR)\}.c{$(LIBGD_OBJ_DIR)\}.obj:
	$(CC) $(CFLAGS) /Fo"$@"  $<

$(STATICLIB): $(LIB_OBJS)
	$(LD) /lib /out:$(LIBGD_BIN_DIR)/$(STATICLIB) $(LIB_OBJS)

dist: all
	-rmdir /s /q distro
	mkdir distro
	mkdir distro\bin
	copy *.exe distro\bin
	copy *.dll distro\bin
	mkdir distro\include
	copy ..\*.h distro\include
	mkdir distro\lib
	copy *.lib distro\lib
	copy ..\COPYING distro\COPYING.TXT
	
clean:
	-del /q $(LIBGD_OBJ_DIR)\*.obj $(LIBGD_OBJ_DIR)\*.dll $(LIBGD_OBJ_DIR)\*.lib $(LIBGD_OBJ_DIR)\*.ilk $(LIBGD_OBJ_DIR)\*.pdb $(LIBGD_OBJ_DIR)\*.exp $(LIBGD_OBJ_DIR)\*.exe $(LIBGD_OBJ_DIR)\*.png $(LIBGD_OBJ_DIR)\*.res
	-rmdir /s /q distro