# ==================== Things `configure' Might Edit ====================

OOC=@OOC@
OFLAGS=@OFLAGS@
OOCONFIG=@OOCONFIG@
OOCN=@OOCN@

### The compiler's installation directory, and its primary initialization file.
OOC_LIBDIR=@OOC_LIBDIR@
OOC_INIT=@OOC_INIT@

### Does the compiler support creating libraries (yes/no)?
ooc_have_libs=@ooc_have_libs@

### Name of this package.
package=XML

### Transformation applied to program names when installing.
transform=@program_transform_name@

### File name extension of executables.
exeext=@EXEEXT@

# ==================== Where To Install Things ====================

# The default location for installation.  Everything is placed in
# subdirectories of this directory.  The default values for many of
# the variables below are expressed in terms of this one, so you may
# not need to change them.  This defaults to dirname(dirname($OOC_LIBDIR)).
prefix=@prefix@

# Like `prefix', but used for architecture-specific files.
exec_prefix=@exec_prefix@

# Where to install binaries that people will want to run directly.
bindir=@bindir@

# Where to install library and other files to run the package.
libdir=@libdir@

### Allow the installation directory to differ from that specified at build time
OOC_LIBDIR_INSTALL=${exec_prefix}/$(shell echo ${OOC_LIBDIR} | sed 's,^/usr/,,')
OOC_INIT_INSTALL=${exec_prefix}/$(shell echo ${OOC_INIT} | sed 's,^/usr/,,')

# The default location for installation of compiler specific files
# (symbol files, header files, etc) and the module source code.
ooc_pkgdir=${OOC_LIBDIR_INSTALL}/${package}

subdirs=IO OS URI URI/Authority URI/Fragment URI/Query URI/Scheme

# ==================== Utility Programs for the Build ====================

# Allow the user to specify the install program.
INSTALL = @INSTALL@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_SCRIPT = @INSTALL_PROGRAM@
INSTALL_DATA = @INSTALL_DATA@

version=3.0

# ============================= Targets ==============================


.PHONY: all clean test doc

all: libxml$(exeext)

libxml$(exeext): oo2crc localdirs
	if test $(ooc_have_libs) = yes; then \
	  $(OOC) --config oo2crc --make-lib $(OFLAGS) --lib-path $(libdir) libxml && touch libxml$(exeext); \
	else \
	  $(OOC) --config oo2crc -Mv $(OFLAGS) libxml && touch libxml$(exeext); \
	fi

install: all mkdir config.ooc
	(cd src; for dir in . ${subdirs}; do \
	  for i in $$dir/*.Mod; do \
            (cd .. && $(INSTALL_DATA) src/$$i ${ooc_pkgdir}/$$dir); \
	  done; \
	done)
	for i in src/*.[ch]; do \
          $(INSTALL_DATA) $$i ${ooc_pkgdir}; \
	done; \
	echo "--remove-line \"*:$(package):*\"" >> $(package).ooc
	echo "--append-line PATHS:$(package):SRC \"GET *.Mod,*.c FROM $(ooc_pkgdir);\"" | sed 's;$(shell pwd)/debian/libooc-xml-dev;;' >> $(package).ooc
	echo "--append-line PATHS:$(package):SYM \"GET *.Sym,*.Lib FROM $(ooc_pkgdir)/sym;\"" | sed 's;$(shell pwd)/debian/libooc-xml-dev;;' >> $(package).ooc
	echo "--append-line PATHS:$(package):OBJ \"GET *.h,*.c,*.d,*.o FROM $(ooc_pkgdir)/obj;\"" | sed 's;$(shell pwd)/debian/libooc-xml-dev;;' >> $(package).ooc
	cat config.ooc >> $(package).ooc
	cat $(package).ooc | xargs $(OOCONFIG) $(OOC_INIT_INSTALL)
	for i in sym/*.Sym; do \
          $(INSTALL_DATA) $$i ${ooc_pkgdir}/sym; \
	done
	for i in obj/*.[cdh]; do \
	  $(INSTALL_DATA) $$i ${ooc_pkgdir}/obj; \
	done
	if test $(ooc_have_libs) = yes; then \
	  for i in sym/*.Lib; do \
            $(INSTALL_DATA) $$i ${ooc_pkgdir}/sym; \
	  done; \
          umask 022; $(OOC) --install-lib --config oo2crc --lib-path $(libdir) libxml; \
	else \
	  sleep 1; \
	  for i in obj/*.o; do \
	    $(INSTALL_DATA) $$i ${ooc_pkgdir}/obj; \
	  done; \
	fi

installlib: all mkdir config.ooc
	if test $(ooc_have_libs) = yes; then \
          umask 022; $(OOC) --install-lib --config oo2crc --lib-path $(libdir) libxml; \
	fi

### `doc'
###      Create documentation from module sources.
doc:	mkdir
	${OOCN} --def-txt -Cv -o doc/txt libxml
	${OOCN} --def-html -Cv -o doc/html libxml
	${OOCN} --xref -Cv -o doc/xref libxml

# ======================== Auxiliary Targets =========================

oo2crc: config.ooc
	cp $(OOC_INIT) oo2crc.tmp
	cat config.ooc | xargs $(OOCONFIG) oo2crc.tmp --fix-includes --remove-line "*:$(package):*" \
	  --prepend-line "PATHS:$(package):SRC" "GET *.Mod,*.c FROM src;" \
	  --prepend-line "PATHS:$(package):OBJ" "GET *.h,*.c,*.d,*.o FROM obj;" \
	  --prepend-line "PATHS:$(package):SYM" "GET *.Sym,*.Lib FROM sym;"
	mv oo2crc.tmp oo2crc

FRC:

localdirs:
	for i in sym obj; do if test ! -d $$i; then mkdir $$i; fi; done

mkdir: FRC
	(umask 022; \
          ./mkinstalldirs ${ooc_pkgdir} ${ooc_pkgdir}/IO \
	                  ${ooc_pkgdir}/sym ${ooc_pkgdir}/obj; \
	  for i in ${subdirs}; do ./mkinstalldirs ${ooc_pkgdir}/$$i; done; \
	  for i in doc doc/txt doc/html doc/xref; do \
	    ./mkinstalldirs $$i; \
	  done )

Makefile: Makefile.in config.status
	./config.status

test: localdirs
	${OOC} -MOv TestGet
	${OOC} -MOv TestServer
	cd tests && ${MAKE} test

dist: distclean
	autoconf
	(d="ooc-libxml-${version}"; f="$$d.tar"; \
	  cd .. && ln -s libxml $$d && \
	  tar -c -h -v -f $$f $$d && bzip2 -9 $$f && rm -f $$d)

# ==================== Cleaning up and miscellanea ====================

.PHONY: clean distclean

### `clean'
###      Delete all files from the current directory that are normally
###      created by building the program.  Don't delete the files that
###      record the configuration.  Also preserve files that could be made
###      by building, but normally aren't because the distribution comes
###      with them.
clean: FRC
	rm -Rf sym obj doc .libs TestCodecs TestParser TestURI TestGet TestServer oo2crc oo2crc.tmp.orig libxml$(exeext)
	rm -f *.o *.lo *.la
	cd tests && ${MAKE} clean

### `distclean'
###      Delete all files from the current directory that are created by
###      configuring or building the program.  If you have unpacked the
###      source and built the program without creating any other files,
###      `make distclean' should leave only the files that were in the
distclean: clean
	rm -f config.status config.cache config.log config.ooc Makefile
