AWARE SYSTEMS
TIFF and LibTiff Mail List Archive

1998.11.09 19:27 "Win32 port enhancement", by John McCann

Hello everyone,

I am using libtiff v3.4beta037. I am supporting an application that uses libtiff on multiple UNIX platforms and now windows... I needed to compile libtiff as a Microsoft Windows console application using Microsoft Visual C++ 5.0. I reviewed the README and Makefiles in the contrib directory. They all solved bits and pieces, however, I found them outdated or missing important features. What I was looking for was a way to take my unix application to a WIN95/NT machine and simply type make (or nmake in this case). After reviewing the information in contrib, I was not able to find a makefile that would just simply work. After taking the time to come up with something, I figured the least I could do is share it.

In contrib/win32 Sam mentions Scott Wagners patches were applied (and they work fine). However, his tif_win32.c assumes you are writing a windows program and want window messages boxes. I did not have this requirement. I included a patch to tif_win32.c where I copied unixWarningHandler and unixErrorHandler from tif_unix.c and compile them based on the -D_CONSOLE compile flag. This compiles libtiff as a pure windows console application. Philippe Tenenhaus makefile.w95 is out of date for the new Microsoft compilers. It was also missing support for compiling mkversion.exe, mkg3states.exe. Also lacking was fax3 support. I then took a look at the contrib/winnt directory. As a side note, Dave Dyers url that is mentioned is old and apparently no longer valid. His makefile appears to be out of date, and lacks support for mkversion.exe and mkg3states.exe. Xingong Changs approach was good, however, using tif_msdos.c instead of tif_win32.c is taking a step backwards. Scott Wagners tif_win32.c using Microsoft version of mmap files and utilizing Microsoft memory and file management utilities is definitely a plus. Xingongs README.console mentions needed modifications to tif_fax.c and tif_fax3.c, I didn't find this necessary.

Since my experience with libtiff is mainly on UNIX platforms I based my makefiles on the unix makefile.in. The main change I made to the libtiff makefile was to use Scott Wagners tif_win32.c. instead of tif_unix.c and I added flags for jpeg support. The makefile for the tools directory was just a straight port from the unix makefile.in. I needed to make slight changes to some of the tools (just included the windows headers instead of the unix ones, nothing major). The changes will not effect any of the unix code. I used Microsoft's nmake program to compile the library. It's important to note that this will compile the library to uses the DLL version of the Microsoft runtime. If you statically link the Microsoft runtime into your executable, change all occurances of $(cvarsdll) to $(cvarsmt) and $(conlibsdll) to $(conlibsmt).

Thanks, I hope this is useful to someone...

John McCann
jmccann@feith.com

========================================================================
LIBTIFF DIRECTORY MAKEFILE.NT
Microsoft Visual C++ 5.0 (based upon Unix Makefile.in)
========================================================================
#       $Header: /d1/sam/tiff/libtiff/RCS/Makefile.in,v 1.43 1997/08/29 22:47:50 sam Exp $
#
# Tag Image File Format Library
#
# Copyright (c) 1988-1997 Sam Leffler
# Copyright (c) 1991-1997 Silicon Graphics, Inc.

# Permission to use, copy, modify, distribute, and sell this software and 
# its documentation for any purpose is hereby granted without fee, provided
# that (i) the above copyright notices and this permission notice appear in
# all copies of the software and related documentation, and (ii) the names of
# Sam Leffler and Silicon Graphics may not be used in any advertising or
# publicity relating to the software without the specific, prior written
# permission of Sam Leffler and Silicon Graphics.

# THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, 
# EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY 
# WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  

# IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
# ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
# OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
# WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF 
# LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 
# OF THIS SOFTWARE.
#

!include <ntwin32.mak>

SRCDIR  = .

#
# VERSION:      v3.4beta037
# DATE:         Thu Nov  5 11:19:23 EST 1998
# TARGET:       x86
# CCOMPILER:    Microsoft Visual C++ Verion 5.0
#
#SHELL   = /usr/bin/sh
NULL    =
CC      = $(cc)
#AR      = /usr/ccs/bin/ar
#AROPTS  = rc
#RANLIB  = /usr/ccs/bin/ranlib
#INSTALL = ${SHELL} ../port/install.sh

