# Makefile for pbm 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.

# Default values, usually overridden by top-level Makefile.
#CC =		cc
CC =		gcc -ansi -pedantic -fpcc-struct-return
CFLAGS =	-O
#CFLAGS =	-g
#CFLAGS =	-g -O
TIFFDEF =       -DLIBTIFF
#LDFLAGS =	-s
LDFLAGS =	
INSTALLBINARIES =	/usr/new/pbm
INSTALLMANUALS1 =	/usr/man/man1
SUFFIXMANUALS1 =	1
INSTALLMANUALS3 =	/usr/man/man3
SUFFIXMANUALS3 =	3
INSTALLMANUALS5 =	/usr/man/man5
SUFFIXMANUALS5 =	5
MANCP =			cp

SHELL =		/bin/sh
INCLUDE =	-I..
ALLCFLAGS =	$(CFLAGS) $(TIFFDEF) $(INCLUDE)
LIBPBM =	libpbm.a
DEFPBM =	pbm.h ../pbmplus.h

PORTBINARIES =	atktopbm brushtopbm cmuwmtopbm g3topbm \
		icontopbm gemtopbm macptopbm mgrtopbm \
		pbmclean pbmlife pbmmake pbmmask pbmpscale \
		pbmreduce pbmtext \
		pbmto10x pbmto4425 pbmtoascii pbmtoatk \
		pbmtobbnbg pbmtocmuwm \
		pbmtoepsi pbmtoepson \
		pbmtog3 pbmtogem pbmtogo pbmtoicon pbmtolj \
		pbmtoln03 pbmtolps pbmtomacp pbmtomgr \
		pbmtopi3 pbmtoplot pbmtoptx \
		pbmtox10bm pbmtoxbm pbmtoybm pbmtozinc \
		pbmupc pi3topbm pktopbm xbmtopbm ybmtopbm
MATHBINARIES =	pbmtopk
BINARIES =	$(PORTBINARIES) $(MATHBINARIES)

OBJECTS =	atktopbm.o brushtopbm.o cmuwmtopbm.o g3topbm.o \
		icontopbm.o gemtopbm.o macptopbm.o mgrtopbm.o \
		pbmclean.o pbmlife.o pbmmake.o pbmmask.o pbmpscale.o \
		pbmreduce.o pbmtext.o \
		pbmto10x.o pbmto4425.o pbmtoascii.o pbmtoatk.o \
		pbmtobbnbg.o pbmtocmuwm.o \
		pbmtoepsi.o pbmtoepson.o \
		pbmtog3.o pbmtogem.o pbmtogo.o pbmtoicon.o pbmtolj.o \
		pbmtoln03.o pbmtolps.o pbmtomacp.o pbmtomgr.o \
		pbmtopi3.o pbmtoplot.o pbmtoptx.o \
		pbmtox10bm.o pbmtoxbm.o pbmtoybm.o pbmtozinc.o \
		pbmupc.o pi3topbm.o pktopbm.o xbmtopbm.o ybmtopbm.o \
		pbmtopk.o

MANUALS1 =	$(BINARIES)
MANUALS3 =	libpbm
MANUALS5 =	pbm


#all:		binaries
all:		merge
#install:	install.bin
install:	install.merge


binaries:	$(BINARIES)

install.bin:	binaries
	cd $(INSTALLBINARIES) ; rm -f $(BINARIES)
	cp $(BINARIES) $(INSTALLBINARIES)


merge:		pbmmerge
pbmmerge:	pbmmerge.c $(OBJECTS) $(LIBPBM)
	$(CC) $(ALLCFLAGS) $(LDFLAGS) -o $@ $@.c $(OBJECTS) $(LIBPBM)

install.merge:	install.pbmmerge
install.pbmmerge:	pbmmerge
	cd $(INSTALLBINARIES) ; rm -f $(BINARIES)
	cp pbmmerge $(INSTALLBINARIES)
	cd $(INSTALLBINARIES) ; for i in $(BINARIES) ; do ln pbmmerge $$i ; done
	rm -f $(INSTALLBINARIES)/pbmmerge


install.man:
	for i in $(MANUALS1) ; do \
	    rm -f $(INSTALLMANUALS1)/$$i.$(SUFFIXMANUALS1) ; \
	    $(MANCP) $$i.1 $(INSTALLMANUALS1)/$$i.$(SUFFIXMANUALS1) ; \
	done
	for i in $(MANUALS3) ; do \
	    rm -f $(INSTALLMANUALS3)/$$i.$(SUFFIXMANUALS3) ; \
	    $(MANCP) $$i.3 $(INSTALLMANUALS3)/$$i.$(SUFFIXMANUALS3) ; \
	done
	for i in $(MANUALS5) ; do \
	    rm -f $(INSTALLMANUALS5)/$$i.$(SUFFIXMANUALS5) ; \
	    $(MANCP) $$i.5 $(INSTALLMANUALS5)/$$i.$(SUFFIXMANUALS5) ; \
	done

