# Makefile for ppm tools, for use with Amiga DICE
#
# Copyright (C) 1989, 1991 by Jef Poskanzer.
# Modified for Amiga DICE by Ingo Wilken (Ingo.Wilken@informatik.uni-oldenburg.de)
#
# 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.

# CONFIG: generate executable with debugging information
#DEBUG =     -s -d1
# CONFIG: use memory pools
#MPOOL =     -L/amiga -l mpool

CC =            dcc
CFLAGS =        -E DCC_ERRORS -ms -mu -gs $(DEBUG)
#RGBDEF =        -DRGB_DB="RGBDEF"
LDFLAGS =       $(MPOOL) /amiga/dice_stack.o
BINDIR =        bin
MERGE=          ppmmerge

# where to install the binaries, libraries and important header files
INSTALLBIN =    bin:pbmplus
INSTALLLIB =    dlib:local
INSTALLINCL=    dinclude:local
# install which headers
HEADERS=        ppm.h ppmcmap.h ppmdraw.h /pbmplus.h

PBMDIR =        /pbm
INCLUDEPBM =    -I$(PBMDIR)
RLIBPBM =       $(PBMDIR)/pbmsr.lib
RLLIBPBM =      $(PBMDIR)/pbmrl.lib
SLIBPBM =       $(PBMDIR)/pbms.lib
SLLIBPBM =      $(PBMDIR)/pbml.lib
DEFPBM =        $(PBMDIR)/pbm.h /pbmplus.h
DEFLIBPBM =     $(PBMDIR)/libpbm.h

PGMDIR =        /pgm
INCLUDEPGM =    -I$(PGMDIR)
RLIBPGM =       $(PGMDIR)/pgmsr.lib
RLLIBPGM =      $(PGMDIR)/pgmrl.lib
SLIBPGM =       $(PGMDIR)/pgms.lib
SLLIBPGM =      $(PGMDIR)/pgml.lib
DEFPGM =        $(PGMDIR)/pgm.h
DEFLIBPGM =     $(PGMDIR)/libpgm.h

INCLUDE =       -I/ $(INCLUDEPGM) $(INCLUDEPBM)
RALLCFLAGS =    $(CFLAGS) $(RGBDEF) $(INCLUDE) -proto -mRR
SALLCFLAGS =    $(CFLAGS) $(RGBDEF) $(INCLUDE) -proto
MALLCFLAGS =    $(CFLAGS) $(RGBDEF) $(INCLUDE) -mC -mD
DEFPPM =        ppm.h
DEFLIBPPM =     libppm.h
RLIBPPM =       ppmsr.lib
RLLIBPPM =      ppmrl.lib
SLIBPPM =       ppms.lib
SLLIBPPM =      ppml.lib


LIBRARIES =     $(RLIBPPM) $(RLLIBPPM) $(SLIBPPM) $(SLLIBPPM)

BINS =          gouldtoppm hpcdtoppm imgtoppm mtvtoppm \
                pcxtoppm pi1toppm pjtoppm ppm3d ppmchange ppmdither \
                ppmhist ppmquant ppmrelief ppmshift ppmspread \
                ppmtogif ppmtoicr ppmtoilbm ppmtopcx ppmtopgm ppmtopi1 \
                ppmtopict ppmtopj ppmtopuzz ppmtorgb3 ppmtosixel \
                ppmtotga ppmtouil ppmtoxpm ppmtoyuv qrttoppm \
                rawtoppm rgb3toppm ximtoppm yuvtoppm \
                bmptoppm ppmtobmp ppmdist ppmtoyuvsplit yuvsplittoppm \
                ppmbrighten ppmtomitsu picttoppm xvminitoppm

MATHBINS =      ilbmtoppm ppmtoacad pgmtoppm ppmforge ppmmake sldtoppm \
                xpmtoppm  ppmtopjxl ppmnorm ppmdim ppmflash ppmmix \
                ppmntsc

LBINS    =      spctoppm sputoppm tgatoppm \
                ppmtomap

LMATHBINS =     ppmqvga

SLBINS =        ppmpat

BINARIES =      $(BINS) $(MATHBINS) $(LBINS) $(SLBINS) $(LMATHBINS)

