# Makefile for Netpbm

# Configuration should normally be done in the included file Makefile.config.

# Targets in this file:
#
#   all: (default).  Build everything, in the source directory.
#   install:  Install everything into the live system
#   install.bin:  Install executables into the live system
#   install.lib:  Install Netpbm (and maybe tiff) libraries
#   install.man:  Install man pages
#   merge:  Build everything, but in the "merge" style.  See below.
#   install.merge: Install everything, built in the "merge" style.

# About the "merge" target: Normally the Makefiles build and install
# separate executables for each program.  However, on some systems
# (especially those without shared libraries) this can mean a lot of
# space.  In this case you might try building a "merge" instead.  The
# idea here is to link all the programs together into one huge
# executable, along with a tiny dispatch program that runs one of the
# programs based on the command name with which it was invoked.  You
# install the merged executable with a file system link for the name
# of each program it includes.  On a Sun3 under SunOS 3.5 the space
# for executables went from 2970K to 370K in an older Netpbm.
# On a Linux x86 system with Netpbm 8.4, it saved 615K.
#
# To build a "merge" system, do a "make merge" instead of "make [all]"
# and "make install-merge" instead of "make install".

SRCDIR = .
include $(SRCDIR)/Makefile.config

SUBDIRS =	pbm pgm ppm pnm ppmtompeg

# Note that the Tiff library, from the libtiff subdirectory, only gets built
# if you specify the homegrown libtiff as $(TIFFLIB), in which case it is
# a dependency of stuff in the pnm subdirectory.  Or you can cd to the 
# libtiff subdirectory and do a "make all" there.

.PHONY: all
all: compile.h $(SUBDIRS)

.PHONY: libtiff
libtiff:
	$(MAKE) -C $@ all

.PHONY: $(SUBDIRS)
$(SUBDIRS):
	$(MAKE) -C $@ all

# Note that we create a new compile.h only for the first make after a 
# make clean.  This is good enough.  We used to do stamp-date for every
# build of "all" from this make file, but nowhere else, so it was really
# sloppy.

compile.h:
	./stamp-date

.PHONY: install
install: install.bin install.lib install.man 

.PHONY: merge
merge:  compile.h
	for i in $(SUBDIRS) ; do \
	    ( echo merge.$$i ; cd $$i ; $(MAKE) merge );\
	done

.PHONY: install.bin
install.bin:
	-mkdir -p $(INSTALLBINARIES)
	for i in $(SUBDIRS) ; do \
	    ( echo install.bin.$$i ; cd $$i ; $(MAKE) install.bin ); \
	done

.PHONY: install-merge
install-merge:
	-mkdir -p $(INSTALLBINARIES)
	for i in $(SUBDIRS) ; do \
	    ( echo install.merge.$$i ; cd $$i ; $(MAKE) install.merge ); \
	done

.PHONY: install.lib
install.lib:
	-mkdir -p $(INSTALLLIBS)
	for i in $(SUBDIRS) ; do \
	    ( echo install.lib.$$i ; cd $$i ; $(MAKE) install.lib ); \
	done
ifeq (TIFFLIB_DIR, $(SRCDIR)/libtiff)
# We built using our own TIFF library, so better install it too.
	cd libtiff; $(MAKE) install
endif

.PHONY: install.man
install.man:
	-mkdir -p $(INSTALLMANUALS1)
	-mkdir -p $(INSTALLMANUALS3)
	-mkdir -p $(INSTALLMANUALS5)
	for i in $(SUBDIRS) ; do \
	    ( echo install.man.$$i ; cd $$i ; $(MAKE) install.man ); \
	done

.PHONY: clean
clean:
	rm -f compile.h
	for i in $(SUBDIRS) libtiff shhopt ; do \
	    ( echo clean.$$i ; cd $$i ; $(MAKE) clean ); \
	done

.PHONY: dep
dep:
	for i in $(SUBDIRS) libtiff ; do \
	    ( echo dep.$$i ; cd $$i ; $(MAKE) dep ); \
	done
