# Makefile for pnm tools.
#
# Copyright (C) 1989, 1991 by Jef Poskanzer.
#
# Permission to use, copy, modify, and distribute this software and its
# documentation for any purpose and without fee is hereby granted, provided
# that the above copyright notice appear in all copies and that both that
# copyright notice and this permission notice appear in supporting
# documentation.  This software is provided "as is" without express or
# implied warranty.

CC =            dcc
CFLAGS =        -O0 -E DCC_ERRORS -T RAM: -ffp -ms -mu -gs -proto -mRR
SCFLAGS =        -O0 -E DCC_ERRORS -T RAM: -ffp -ms -mu -gs -proto
TIFFDEF =       -DLIBTIFF
TIFFINC =       -I/libtiff
TIFFLIB =       /libtiff/libtiff.lib
TIFFBINARIES =  tifftopnm pnmtotiff
TIFFOBJECTS =   tifftopnm.o pnmtotiff.o
LDFLAGS =
BINDIR  =       bin

PPMDIR =        /ppm
INCLUDEPPM =    -I$(PPMDIR)
LIBPPM =        $(PPMDIR)/libppm_sr.lib
LARGELIBPPM =   $(PPMDIR)/libppm_lr.lib
STKLIBPPM =     $(PPMDIR)/libppm_l.lib
DEFPPM =        $(PPMDIR)/ppm.h
DEFLIBPPM =     $(PPMDIR)/libppm.h

PGMDIR =        /pgm
INCLUDEPGM =    -I$(PGMDIR)
LIBPGM =        $(PGMDIR)/libpgm_sr.lib
LARGELIBPGM =   $(PGMDIR)/libpgm_lr.lib
STKLIBPGM =     $(PGMDIR)/libpgm_l.lib
DEFPGM =        $(PGMDIR)/pgm.h
DEFLIBPGM =     $(PGMDIR)/libpgm.h

PBMDIR =        /pbm
INCLUDEPBM =    -I$(PBMDIR)
LIBPBM =        $(PBMDIR)/libpbm_sr.lib
LARGELIBPBM =   $(PBMDIR)/libpbm_lr.lib
STKLIBPBM =     $(PBMDIR)/libpbm_l.lib
DEFPBM =        $(PBMDIR)/pbm.h /pbmplus.h
DEFLIBPBM =     $(PBMDIR)/libpbm.h

INCLUDE =       -I/ $(INCLUDEPPM) $(INCLUDEPGM) $(INCLUDEPBM)
ALLCFLAGS =     $(CFLAGS) $(INCLUDE) $(TIFFDEF) $(TIFFINC)
SALLCFLAGS =     $(SCFLAGS) $(INCLUDE) $(TIFFDEF) $(TIFFINC)
LIBPNM =        libpnm_sr.lib
LARGELIBPNM =   libpnm_lr.lib
STKLIBPNM =     libpnm_l.lib

PORTBINARIES =  pnmarith pnmcat pnmconvol pnmcrop pnmcut \
                pnmdepth pnmenlarge pnmfile pnmflip pnmgamma pnminvert \
                pnmnoraw pnmpaste pnmtile \
                pnmtorast pnmtoxwd rasttopnm xwdtopnm
MATHBINARIES =  pnmrotate pnmscale pnmshear pnmtops
BINARIES =      $(PORTBINARIES) $(MATHBINARIES) $(TIFFBINARIES)
SCRIPTS =       anytopnm pnmindex pnmmargin pnmsmooth

PORTOBJECTS =   pnmarith.o pnmcat.o pnmconvol.o pnmcrop.o pnmcut.o \
                pnmdepth.o pnmenlarge.o pnmfile.o pnmflip.o pnminvert.o \
                pnmnoraw.o pnmpaste.o pnmscale.o pnmtile.o pnmtops.o \
                pnmtorast.o pnmtoxwd.o rasttopnm.o xwdtopnm.o \
                pnmgamma.o pnmrotate.o pnmshear.o
OBJECTS =       $(PORTOBJECTS) $(TIFFOBJECTS)



