]> git.donarmstrong.com Git - lilypond.git/blob - scripts/auxiliar/doc-section.sh
Add '-dcrop' option to ps and svg backends
[lilypond.git] / scripts / auxiliar / doc-section.sh
1 #!/bin/sh
2
3 #  Build html versions of sections of lilypond documentation
4 #
5 #  Usage:  ./doc-section.sh MANUAL SECTION
6 #
7 #    where MANUAL is the manual and SECTION is the section to be
8 #    built.
9 #
10 #  For example, NR 1.2 would be built by
11 #       ./doc-section.sh notation rhythms
12 #
13 #     and LM 1 would be built by
14 #       ./doc-section.sh learning tutorial
15 #
16 #  At the end of the run, the user is prompted whether or not to
17 #  remove the generated files.
18 #
19 #  According to http://code.google.com/p/lilypond/issues/detail?id=1236
20 #  the location of the lilypond git tree is taken from $LILYPOND_GIT
21 #  if specified, otherwise it is auto-detected.
22 #
23 #  It is assumed that compilation takes place in the build/
24 #  subdirectory, but this can be overridden by setting the environment
25 #  variable LILYPOND_BUILD_DIR.
26 #
27 #  Similarly, output defaults to build/tempdocs/ but this can be
28 #  overridden by setting the environment variable LILYPOND_TEMPDOCS.
29 #
30 #
31 #  Known limitations:
32 #
33 #     * Doesn't use website css files
34 #     * Bitmap images aren't loaded properly
35 #     * Won't build Contributors' Guide; see scripts/auxiliar/cg-section.sh
36 #
37
38 usage () {
39     cat <<EOF >&2
40
41 Usage: $0 MANUAL SECTION
42 e.g. $0 notation rhythms
43
44 EOF
45     exit "$1"
46 }
47
48 if [ "$1" = '-h' ] || [ "$1" = '--help' ]; then
49     usage 0
50 fi
51
52 [ $# = 2 ] || usage 1
53
54 if [ -n "$LILYPOND_GIT" ]; then
55     echo "Using source tree from value of \$LILYPOND_GIT: $LILYPOND_GIT"
56 else
57     cd "`dirname $0`"
58     cd ../..
59     LILYPOND_GIT="`pwd`"
60     echo "\$LILYPOND_GIT was not set; auto-detected source tree at $LILYPOND_GIT"
61 fi
62
63 if [ -n "$BROWSER" ]; then
64     echo "Using browser from \$BROWSER: $BROWSER"
65 else
66     echo "\$BROWSER not set; using firefox as default"
67     BROWSER="firefox"
68 fi
69
70 if test ! -e "$LILYPOND_GIT/DEDICATION"; then
71     echo "Error: $LILYPOND_GIT did not look like a LilyPond source tree; aborting." >&2
72     exit 1
73 fi
74
75 : "${LILYPOND_BUILD_DIR:=$LILYPOND_GIT/build}"
76 DOC_DIR="${LILYPOND_TEMPDOCS:-$LILYPOND_BUILD_DIR/tempdocs}"
77 LILYPOND_BOOK="$LILYPOND_BUILD_DIR/out/bin/lilypond-book"
78 TEXI2HTML="texi2html"
79 REFCHECK="$LILYPOND_GIT/scripts/auxiliar/ref_check.py"
80
81 MANUAL="$1"
82 SECTION="$2"
83 OUTPUT_DIR="$DOC_DIR/$SECTION"
84 MANUAL_PATH="$LILYPOND_GIT/Documentation/$MANUAL"
85 SECTION_PATH="$MANUAL_PATH/$SECTION.itely"
86
87 if test ! -d "$LILYPOND_BUILD_DIR"; then
88     echo "$LILYPOND_BUILD_DIR did not exist; check your setting of LILYPOND_BUILD_DIR. Aborting." >&2
89     exit 1
90 fi
91
92 if test ! -d "$MANUAL_PATH"; then
93     echo "$MANUAL_PATH was not a valid directory; is $MANUAL a valid manual?" >&2
94     exit 1
95 fi
96
97 if test ! -e "$SECTION_PATH"; then
98     echo "$SECTION_PATH did not exist; is $SECTION a valid section in the $MANUAL manual?" >&2
99     exit 1
100 fi
101
102 if test ! -d "$DOC_DIR"; then
103     mkdir "$DOC_DIR"
104     cp "$LILYPOND_BUILD_DIR/Documentation/out/version.itexi" "$DOC_DIR"
105 fi
106 if test ! -d "$OUTPUT_DIR"; then
107     mkdir "$OUTPUT_DIR"
108 fi
109 if test ! -d "$OUTPUT_DIR/out"; then
110     mkdir "$OUTPUT_DIR/out"
111 fi
112
113 cp "$LILYPOND_GIT/Documentation/common-macros.itexi" "$OUTPUT_DIR/common-macros.itexi"
114 cp "$LILYPOND_GIT/Documentation/macros.itexi" "$DOC_DIR/macros.itexi"
115 cp "$DOC_DIR/version.itexi" "$OUTPUT_DIR/version.itexi"
116 cp -r "$LILYPOND_GIT/Documentation/pictures/" "$OUTPUT_DIR/out/pictures"
117
118 if test -e "$OUTPUT_DIR/$SECTION.html"; then
119     rm "$OUTPUT_DIR/$SECTION.html"
120 fi
121
122 if test -e "$OUTPUT_DIR/out/$SECTION.texi"; then
123     rm "$OUTPUT_DIR/out/$SECTION.texi"
124 fi
125
126 echo "Running $LILYPOND_BOOK"
127 "$LILYPOND_BOOK" \
128         -f texi-html \
129         -I "$LILYPOND_GIT/Documentation/snippets" \
130         -I "$LILYPOND_GIT/Documentation/snippets/new" \
131         -I "$LILYPOND_GIT/input/manual" \
132         -I "$LILYPOND_GIT/Documentation" \
133         -I "$LILYPOND_GIT/Documentation/included"  \
134         -I "$LILYPOND_GIT/Documentation/pictures" \
135         -o "$OUTPUT_DIR/out" \
136         "$SECTION_PATH"
137 BOOKRC=$?
138 if [ "$BOOKRC" != 0 ]; then
139     echo "Lilypond-book returned code $BOOKRC"
140     exit $BOOKRC
141 fi
142
143 echo "Running RefCheck"
144 python "$REFCHECK"
145
146 cd "$DOC_DIR"
147 if test -f "$OUTPUT_DIR/out/$SECTION.texi"; then
148     echo "Running $TEXI2HTML"
149     cat "$DOC_DIR/macros.itexi" "$OUTPUT_DIR/out/$SECTION.texi" > "$OUTPUT_DIR/$SECTION.texi"
150     "$TEXI2HTML" \
151         --no-validate \
152         --output="$OUTPUT_DIR/out/$SECTION.html" \
153         --I="$OUTPUT_DIR/out" \
154         "$OUTPUT_DIR/$SECTION.texi"
155 fi
156
157 echo "Displaying output in $BROWSER; close browser window when done."
158
159 $BROWSER $OUTPUT_DIR/out/$SECTION.html
160
161 cat <<EOF
162
163 If you want to avoid recompiling the snippets on the next 
164 invocation with '$MANUAL $SECTION', answer 'n' to the next question.
165
166 EOF
167
168 echo "Delete temp files? [y/n]"
169 read REPLY;
170 if [ "$REPLY" = "y" ]; then
171     echo "deleting files"
172     rm -rf "$OUTPUT_DIR"
173 fi