Making schemas

<p:library xmlns:p="http://www.w3.org/ns/xproc"
	   xmlns:c="http://www.w3.org/ns/xproc-step"
	   xmlns:cx="http://xmlcalabash.com/ns/extensions"
	   xmlns:xs="http://www.w3.org/2001/XMLSchema"
	   xmlns:pl="http://www.w3.org/XML/XProc/docs/library">

<p:import href="http://xmlcalabash.com/extension/steps/library-1.0.xpl"/>
<p:import href="/home/ndw/xmlcalabash.com/library/depends.xpl"/>

<p:pipeinfo xml:id="dtd-parts">
  <cx:targets>
    <cx:target>xproc_dtd_1.ent</cx:target>
    <cx:target>xproc_dtd_2.ent</cx:target>
    <cx:target>xproc_dtd_3.ent</cx:target>
    <cx:target>xproc_dtd_4.ent</cx:target>
  </cx:targets>
</p:pipeinfo>

<p:pipeinfo xml:id="steps-depends">
  <cx:depends>
    <cx:target>steps.rnc</cx:target>
    <cx:source>../typed-pipeline-library.xml</cx:source>
    <cx:source>../../style/library-to-rnc.xsl</cx:source>
  </cx:depends>
</p:pipeinfo>

<p:pipeinfo xml:id="xproc-depends">
  <cx:depends>
    <cx:target>steps.rnc</cx:target>
    <cx:source>xproc.rnc</cx:source>
    <cx:source>steps.rnc</cx:source>
  </cx:depends>
</p:pipeinfo>

<p:pipeinfo xml:id="dtd-depends">
  <cx:depends>
    <cx:target>xproc.dtd</cx:target>
    <cx:source>xproc_dtd_1.ent</cx:source>
    <cx:source>xproc_dtd_3.ent</cx:source>
    <cx:source>../typed-pipeline-library.xml</cx:source>
    <cx:source>../../style/library-to-dtd.xsl</cx:source>
  </cx:depends>
</p:pipeinfo>

<p:pipeinfo xml:id="xsd-depends">
  <cx:depends>
    <cx:target>xproc.xsd</cx:target>
    <cx:source>xproc_xsd_skeleton.xml</cx:source>
    <cx:source>../typed-pipeline-library.xml</cx:source>
    <cx:source>../../style/library-to-xsd.xsl</cx:source>
  </cx:depends>
</p:pipeinfo>

<p:declare-step name="main" type="pl:build-schemas">
  <p:input port="parameters" kind="parameter"/>
  <pl:make-steps/>
  <pl:make-xproc/>
  <pl:make-dtd/>
  <pl:make-xsd/>
</p:declare-step>

<p:declare-step name="main" type="pl:make-steps">
  <p:input port="parameters" kind="parameter"/>

  <cx:out-of-date>
    <p:input port="source" select="id('steps-depends')/cx:depends">
      <p:document href="#"/>
    </p:input>
  </cx:out-of-date>

  <p:choose>
    <p:when test="/c:result = 'true'">
      <cx:message message="Updating: steps.rnc">
	<p:input port="source"><p:empty/></p:input>
      </cx:message>
      <p:sink/>
      <p:xslt>
	<p:input port="source">
	  <p:document href="../typed-pipeline-library.xml"/>
	</p:input>
	<p:input port="stylesheet">
	  <p:document href="../../style/library-to-rnc.xsl"/>
	</p:input>
      </p:xslt>
      <p:store href="steps.rnc" method="text"/>
    </p:when>
    <p:otherwise>
      <cx:message message="Up-to-date: steps.rnc">
	<p:input port="source"><p:empty/></p:input>
      </cx:message>
      <p:sink/>
    </p:otherwise>
  </p:choose>
</p:declare-step>