all:            bindir lib binaries

bindir:
                -makedir $(BINDIR)

binaries:       $(BINARIES)



# Rules for plain programs.
$(PORTBINARIES):        pnm.h $(DEFPPM) $(DEFPGM) $(DEFPBM) \
                        $(LIBPNM) $(LIBPPM) $(LIBPGM) $(LIBPBM)
        $(CC) -r $(ALLCFLAGS) $(LDFLAGS) -o $(BINDIR)/$@ $@.c -l $(LIBPNM) -l $(LIBPPM) -l $(LIBPGM) -l $(LIBPBM)

$(TIFFBINARIES):        pnm.h $(DEFPPM) $(DEFPGM) $(DEFPBM) \
                        $(STKLIBPNM) $(STKLIBPPM) $(STKLIBPGM) $(STKLIBPBM) $(TIFFLIB)
        $(CC) -mD -mC $(SALLCFLAGS) $(LDFLAGS) $@.c -o $(BINDIR)/$@ -l $(STKLIBPNM) -l $(STKLIBPPM) -l $(STKLIBPGM) -l $(STKLIBPBM) -l $(TIFFLIB) -lm

# Rule for math-dependent programs.
$(MATHBINARIES):        pnm.h $(DEFPPM) $(DEFPGM) $(DEFPBM) $(LIBPNM) \
                        $(LIBPPM) $(LIBPGM) $(LIBPBM)
        $(CC) -r $(ALLCFLAGS) $(LDFLAGS) -o $(BINDIR)/$@ $@.c -l $(LIBPNM) -l $(LIBPPM) -l $(LIBPGM) -l $(LIBPBM) -lm

# Rule for objects.
#$(OBJECTS):     pnm.h $(DEFPPM) $(DEFPGM) $(DEFPBM)
#        $(CC) $(ALLCFLAGS) "-Dmain=$*_main" -c $*.c

# And libraries.
#$(LIBPBM):
#        cd $(PBMDIR) ; make lib
#$(LIBPGM) FOO:
#        cd $(PGMDIR) ; make lib
#$(LIBPPM) BAR:
#        cd $(PPMDIR) ; make lib
lib:            $(LIBPNM) $(LARGELIBPNM) $(STKLIBPNM)

$(LIBPNM):      libpnm1.or libpnm2.or libpnm3.or libpnm4.or
        -delete $(LIBPNM)
        join libpnm1.or libpnm2.or libpnm3.or libpnm4.or to $(LIBPNM)

libpnm1.or:      pnm.h $(DEFPPM) $(DEFPGM) $(DEFPBM) libpnm1.c
        $(CC) $(ALLCFLAGS) -S -o $@ -c libpnm1.c
libpnm2.or:      pnm.h $(DEFPPM) $(DEFPGM) $(DEFPBM) libpnm2.c $(DEFLIBPPM) \
                $(DEFLIBPGM) $(DEFLIBPBM)
        $(CC) $(ALLCFLAGS) -S -o $@ -c libpnm2.c
libpnm3.or:      pnm.h $(DEFPPM) $(DEFPGM) $(DEFPBM) libpnm3.c $(DEFLIBPPM) \
                $(DEFLIBPGM) $(DEFLIBPBM)
        $(CC) $(ALLCFLAGS) -S -o $@ -c libpnm3.c
libpnm4.or:      pnm.h $(DEFPPM) $(DEFPGM) $(DEFPBM) rast.h libpnm4.c
        $(CC) $(ALLCFLAGS) -S -o $@ -c libpnm4.c


# large data version
$(LARGELIBPNM):      libpnm1.olr libpnm2.olr libpnm3.olr libpnm4.olr
        -delete $(LARGELIBPNM)
        join libpnm1.olr libpnm2.olr libpnm3.olr libpnm4.olr to $(LARGELIBPNM)

libpnm1.olr:      pnm.h $(DEFPPM) $(DEFPGM) $(DEFPBM) libpnm1.c
        $(CC) -mD $(ALLCFLAGS) -S -o $@ -c libpnm1.c
