]> git.donarmstrong.com Git - lilypond.git/blob - scripts/auxiliar/doc-section.sh
Merge branch 'lilypond/translation' into staging
[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 Usage: $0 MANUAL SECTION
41
42 e.g. $0 notation rhythms
43 EOF
44     exit "$1"
45 }
46
47 if [ "$1" == '-h' ] || [ "$1" == '--help' ]; then
48     usage 0
49 fi
50
51 [ $# = 2 ] || usage 1
52
53 if [ -n "$LILYPOND_GIT" ]; then
54     echo "Using source tree from value of \$LILYPOND_GIT: $LILYPOND_GIT"
55 else
56     cd "`dirname $0`"
57     cd ../..
58     LILYPOND_GIT="`pwd`"
59     echo "\$LILYPOND_GIT was not set; auto-detected source tree at $LILYPOND_GIT"
60 fi
61
62 if test ! -e "$LILYPOND_GIT/DEDICATION"; then
63     echo "Error: $LILYPOND_GIT did not look like a LilyPond source tree; aborting." >&2
64     exit 1
65 fi
66
67 : "${LILYPOND_BUILD_DIR:=$LILYPOND_GIT/build}"
68 DOC_DIR="${LILYPOND_TEMPDOCS:-$LILYPOND_BUILD_DIR/tempdocs}"
69 LILYPOND_BOOK="$LILYPOND_BUILD_DIR/out/bin/lilypond-book"
70 TEXI2HTML="texi2html"
71 REFCHECK="$LILYPOND_GIT/scripts/auxiliar/ref_check.py"
72
73 MANUAL="$1"
74 SECTION="$2"
75 OUTPUT_DIR="$DOC_DIR/$SECTION"
76 MANUAL_PATH="$LILYPOND_GIT/Documentation/$MANUAL"
77 SECTION_PATH="$MANUAL_PATH/$SECTION.itely"
78
79 if test ! -d "$LILYPOND_BUILD_DIR"; then
80     echo "$LILYPOND_BUILD_DIR did not exist; check your setting of LILYPOND_BUILD_DIR. Aborting." >&2
81     exit 1
82 fi
83
84 if test ! -d "$MANUAL_PATH"; then
85     echo "$MANUAL_PATH was not a valid directory; is $MANUAL a valid manual?" >&2
86     exit 1
87 fi
88
89 if test ! -e "$SECTION_PATH"; then
90     echo "$SECTION_PATH did not exist; is $SECTION a valid section in the $MANUAL manual?" >&2
91     exit 1
92 fi
93
94 if test ! -d "$DOC_DIR"; then
95     mkdir "$DOC_DIR"
96     cp "$LILYPOND_BUILD_DIR/Documentation/out/version.itexi" "$DOC_DIR"
97 fi
98 if test ! -d "$OUTPUT_DIR"; then
99     mkdir "$OUTPUT_DIR"
100 fi
101 if test ! -d "$OUTPUT_DIR/out"; then
102     mkdir "$OUTPUT_DIR/out"
103 fi
104
105 cp "$LILYPOND_GIT/Documentation/common-macros.itexi" "$OUTPUT_DIR/common-macros.itexi"
106 cp "$LILYPOND_GIT/Documentation/macros.itexi" "$DOC_DIR/macros.itexi"
107 cp "$DOC_DIR/version.itexi" "$OUTPUT_DIR/version.itexi"
108
109 if test -e "$OUTPUT_DIR/$SECTION.html"; then
110     rm "$OUTPUT_DIR/$SECTION.html"
111 fi
112
113 if test -e "$OUTPUT_DIR/out/$SECTION.texi"; then
114     rm "$OUTPUT_DIR/out/$SECTION.texi"
115 fi
116
117 echo "Running $LILYPOND_BOOK"
118 "$LILYPOND_BOOK" \
119         -f texi-html \
120         -I "$LILYPOND_GIT/Documentation/snippets" \
121         -I "$LILYPOND_GIT/Documentation/snippets/new" \
122         -I "$LILYPOND_GIT/input/manual" \
123         -I "$LILYPOND_GIT/Documentation" \
124         -I "$LILYPOND_GIT/Documentation/included"  \
125         -I "$LILYPOND_GIT/Documentation/pictures" \
126         -o "$OUTPUT_DIR/out" \
127         "$SECTION_PATH"
128 BOOKRC=$?
129 if [ "$BOOKRC" != 0 ]; then
130     echo "Lilypond-book returned code $BOOKRC"
131     exit $BOOKRC
132 fi
133
134 echo "Running RefCheck"
135 python "$REFCHECK"
136
137 cd "$DOC_DIR"
138 if test -f "$OUTPUT_DIR/out/$SECTION.texi"; then
139     echo "Running $TEXI2HTML"
140     cat "$DOC_DIR/macros.itexi" "$OUTPUT_DIR/out/$SECTION.texi" > "$OUTPUT_DIR/$SECTION.texi"
141     "$TEXI2HTML" \
142         --no-validate \
143         --output="$OUTPUT_DIR/out/$SECTION.html" \
144         --I="$OUTPUT_DIR/out" \
145         "$OUTPUT_DIR/$SECTION.texi"
146 fi
147
148 cat <<EOF
149
150 The $SECTION section of the $MANUAL manual should now be viewable at
151
152   $OUTPUT_DIR/out/$SECTION.html
153
154 If you want to keep the generated docs around for a while, answer
155 'n' to the next question.  If you only needed them to quickly check
156 something, view them now and then answer 'y' when you're done.
157
158 EOF
159
160 read -p "rm -rf $OUTPUT_DIR ? (y/n): "
161 if [ "$REPLY" = "y" ]; then
162     echo "deleting files"
163     rm -rf "$OUTPUT_DIR"
164 fi