###############################################################################
# The following macros should be defined before this script is
# invoked:
#
# DOC              The toplevel directory of the documentation source tree.
#
# SRC              The toplevel directory of the source code source tree.
#
# NAWK             Nawk compatible awk program.  Older (obsolete?) solaris
#                  systems need this to avoid using the original AT&T AWK.
#
# Once the macros above are defined, the rest of this make script will
# build the SQLite library and testing tools.
################################################################################

all:	doc

sqlite3.h:	$(SRC)/src/sqlite.h.in 
	sed -e s/--VERS--/`cat ${SRC}/VERSION`/ \
	    -e s/--VERSION-NUMBER--/`cat ${SRC}/VERSION | \
	sed 's/[^0-9]/ /g' | \
	$(NAWK) '{printf "%d%03d%03d",$$1,$$2,$$3}'`/ \
		$(SRC)/src/sqlite.h.in >sqlite3.h


# Rules used to build documentation
#
%.html: $(DOC)/%.tcl common.tcl
	tclsh $< > $@

common.tcl:	$(DOC)/common.tcl
	cp $(DOC)/common.tcl .

lang.html: $(DOC)/lang.tcl
	tclsh $(DOC)/lang.tcl doc >lang.html

opcode.html:	$(DOC)/opcode.tcl $(SRC)/src/vdbe.c
	tclsh $(DOC)/opcode.tcl $(SRC)/src/vdbe.c >opcode.html

capi3ref.html:	$(DOC)/mkapidoc.tcl sqlite3.h
	tclsh $(DOC)/mkapidoc.tcl <sqlite3.h >capi3ref.html

copyright-release.html:	$(DOC)/copyright-release.html
	cp $(DOC)/copyright-release.html .

copyright-release.pdf:	$(DOC)/copyright-release.pdf
	cp $(DOC)/copyright-release.pdf .

#%: $(DOC)/%
#	cp $< $@

# Files to be published on the website.
#
DOCFILES = \
  arch.html \
  autoinc.html \
  c_interface.html \
  capi3.html \
  capi3ref.html \
  changes.html \
  compile.html \
  copyright.html \
  copyright-release.html \
  copyright-release.pdf \
  conflict.html \
  datatypes.html \
  datatype3.html \
  different.html \
  docs.html \
  download.html \
  faq.html \
  fileformat.html \
  formatchng.html \
  index.html \
  limits.html \
  lang.html \
  lockingv3.html \
  mingw.html \
  nulls.html \
  oldnews.html \
  omitted.html \
  opcode.html \
  optimizer.html \
  optoverview.html \
  pragma.html \
  quickstart.html \
  sharedcache.html \
  speed.html \
  sqlite.html \
  support.html \
  tclsqlite.html \
  vdbe.html \
  version3.html \
  whentouse.html \
  34to35.html

docdir:
	mkdir -p doc

doc:	docdir $(DOCFILES)
	mv $(DOCFILES) doc
	cp $(DOC)/*.gif $(SRC)/art/*.gif doc

clean:	
	rm -f doc sqlite3.h
