include Makefile.srcdir

BLDDIR = $(CURDIR)
SUBDIR =

export SRCDIR
export BLDDIR

include $(BLDDIR)/Makefile.config

SUBDIRS = include lib src tools examples

PROGRAMS_TO_INSTALL = xmlrpc-c-config

# We're in a transition between the bloated, complex GNU
# Autoconf/Automake style of build, in which 'configure' creates all
# the make files, to simpler static make files.  Some directories have
# been converted; some haven't.  So we have the hack of putting
# 'xmlrpc_config.h' as the first dependency of 'all' to make sure
# 'configure runs before anything in the case that the user neglects
# to run 'configure' before doing 'make'.

default: xmlrpc_config.h all

.PHONY: all
all: xmlrpc-c-config xmlrpc-c-config.test $(SUBDIRS:%=%/all)

# The examples subdirectory is special, because even the make file in there
# is designed to be an example.  So it has to be simple and as close as
# possible to something a person could use outside of the Xmlrpc-c source
# tree.  One ramification of that is that it does not specify dependencies
# on other parts of the Xmlrpc-c build.  That means we must separately
# ensure that the Xmlrpc-c libraries are built before making the example
# programs.
#
# It also means that you have to manually clean the examples directory
# in order to get the examples rebuilt after you modify the Xmlrpc-c
# libraries.

examples/all: lib/all src/all include/all

# Parallel make (make --jobs) is not smart enough to coordinate builds
# between submakes, so a naive parallel make would cause certain
# targets to get built multiple times simultaneously.  That is usually
# unacceptable.  So we introduce extra dependencies here just to make
# sure such targets are already up to date before the submake starts,
# for the benefit of parallel make.  Note that we ensure that parallel
# make works for 'make all' in top top directory, but it may still fail
# for the aforementioned reason for other invocations.

tools/all: include/all lib/all src/all
src/all lib/all: include/all
src/all: lib/all

version.h: $(BLDDIR)/Makefile.config
	rm -f $@
	echo '/* This file was generated by a make rule */' >>$@
	echo '#define XMLRPC_C_VERSION "$(XMLRPC_C_VERSION)"' >>$@

# We don't want Makefile.common's rule for version.h
OMIT_VERSION_H = Y

# We don't want Makefile.common's rule for transport_config.h
OMIT_TRANSPORT_CONFIG_H = Y

include transport_config.make

# shell_config is a fragment to place inside a Bourne shell program that
# sets variables that tell how the build is configured.

shell_config: $(BLDDIR)/Makefile.config
	rm -f $@
	@echo "Lots of echoes to '$@' suppressed here ..."
	@echo '#' >>$@ || (rm -f $@; false)
	@echo '#######################################################' >>$@
	@echo "# From '$@'"                                             >>$@
	@echo '#######################################################' >>$@
	@echo 'ENABLE_ABYSS_THREADS="$(ENABLE_ABYSS_THREADS)"'		>>$@
	@echo 'ENABLE_LIBXML2_BACKEND="$(ENABLE_LIBXML2_BACKEND)"'      >>$@
	@echo 'MUST_BUILD_WININET_CLIENT="$(MUST_BUILD_WININET_CLIENT)"'>>$@
	@echo 'MUST_BUILD_CURL_CLIENT="$(MUST_BUILD_CURL_CLIENT)"'	>>$@
	@echo 'MUST_BUILD_LIBWWW_CLIENT="$(MUST_BUILD_LIBWWW_CLIENT)"'	>>$@
	@echo 'NEED_RPATH="$(NEED_RPATH)"'				>>$@
	@echo 'NEED_WL_RPATH="$(NEED_WL)RPATH)"'			>>$@
	@echo 'LSOCKET="$(LSOCKET)"'					>>$@
	@echo 'WININET_LDADD="$(WININET_LDADD)"'			>>$@
	@echo 'WININET_RPATH="$(WININET_RPATH)"'			>>$@
	@echo 'WININET_WL_RPATH="$(WININET_WL_RPATH)"'			>>$@
	@echo 'CURL_LDADD="$(CURL_LDADD)"'				>>$@
	@echo 'CURL_RPATH="$(CURL_RPATH)"'				>>$@
	@echo 'CURL_WL_RPATH="$(CURL_WL_RPATH)"'			>>$@
	@echo 'LIBWWW_LDADD="$(LIBWWW_LDADD)"'				>>$@
	@echo 'LIBWWW_RPATH="$(LIBWWW_RPATH)"'				>>$@
	@echo 'LIBWWW_WL_RPATH="$(LIBWWW_WL_RPATH)"'			>>$@
	@echo 'VERSION="$(VERSION)"'					>>$@
	@echo 'FEATURE_LIST="$(FEATURE_LIST)"'				>>$@
	@echo 'PREFIX="$(PREFIX)"'					>>$@
	@echo 'EXEC_PREFIX="$(EXEC_PREFIX)"'				>>$@
	@echo 'INCLUDEDIR="$(INCLUDEDIR)"'                              >>$@
	@echo 'BLDDIR="$(BLDDIR)"'                                      >>$@
	@echo 'ABS_SRCDIR="$(ABS_SRCDIR)"'                              >>$@
	@echo '#######################################################' >>$@

