#
# $Id
#
# This is not a proper HOWTO, just a quick guide on how to compile imview for Windows using MSVC++
#
# This document references imview-1.0.x
#

1- Introduction
===============

I'm an old Unix hand but I now program regularly in C/C++ using
Microsoft Visual Studio, version 6.0.  While I can't speak for
everybody, MSVC++ has a few quirks, which for the uninitiated might be
a bit daunting. I don't particularly like the compiler (not very ISO
compliant) but it dates back from 1998, the C++ library is from
DinkumWare and all things considered I'm happy to continue maintaining
Imview for it until I get a newer version, even if that means a
reasonable number of #defines in my code.

The rest of this document explains what is special with compiling
imview for that environment.

2- Prerequisite
===============

You need to be reasonably familiar with visual studio. It's all fairly
intuitive but you need to know where the menu items are.

You will need to compile with MSVC++:

-  the FLTK library http://www.fltk.org 
-  the pthread-win32 library http://wwwhttp://sources.redhat.com/pthreads-win32/

Optionally:

-  the TIFF library: http://www.libtiff.org
-  the JPEG library: http://www.ijg.org/files/ 

Even more optionally:

-  the ImageMagick library: http://www.imagemagick.org/

Note: Good luck with that one, let me know if you succeed.

<rant> While I respect and even use that library (imagemagick) I don't
like it. 

The major problem with ImageMagick is the unstability of the API. Look
at the series of tests in configure.in to find out precisely what the
version of ImageMagick is so I can tell which API to use. Some of the
changes are purely gratuitous (a silly change of name for a function),
some are more fundamental. All are very annoying.
</rant>

The project file assumes that you have compiled the TIFF and JPEG
libraries but not the ImageMagick one.

3- Directory structure
======================

Being a Unix guy I don't like putting together huge project files, I
like my projects to be independent. That's why I compile the various
libraries separately and the copy the useful files under a
directory tree structure.

The directory tree in question by default is 

H:\win32\msvc

(I use various compilers, hence the \msvc).

The main subdirectories in there are:

H:\win32\msvc\bin
H:\win32\msvc\lib
H:\win32\msvc\include

There might be others but at this stage they don't matter. My general
recommendation for this project is to put all the .lib and .dlls in
\lib, all the .h, etc in \include and all the .exe in \bin.

If you have a different drive letter and/or directory structure, you
will need to edit the imview.dsp file (preferably from within visual
studio using the project preference dialog). Look for H:\win32\msvc in
the include path and in the library path.

4- Compiling the libraries
==========================

One thing to watch for is to make sure all the libraries are compiled with
a compatible C library. Since imview is multithreaded, we need the MT
DLL, either debug or not (MSVCRTD.DLL/MSVCRT.DLL). If you have problems at 
link time this is the parameter to watch.

In the libraries controlled by a .dsp file for Visual Studio, this is easy
to do, just verify that the project's settings are fine (Alt+F7 -> C++ tab 
-> Code generation -> select [Debug] Multithreaded DLL


Compiling FLTK
--------------

This is very easy as a .dsw is provided. Just compile fltk*.lib, copy them from 
<fltk-dir>/lib to H:\win32\msvc\lib ; don't bother with the demos (unless you want
to of course). You should end up with an fltkd.lib if you compile the  debug 
version and an fltk.lib if you compile the optimized one.


Copy the whole of <fltk-dir>/FL/*.* to  H:\win32\msvc\include\FL\

Don't bother with the dlls, as fltk is really small.

If you want to be able to edit imview's dialog boxes you will
certainly need to compile and install the `fluid.exe' project (see
below the section on modifying imview).


Compiling pthread-win32
-----------------------

Don't even do it as a precompiled package is available. Copy the
libraries and include files in the default directories as above. The
library for MSVC you want to use is `pthreadVCE.lib', that's the one
by default in the project.

If you want to re-make this library you can. The pre-compiled one
works for me.

Compiling TIFF
--------------

unpack the library sources, cd to libtiff and, from the `DOS' console, type:

H:> cd tiff-v3.5.7\libtiff

Change the line:

- CFLAGS  = /nologo /W3 $(INCL) $(WINMODE)
+ CFLAGS  = /nologo /W3 /D_MT /D_DLL /MD $(INCL) $(WINMODE)

H:> nmake /f makefile.vc all
H:> copy libtiff.lib libtiff.dll h:\win32\msvc\lib
H:> copy tiffvers.h tiffio.h tiff.h tiffconf.h h:\win32\msvc\lib

Done.

Compiling JPEG
--------------

You should read the install.doc file (not a Word document, just plain text), but here
is a condensed version that works for me:


H:> cd jpeg-6b
H:> copy jconfig.vc jconfig.h
H:> copy makelib.ds jpeg.mak
H:> copy makeapps.ds apps.mak

You will want to change the following:

- CFLAGS= $(cflags) $(cdebug) $(cvars) -I
+ CFLAGS= $(cflags) $(cdebug) $(cvarsdll) -I.

- LDLIBS= $(conlibs)
+ LDLIBS= $(conlibsdll)

To link with the multhreaded DLLs.

H:> nmake /f makefile.vc [nodebug=1]

The instructions say to go and grab a cup of coffee, but you have to be quick to do
that these days before the compilation is over. After that:

H:> copy libjpeg.lib h:\win32\msvc\lib\
H:> copy jconfig.h jerror.h jmorecfg.h jpeglib.h h:\win32\msvc\include\


Compiling Imview
================

Once you have all the libraries installed, you can just fire up the
imview.dsw file and click on `build imview'

You will see a few warnings along the lines of:

1- identifier truncated to 255 chars (a great classic) 

2- a couple of complaints about `this' in constructor initialization
list (this is fine, read
http://www.parashift.com/c++-faq-lite/ctors.html#faq-10.7).


Other than that it should compile, link and run cleanly.

Modifying Imview
================

Because MSVC++ 6.0 is an older compiler there are a few missing
ISO/C++ features. There are quite a few #define in the code to work
around most problems, but as a result the MSVC++-compiled version of
imview a lso has some reduce features. This is something to watch for.

If you want to change the dialog boxes you will need to compile the
.fl files into .cxx and .hxx files -- After your changes you will need
to run `fluid' manually like so:

H:> fluid -h .hxx -o .cxx -c <dialogfile.fl>

Note that there is a small problem with `toolbardlg.fl' because of the
embedded icons. The C++ code generated is fine but MSVC++ is incapable
of compiling it, you will need to edit the resulting `toolbardlg.cxx'
to put in some manual casts along the lines of:

- static Fl_Pixmap pixmap_zoom_s(image_zoom_s);
+ static Fl_Pixmap pixmap_zoom_s((char *const*)image_zoom_s);

There are half a dozen such lines to change like so.

No other compiler I've tried has any problem with the original code
generated by fluid, but MSVC++ does.
