sourcesdir = $(libdir)/monodoc/sources
cserrors_sourcesdir = $(libdir)/monodoc/sources

sources_DATA = \
	ecma334.tree ecma334.zip ecma334.source 		\
	netdocs.tree netdocs.zip netdocs.source			\
	nunit-docs.tree nunit-docs.zip nunit-docs.source	\
	Mono.tree Mono.zip Mono.source 				\
	Novell.source Novell.zip Novell.tree

if BUILD_CSERRORS
cserrors_sources_DATA = \
	cs-errors.tree cs-errors.zip cs-errors.source
endif

ASSEMBLER = ../engine/assembler.exe

#
# Netdocs contains all the .NET Framework documentation
#
netdocs: netdocs.tree

netdocs.tree netdocs.zip: $(srcdir)/*/en/*/*.xml $(srcdir)/*/en/*.xml
	mono --debug $(ASSEMBLER) -o netdocs			\
		--ecma $(srcdir)/corlib/en/			\
		--ecma $(srcdir)/System/en/			\
		--ecma $(srcdir)/System.XML/en/			\
		--ecma $(srcdir)/System.Web/en			\
		--ecma $(srcdir)/System.Web.Services/en		\
		--ecma $(srcdir)/System.Data/en			\
		--ecma $(srcdir)/System.DirectoryServices/en	\
		--ecma $(srcdir)/System.Drawing/en		\
		--ecma $(srcdir)/System.Security/en		\
		--ecma $(srcdir)/Microsoft.Build.Framework/en	\
		--ecma $(srcdir)/Microsoft.Build.BuildEngine/en	\
		--ecma $(srcdir)/Microsoft.Build.Utilities/en

#
# All the Mono.* namespaces go into a single package
#
Mono.tree Mono.zip: $(srcdir)/Mono.Cairo/en/*/*.xml  $(srcdir)/Mono.GetOptions/en/*/*.xml $(srcdir)/Mono.Posix/en/*/*.xml $(srcdir)/Mono.Security/en/*/*.xml $(srcdir)/Mono.Security.Win32/en/*/*.xml $(srcdir)/Commons.Xml.Relaxng/en/*/*.xml $(srcdir)/Mono.Addins/en/*/*.xml
	mono --debug $(ASSEMBLER) --ecma $(srcdir)/Mono.Cairo/en --ecma $(srcdir)/Mono.GetOptions/en --ecma $(srcdir)/Mono.Posix/en --ecma $(srcdir)/Mono.Security.Win32/en/ --ecma $(srcdir)/Mono.Security/en/ --ecma $(srcdir)/Commons.Xml.Relaxng/en/ --ecma $(srcdir)/Mono.Addins/en/ -o Mono

#
# All the Novell namespaces we handle go into a single file (one for now).
#
Novell.tree Novell.zip: $(srcdir)/Novell.Directory.Ldap/en/*/*.xml
	mono --debug $(ASSEMBLER) --ecma $(srcdir)/Novell.Directory.Ldap/en/ -o Novell

#
# These are the NUnit documents, not sure why we have these, if NUnit is well documented
#
nunit-docs.tree nunit-docs.zip: $(srcdir)/nunit/en/*/*.xml $(srcdir)/nunit/en/*.xml
	mono --debug $(ASSEMBLER) --ecma $(srcdir)/nunit/en/ -o nunit-docs

#
# Generation of C# errors, from the mcs source tree
#
cs-errors.tree cs-errors.zip: $(srcdir)/cs-errors.config
	mono --debug $(ASSEMBLER) --error $(srcdir)/cs-errors.config -o cs-errors

#
# The ECMA C# specification, from Jon Jagger.
#
ecma334.tree ecma334.zip: $(srcdir)/../ecma334/*
	mono --debug $(ASSEMBLER) --ecmaspec $(srcdir)/../ecma334 -o ecma334

CLEANFILES = \
	ecma334.tree ecma334.zip 	\
	netdocs.tree netdocs.zip 	\
	nunit-docs.tree nunit-docs.zip 	\
	cs-errors.tree cs-errors.zip 	\
	Mono.tree Mono.zip 		\
	Novell.tree Novell.zip		\
	tmp 

EXTRA_DIST = \
	$(sources_DATA) $(cserrors_sources_DATA)

dirs = \
	corlib System System.Configuration.Install System.Data System.Design 	\
	System.Drawing System.Runtime.Remoting 					\
	System.Runtime.Serialization.Formatters.Soap System.Web 		\
	System.Web.Services System.Windows.Forms System.XML 			\
	nunit Mono.Cairo Mono.GetOptions Mono.Posix Mono.Security Mono.Security.Win32 Mono.Addins	\
	Microsoft.Build.Framework Microsoft.Build.BuildEngine Microsoft.Build.Utilities

UPDATE_DIRS = \
	mscorlib:corlib \
	System System.Configuration.Install System.Data System.Design 		\
	System.Drawing System.Runtime.Remoting 					\
	System.Runtime.Serialization.Formatters.Soap System.Web 		\
	System.Web.Services System.Windows.Forms Npgsql 			\
	Mono.Cairo Mono.GetOptions Mono.Posix Mono.Security Mono.Security.Win32 Mono.Addins \
	System.Security \
	System.Xml:System.XML

UPDATE_COMMAND = \
	mono --debug ../tools/monodocer1.exe -pretty -overrides -ignore_extra_docs  \
		-assembly:@prefix@/lib/mono/1.0/$(1).dll                                  \
		-path:./$(2)/en || exit 1;                                                \
	mono --debug ../tools/monodocer.exe -pretty -overrides -since:".NET 2.0"    \
		-assembly:@prefix@/lib/mono/2.0/$(1).dll                                  \
		-path:./$(2)/en || exit 1;

IMPORT_COMMAND = \
	mono --debug ../tools/monodocer.exe -pretty -overrides                      \
		-assembly:@prefix@/lib/mono/2.0/$(1).dll                                  \
		-path:./$(2)/en -importecmadoc:$(ECMA_XML_DOCS) || exit 1;

update:
	for i in $(UPDATE_DIRS); do \
		a=`echo $$i | sed -r 's/^([^:]+).*$$/\1/'`; \
		d=`echo $$i | sed -r 's/^[^:]+:(.*)$$/\1/'`; \
		if test -z "$$d" ; then d="$$a"; fi; \
		$(call UPDATE_COMMAND,$$a,$$d)
	done
	mono --debug ../tools/monodocer.exe -pretty -overrides \
		-assembly:@prefix@/lib/mono/1.0/nunit.framework.dll -path:./nunit/en

import:
	for i in $(UPDATE_DIRS); do \
		a=`echo $$i | sed -r 's/^([^:]+).*$$/\1/'`; \
		d=`echo $$i | sed -r 's/^[^:]+:(.*)$$/\1/'`; \
		if test -z "$$d" ; then d="$$a"; fi; \
		$(call UPDATE_COMMAND,$$a,$$d)
	done

update-dir:
	$(call UPDATE_COMMAND,$(ASSEMBLY),$(DIR))

import-dir:
	$(call IMPORT_COMMAND,$(ASSEMBLY),$(DIR))

dist-hook:
	find . -name '*.xml' > files
	tar cTf files - | (cd $(distdir); tar xf -)
	cp $(srcdir)/cs-errors.* $(distdir)