# Rule for plain programs.
$(PORTBINARIES):	$(DEFPBM) $(LIBPBM)
	$(CC) $(ALLCFLAGS) $(LDFLAGS) -o $@ $@.c $(LIBPBM)

# Rule for math-dependent programs.
$(MATHBINARIES):	$(DEFPBM) $(LIBPBM)
	$(CC) $(ALLCFLAGS) $(LDFLAGS) -o $@ $@.c -lm $(LIBPBM)

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

# And library.
lib:		$(LIBPBM)
$(LIBPBM):	libpbm1.o libpbm2.o libpbm3.o libpbm4.o libpbm5.o
	-rm -f $(LIBPBM)
	ar rc $(LIBPBM) libpbm1.o libpbm2.o libpbm3.o libpbm4.o libpbm5.o
	-ranlib $(LIBPBM)

libpbm1.o:	$(DEFPBM) ../version.h ../compile.h libpbm.h libpbm1.c
	$(CC) $(ALLCFLAGS) -c libpbm1.c
libpbm2.o:	$(DEFPBM) libpbm.h libpbm2.c
	$(CC) $(ALLCFLAGS) -c libpbm2.c
libpbm3.o:	$(DEFPBM) libpbm.h libpbm3.c
	$(CC) $(ALLCFLAGS) -c libpbm3.c
libpbm4.o:	$(DEFPBM) libpbm.h libpbm4.c
	$(CC) $(ALLCFLAGS) -c libpbm4.c
libpbm5.o:	$(DEFPBM) pbmfont.h libpbm5.c
	$(CC) $(ALLCFLAGS) -c libpbm5.c

# Other dependencies.
atktopbm atktopbm.o:		atktopbm.c
brushtopbm brushtopbm.o:	brushtopbm.c
cmuwmtopbm cmuwmtopbm.o:	cmuwmtopbm.c cmuwm.h
g3topbm g3topbm.o:		g3topbm.c g3.h
icontopbm icontopbm.o:		icontopbm.c
gemtopbm gemtopbm.o:		gemtopbm.c
macptopbm macptopbm.o:		macptopbm.c macp.h
mgrtopbm mgrtopbm.o:		mgrtopbm.c mgr.h
pbmclean pbmclean.o:		pbmclean.c
pbmlife pbmlife.o:		pbmlife.c
pbmmake pbmmake.o:		pbmmake.c
pbmmask pbmmask.o:		pbmmask.c
pbmpscale pbmpscale.o:		pbmpscale.c
pbmreduce pbmreduce.o:		pbmreduce.c
pbmtext pbmtext.o:		pbmtext.c pbmfont.h
pbmto10x pbmto10x.o:		pbmto10x.c
pbmto4425 pbmto4425.o:		pbmto4425.c
pbmtoascii pbmtoascii.o:	pbmtoascii.c
pbmtoatk pbmtoatk.o:		pbmtoatk.c
pbmtobbnbg pbmtobbnbg.o:	pbmtobbnbg.c
pbmtocmuwm pbmtocmuwm.o:	pbmtocmuwm.c cmuwm.h
pbmtoepson pbmtoepson.o:	pbmtoepson.c
pbmtog3 pbmtog3.o:		pbmtog3.c g3.h
pbmtogem pbmtogem.o:		pbmtogem.c
pbmtogo pbmtogo.o:		pbmtogo.c
pbmtoicon pbmtoicon.o:		pbmtoicon.c
pbmtolj pbmtolj.o:		pbmtolj.c
pbmtoln03 pbmtoln03.o:		pbmtoln03.c
pbmtolps pbmtolps.o:		pbmtolps.c
pbmtomacp pbmtomacp.o:		pbmtomacp.c macp.h
pbmtomgr pbmtomgr.o:		pbmtomgr.c mgr.h
pbmtopi3 pbmtopi3.o:		pbmtopi3.c
pbmtopk pbmtopk.o:		pbmtopk.c
pbmtoplot pbmtoplot.o:		pbmtoplot.c
pbmtoptx pbmtoptx.o:		pbmtoptx.c
pbmtox10bm pbmtox10bm.o:	pbmtox10bm.c
pbmtoxbm pbmtoxbm.o:		pbmtoxbm.c
pbmtoybm pbmtoybm.o:		pbmtoybm.c
pbmtozinc pbmtozinc.o:		pbmtozinc.c
pbmupc pbmupc.o:		pbmupc.c
pi3topbm pi3topbm.o:		pi3topbm.c
pktopbm pktopbm.o:		pktopbm.c
xbmtopbm xbmtopbm.o:		xbmtopbm.c
ybmtopbm ybmtopbm.o:		ybmtopbm.c
pbmtoepsi pbmtoepsi.o:		pbmtoepsi.c

clean:
	-rm -f *.o *.a *.cat *~ core $(BINARIES) pbmmerge
