################################################################
# Makefile template for SWI-Prolog CLIB package
#
# This template is used by configure to create Makefile.  See
# the file INSTALL for further installation instructions.
#
# License: LGPL
#
# Author: Jan Wielemaker (wielemak@science.uva.nl)
################################################################

.SUFFIXES: .tex .dvi .doc .pl

ifeq (@PROLOG_SYSTEM@,yap)


prefix = @prefix@
exec_prefix = @exec_prefix@
ROOTDIR = $(prefix)
EROOTDIR = @exec_prefix@
abs_top_builddir = @abs_top_builddir@

srcdir=@srcdir@

BINDIR = $(EROOTDIR)/bin
LIBDIR=@libdir@
YAPLIBDIR=@libdir@/Yap
SHAREDIR=$(ROOTDIR)/share/Yap

SHELL=@SHELL@
PL=@INSTALL_ENV@ $(DESTDIR)$(BINDIR)/yap $(DESTDIR)$(YAPLIBDIR)/startup.yss
EXDIR=$(YAPLIBDIR)/examples/http
LN_S=@LN_S@
#
#
CC=@CC@
CFLAGS= @SHLIB_CFLAGS@ $(YAP_EXTRAS) $(DEFS) -D_YAP_NOT_INSTALLED_=1 -I$(srcdir) -I../.. -I$(srcdir)/../../include @CPPFLAGS@
MKINDEX=true
LIBS=@ZLIBS@                                                            


SO=@SO@
#4.1VPATH=@srcdir@:@srcdir@/OPTYap
CWD=$(PWD)
#

LD=@DO_SECOND_LD@	@SHLIB_LD@
LDFLAGS=@EXTRA_LIBS_FOR_SWIDLLS@

BINTARGET=$(DESTDIR)$(YAPLIBDIR)
PLTARGET=$(DESTDIR)$(SHAREDIR)

FINAL_BINTARGET=$(YAPLIBDIR)
FINAL_PLTARGET=$(SHAREDIR)

LIBPL=		@ZLIB_PLTARGETS@
TARGETS=	@ZLIB_TARGETS@

%.o: $(srcdir)/%.c
		$(CC) -c $(CFLAGS) $< -o $@

else	# SWI

PL=@PL@
PLBASE=@PLBASE@
PLARCH=@PLARCH@
PLINCL=@PLINCL@
PKGDOC=$(PLBASE)/doc/packages
PCEHOME=../xpce

CC=@CC@
COFLAGS=@COFLAGS@
CWFLAGS=@CWFLAGS@
CMFLAGS=@CMFLAGS@
CIFLAGS=
CFLAGS=$(COFLAGS) $(CWFLAGS) $(CMFLAGS) $(CIFLAGS) @DEFS@
LIBS=@LIBS@ @ZLIBS@                                                            

DOCTOTEX=$(PCEHOME)/bin/doc2tex
PLTOTEX=$(PCEHOME)/bin/pl2tex
DOC=zlib
TEX=$(DOC).tex
DVI=$(DOC).dvi
PDF=$(DOC).pdf
RUNTEX=../../man/runtex

LD=@LD@
LDFLAGS=@LDSOFLAGS@

LIBPL=		@PLTARGETS@
TARGETS=	@TARGETS@

endif

INSTALL=@INSTALL@
INSTALL_PROGRAM=@INSTALL_PROGRAM@
INSTALL_DATA=@INSTALL_DATA@

ZOBJ=		zlib4pl.o

all:		$(TARGETS)

nolib::
		@echo "WARNING: Could not find zlib library; skipped"

zlib4pl.@SO@:	$(ZOBJ)
		$(LD) $(LDFLAGS) -o $@ $(ZOBJ) $(LIBS)

install:	$(TARGETS) $(LIBPL)
		mkdir -p $(DESTDIR)$(BINTARGET)
		for f in $(TARGETS); do \
		  $(INSTALL_PROGRAM) $$f $(BINTARGET); \
		done
		mkdir -p $(PLTARGET)
		for f in $(LIBPL); do \
		  $(INSTALL_DATA) $$f $(PLTARGET); \
		done
		$(PL) -f none -g make -t halt

ln-install::
		$(MAKE) INSTALL_DATA="../ln-install" INSTALL_PROGRAM="../ln-install" install

rpm-install:	install

html-install::
		mkdir -p $(DESTDIR)$(PKGDOC)
		$(INSTALL) -m 644 $(DOC).html $(DESTDIR)$(PKGDOC)

pdf-install::
		mkdir -p $(DESTDIR)$(PKGDOC)
		$(INSTALL) -m 644 $(DOC).pdf $(DESTDIR)$(PKGDOC)

uninstall::
		(cd $(PLBASE)/lib/$(PLARCH) && rm -f $(TARGETS))
		(cd $(PLBASE)/library && rm -f $(LIBPL))
		$(PL) -f none -g make -t halt

################################################################
# Testing
################################################################

check::
		$(PL) -q -f $(srcdir)/test_zlib.pl -g test_zlib,halt -t 'halt(1)'

################################################################
# Documentation
################################################################

pdf:		$(PDF)

$(DVI):		$(TEX)
		$(RUNTEX) $(DOC)

$(PDF):		$(TEX)
		$(RUNTEX) --pdf $(DOC)

html:		$(TEX)
		latex2html $(DOC)
		mv html/index.html $(DOC).html
		rm -r html

$(TEX):		$(DOCTOTEX)

.doc.tex:
		$(DOCTOTEX) $*.doc > $*.tex
.pl.tex:
		$(PLTOTEX) $*.pl > $*.tex

################################################################
# Clean
################################################################

clean:
		rm -f $(ZOBJ) *~ *.o *% a.out core config.log

distclean:	clean
		rm -f $(TARGETS) config.cache config.h config.status Makefile
		rm -f $(DOC).aux $(DOC).log $(DOC).out $(DOC).toc
		rm -rf html
		rm -rf autom4te.cache