SCRIPTS =       ppmquantall

OBJECTS =       gouldtoppm.om hpcdtoppm.om ilbmtoppm.om imgtoppm.om mtvtoppm.om \
                pcxtoppm.om pgmtoppm.om pi1toppm.om picttoppm.om \
                pjtoppm.om ppm3d.om ppmchange.om ppmdim.om ppmdither.om ppmflash.om ppmhist.om \
                ppmmake.om ppmmix.om ppmntsc.om ppmquant.om ppmrelief.om \
                ppmshift.om ppmspread.om \
                ppmtoacad.om ppmtogif.om ppmtoicr.om \
                ppmtoilbm.om ppmtopcx.om ppmtopgm.om ppmtopi1.om ppmtopict.om \
                ppmtopj.om ppmtopuzz.om ppmtorgb3.om ppmtosixel.om \
                ppmtotga.om ppmtouil.om ppmtoxpm.om ppmtoyuv.om qrttoppm.om \
                rawtoppm.om rgb3toppm.om sldtoppm.om spctoppm.om sputoppm.om \
                tgatoppm.om ximtoppm.om xpmtoppm.om yuvtoppm.om \
                ppmforge.om ppmpat.om bmptoppm.om ppmtobmp.om ppmdist.om \
                ppmtomap.om ppmtoyuvsplit.om yuvsplittoppm.om \
                ppmbrighten.om ppmtomitsu.om ppmtopjxl.om ppmnorm.om \
                ppmqvga.om xvminitoppm.om

all:            lib binaries

bindir:
                -makedir $(BINDIR)

binaries:       lib bindir $(BINARIES)

lib:            $(LIBRARIES)

merge:          lib bindir $(MERGE)


# Rules for merged binary
.c.om:       $(DEFPPM) $(DEFPGM) $(DEFPBM) $<
        $(CC) -proto $(MALLCFLAGS) "-Dmain=$*_main" -c $*.c -o $*.om
$(MERGE):   ppmmerge.c $(OBJECTS) $(SLLIBPPM) $(SLLIBPGM) $(SLLIBPBM)
        $(CC) $(MALLCFLAGS) $(LDFLAGS) -o $(BINDIR)/$@ $@.c $(OBJECTS) -l $(SLLIBPPM) -l $(SLLIBPGM) -l $(SLLIBPBM) -lm
#$(OBJECTS):     $(DEFPPM) $(DEFPGM) $(DEFPBM)
#        $(CC) -mD -mC $(SALLCFLAGS) "-Dmain=$*_main" -c $*.c


# Rule for plain programs.
$(BINS):        $(DEFPPM) $(DEFPGM) $(DEFPBM) $(RLIBPPM) $(RLIBPGM) $(RLIBPBM)
        $(CC) -r $(RALLCFLAGS) $(LDFLAGS) -o $(BINDIR)/$@ $@.c -l $(RLIBPPM) -l $(RLIBPGM) -l $(RLIBPBM)

$(LBINS):       $(DEFPPM) $(DEFPGM) $(DEFPBM) $(RLLIBPPM) $(RLLIBPGM) $(RLLIBPBM)
        $(CC) -mD -mC $(RALLCFLAGS) $(LDFLAGS) -o $(BINDIR)/$@ $@.c -l $(RLLIBPPM) -l $(RLLIBPGM) -l $(RLLIBPBM)

$(SLBINS):      $(DEFPPM) $(DEFPGM) $(DEFPBM) $(SLLIBPPM) $(SLLIBPGM) $(SLLIBPBM)
        $(CC) -mD -mC $(SALLCFLAGS) $(LDFLAGS) -o $(BINDIR)/$@ $@.c -l $(SLLIBPPM) -l $(SLLIBPGM) -l $(SLLIBPBM)

# Rule for math-dependent programs.
$(MATHBINS):    $(DEFPPM) $(DEFPGM) $(DEFPBM) $(RLIBPPM) $(RLIBPGM) $(RLIBPBM)
        $(CC) -r $(RALLCFLAGS) $(LDFLAGS) -o $(BINDIR)/$@ $@.c -l $(RLIBPPM) -l $(RLIBPGM) -l $(RLIBPBM) -lm