#
# If JPEG support is to be included and the Independent JPEG
# Software distribution is not installed then DIR_JPEG must
# refer to the directory where the include files reside.
#
DIR_JPEG = -I \local\src\jpeg
LIB_JPEG = \local\src\jpeg\libjpeg.lib

# Similarly, if the libgz distribution is not installed, then
# DIR_LIBGZ must refer to the directory where the include files
# are located.  Note that recent versions 
#
IPATH   = -I . -I $(SRCDIR) $(DIR_JPEG)
#
# To enable JPEG support include -DJPEG_SUPPORT here.
# To enable Deflate support add a -DZIP_SUPPORT here.
# Note that where the configure script is used these defines
# are automatically setup when JPEG/ZIP is set to "yes".
#
# Otherwise, consult tiffconf.h for information on controlling
# the configuration of optional library support.
#
CONF_LIBRARY= -D_CONSOLE -DHAVE_BOOLEAN -DJPEG_SUPPORT
COPTS   = $(cdebug) $(cflags) $(cvarsdll)
OPTIMIZER= 
CFLAGS  = $(COPTS) $(OPTIMIZER) $(IPATH) $(CONF_LIBRARY)
#
SRCS    = \
        tif_aux.c \
        tif_close.c \
        tif_codec.c \
        tif_compress.c \
        tif_dir.c \
        tif_dirinfo.c \
        tif_dirread.c \
        tif_dirwrite.c \
        tif_dumpmode.c \
        tif_error.c \
        tif_fax3.c \
        tif_fax3sm.c \
        tif_getimage.c \
        tif_jpeg.c \
        tif_flush.c \
        tif_luv.c \
        tif_lzw.c \
        tif_next.c \
        tif_open.c \
        tif_packbits.c \
        tif_pixarlog.c \
        tif_predict.c \
        tif_print.c \
        tif_read.c \
        tif_swab.c \
        tif_strip.c \
        tif_thunder.c \
        tif_tile.c \
        tif_win32.c \
        tif_version.c \
        tif_warning.c \
        tif_write.c \
        tif_zip.c \
        $(NULL)
OBJS    = \
        tif_aux.obj \
        tif_close.obj \
        tif_codec.obj \
        tif_compress.obj \
        tif_dir.obj \
        tif_dirinfo.obj \
        tif_dirread.obj \
        tif_dirwrite.obj \
        tif_dumpmode.obj \
        tif_error.obj \
        tif_fax3.obj \
        tif_fax3sm.obj \
        tif_getimage.obj \
        tif_jpeg.obj \
        tif_flush.obj \
        tif_luv.obj \
        tif_lzw.obj \
        tif_next.obj \
        tif_open.obj \
        tif_packbits.obj \
        tif_pixarlog.obj \
        tif_predict.obj \
        tif_print.obj \
        tif_read.obj \
        tif_swab.obj \
        tif_strip.obj \
        tif_thunder.obj \
        tif_tile.obj \
        tif_win32.obj \
        tif_version.obj \
        tif_warning.obj \
        tif_write.obj \
        tif_zip.obj \
        $(NULL)
TARGETS = libtiff.a

all:    $(TARGETS)


libtiff.a: $(OBJS)
    lib -out:libtiff.lib $(OBJS) $(LIB_JPEG)

#
# DSO Support admitted
#

$(OBJS): $(SRCDIR)/tiffio.h $(SRCDIR)/tiff.h $(SRCDIR)/tif_dir.h
$(OBJS): $(SRCDIR)/tiffcomp.h $(SRCDIR)/tiffiop.h $(SRCDIR)/tiffconf.h

ALPHA   = ../dist/tiff.alpha
VERSION = ../version

version.h: $(VERSION) $(ALPHA) $(SRCDIR)/mkversion.c $(SRCDIR)/mkversion.obj
    $(link) $(ldebug) $(conlflags) -out:mkversion.exe \
      $(SRCDIR)/mkversion.obj $(conlibsdll)
        del version.h
    .\mkversion -v $(VERSION) -a $(ALPHA) version.h
