SRCDIR=../..
BUILDDIR = $(SRCDIR)

include $(BUILDDIR)/Makefile.config

LIBOPT = $(BUILDDIR)/libopt

PNMDIR = $(BUILDDIR)/pnm
LIBPNM = libpnm.$(NETPBMLIBSUFFIX)

PPMDIR = $(BUILDDIR)/ppm
LIBPPM = libppm.$(NETPBMLIBSUFFIX)

PGMDIR = $(BUILDDIR)/pgm
LIBPGM = libpgm.$(NETPBMLIBSUFFIX)

PBMDIR = $(BUILDDIR)/pbm
LIBPBM = libpbm.$(NETPBMLIBSUFFIX)

INCLUDE = -I$(SRCDIR)/shhopt -I. -Icodec -Iinput -Ioutput -Ilib

NETPBMLIBS = $(PNMDIR)/$(LIBPNM) \
           $(PPMDIR)/$(LIBPPM) $(PGMDIR)/$(LIBPGM) $(PBMDIR)/$(LIBPBM) 

BINARIES = pnmtofiasco fiascotopnm

MANUALS1 = $(BINARIES)

all: $(BINARIES)

pnmtofiasco_OBJECTS = binerror.o cwfa.o getopt.o getopt1.o params.o
fiascotopnm_OBJECTS =  binerror.o dwfa.o getopt.o getopt1.o params.o

OBJECTS = binerror.o cwfa.o getopt.o getopt1.o params.o dwfa.o

FIASCOLIBS = codec/libfiasco_codec.a input/libfiasco_input.a \
	    output/libfiasco_output.a lib/libfiasco_lib.a 

pnmtofiasco: $(pnmtofiasco_OBJECTS) $(FIASCOLIBS) $(LIBOPT) $(NETPBMLIBS)
	$(LD) $(LDFLAGS) -o $@ $(pnmtofiasco_OBJECTS) \
	`$(LIBOPT) $(FIASCOLIBS)` \
	 `$(LIBOPT) $(NETPBMLIBS)` -lm $(CDEBUG)

fiascotopnm: $(fiascotopnm_OBJECTS) $(FIASCOLIBS) $(LIBOPT)
	$(LD) $(LDFLAGS) -o $@ $(fiascotopnm_OBJECTS) \
	`$(LIBOPT) $(FIASCOLIBS)` \
	 `$(LIBOPT) $(NETPBMLIBS)` -lm $(CDEBUG)

$(pnmtofiasco_OBJECTS) $(fiascotopnm_OBJECTS): \
	fiasco.h config.h

codec/libfiasco_codec.a: FORCE
	$(MAKE) -C codec libfiasco_codec.a

input/libfiasco_input.a: FORCE
	$(MAKE) -C input libfiasco_input.a

output/libfiasco_output.a: FORCE
	$(MAKE) -C output libfiasco_output.a

lib/libfiasco_lib.a: FORCE
	$(MAKE) -C lib libfiasco_lib.a

.PHONY: install.bin
install.bin: install.bin.common

.PHONY: install.man
install.man: install.man.common

# And libraries.
$(PBMDIR)/$(LIBPBM): FORCE
	$(MAKE) -C $(PBMDIR) $(LIBPBM)
$(PGMDIR)/$(LIBPGM): FORCE
	$(MAKE) -C $(PGMDIR) $(LIBPGM)
$(PPMDIR)/$(LIBPPM): FORCE
	$(MAKE) -C $(PPMDIR) $(LIBPPM)
$(PNMDIR)/$(LIBPNM): FORCE
	$(MAKE) -C $(PNMDIR) $(LIBPNM)

HEADERLINKS = pbmplus.h pbm.h pgm.h ppm.h pnm.h

include $(SRCDIR)/Makefile.common

.PHONY: clean
clean: clean.common
	$(MAKE) -C codec clean
	$(MAKE) -C input clean
	$(MAKE) -C output clean
	$(MAKE) -C lib clean

FORCE:

