### User-configurable section begins

# Installation directory prefix for Debian GNU/Linux
DESTDIR =
# Installation directory prefix for other systems
PREFIX = $(DESTDIR)/usr
#PREFIX = $(DESTDIR)/usr/local

# Where to put binaries on 'make install'?
BINDIR = $(PREFIX)/bin
# Where to put manual pages on 'make installman'?
MANDIR = $(PREFIX)/share/man/man1

## Installation commands
RM = rm -f
INSTALLDIR = install -d
INSTALLDATA = install -c -m 444
INSTALLBIN = install -c

## C compiler and its options
#CC = gcc
#CFLAGS = -Wall -ansi -pedantic -O6 -fomit-frame-pointer
#LDFLAGS = -s
#DEFINES =
#INCLUDES =

### User-configurable section ends

TARGETS = photomolo jpegcom exifiron jpegnail
MANPAGES = photomolo.1 jpegcom.1 exifiron.1 jpegnail.1
HDRS = scale.h tree.h info.h spec.h html.h
SRCS = photomolo.c $(HDRS:.h=.c)
OBJS = $(SRCS:.c=.o)
ALLSRCS = $(SRCS) jpegcom.c exifiron.c jpegnail.c rename.c
ALLOBJS = $(ALLSRCS:.c=.o)
LIBS = -ljpeg

all: depend $(TARGETS)

clean:
	$(RM) $(ALLOBJS)

reallyclean: clean
	$(RM) $(TARGETS)

install: $(TARGETS)
	$(INSTALLDIR) $(BINDIR)
	$(INSTALLBIN) $(TARGETS) $(BINDIR)

installman: $(MANPAGES)
	$(INSTALLDIR) $(MANDIR)
	$(INSTALLDATA) $(MANPAGES) $(MANDIR)

depend: $(ALLSRCS) $(HDRS)
	$(CC) -MM $(DEFINES) $(INCLUDES) $(ALLSRCS) > depend

jpegcom: jpegcom.o rename.o
	$(CC) $(LDFLAGS) -o $@ jpegcom.o rename.o

exifiron: exifiron.o rename.o
	$(CC) $(LDFLAGS) -o $@ exifiron.o rename.o $(LIBS)

jpegnail: jpegnail.o scale.o rename.o
	$(CC) $(LDFLAGS) -o $@ jpegnail.o scale.o rename.o $(LIBS)

photomolo: $(OBJS)
	$(CC) $(LDFLAGS) -o $@ $(OBJS) $(LIBS)

.phony: all clean reallyclean install installman

.SUFFIXES:
.SUFFIXES: .o .c .1 .dvi .pdf .txt

.c.o:
	$(CC) $(INCLUDES) $(CFLAGS) -c $< -o $@
.1.dvi:
	groff -man -Tdvi $< > $@
.dvi.pdf:
	dvipdfm $<
.1.txt:
	groff -man -Tlatin1 $< | sed -e 's/.//g;' > $@

include depend