$(LMATHBINS):   $(DEFPPM) $(DEFPGM) $(DEFPBM) $(RLLIBPPM) $(RLLIBPGM) $(RLLIBPBM)
        $(CC) -mD -mC $(RALLCFLAGS) $(LDFLAGS) -o $(BINDIR)/$@ $@.c -l $(RLLIBPPM) -l $(RLLIBPGM) -l $(RLLIBPBM) -lm


# And libraries.
#$(LIBPBM):
#        cd $(PBMDIR) ; make lib
#$(LIBPGM):
#        cd $(PGMDIR) ; make lib

# small data version of libppm
$(RLIBPPM):      libppm1.or libppm2.or libppm3.or libppm4.or libppm5.or bitio.or
        -delete $(RLIBPPM)
        join libppm1.or libppm2.or libppm3.or libppm4.or libppm5.or bitio.or to $(RLIBPPM)
libppm1.or:      $(DEFPPM) $(DEFPGM) $(DEFPBM) $(DEFLIBPPM) libppm1.c
        $(CC) -r $(RALLCFLAGS) -S -o $@ -c libppm1.c
libppm2.or:      $(DEFPPM) $(DEFPGM) $(DEFPBM) $(DEFLIBPPM) libppm2.c $(DEFLIBPGM) $(DEFLIBPBM)
        $(CC) -r $(RALLCFLAGS) -S -o $@ -c libppm2.c
libppm3.or:      $(DEFPPM) $(DEFPGM) $(DEFPBM) ppmcmap.h $(DEFLIBPPM) libppm3.c
        $(CC) -r $(RALLCFLAGS) -S -o $@ -c libppm3.c
libppm4.or:      $(DEFPPM) $(DEFPGM) $(DEFPBM) libppm4.c
        $(CC) -r $(RALLCFLAGS) -S -o $@ -c libppm4.c
libppm5.or:      $(DEFPPM) $(DEFPGM) $(DEFPBM) ppmdraw.h libppm5.c
        $(CC) -r $(RALLCFLAGS) -S -o $@ -c libppm5.c
bitio.or:        bitio.h /pbmplus.h bitio.c
        $(CC) -r $(RALLCFLAGS) -S -o $@ -c bitio.c

# small data version of libppm, not registerized (arguments on stack)
$(SLIBPPM):     libppm1.os libppm2.os libppm3.os libppm4.os libppm5.os bitio.os
        -delete $(SLIBPPM)
        join libppm1.os libppm2.os libppm3.os libppm4.os libppm5.os bitio.os to $(SLIBPPM)
libppm1.os:      $(DEFPPM) $(DEFPGM) $(DEFPBM) $(DEFLIBPPM) libppm1.c
        $(CC) -r $(SALLCFLAGS) -S -o $@ -c libppm1.c
libppm2.os:      $(DEFPPM) $(DEFPGM) $(DEFPBM) $(DEFLIBPPM) libppm2.c $(DEFLIBPGM) $(DEFLIBPBM)
        $(CC) -r $(SALLCFLAGS) -S -o $@ -c libppm2.c
libppm3.os:      $(DEFPPM) $(DEFPGM) $(DEFPBM) ppmcmap.h $(DEFLIBPPM) libppm3.c
        $(CC) -r $(SALLCFLAGS) -S -o $@ -c libppm3.c
libppm4.os:      $(DEFPPM) $(DEFPGM) $(DEFPBM) libppm4.c
        $(CC) -r $(SALLCFLAGS) -S -o $@ -c libppm4.c
libppm5.os:      $(DEFPPM) $(DEFPGM) $(DEFPBM) ppmdraw.h libppm5.c
        $(CC) -r $(SALLCFLAGS) -S -o $@ -c libppm5.c
bitio.os:        bitio.h /pbmplus.h bitio.c
        $(CC) -r $(SALLCFLAGS) -S -o $@ -c bitio.c

# large data version of libppm
$(RLLIBPPM):    libppm1.olr libppm2.olr libppm3.olr libppm4.olr libppm5.olr bitio.olr
        -delete $(RLLIBPPM)
        join libppm1.olr libppm2.olr libppm3.olr libppm4.olr libppm5.olr bitio.olr to $(RLLIBPPM)