<p:declare-step name="main" type="pl:make-xproc">
  <cx:out-of-date>
    <p:input port="source" select="id('xproc-depends')/cx:depends">
      <p:document href="#"/>
    </p:input>
  </cx:out-of-date>

  <p:choose>
    <p:when test="/c:result = 'true'">
      <cx:message message="Updating: xproc.rng">
	<p:input port="source"><p:empty/></p:input>
      </cx:message>
      <p:sink/>
      <p:exec name="exec" result-is-xml="false" source-is-xml="false"
	      command="/sourceforge/docbook/buildtools/runtrang"
	      args="xproc.rnc xproc.rng">
	<p:input port="source">
	  <p:empty/>
	</p:input>
      </p:exec>
      <p:sink/>
    </p:when>
    <p:otherwise>
      <cx:message message="Up-to-date: xproc.rng">
	<p:input port="source"><p:empty/></p:input>
      </cx:message>
      <p:sink/>
    </p:otherwise>
  </p:choose>
</p:declare-step>

<p:declare-step name="main" type="pl:make-dtd">
  <p:input port="parameters" kind="parameter"/>
  <cx:out-of-date>
    <p:input port="source" select="id('dtd-depends')/cx:depends">
      <p:document href="#"/>
    </p:input>
  </cx:out-of-date>

  <p:choose>
    <p:when test="/c:result = 'true'">
      <cx:message message="Updating: xproc.dtd">
	<p:input port="source"><p:empty/></p:input>
      </cx:message>
      <p:sink/>

      <p:xslt>
	<p:input port="source">
	  <p:document href="../typed-pipeline-library.xml"/>
	</p:input>
	<p:input port="stylesheet">
	  <p:document href="../../style/library-to-dtd.xsl"/>
	</p:input>
	<p:with-param name="step-cm" select="'xproc_dtd_2.ent'">
	  <p:empty/>
	</p:with-param>
	<p:with-param name="step-decls" select="'xproc_dtd_4.ent'">
	  <p:empty/>
	</p:with-param>
      </p:xslt>
      <p:sink/>

      <p:exec name="exec" result-is-xml="false" source-is-xml="false"
	      command="/bin/cat">
	<p:with-option name="args"
		       select="string-join(id('dtd-parts')//cx:target, ' ')">
	  <p:document href="#"/>
	</p:with-option>
	<p:input port="source">
	  <p:empty/>
	</p:input>
      </p:exec>

      <p:store href="xproc.dtd" method="text"/>
    </p:when>
    <p:otherwise>
      <cx:message message="Up-to-date: xproc.dtd">
	<p:input port="source"><p:empty/></p:input>
      </cx:message>
      <p:sink/>
    </p:otherwise>
  </p:choose>
</p:declare-step>

<p:declare-step name="main" type="pl:make-xsd">
  <p:input port="parameters" kind="parameter"/>
  <cx:out-of-date>
    <p:input port="source" select="id('xsd-depends')/cx:depends">
      <p:document href="#"/>
    </p:input>
  </cx:out-of-date>

  <p:choose>
    <p:when test="/c:result = 'true'">
      <cx:message message="Updating: xproc.xsd">
	<p:input port="source"><p:empty/></p:input>
      </cx:message>
      <p:sink/>

      <p:xslt>
	<p:input port="source">
	  <p:document href="../typed-pipeline-library.xml"/>
	</p:input>
	<p:input port="stylesheet">
	  <p:document href="../../style/library-to-xsd.xsl"/>
	</p:input>
      </p:xslt>

      <p:store name="store" href="xproc_xsd_generated.xml"
	       method="xml" indent="true"/>

      <p:xinclude cx:depends-on="store">
	<p:input port="source">
	  <p:document href="xproc_xsd_skeleton.xml"/>
	</p:input>
      </p:xinclude>

      <p:store href="xproc.xsd"/>
    </p:when>
    <p:otherwise>
      <cx:message message="Up-to-date: xproc.xsd">
	<p:input port="source"><p:empty/></p:input>
      </cx:message>
      <p:sink/>
    </p:otherwise>
  </p:choose>
</p:declare-step>

</p:library>