tif_version.obj: version.h

#
# The finite state machine tables used by the G3/G4 decoders
# are generated by the mkg3states program.  On systems without
# make these rules have to be manually carried out.
#

tif_fax3sm.c: $(SRCDIR)/mkg3states.c $(SRCDIR)/tif_fax3.h \
              $(SRCDIR)/mkg3states.obj $(SRCDIR)/getopt.obj
    $(link) $(ldebug) $(conlflags) -out:mkg3states.exe \
      $(SRCDIR)/mkg3states.obj getopt.obj $(conlibsdll)
    del tif_fax3sm.c
    .\mkg3states -c const tif_fax3sm.c

getopt.obj: ../port/getopt.c
    $(CC) $(CFLAGS) ../port/getopt.c

.c.obj:
    $(CC) $(CFLAGS) $<

INCS    = $(SRCDIR)/tiff.h $(SRCDIR)/tiffio.h

clean:
        del *.obj
        del libtiff.lib 
        del tif_fax3sm.c
        del mkg3states.exe 
        del version.h 
        del mkversion.exe 



========================================================================
TOOLS DIRECTORY MAKEFILE.NT
Microsoft Visual C++ 5.0 Makefile (based upon Unix Makefile.in)
========================================================================
#       $Header: /d1/sam/tiff/tools/RCS/Makefile.in,v 1.22 1997/08/29 21:46:45 sam Exp $
#
# @WARNING@
#
# TIFF Library Tools
#
# Copyright (c) 1988-1997 Sam Leffler
# Copyright (c) 1991-1997 Silicon Graphics, Inc.

# Permission to use, copy, modify, distribute, and sell this software and 
# its documentation for any purpose is hereby granted without fee, provided
# that (i) the above copyright notices and this permission notice appear in
# all copies of the software and related documentation, and (ii) the names of
# Sam Leffler and Silicon Graphics may not be used in any advertising or
# publicity relating to the software without the specific, prior written
# permission of Stanford and Silicon Graphics.

# THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, 
# EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY 
# WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  

# IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
# ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
# OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
# WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF 
# LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 
# OF THIS SOFTWARE.
#

!include <ntwin32.mak>

DEPTH   = ..

SRCDIR  = .
LIBDIR  = $(DEPTH)\libtiff

#
# VERSION:      v3.4beta037
# DATE:         Thu Nov  5 11:19:23 EST 1998
# TARGET:       x86
# CCOMPILER:    Microsoft Visual C++ Verion 5.0
#
#SHELL  = @SCRIPT_SH@
NULL    =
CC      = $(cc)
#INSTALL        = @INSTALL@
#
COPTS   = $(cdebug) $(cflags) $(cvarsdll)
OPTIMIZER=
IPATH   = -I. -I$(LIBDIR)
CFLAGS  = $(COPTS) $(OPTIMIZER) $(IPATH)
#
TIFFLIB = $(DEPTH)\libtiff\libtiff.lib
LIBJPEG = \local\src\jpeg\libjpeg.lib
LIBGZ   = 
LIBTIFF = $(DEPTH)\libtiff\libtiff.lib
LIBPORT = 
MACHLIBS= $(conlibsdll)
LIBS    = $(LIBTIFF) $(LIBJPEG) $(LIBGZ) $(LIBPORT) $(MACHLIBS)
#
OBJS=   \
        getobj.obj  \
        fax2tiff.obj \
        fax2ps.obj \
        gif2tiff.obj \
        pal2rgb.obj \
        ppm2tiff.obj \
        rgb2ycbcr.obj \
        ras2tiff.obj \
        thumbnail.obj \
        tiff2bw.obj \
        tiff2ps.obj \
        tiffcmp.obj \
        tiffcp.obj \
        tiffdither.obj \
        tiffdump.obj \
        tiffinfo.obj \
        tiffmedian.obj \
        tiffsplit.obj \
        $(NULL)
