garden tote with tools
back link arrowPictools

Makefiles

 two beers
by Zweibieren

Up ArrowPhyspics
Up ArrowAnnals of ZB
Download pictools


Most directories in the web sources tree have a Makefile, but only a small one. For a directory having subdirectories, the Makefile could be as little as
    SUBDIRS = subdirectory-1 subdirectory-2 ...
    include ${PICTOOLS}/MakeVars
    include ${PICTOOLS}/MakeTargets
and if there are no subdirectories, not even the first line is needed. MakeVars defines variables for later use by MakeTargets. Between the two include lines, the client Makefile can set additional values or modify the values of variables already set.

For picture group directories, a Makefile has an additional line pointing to the pictures:

# websrc/annals/2007/Highlights/Makefile
DIGESTDIR = /cygdrive/C/Pictures/2007/Highlights
include $(PICTOOLS)/MakeVars
include $(PICTOOLS)/MakeTargets

NOTE: Spaces in file or directory names will not work with pictools. Symbolic links can get around the problem, if absolutely necessary.

Targets

MakeTargets builds from PICSRC into the staging area at PICSTAGE and then uploads from PICSTAGE to PICSERVER. The nascent pages can be viewed in PICSTAGE.

MakeTargets defines the targets in the following table. The default is buildall. The full text is in MakeTargets.

