
SHELL=	/bin/sh
pp=
prefix=	@prefix@
exec_prefix = @exec_prefix@
bindir = @bindir@
sbindir = @sbindir@
libexecdir = @libexecdir@
datadir = @datadir@
sysconfdir = @sysconfdir@
mandir = @mandir@
incdir = @includedir@
libdir = @libdir@
srcdir = @srcdir@
RANLIB= @RANLIB@

sharedlibdir = $(libdir)/shared
LD=$(CC)

INCLUDES=	-I. -I$(srcdir) -I$(incdir)
DEFS=		@DEFS@

COMPILEC=	$(CC) $(DEFS) $(INCLUDES) $(CFLAGS) $(CPPFLAGS) $(VERSNO)

LINK=		$(CC) $(DEFS) $(INCLUDES) $(CFLAGS) -L. $(LDFLAGS) -o $@
MKSO=		$(CC) $(DEFS) $(INCLUDES) $(CFLAGS) $(CPPFLAGS) $(VERSNO) -shared

all:	bmeps
	-mkdir -p lib
	-mkdir -p share/doc/bmeps
	cp DOCU/*.pdf share/doc/bmeps
	find lib -type d -exec chmod 755 {} \;
	find lib -type f -exec chmod 644 {} \;
	find share -type d -exec chmod 755 {} \;
	find share -type f -exec chmod 644 {} \;
	touch all

install:	all
	-[ ! -d $(pp)$(bindir) ] && mkdir -p $(pp)$(bindir) && chmod 755 $(pp)$(bindir)
	-[ ! -d $(pp)$(libdir) ] && mkdir -p $(pp)$(libdir) && chmod 755 $(pp)$(libdir)
	-[ ! -d $(pp)$(incdir) ] && mkdir -p $(pp)$(incdir) && chmod 755 $(pp)$(incdir)
	-[ ! -d $(pp)$(datadir) ] && mkdir -p $(pp)$(datadir) && chmod 755 $(pp)$(datadir)
	cp bmeps  $(pp)$(bindir)/bmeps
	chmod 755 $(pp)$(bindir)/bmeps
	cp libbmeps.a $(pp)$(libdir)/libbmeps.a
	chmod 644 $(pp)$(libdir)/libbmeps.a
	cp bmeps.h $(pp)$(incdir)/bmeps.h
	chmod 644 $(pp)$(incdir)/bmeps.h
	cp pngeps.h $(pp)$(incdir)/pngeps.h
	chmod 644 $(pp)$(incdir)/pngeps.h
	-(cd share; tar cf - ./*) | (cd $(pp)$(datadir) ; tar xf -)
	-[ ! -d $(pp)$(mandir)/man1 ] && mkdir -p $(pp)$(mandir)/man1 && chmod 755 $(pp)$(mandir)/man1
	cp man/man1/bmeps.1 $(pp)$(mandir)/man1/bmeps.1
	chmod 644 $(pp)$(mandir)/man1/bmeps.1
	@echo Documentation resides in $(pp)$(datadir)/doc/bmeps.

IMGOBJECTS=	pngeps.o jpgeps.o pnmeps.o
LIBOBJECTS=	bmeps.o $(IMGOBJECTS) bmepsoe.o

OBJECTS=	bmepsm.o	$(LIBOBJECTS)

# IMGLIBS= -lpnm -lppm -lpgm -lpbm @LIBJPG@ @LIBPNG@
IMGLIBS= @LIBPNM@ @LIBJPG@ @LIBPNG@
LIBS=	$(IMGLIBS) @ZLIB@ -lm

bmeps:	$(OBJECTS) libbmeps.a
	@echo '*** If the linker can not find the "-lnetpbm" library ***'
	@echo '*** replace all occurances of "-lnetpbm" by           ***'
	@echo '*** "-lpnm -lppm -lpgm -lpbm" in this Makefile.       ***'
	$(LD)	-L. $(LDFLAGS)	-o bmeps bmepsm.o -lbmeps $(LIBS)
	chmod	755		bmeps

libbmeps.a:	$(LIBOBJECTS)
	-rm	libbmeps.a
	ar	-r	libbmeps.a	$(LIBOBJECTS)
	$(RANLIB) libbmeps.a
	chmod	755	libbmeps.a

.SUFFIXES:
.SUFFIXES:	.c	.o

.c.o:
	$(COMPILEC) -c $< -o $@

clean:
	-rm -f *.o *.a *.so bmeps all

distclean:	clean
	-rm -f config.status config.log config.h config.cache Makefile

VERSNUMB= -DVERSNUMB=\"1.2.5\"