TARGETS =\
        fax2tiff.exe \
        fax2ps.exe \
        gif2tiff.exe \
        pal2rgb.exe \
        ppm2tiff.exe \
        rgb2ycbcr.exe \
        thumbnail.exe \
        ras2tiff.exe \
        tiff2bw.exe \
        tiff2ps.exe \
        tiffcmp.exe \
        tiffcp.exe \
        tiffdither.exe \
        tiffdump.exe \
        tiffinfo.exe \
        tiffmedian.exe \
        tiffsplit.exe \
        $(NULL)

.c.obj:
        $(CC) $(CFLAGS) $<

.obj.exe:
        $(link) $(ldebug) $(conlflags) $< getopt.obj $(LIBS)

all:    $(TARGETS)

clean:
        del *.exe
        del *.obj

#
# System-independent tools
#
getopt.obj: $(DEPTH)\port\getopt.c
        $(CC) $(CFLAGS) ..\port\getopt.c

tiffinfo.exe: tiffinfo.obj getopt.obj $(TIFFLIB)
tiffinfo.obj: $(SRCDIR)\tiffinfo.c

tiffcmp.exe:tiffcmp.obj getopt.obj $(TIFFLIB)
tiffcmp.obj: $(SRCDIR)\tiffcmp.c

tiffcp.exe:     tiffcp.obj getopt.obj $(TIFFLIB)
tiffcp.obj: $(SRCDIR)\tiffcp.c

tiffdump.exe: tiffdump.obj getopt.obj $(TIFFLIB)
tiffdump.obj: $(SRCDIR)\tiffdump.c

tiffmedian.exe: tiffmedian.obj getopt.obj $(TIFFLIB)
tiffmedian.obj: $(SRCDIR)\tiffmedian.c

tiffsplit.exe: tiffsplit.obj getopt.obj $(TIFFLIB)
tiffsplit.obj: $(SRCDIR)\tiffsplit.c

tiff2ps.exe: tiff2ps.obj getopt.obj $(TIFFLIB)
tiff2ps.obj: $(SRCDIR)\tiff2ps.c

#
# Junky stuff... programs that are more examples of how
# to use the library than full-blown useful tools.
#

# convert RGB image to B&W
tiff2bw.exe: tiff2bw.obj getopt.obj $(TIFFLIB)
tiff2bw.obj: $(SRCDIR)\tiff2bw.c

# convert B&W image to bilevel w/ FS dithering
tiffdither.exe: tiffdither.obj getopt.obj $(TIFFLIB)
tiffdither.obj: $(SRCDIR)\tiffdither.c

# simple Sun rasterfile converter
ras2tiff.exe: ras2tiff.obj getopt.obj $(TIFFLIB)
ras2tiff.obj: $(SRCDIR)\ras2tiff.c

# simple GIF converter
gif2tiff.exe: gif2tiff.obj getopt.obj $(TIFFLIB)
gif2tiff.obj: $(SRCDIR)\gif2tiff.c

# very limited PBM converter
ppm2tiff.exe: ppm2tiff.obj getopt.obj $(TIFFLIB)
ppm2tiff.obj: $(SRCDIR)\ppm2tiff.c

# Group 3/4 FAX file converter
fax2tiff.exe: fax2tiff.obj getopt.obj $(TIFFLIB)
fax2tiff.obj: $(SRCDIR)\fax2tiff.c

# Group 3/4 FAX to encoded PS converter
fax2ps.exe: fax2ps.obj getopt.obj $(TIFFLIB)
fax2ps.obj: $(SRCDIR)\fax2ps.c

# convert Palette image to RGB
pal2rgb.exe: pal2rgb.obj getopt.obj $(TIFFLIB)
pal2rgb.obj: $(SRCDIR)\pal2rgb.c

# convert RGB image to YCbCr
rgb2ycbcr.exe: rgb2ycbcr.obj getopt.obj $(TIFFLIB)
rgb2ycbcr.obj: $(SRCDIR)\rgb2ycbcr.c

# generate thumbnail images from fax (example of SubIFD usage)
thumbnail.exe: thumbnail.obj getopt.obj $(TIFFLIB)
thumbnail.obj: $(SRCDIR)\thumbnail.c

========================================================================
Required Patches
========================================================================