all
same as buildall, this is the default target for `make'
build transfer local files to DEST (that is, to PICSTAGE/THISDIR)
buildall does the build target in this directory and then in all the SUBDIRS directories
upload makes the buildall target and then uploads to the server all the files from DEST and its subdirectories
newpix if DIGESTDIR has been defined, the newpix target constructs newpix.cap listing all pictures in DIGESTDIR that are not mentioned in existing *.cap files. If newpix.cap exists, the target fails with an error.
clean
removes all files listed in JUNKFILES, including those in LOCALJUNK.
cleanall does the 'clean' target and then recurses through the SUBDIRS to clean them, too

Variables

MakeVars defines the variables noted in susequent paragraphs. Lines followin the "include ...MakeVars" may modify the  variables before they are used by MakeTargets. See also the required environment variables. The full text is in MakeVars.

These first four variables are set by MakeVars and may be used by the client Makefile. The client should ordinarily not change the values.
    THISDIR
        path from $(PICSRC) to $(CURDIR)
        value is something like: annals/2007/halo
    DEST = ${PICSTAGE}/${THISDIR}
        the directory where 'make build' installs files
    SERVER = $(PICSERVER):$(PICSDIR)/${THISDIR}
        'upload' runs 'scp' to copy from DEST to SERVER
    SRC = the original working directory
         (some make rules change to other directories)
DEST and SERVER can be defined in the environment and will override the internal values. This is seldom useful and usually dangerous.

The following variables are not defined by MakeVar, but may be set by the client Makefile to set conditions for MakeTargets.
    SUBDIRS = dir1 dir2 ...
        subdirectories to be 'made' AFTER the current directory;
        the recursive make builds to the same target as this build
    COPYFILES = file1 file2 file3 ...
        'build' copies these files to DEST
        and 'upload' copies them from there to SERVER
    BUILDFILES = files to be generated locally for the 'build' target
        usually these files are NOT copied to the server
    UPLOADFILES = Files to be uploaded. Should come from $(DEST).
        Should be built by other rules.
    DIGESTDIR = name of pictures digest directory
        This directory contains .jpg and other image files
        that are to be viewed from the website.
        Replicas reduced to have maximum dimension 512
        are placed in  DEST and then uploaded.
        Replicas reduced to maximum dimension 128 are
        placed in DEST/thumbs and uploaded thereunder, as well.
    DEFINES = symbol defines for genhtml. Form: -Dsymbol=value
        Typically used to fill in fields in templates.
        example -DtripTitle="Florida, Spring, 2007"
    LOCALJUNK = additional files to be deleted for the 'clean' target.
 
 The following variables are given tentative values in MakeVars
 If the client wants some other value, it can reset them
    IMAGEFILES = *.gif *.jpg *.png
        set in MakeVars to a list of the image files in the current directory.
        That is, it lists all files with extensions .png .gif .jpg
            (The check is case insensitive, accepting: Png, PNG, ...)
        These files are copied to DEST and later uploaded.
    HINFILES = list of .hin files as sources for .html files
        These files are process through genhtml to create
        .html files in DEST. Later the .html files are uploaded.
        HINFILES is initially $(wildcard *.hin), but can be
        changed in the Makefile.
        File xyz.html is generated from xyz.hin by running
            genhtml -o $(DEST)/$(THISDIR)/xyz.html xyz.hin
    CAPTIONS = *.cap
        is set by MakeVars to *.cap. May be set by the
        client to some other value. These files are all
        processed through gendirs to create image viewing pages.
        For each xxx.cap file, MakeTargets generates
        a file called xxx-titles.txt. This has HTML code
        for the elements of a list and should be $included in
        one of the .hin files. That is, the HTML source should
        have something like:
            <ul> $include(xxx-titles.txt) </ul>
        NOTE: If file XXX.hin includes YYY-titles.cap,
        the client must have a dependency line like:
              $(DEST)/XXX.html: YYY-title.txt
    JUNKFILES = *~ $(LOCALJUNK)
         Files to be removed by `make clean'
 
 If DIGESTDIR has been set, then a number of other variables will be set
 They can be changed after the inclusion of MakeVars.
    PICTURES = $(DIGESTDIR)/*.{jpg,gif,png,bmp,JPG,PNG,GIF,BMP}
        the names of the image files in DIGESTDIR.
        The files listed will be uploaded
    INDEXTPL   = $(SRC)/template.tpl
    PICFILETPL = $(SRC)/frame.tpl
    PICCELLTPL = $(SRC)/pictd.tpl
        templates to use for gendirs. If absent from the working
        directory, the version in ${PICTOOLS} is used.
        To use different templates for different .hin files,
        do them in two different directories.
    THUMBCOLS = 3
        how many columns of thumb images to generate from gendirs
    IMAGEMAX = 512, THUMBMAX = 128
        maximum dimension for full-sized and thumb images, respectively

If DIGESTDIR has been assigned a value, and if there are no .cap files, then captions.cap is generated by running gencaps.

MakeResources

A build directory may have a "resources" subdirectory. Sometimes files are generated from it for the ../images directory. MakeResources aids in one kind of image transformation, that of converting files to transparent backgrounds while eliminating the "halo" effect. See TRANSPARENTSURROUND and TRANSPARENTBACKGROUND, below, and the halo page. For the full text, click MakeResources.

A resources Makefile has the form:
    <set some variables>
    include $(PICTOOLS)/MakeResources
    <define build rules as required>

$(PICTOOLS)/MakeVars is included, so the variables defined therein are available. In particular, this Makefile supports SUBDIRS and the targets build and buildall. The upload target is supported only to the extent that it causes the build to happen.

Applicable Variables

The following variables are, or may be, defined:

IMAGESDIR - The directory into which images should be built. Ordinarily this is ../images. The client may assign a different value before including MakeResources.

IMAGEDIRFILES - Names -- without directory - of files to be built or copied into IMAGESDIR. The default is to copy a file. (Although usually such files can simply reside directly in .../images/...)  If the file needs to be built, a rule to build it must be  written. This rule should have the form:
    $(IMAGESDIR)/file: source file(s)
             commands to process the sources and write file $@

BUILDFILES - As in MakeTargets, this variable lists additional files to be created for the 'build' target.  Somewhere in the Makefile there must be rules for generating these files. Their inclusion in BUILDFILES is just to make sure that Make knows when to use these rules.

TRANSPARENTBACKGROUND, TRANSPARENTSURROUND
Lists of files to undergo halo removal. See below.

Halo Removal

When an image is placed on a background, dithering usually leaks colors between the background and the image. Then when the image background is made transparent and  the image is placed on a background of another color, a halo appears around it. Similar artifacts occur when anti-aliasing is applied to soften jagged lines.

MakeResources and Pictools provide two halo reduction tricks; both documented exhaustively. Each makes the background transparent and the halo pixels semi-transparent. When the image is laid over a new background its pixels will glimmer through where the halo used to be. The first trick, TRANSPARENTBACKGROUND, makes transparent
all instances of the background color, even those surrounded by foreground portions of the image. The secondtrick, TRANSPARENTSURROUND, makes transparent only those background color pixels which form the edge and adjacent pixels.

To process a source image thourgh one of these tricks and store it in the IMAGESDIR directory, the file should be included in the list after either TRANSPARENTSURROUND OR TRANSPARENTBACKGROUND. The algorithm works best if the original background is light, or even white.

The commands nobg and nosur are used. By default they treat all pixels within 5% (the default fuzzpct) of the transparent color as also being that color. To use non-default parameters a rule needs to be written for the file. List the desired result file, say $(IMAGESDIR)/ring.png, in the BUILDFILES LIST. Then add a rule for generating that file:
      $(IMAGESDIR)/ring.png: ring.gif
                         nosur -f 20 -b 5x2 $< $@
Copyright boilerplate for zweibieren
Copyright 2008, Zweibieren
8 Aug 2008  11:38 PM
Page maintained by Zweibieren  two steins of beer