libppm1.olr:      $(DEFPPM) $(DEFPGM) $(DEFPBM) $(DEFLIBPPM) libppm1.c
        $(CC) -mD $(RALLCFLAGS) -S -o $@ -c libppm1.c
libppm2.olr:      $(DEFPPM) $(DEFPGM) $(DEFPBM) $(DEFLIBPPM) libppm2.c $(DEFLIBPGM) $(DEFLIBPBM)
        $(CC) -mD $(RALLCFLAGS) -S -o $@ -c libppm2.c
libppm3.olr:      $(DEFPPM) $(DEFPGM) $(DEFPBM) ppmcmap.h $(DEFLIBPPM) libppm3.c
        $(CC) -mD $(RALLCFLAGS) -S -o $@ -c libppm3.c
libppm4.olr:      $(DEFPPM) $(DEFPGM) $(DEFPBM) libppm4.c
        $(CC) -mD $(RALLCFLAGS) -S -o $@ -c libppm4.c
libppm5.olr:      $(DEFPPM) $(DEFPGM) $(DEFPBM) ppmdraw.h libppm5.c
        $(CC) -mD $(RALLCFLAGS) -S -o $@ -c libppm5.c
bitio.olr:        bitio.h /pbmplus.h bitio.c
        $(CC) -mD $(RALLCFLAGS) -S -o $@ -c bitio.c

# large data version, not registerized (arguments on stack)
$(SLLIBPPM):    libppm1.ols libppm2.ols libppm3.ols libppm4.ols libppm5.ols bitio.ols
        -delete $(SLLIBPPM)
        join libppm1.ols libppm2.ols libppm3.ols libppm4.ols libppm5.ols bitio.ols to $(SLLIBPPM)
libppm1.ols:      $(DEFPPM) $(DEFPGM) $(DEFPBM) $(DEFLIBPPM) libppm1.c
        $(CC) -mD $(SALLCFLAGS) -S -o $@ -c libppm1.c
libppm2.ols:      $(DEFPPM) $(DEFPGM) $(DEFPBM) $(DEFLIBPPM) libppm2.c $(DEFLIBPGM) $(DEFLIBPBM)
        $(CC) -mD $(SALLCFLAGS) -S -o $@ -c libppm2.c
libppm3.ols:      $(DEFPPM) $(DEFPGM) $(DEFPBM) ppmcmap.h $(DEFLIBPPM) libppm3.c
        $(CC) -mD $(SALLCFLAGS) -S -o $@ -c libppm3.c
libppm4.ols:      $(DEFPPM) $(DEFPGM) $(DEFPBM) libppm4.c
        $(CC) -mD $(SALLCFLAGS) -S -o $@ -c libppm4.c
libppm5.ols:      $(DEFPPM) $(DEFPGM) $(DEFPBM) ppmdraw.h libppm5.c
        $(CC) -mD $(SALLCFLAGS) -S -o $@ -c libppm5.c
bitio.ols:        bitio.h /pbmplus.h bitio.c
        $(CC) -mD $(SALLCFLAGS) -S -o $@ -c bitio.c