xmlrpc-c-config xmlrpc-c-config.test:%: %.main shell_config
	rm -f $@
	@echo "Echoes to '$@' suppressed here ..."
	@echo '#! /bin/sh' >>$@ || rm $@
	@echo '#'                                                       >>$@
	@echo '# This file was generated by a make rule'                >>$@
	@echo '#'                                                       >>$@
	cat shell_config >>$@ || rm $@
	cat $< >>$@ || rm $@
	chmod a+rx $@ || rm $@

.PHONY: clean clean-local
clean: $(SUBDIRS:%=%/clean) clean-common clean-local

clean-local:
	rm -f transport_config.h version.h

.PHONY: distclean distclean-local
distclean: $(SUBDIRS:%=%/distclean) distclean-common distclean-local

distclean-local: clean-local
	rm -f config.log config.status Makefile.config Makefile.srcdir libtool 
	rm -f xmlrpc_config.h xmlrpc_amconfig.h stamp-h 
	rm -f shell_config xmlrpc-c-config xmlrpc-c-config.test

check: $(SUBDIRS:%=%/check)

.PHONY: tags
tags: $(SUBDIRS:%=%/tags) TAGS

DISTFILES = 

.PHONY: distdir
distdir: distdir-common

.PHONY: install
install: $(SUBDIRS:%=%/install) install-common install-compat-hdr

.PHONY: install-compat-hdr
install-compat-hdr:
# Install old names of header files for backward compatibility
	cd $(DESTDIR)$(HEADERINST_DIR); \
	  rm -f xmlrpc.h xmlrpc_client.h xmlrpc_server.h xmlrpc_cgi.h \
                xmlrpc_server_abyss.h xmlrpc_server_w32httpsys.h \
	        XmlRpcCpp.h; \
	  $(LN_S) xmlrpc-c/oldxmlrpc.h         xmlrpc.h; \
	  $(LN_S) xmlrpc-c/client.h            xmlrpc_client.h; \
	  $(LN_S) xmlrpc-c/server.h            xmlrpc_server.h; \
	  $(LN_S) xmlrpc-c/server_cgi.h        xmlrpc_cgi.h; \
	  $(LN_S) xmlrpc-c/server_abyss.h      xmlrpc_server_abyss.h; \
	  $(LN_S) xmlrpc-c/server_w32httpsys.h xmlrpc_server_w32httpsys.h; \
	  $(LN_S) xmlrpc-c/oldcppwrapper.hpp   XmlRpcCpp.h ;\

.PHONY: dep
dep: version.h $(BLDDIR)/include/xmlrpc-c/config.h $(SUBDIRS:%=%/dep)

xmlrpc_config.h xmlrpc_amconfig.h \
	:%:%.in $(SRCDIR)/configure
	$(SRCDIR)/configure

include $(SRCDIR)/Makefile.common
