# Makefile for pbmplus 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.
#
# Makefile modifications Copyright (c) 1997 by Wayne Gramlich
#
# 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.  (Yes, they are identical.)
#
# CONFIGURE: gcc makes things go faster on some machines, but not everyone
# has it.  Warning: do not use gcc's -finline-functions or -fstrength-reduce
# flags, they can produce incorrect code.  (This is with gcc versions 1.35,
# 1.36, and 1.37, later versions may fix these bugs.)  Also, on some systems
# gcc can't compile pnmconvol - dunno why.  And on some systems you can't
# use the -ansi flag, it gives compilation errors in <math.h>.


#CC =		cc
#CC =		/usr/ucb/cc
#CC =		gcc
#CC =		gcc -fcombine-regs -fpcc-struct-return
#CC =		gcc -ansi -pedantic -fcombine-regs -fpcc-struct-return
CC =		gcc -ansi -pedantic

# CONFIGURE: cc flags go here.
COPTS =		-g
#COPTS =	-O4
#COPTS =	-g
#COPTS =	-g -O

CFLAGS =	${COPTS} -DSYSV

# CONFIGURE: ld flags go here.  Eunice users may want to use -noshare so that
# the binaries can run standalone.
#LDFLAGS =	-s 
LDFLAGS =	-s
#LDFLAGS =	
#LDFLAGS =	-noshare

# CONFIGURE: If you have an X11-style rgb color names file, define its
# path here.  This is used by PPM to parse color names into rgb values.
# If you don't have such a file, comment this out and use the alternative
# hex and decimal forms to specify colors (see ppm/pgmtoppm.1 for details).
#RGBDEF =	-DRGB_DB=\"$(OPENWINHOME)/lib/rgb.txt\"
RGBDEF =	-DRGB_DB=\"/usr/lib/X11/rgb.txt\"

PBM_DIRECTORIES =		\
	pbm			\
	pgm			\
	ppm			\
	pnm
SUB_DIRECTORIES =		\
	${PBM_DIRECTORIES}	\
	libtiff

SOURCES = 			\
	CHANGES			\
	FORMATS			\
	Imakefile		\
	Makefile		\
	OTHER.SYSTEMS		\
	README			\
	TODO			\
	compat.csh		\
	compat.ksh		\
	magic			\
	pbmplus.h		\
	version.h
ALL_SOURCES =			\
	${SOURCES}		\
	index.html		\
	source.html

.PHONY: all clean copy install merge site

all:		merge $(WAIT) install $(WAIT) source.html

install: merge
	for i in $(PBM_DIRECTORIES) ; do	\
	    (cd $$i ; $(MAKE) $@ ) ;	 	\
	done

copy:
	set -e ;							\
	if [ "$(COPY_DIRECTORY)" = "" ] ;				\
	  then								\
	    echo "Please set COPY_DIRECTORY in `pwd`" ;			\
	    exit 1 ;							\
	  fi ;								\
	rm -rf $(COPY_DIRECTORY) ;					\
	mkdir -p $(COPY_DIRECTORY) ;					\
	cp ${ALL_SOURCES} $(COPY_DIRECTORY) ;				\
	for i in ${PBM_DIRECTORIES} ; do				\
	    $(MAKE) -C $$i COPY_DIRECTORY=$(COPY_DIRECTORY)/$$i copy;	\
	done

merge:
	for i in $(SUB_DIRECTORIES) ; do	\
	    ( cd $$i ; $(MAKE) ) ;		\
	done

site:
	for i in ${SUB_DIRECTORIES} ; do	\
	    ( cd $$i ; $(MAKE) $@ ) ;		\
	done

clean:
	for i in $(SUB_DIRECTORIES) ; do 	\
	    ( cd $$i ; $(MAKE) $@ ) ;		\

source.html: Makefile ${SOURCES}
	@echo -n "Generating $@..."
	@rm -f $@
	@echo '<HTML>' > $@
	@echo '<Head>' >> $@
	@echo '<Title>PBMPlus Top-Level Source Files</Title>' >> $@
	@echo '</Head>' >> $@
	@echo '<Body>' >> $@
	@echo '<P>These are the source files for the' >> $@
	@echo '<A HRef="index.html">PBMPlus Download</A>' >> $@
	@echo 'top-level directory.</P>' >> $@
	@echo '<H1>' >> $@
	@echo 'PBMPlus Top-Level Source Files' >> $@
	@echo '</H1>' >> $@
	@echo '<P>The following source files are available:</P>' >> $@
	@echo '<UL>' >> $@
	@for i in `ls ${SOURCES} | sort` ; do 				\
		echo "  <LI><A HRef='$$i'>$$i</A></LI>" >> $@ ;		\
		done
	@echo '</UL>' >> $@
	@echo '<HR>' >> $@
	@echo '<Address>' >> $@
	@echo '<A HRef="../../../copyright.html">' >> $@
	@echo 'Copyright</A> (c) 1998 by' >> $@
	@echo '<A HRef="../../../gramlich.html">' >> $@
	@echo 'Wayne Gramlich</A> All rights reserved.' >> $@
	@echo '</Address>' >> $@
	@echo '</Body>' >> $@
	@echo '</HTML>' >> $@
	@echo "Done"
	