*** libtiff/tif_win32.c.ORIGINAL        Tue Sep  2 13:54:31 1997
--- libtiff/tif_win32.c Thu Nov  5 14:16:26 1998
*************** _tiffSizeProc(thandle_t fd)
*** 83,89 ****
        return ((toff_t)GetFileSize(fd, NULL));
  }
  
- #pragma argsused
  static int
  _tiffDummyMapProc(thandle_t fd, tdata_t* pbase, toff_t* psize)
  {
--- 83,88 ----
*************** _tiffMapProc(thandle_t fd, tdata_t* pbas
*** 120,126 ****
        return(1);
  }
  
- #pragma argsused
  static void
  _tiffDummyUnmapProc(thandle_t fd, tdata_t base, toff_t size)
  {
--- 119,124 ----
*************** _TIFFmemcmp(const tdata_t p1, const tdat
*** 247,252 ****
--- 245,275 ----
        return (iTmp);
  }
  
+ #if defined(_CONSOLE)

+ static void
+ consoleWarningHandler(const char* module, const char* fmt, va_list ap)
+ {
+         if (module != NULL)
+                 fprintf(stderr, "%s: ", module);
+         fprintf(stderr, "Warning, ");
+         vfprintf(stderr, fmt, ap);
+         fprintf(stderr, ".\n");
+ }
+ TIFFErrorHandler _TIFFwarningHandler = consoleWarningHandler;

+ static void
+ consoleErrorHandler(const char* module, const char* fmt, va_list ap)
+ {
+         if (module != NULL)
+                 fprintf(stderr, "%s: ", module);
+         vfprintf(stderr, fmt, ap);
+         fprintf(stderr, ".\n");
+ }
+ TIFFErrorHandler _TIFFerrorHandler = consoleErrorHandler;

+ #else

  static void
  Win32WarningHandler(const char* module, const char* fmt, va_list ap)
  {
*************** Win32ErrorHandler(const char* module, co
*** 286,288 ****
--- 309,313 ----
        return;
  }
  TIFFErrorHandler _TIFFerrorHandler = Win32ErrorHandler;

+ #endif
*** tools/tiffdump.c.ORIGINAL   Tue Sep  2 13:54:39 1997
--- tools/tiffdump.c    Thu Nov  5 14:16:26 1998
***************
*** 31,37 ****
  #if defined(VMS)
  #include <unixio.h>
  #include <file.h>
! #elif defined(_WINDOWS)
  #include <io.h>
  #define       off_t   toff_t
  #include "tiffio.h"
--- 31,37 ----
  #if defined(VMS)
  #include <unixio.h>
  #include <file.h>
! #elif defined(_WINDOWS) || defined(_WIN32)
  #include <io.h>
  #define       off_t   toff_t
  #include "tiffio.h"
*** tools/fax2ps.c.ORIGINAL     Tue Sep  2 13:54:34 1997
--- tools/fax2ps.c      Thu Nov  5 14:16:26 1998
***************
*** 28,37 ****
  #include <string.h>
  #include <stdlib.h>
  #include <time.h>
! #ifndef VMS
! #include <unistd.h>
! #else
  #include <unixio.h>
  #endif
  
  #include "tiffio.h"
--- 28,39 ----
  #include <string.h>
  #include <stdlib.h>
  #include <time.h>
! #if defined(VMS)
  #include <unixio.h>
+ #elif defined(_WIN32)
+ #include <io.h>
+ #else
+ #include <unistd.h>
  #endif
  
  #include "tiffio.h"
*** tools/thumbnail.c.ORIGINAL  Tue Sep  2 13:54:38 1997
--- tools/thumbnail.c   Thu Nov  5 14:16:26 1998
***************
*** 30,36 ****
--- 30,40 ----
  
  #include "tiffio.h"
  
+ #if defined(_WIN32)
+ #define       streq(a,b)      (stricmp(a,b) == 0)
+ #else
  #define       streq(a,b)      (strcasecmp(a,b) == 0)
+ #endif
  
  #ifndef howmany
  #define       howmany(x, y)   (((x)+((y)-1))/(y))