Skip to content

Commit

Permalink
scripts/process-markdown: New takes output file arg
Browse files Browse the repository at this point in the history
Previously process-markdown took only an input file argument and
printed the result to standard output. Now it takes both an input file
and output file argument.

The important change is that the '.images' directory containing ditaa
images is now created in the same directory as the output file, and
that directory is created if necessary.

Previously the '.images' was created in the source directory and in
practice this was only the right thing if the output file happened to
also be in that directory. This was true the past when we were
converting foo.src.md -> foo.md but is not true anymore now that we
convert foo.md -> obj/foo.md.

src/Makefile is updated to reflect this. This also made it possible to
drop the Makefile dependency from the manual on the 'snabb'
executable, which was an ugly hack intended to ensure that the
required directory tree in obj/ had been created somehow. Now the
process-markdown script automatically creates any required output
directory.
  • Loading branch information
lukego committed Mar 18, 2016
1 parent 35a2422 commit 64ee8af
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ $(JITOBJS): obj/jit_%.o: ../lib/luajit/src/jit/%.lua $(OBJDIR)

$(RMOBJS): obj/%: %
$(E) "MARKDOWN $@"
$(Q) scripts/process-markdown $< > $@
$(Q) scripts/process-markdown $< $@

$(INCOBJ): obj/%_inc.o: %.inc Makefile | $(OBJDIR)
$(E) "INC $@"
Expand Down Expand Up @@ -181,9 +181,9 @@ obj/jit_vmprof.o: extra/vmprof.c | $(OBJDIR)
$(E) "C $@"
$(Q) gcc $(DEBUG) -Wl,-E -O2 -I ../lib/luajit/src -c -Wall -Werror -o $@ $<

book: doc/snabbswitch.pdf doc/snabbswitch.html doc/snabbswitch.epub
book: obj/doc/snabbswitch.pdf obj/doc/snabbswitch.html obj/doc/snabbswitch.epub

obj/doc/snabbswitch.markdown: snabb markdown Makefile doc/genbook.sh
obj/doc/snabbswitch.markdown: markdown Makefile doc/genbook.sh
(cd doc; ./genbook.sh) > $@

obj/doc/snabbswitch.pdf: obj/doc/snabbswitch.markdown
Expand Down
14 changes: 9 additions & 5 deletions src/scripts/process-markdown
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,19 @@
#
# which uses ditaa (http://ditaa.sourceforge.net/) to create a PNG
# image from the ascii art and put an inline image link in the
# outpt markdown.
# output markdown.

set -e
if [ $# != 1 ]; then
echo "Usage: $0 <filename>" >&2
if [ $# != 2 ]; then
echo "Usage: $0 <input> <output>" >&2
exit 1
fi

cd $(dirname $1)
input=$(readlink -f $1)
output=$(readlink -f $2)

[ -d $(dirname "$output") ] || mkdir -p "$(dirname $output)"
cd $(dirname $output)

awk '/^ DIAGRAM:/ { diagram = $2;
printf("") > diagram
Expand All @@ -30,5 +34,5 @@ awk '/^ DIAGRAM:/ { diagram = $2;
system("mkdir .images 2>/dev/null || true")
system("ditaa " diagram " .images/" diagram ".png > /dev/null");
system("rm " diagram)
diagram = 0 }' < $(basename $1)
diagram = 0 }' < $input > $output

0 comments on commit 64ee8af

Please sign in to comment.