# Other dependencies.
gouldtoppm gouldtoppm.om:        gouldtoppm.c
hpcdtoppm hpcdtoppm.om:          hpcdtoppm.c
ilbmtoppm ilbmtoppm.om:          ilbmtoppm.c ilbm.h
imgtoppm imgtoppm.om:            imgtoppm.c
mtvtoppm mtvtoppm.om:            mtvtoppm.c
pcxtoppm pcxtoppm.om:            pcxtoppm.c
pgmtoppm pgmtoppm.om:            pgmtoppm.c
pi1toppm pi1toppm.om:            pi1toppm.c
picttoppm picttoppm.om:          picttoppm.c
pjtoppm pjtoppm.om:              pjtoppm.c
ppm3d ppm3d.om:                  ppm3d.c
ppmchange ppmchange.om:          ppmchange.c
ppmdim ppmdim.om:                ppmdim.c
ppmdither ppmdither.om:          ppmdither.c
ppmflash ppmflash.om:            ppmflash.c
ppmforge ppmforge.om:            ppmforge.c
ppmhist ppmhist.om:              ppmhist.c ppmcmap.h
ppmmake ppmmake.om:              ppmmake.c
ppmmix ppmmix.om:                ppmmix.c
ppmntsc ppmntsc.om:              ppmntsc.c
ppmpat ppmpat.om:                ppmpat.c ppmdraw.h
ppmquant ppmquant.om:            ppmquant.c $(PGMDIR)/dithers.h ppmcmap.h
ppmrelief ppmrelief.om:          ppmrelief.c
ppmshift ppmshift.om:            ppmshift.c
ppmspread ppmspread.om:          ppmspread.c
ppmtoacad ppmtoacad.om:          ppmtoacad.c ppmcmap.h autocad.h
ppmtogif ppmtogif.om:            ppmtogif.c ppmcmap.h
ppmtoicr ppmtoicr.om:            ppmtoicr.c ppmcmap.h
ppmtoilbm ppmtoilbm.om:          ppmtoilbm.c ilbm.h ppmcmap.h
ppmtopcx ppmtopcx.om:            ppmtopcx.c ppmcmap.h
ppmtopgm ppmtopgm.om:            ppmtopgm.c
ppmtopi1 ppmtopi1.om:            ppmtopi1.c ppmcmap.h
ppmtopict ppmtopict.om:          ppmtopict.c ppmcmap.h
ppmtopj ppmtopj.om:              ppmtopj.c
ppmtopuzz ppmtopuzz.om:          ppmtopuzz.c ppmcmap.h
ppmtorgb3 ppmtorgb3.om:          ppmtorgb3.c
ppmtosixel ppmtosixel.om:        ppmtosixel.c ppmcmap.h
ppmtotga ppmtotga.om:            ppmtotga.c ppmcmap.h
ppmtouil ppmtouil.om:            ppmtouil.c ppmcmap.h
ppmtoxpm ppmtoxpm.om:            ppmtoxpm.c ppmcmap.h
ppmtoyuv ppmtoyuv.om:            ppmtoyuv.c
qrttoppm qrttoppm.om:            qrttoppm.c
rawtoppm rawtoppm.om:            rawtoppm.c
rgb3toppm rgb3toppm.om:          rgb3toppm.c
sldtoppm sldtoppm.om:            sldtoppm.c ppmdraw.h autocad.h
spctoppm spctoppm.om:            spctoppm.c
sputoppm sputoppm.om:            sputoppm.c
tgatoppm tgatoppm.om:            tgatoppm.c tga.h
ximtoppm ximtoppm.om:            ximtoppm.c xim.h
xpmtoppm xpmtoppm.om:            xpmtoppm.c
yuvtoppm yuvtoppm.om:            yuvtoppm.c
bmptoppm bmtoppm.om:             bmptoppm.c bmp.h bitio.h
ppmtobmp ppmtobmp.om:            ppmtobmp.c bmp.h ppmcmap.h bitio.h
ppmdist ppmdist.om:              ppmdist.c ppmcmap.h
ppmtomap ppmtomap.om:            ppmtomap.c ppmcmap.h
ppmtoyuvsplit ppmtoyuvsplit.om:  ppmtoyuvsplit.c
yuvsplittoppm yuvsplittoppm.om:  yuvsplittoppm.c
ppmbrighten ppmbrighten.om:      ppmbrighten.c
ppmtomitsu ppmtomitsu.om:        ppmtomitsu.c mitsu.h ppmcmap.h
ppmtopjxl ppmtopjxl.om:          ppmtopjxl.c ppmcmap.h
ppmnorm ppmnorm.om:              ppmnorm.c lum.h
ppmqvga ppmqvga.om:              ppmqvga.c
xvminitoppm xvminitoppm.om:      xvminitoppm.c

clean:
        -delete \#?.om \#?.os \#?.or \#?.ols \#?.olr DCC_ERRORS

cleanall:   clean
        -delete \#?.lib
        -delete $(BINDIR) all

installlib:     lib
        copy $(LIBRARIES) to $(INSTALLLIB)
        copy $(HEADERS) to $(INSTALLINCL)

installbin:     binaries
        copy $(BINDIR) all to $(INSTALLBIN)

installall:     installlib installbin

install:
        @echo "Please select: installlib, installbin, installall"

