#
# neon source directory Makefile
# 
# Use the NEON_NORMAL_BUILD or NEON_LIBTOOL_BUILD autoconf 
# macros to set up this Makefile correctly.
#

SHELL = @SHELL@

# Installation paths
prefix = @prefix@
exec_prefix = @exec_prefix@
libdir = @libdir@

# Build paths
VPATH = @srcdir@
top_builddir = ..
top_srcdir = @top_srcdir@

# Toolchain settings.
CC = @CC@
AR = @AR@
RANLIB = @RANLIB@
LIBTOOL = @LIBTOOL@

# Flags
CPPFLAGS = @DEFS@ @CPPFLAGS@
CFLAGS = @CFLAGS@  -I$(top_builddir) -I$(top_srcdir)/../expat/lib @NEON_CFLAGS@
LDFLAGS = -L$(top_builddir)/../expat @LDFLAGS@
NEON_LINK_FLAGS = @NEON_LINK_FLAGS@
# Note: don't substitute @LIBS@ in here; during a bundled
# build of this directory, @LIBS@ may include -lneon.
LIBS = @NEON_LIBS@ @NEON_LTLIBS@

COMPILE = $(CC) $(CPPFLAGS) $(CFLAGS)  -I$(top_builddir) -I$(top_srcdir)/../expat/lib @NEON_CFLAGS@
LINK = $(LIBTOOL) --quiet --mode=link $(CC) $(LDFLAGS)

NEON_BASEOBJS = ne_request.@NEON_OBJEXT@ ne_session.@NEON_OBJEXT@ 	    \
	ne_basic.@NEON_OBJEXT@  ne_string.@NEON_OBJEXT@ 		    \
	ne_uri.@NEON_OBJEXT@ ne_dates.@NEON_OBJEXT@ ne_alloc.@NEON_OBJEXT@  \
	ne_md5.@NEON_OBJEXT@ ne_utils.@NEON_OBJEXT@    \
	ne_socket.@NEON_OBJEXT@ ne_auth.@NEON_OBJEXT@ 			    \
	ne_cookies.@NEON_OBJEXT@ ne_redirect.@NEON_OBJEXT@		    \
	ne_compress.@NEON_OBJEXT@

NEON_DAVOBJS = $(NEON_BASEOBJS) \
	ne_207.@NEON_OBJEXT@ ne_xml.@NEON_OBJEXT@ \
	ne_props.@NEON_OBJEXT@ ne_locks.@NEON_OBJEXT@

OBJECTS = @NEONOBJS@ @NEON_EXTRAOBJS@

.SUFFIXES:
.SUFFIXES: .c .lo .o

NEON_TARGET = @NEON_TARGET@

# Thanks to gettext for this neat trick.
all: all-@NEON_BUILD_BUNDLED@ libneon.a

all-yes: $(NEON_TARGET)
all-no:
	@echo "Bundled neon build not being used."

.c.lo:
	$(LIBTOOL) --quiet --mode=compile $(COMPILE) -c $< -o $@
.c.o:
	$(COMPILE) -c $< -o $@

libneon.la: $(OBJECTS)
	$(LINK) -rpath $(libdir) $(NEON_LINK_FLAGS) -o $@ $(OBJECTS) $(LIBS)

libneon.a: $(OBJECTS)
	$(AR) cru $@ $(addsuffix .o, $(basename $(OBJECTS)))
	$(RANLIB) $@

clean:
	rm -f $(NEON_TARGET) *.o *.lo
	rm -rf .libs

c++.c:
	find . -name ne_\*.h -print | sed 's/.*/#include "&"/;/ne_private/d' > $@
	echo "int main(void) {}" >> $@

check-c++: c++.c
	c++ -I. c++.c

check-incl:
	@for f in ne_*.h; do \
	 echo Checking $$f...; \
	 echo "#include \"$$f\"" > checkincl.c; \
	 $(COMPILE) -c checkincl.c -o checkincl.o || exit 1; done

neonreq = ne_request.h ne_session.h ne_utils.h ne_string.h ne_socket.h \
	ne_alloc.h $(top_builddir)/config.h ne_private.h

ne_request.@NEON_OBJEXT@: ne_request.c $(neonreq) ne_i18n.h ne_private.h \
	ne_uri.h

ne_session.@NEON_OBJEXT@: ne_session.c ne_session.h ne_alloc.h \
	ne_utils.h ne_private.h $(top_builddir)/config.h

ne_openssl.@NEON_OBJEXT@: ne_openssl.c ne_session.h ne_ssl.h ne_privssl.h \
	ne_private.h $(top_builddir)/config.h

ne_socket.@NEON_OBJEXT@: ne_socket.c ne_socket.h $(top_builddir)/config.h \
	ne_privssl.h ne_string.h

ne_auth.@NEON_OBJEXT@: ne_auth.c ne_auth.h $(neonreq) \
	ne_dates.h ne_md5.h ne_uri.h 

ne_basic.@NEON_OBJEXT@: ne_basic.c ne_basic.h $(neonreq)

ne_utils.@NEON_OBJEXT@: ne_utils.c $(top_builddir)/config.h \
	ne_utils.h ne_dates.h

ne_xml.@NEON_OBJEXT@: ne_xml.c ne_xml.h ne_string.h ne_utils.h \
	$(top_builddir)/config.h

ne_207.@NEON_OBJEXT@: ne_207.c ne_207.h ne_xml.h \
	$(top_builddir)/config.h ne_utils.h ne_i18n.h

ne_string.@NEON_OBJEXT@: ne_string.c ne_string.h ne_alloc.h \
	$(top_builddir)/config.h

ne_alloc.@NEON_OBJEXT@: ne_alloc.c ne_alloc.h $(top_builddir)/config.h

ne_dates.@NEON_OBJEXT@: ne_dates.c ne_dates.h $(top_builddir)/config.h

ne_uri.@NEON_OBJEXT@: ne_uri.c ne_uri.h ne_utils.h ne_string.h ne_alloc.h \
	$(top_builddir)/config.h

ne_md5.@NEON_OBJEXT@: ne_md5.c ne_md5.h $(top_builddir)/config.h

ne_props.@NEON_OBJEXT@: ne_props.c $(top_builddir)/config.h \
	ne_props.h ne_207.h ne_xml.h $(neonreq)

ne_locks.@NEON_OBJEXT@: ne_locks.c $(neonreq) ne_locks.h ne_207.h ne_xml.h

ne_redirect.@NEON_OBJEXT@: ne_redirect.c $(neonreq) ne_redirect.h \
	ne_uri.h ne_private.h

ne_cookies.@NEON_OBJEXT@: ne_cookies.c $(neonreq) ne_cookies.h ne_uri.h \
	ne_private.h

ne_compress.@NEON_OBJEXT@: ne_compress.c $(neonreq) ne_compress.h

ne_acl.@NEON_OBJEXT@: ne_acl.c ne_acl.h $(neonreq)
