# This is the master makefile to build all tkimg components. Run as
#
#   nmake /s /nologo /f makefile.vc INSTALLDIR=c:\full\path\to\installdir TCLDIR=c:\full\path\to\tcl\sources TKDIR=c:\full\path\to\tk\sources
#
# To build specific modules, pass the MODULES macro on the command line
#
#   nmake /s /nologo /f makefile.vc INSTALLDIR=path\to\installdir TCLDIR=path\to\tcl\sources TKDIR=path\to\tk\sources MODULES="png jpeg"
#
# You may specify following additional targets: install, clean, hose, realclean. For example, to install
#
#   nmake /s /nologo /f makefile.vc INSTALLDIR=path\to\installdir TCLDIR=path\to\tcl\sources TKDIR=path\to\tk\sources install

!if !exist("makefile.vc")
!error You must run nmake from the directory containing this makefile.
!endif

!if "$(TCLDIR)" == "" || "$(TKDIR)" == ""
!error You must define TCLDIR and TKDIR on the command line as paths to the Tcl and Tk source trees.
!endif

# If relative paths are passed in, we need to convert them to absolute paths.
# Since nmake is so lame, we need to use nmakehlp for the purpose
!if [$(CC) -nologo "nmakehlp.c" -link -subsystem:console > nul]
!error Failed to compiler nmakehlp.
!endif
!if [echo TCLDIR = \> nmakehlp.out] \
   || [nmakehlp -Q "$(TCLDIR)" >> nmakehlp.out]
!error *** Could not fully qualify path TCLDIR="$(TCLDIR)"
!endif

!if [echo TKDIR = \>> nmakehlp.out] \
   || [nmakehlp -Q "$(TKDIR)" >> nmakehlp.out]
!error *** Could not fully qualify path TKDIR="$(TKDIR)"
!endif

!if [echo INSTALLDIR = \>> nmakehlp.out] \
   || [nmakehlp -Q "$(INSTALLDIR)" >> nmakehlp.out]
!error *** Could not fully qualify path INSTALLDIR="$(INSTALLDIR)"
!endif

# We need to undef TCLDIR and TKDIR since macros passed on command line
# do not get overridden from within makefile definitions
!undef INSTALLDIR
!undef TCLDIR
!undef TKDIR
!include nmakehlp.out

# Find out the main TKIMG_VERSION as we need it for the install directory
!if [echo TKIMG_VERSION = \> versions.vc] \
   || [nmakehlp -V ..\base\configure.ac ^[tkimg^] >> versions.vc]
!error Could not determine tkimg base version.
!endif
!include versions.vc
TKIMG_INSTALL_SUBDIR = Img$(TKIMG_VERSION)

ALLMODULES = bmp dted flir gif ico jpeg libjpeg libpng libtiff pcx pixmap png ppm \
	  ps raw sgi sun tga tiff window xbm xpm zlib
!if "$(MODULES)" == ""
MODULES = $(ALLMODULES)
!endif

all: $(MODULES)

base $(ALLMODULES): .PHONY
	echo Making $@
	cd ..\$@\win && $(MAKE) /$(MAKEFLAGS) /f makefile.vc $(TARGET) OPTS=$(OPTS) STATS=$(STATS) CHECKS=$(CHECKS) INSTALLDIR=$(INSTALLDIR) TCLDIR=$(TCLDIR) TKDIR=$(TKDIR)

$(ALLMODULES): base
png: zlib libpng
jpeg: libjpeg
tiff: zlib libjpeg libtiff
libpng: zlib

install:
	$(MAKE) /$(MAKEFLAGS) /f makefile.vc TARGET=install OPTS=$(OPTS) STATS=$(STATS) CHECKS=$(CHECKS) INSTALLDIR=$(INSTALLDIR) TCLDIR=$(TCLDIR) TKDIR=$(TKDIR) TKIMG_INSTALL_SUBDIR=$(TKIMG_INSTALL_SUBDIR)

clean hose realclean: .PHONY
	$(MAKE) /$(MAKEFLAGS) /f makefile.vc TARGET=$@ OPTS=$(OPTS) STATS=$(STATS) CHECKS=$(CHECKS) INSTALLDIR=$(INSTALLDIR) TCLDIR=$(TCLDIR) TKDIR=$(TKDIR)
	@del nmakehlp.out version*.vc nmakehlp.obj nmakehlp.exe

.PHONY:

