# include paths and global variables
include ../../../common/Make.global_options
-example-directories = $(shell echo $D/examples/step-? $D/examples/step-??)
-example-names = $(notdir $(example-directories))
+
+# plain names of those files that we shall treat
+example-names = $(notdir $(shell echo $D/examples/step-? \
+ $D/examples/step-??))
+
+# prefix names for generated intermediate files
+gen-example-names = $(addprefix generated/, $(example-names))
+
+# names of commented program files, plain files, and tocs for the commented
+# and commented and plain versions of the program as well as a combined one
+example-commprogs = $(addsuffix _prog.html,$(gen-example-names))
+example-plainprogs = $(addsuffix _plain.html,$(gen-example-names))
+example-toc-prog = $(addsuffix _toc.prog,$(gen-example-names))
+example-toc-plain = $(addsuffix _toc.plain,$(gen-example-names))
+example-toc = $(addsuffix _toc.combined,$(gen-example-names))
+
example-htmls = $(addsuffix .html,$(example-names))
-example-sgmls = $(addsuffix .sgml,$(example-names))
+
+
+# a makefile command that extracts the base name of a program
+get_basename = $(shell echo $(1) | $(PERL) -pi -e 's/generated.//g; s/\..*//g; s/_(prog|plain|toc.*)//g;')
+
+
all: $(example-htmls)
+test:
+ echo $(example-commprogs)
-$(example-htmls):
- @echo ================== Assembling $@
- @TOC=`cat $D/examples/$(@:.html=)/$(@:.html=.cc) \
- | $(PERL) program2toc \
- | $(PERL) -pi -e 's/\"/\\\"/g;'` ; \
- plainTOC=`echo $$TOC | $(PERL) -pi -e 's/href=.../href=\\\"\#plain-/g;'` ; \
- cat head.html \
- | $(PERL) -pi -e '$$step="$@"; \
- $$step=~s/step-(\d+).html/$$1/g; \
- s/step xxx/step $$step/g;' \
- | $(PERL) -pi -e "s!commentedTOC!$$TOC!g;" \
- | $(PERL) -pi -e "s!plainTOC!$$plainTOC!g;" \
- > $@
- @cat $(@:.html=.data/intro.html) >> $@
- @cat $D/examples/$(@:.html=)/$(@:.html=.cc) \
+$(example-commprogs):
+ @echo ================== Making $@
+ @cat $D/examples/$(call get_basename, $@)/*.cc \
| $(PERL) program2html \
- >> $@
- @cat $(@:.html=.data/results.html) >> $@
- @cat $D/examples/$(@:.html=)/$(@:.html=.cc) \
+ > $@
+
+
+$(example-plainprogs):
+ @echo ================== Making $@
+ @cat $D/examples/$(call get_basename, $@)/*.cc \
| $(PERL) program2plain \
- | $(PERL) -e '$$path="$D/examples/$(@:.html=)/$(@:.html=.cc)"; \
+ | $(PERL) -e '$$path="$D/examples/$(call get_basename,$@)/*.cc)"; \
$$path =~ s!/! /!g; \
while (<>) { s!PROGRAMPATH!$$path!g; print; };' \
- >> $@
- @cat foot.html >> $@
+ > $@
+
+
+$(example-toc-prog):
+ @echo ================== Making $@
+ @cat $D/examples/$(call get_basename, $@)/*.cc \
+ | $(PERL) program2toc \
+ > $@
+
+
+$(example-toc-plain): $(example-toc-prog)
+ @echo ================== Making $@
+ @cat generated/$(call get_basename, $@)_toc.prog \
+ | $(PERL) -pi -e 's/href=\"\#/href=\"\#plain-/g;' \
+ > $@
+
+
+$(example-toc): $(example-toc-prog) $(example-toc-plain)
+ @echo ================== Making $@
+ @echo "<table class=\"tutorial\"> <tr> <td>" > $@
+ @echo "<ol>" >> $@
+ @echo " <li> <a href=\"#Intro\" class=bold>Introduction</a>" >> $@
+ @echo " <li> <a href=\"#CommProg\" class=bold>The commented program</a>" >> $@
+ @cat generated/$(call get_basename, $@)_toc.prog >> $@
+ @echo " <li> <a href=\"#Results\" class=bold>Results</a>" >> $@
+ @echo " <li> <a href=\"#PlainProg\" class=bold>The plain program</a>" >> $@
+ @cat generated/$(call get_basename, $@)_toc.plain >> $@
+ @echo "</ol> </td> </tr> </table>" >> $@
-# Note: SGML support is very preliminary and not very functional at present!
-$(example-sgmls):
+
+
+$(example-htmls): $(example-commprogs) $(example-plainprogs) \
+ $(example-toc)
@echo ================== Assembling $@
- @cat $(@:.sgml=.data/intro.html) >> $@
- @echo "</sect2>" >> $@
- @cat $D/examples/$(@:.sgml=)/$(@:.sgml=.cc) \
- | $(PERL) program2html \
- >> $@
- @echo "</sect2>" >> $@
- @cat $(@:.sgml=.data/results.html) >> $@
- @echo "</sect2>" >> $@
- @cat $D/examples/$(@:.sgml=)/$(@:.sgml=.cc) \
- | $(PERL) program2plain \
- | $(PERL) -e '$$path="$D/examples/$(@:.sgml=)/$(@:.sgml=.cc)"; \
- $$path =~ s!/! /!g; \
- while (<>) { s!PROGRAMPATH!$$path!g; print; };' \
- >> $@
- @echo "</sect2>" >> $@
- @$(PERL) -pi -e 's!<a .*</a>!!gi; \
- s!<h1>(.*)</h1>!<sect2><title>$$1</title>!gi; \
- s!<p>!\n<para>!gi; \
- s!</p>!</para>!gi; \
- s!<pre><code>!<programlisting>!gi; \
- s!</code></pre>!</programlisting>!gi; ' $@
-
-step-by-step.sgml: $(example-sgmls)
- @echo ================== Concating $@
- @cat step-by-step.header.sgml \
- | $(PERL) -pi -e 's/TODAY/$(shell date)/;' \
- > $@
- @for step in $(example-names) ; do \
- echo "<sect1><title>$$step</title>" >> $@ ; \
- cat $$step.sgml >> $@ ; \
- echo "</sect1>" >> $@ ; \
- done
- @echo "</chapter>" >> $@
- @echo "</book>" >> $@
- @rm $(example-sgmls)
+ @cat head.html > $@
+ @echo "<h2>Overview of $(call get_basename,$@)</h2>" >> $@
+ @cat generated/$(call get_basename, $@)_toc.combined \
+ $(call get_basename, $@).data/intro.html \
+ generated/$(call get_basename, $@)_prog.html \
+ $(call get_basename, $@).data/results.html\
+ generated/$(call get_basename, $@)_plain.html \
+ foot.html >> $@
+
+
validate-xrefs:
clean:
-rm -f $(example-htmls)
+ -rm -f $(example-commprogs) $(example-plainprogs) $(example-toc)
# mark the output files as phony, i.e. generate them every time
-.PHONY: $(example-htmls) validate-xrefs clean
+.PHONY: $(example-htmls) $(example-commprogs) \
+ $(example-plainprogs) $(example-toc) \
+ $(example-toc-prog) $(example-toc-plain) \
+ validate-xrefs clean