libpnm2.olr:      pnm.h $(DEFPPM) $(DEFPGM) $(DEFPBM) libpnm2.c $(DEFLIBPPM) \
                $(DEFLIBPGM) $(DEFLIBPBM)
        $(CC) -mD $(ALLCFLAGS) -S -o $@ -c libpnm2.c
libpnm3.olr:      pnm.h $(DEFPPM) $(DEFPGM) $(DEFPBM) libpnm3.c $(DEFLIBPPM) \
                $(DEFLIBPGM) $(DEFLIBPBM)
        $(CC) -mD $(ALLCFLAGS) -S -o $@ -c libpnm3.c
libpnm4.olr:      pnm.h $(DEFPPM) $(DEFPGM) $(DEFPBM) rast.h libpnm4.c
        $(CC) -mD $(ALLCFLAGS) -S -o $@ -c libpnm4.c


# large data version, not registerized
$(STKLIBPNM):      libpnm1.ol libpnm2.ol libpnm3.ol libpnm4.ol
        -delete $(STKLIBPNM)
        join libpnm1.ol libpnm2.ol libpnm3.ol libpnm4.ol to $(STKLIBPNM)

libpnm1.ol:      pnm.h $(DEFPPM) $(DEFPGM) $(DEFPBM) libpnm1.c
        $(CC) -mD $(SALLCFLAGS) -S -o $@ -c libpnm1.c
libpnm2.ol:      pnm.h $(DEFPPM) $(DEFPGM) $(DEFPBM) libpnm2.c $(DEFLIBPPM) \
                $(DEFLIBPGM) $(DEFLIBPBM)
        $(CC) -mD $(SALLCFLAGS) -S -o $@ -c libpnm2.c
libpnm3.ol:      pnm.h $(DEFPPM) $(DEFPGM) $(DEFPBM) libpnm3.c $(DEFLIBPPM) \
                $(DEFLIBPGM) $(DEFLIBPBM)
        $(CC) -mD $(SALLCFLAGS) -S -o $@ -c libpnm3.c
libpnm4.ol:      pnm.h $(DEFPPM) $(DEFPGM) $(DEFPBM) rast.h libpnm4.c
        $(CC) -mD $(SALLCFLAGS) -S -o $@ -c libpnm4.c


# Other dependencies.
pnmarith pnmarith.o:            pnmarith.c
pnmcat pnmcat.o:                pnmcat.c
pnmconvol pnmconvol.o:          pnmconvol.c
pnmcrop pnmcrop.o:              pnmcrop.c
pnmcut pnmcut.o:                pnmcut.c
pnmdepth pnmdepth.o:            pnmdepth.c
pnmenlarge pnmenlarge.o:        pnmenlarge.c
pnmfile pnmfile.o:              pnmfile.c
pnmflip pnmflip.o:              pnmflip.c
pnmgamma pnmgamma.o:            pnmgamma.c
pnminvert pnminvert.o:          pnminvert.c
pnmnoraw pnmnoraw.o:            pnmnoraw.c
pnmpaste pnmpaste.o:            pnmpaste.c
pnmrotate pnmrotate.o:          pnmrotate.c
pnmscale pnmscale.o:            pnmscale.c
pnmshear pnmshear.o:            pnmshear.c
pnmtile pnmtile.o:              pnmtile.c
pnmtops pnmtops.o:              pnmtops.c
pnmtorast pnmtorast.o:          pnmtorast.c rast.h
pnmtotiff pnmtotiff.o:          pnmtotiff.c
pnmtoxwd pnmtoxwd.o:            pnmtoxwd.c x11wd.h
rasttopnm rasttopnm.o:          rasttopnm.c rast.h
tifftopnm tifftopnm.o:          tifftopnm.c
xwdtopnm xwdtopnm.o:            xwdtopnm.c x10wd.h x11wd.h

clean:
        -delete \#?.o \#?.or \#?.ol \#?.olr \#?.lib DCC_ERRORS

cleanbin:   clean
        -delete $(BINDIR) all
