makedocs 10.1 KB
Newer Older
1
2
3
4
5
6
7
8
#!/bin/bash

report_failure ()
{
    echo "  **** failed to complete **** "
    exit 1
}

9
10
11
12
13
htmlify_python_file ()
{
    pygmentize -f html -O full,style=vs $1 > $1.html
}

Davis King's avatar
Davis King committed
14
15
16
17
18
19
20
build_python_interface ()
{
    pushd ../python_examples
    mkdir build 
    cd build                 || report_failure
    cmake ../../tools/python || report_failure
    make -j4 install         || report_failure
21
22
23
24
25
26
27
28
29
30


    # Check if we should run all the python examples to make sure they
    # work without generating an error.
    if [ $1 == "test-python" ]
    then
        cd ..
        FILES=`ls *.py`
        for f in $FILES
        do
Davis King's avatar
Davis King committed
31
            python $f > /dev/null < /dev/null || report_failure 
32
33
34
        done
    fi

Davis King's avatar
Davis King committed
35
36
37
    popd
}

38
39
add_links_between_example_programs()
{
40
    EXT=$3
41
42
    # Get the list of example program filenames
    pushd $1 > /dev/null
43
    FILES=`ls *.$EXT`
44
45
46
47
48
49
50
51
52
    popd > /dev/null

    # Now run sed on all the htmlified example programs to add the links between them.
    for f in $FILES
    do
        #escape the . in the filename
        escaped_name=`echo $f | sed -e 's/\./\\\./g'`
        pushd $1 > /dev/null
        # get a list of all the html example files that contain the name
53
        matching_html_files=`grep -e "\b$escaped_name\b" -l *.$EXT | sed -e "s/\.$EXT\b/.$EXT.html/g"`
54
55
56
57
58
59
60
61
62
63
64
65
66
        popd > /dev/null

        # now actually run sed to add the links
        pushd $2 > /dev/null
        if [ -n "$matching_html_files" ]
        then
            sed -i -e "s/\b$escaped_name\b/<a href=\"$escaped_name.html\">$escaped_name<\/a>/g" $matching_html_files
        fi
        popd > /dev/null
    done

}

67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
htmlify_cmake ()
{
    echo "<html><head><title>" > $1.html;
    echo $1 >> $1.html;
    echo "</title></head><body bgcolor='white'><pre>" >> $1.html;

#  line 1: make comments green
#  line 2: add links into the add_subdirectory directives
#  line 3: make literal quotes red
#  line 4: make the directives show up blue
#  line 5: make variable names show up purple
    sed -e "s/^\([ ]*#.*\)/<font color='#009900'>\1<\/font>/" \
        -e "s/add_subdirectory\([ ]*\)(\([ ]*\)\([^ ]*\)\([ ]*\)\([^ )]*\)/add_subdirectory\1(\2\3\4<a href='\3\/CMakeLists.txt.html'>\5<\/a>/"  \
        -e "s/\"\([^\"]*\)\"/\"<font color='#CC0000'>\1<\/font>\"/g"  \
        -e "s/^\([ ]*[^( ]*[ ]*\)(/<font color='blue'>\1<\/font>(/" \
        -e "s/{\([^}]*\)}/\{<font color='#BB00BB'>\1<\/font>}/g"  \
        $1 >> $1.html;

85
86
87
88
89
90
91
92
93
94
95
    echo "</pre></body></html>" >> $1.html;
}

htmlify_python()
{
    FILES=`\ls $1/*.py`
    for i in $FILES
    do
        htmlify_python_file ${i}
        rm ${i}
    done
96
97
}

98
99
100
101
102
get_short_revision_number()
{    
    RESULT=`hg log -r $1 | grep changeset | awk '{print $2}' | sed -e 's/:.*//'`  
}

103
104
105
106
107
get_last_modified_date()
{
    RESULT=`hg log $1 -l1 --template '{date|date}\n' | awk '{ print $2" "$3", " $5}'`
}

108
109
110
111
112
113
114
115
116
makedocs ()
{

    COUNTER_FILE=.current_release_number
    MINOR_COUTNER_FILE=.current_minor_release_number
    REVNUM_FILE=.logger_revnum



117
118
119
120
# figure out the short number that identifies this particular changeset
    get_short_revision_number `cat $REVNUM_FILE`
    LOGGER_REVNUM=$RESULT

121
    XSLT_OPTIONS="--nodtdattr   --nonet   --novalid"
122
    DATE_TODAY=`date --date= "+%b %d, %Y"`;
123
124
125
126
127




# The revision number we are currently at
128
129
130
    CHANGESET_ID=`hg id -i | sed -e 's/\+//'`
    get_short_revision_number $CHANGESET_ID 
    REVISION=$RESULT
131
132


133
134
    MAJOR_NUM=`cat $COUNTER_FILE` 
    MINOR_NUM=`cat $MINOR_COUTNER_FILE` 
135
136
137
138
139
140
    if [ "$1" = "makerel" ] 
        then
        RELEASE=${MAJOR_NUM}.${MINOR_NUM} 
    else
        RELEASE=${MAJOR_NUM}.`echo ${MINOR_NUM}+1|bc`-RC
    fi;
141

142
143
# get XML versions of the change logs
    BASE_LOGGER_REVNUM=`echo $LOGGER_REVNUM - 1000 | bc`
144
145
    NEXT_LOGGER_REVNUM=`echo $LOGGER_REVNUM + 1 | bc`
    echo Getting the mercurial change logs for revisions $NEXT_LOGGER_REVNUM:$REVISION
146
    hg log -v ../dlib ../examples ../tools ../python_examples --style=xml  -r$NEXT_LOGGER_REVNUM:$REVISION > docs/log.txt || report_failure
147
    echo Getting the mercurial change logs for revisions $BASE_LOGGER_REVNUM:$LOGGER_REVNUM
148
    hg log -v ../dlib ../examples ../tools ../python_examples --style=xml  -r$BASE_LOGGER_REVNUM:$LOGGER_REVNUM > docs/old_log.txt || report_failure 
149

150
151
# grab a clean copy of the repository 
    rm -rf docs/cache
152
153
    rm -rf docs/web
    rm -rf docs/chm/docs
154
    rm -rf cache.$$
155
    hg archive cache.$$ || report_failure
156
157
158
159
# put the stuff we need into the docs/cache folder
    mkdir docs/cache
    mv cache.$$/dlib docs/cache/
    mv cache.$$/examples docs/cache/
160
    mv cache.$$/python_examples docs/cache/
161
    mv cache.$$/tools docs/cache/
162
    rm -rf cache.$$
163
164


165
166
167
    echo "#ifndef DLIB_REVISION_H"           > docs/cache/dlib/revision.h
    echo "// Version: " $RELEASE            >> docs/cache/dlib/revision.h
    echo "// Date:    " `date`              >> docs/cache/dlib/revision.h
168
169
170
    echo "// Mercurial Revision ID: " $CHANGESET_ID >> docs/cache/dlib/revision.h
    echo "#define DLIB_MAJOR_VERSION " $MAJOR_NUM >> docs/cache/dlib/revision.h
    echo "#define DLIB_MINOR_VERSION " $MINOR_NUM >> docs/cache/dlib/revision.h
171
172
173
    echo "#endif"                           >> docs/cache/dlib/revision.h


174
175
176
177
    rm -rf docs/web
    rm -rf docs/chm/docs
    mkdir docs/web
    mkdir docs/chm/docs
178
179
180

    echo Creating HTML version of the source
    htmlify --title "dlib C++ Library - " -i docs/cache -o htmltemp.$$
181
    add_links_between_example_programs docs/cache/examples htmltemp.$$/examples cpp
182
183
184
185
186
187
188
189

    echo Copying files around...
    cp -r htmltemp.$$/dlib docs/web
    cp -r htmltemp.$$/dlib docs/chm/docs
    cp -r htmltemp.$$/examples/* docs/web
    cp -r htmltemp.$$/examples/* docs/chm/docs
    rm -rf htmltemp.$$

Davis King's avatar
Davis King committed
190
191
192
    # Create python docs.  If we are making a release then stop immediately if 
    # the python docs can't be created (this happens if the .so file isn't compiled)
    if [ "$1" = "makerel" ] 
193
    then
194
        build_python_interface test-python
Davis King's avatar
Davis King committed
195
196
        sphinx-build -b html docs/python sphinx.$$ || report_failure
    else
Davis King's avatar
Davis King committed
197
198
        if [ "$1" != "fast" ]
        then
Davis King's avatar
Davis King committed
199
            build_python_interface no-test-python
Davis King's avatar
Davis King committed
200
        fi;
Davis King's avatar
Davis King committed
201
202
203
204
205
206
        sphinx-build -b html docs/python sphinx.$$
    fi;

    cp -r sphinx.$$ docs/web/python
    mv  sphinx.$$ docs/chm/docs/python

207
208
209
210
211
212
213
214
215
216
217
    cp docs/cache/dlib/test/makefile docs/web/dlib/test
    cp docs/cache/dlib/test/makefile docs/chm/docs/dlib/test

    cp docs/cache/dlib/test/CMakeLists.txt docs/web/dlib/test
    cp docs/cache/dlib/test/CMakeLists.txt docs/chm/docs/dlib/test
    cp docs/cache/dlib/CMakeLists.txt docs/web/dlib
    cp docs/cache/dlib/CMakeLists.txt docs/chm/docs/dlib
    mkdir docs/web/examples || report_failure
    cp docs/cache/examples/CMakeLists.txt docs/web/examples
    mkdir docs/chm/docs/examples || report_failure 
    cp docs/cache/examples/CMakeLists.txt docs/chm/docs/examples
218
219
220
221
222
    cp docs/cache/python_examples/*.py docs/chm/docs/
    cp docs/cache/python_examples/*.py docs/web/

    htmlify_python docs/chm/docs/
    htmlify_python docs/web/
223
224
    add_links_between_example_programs docs/cache/python_examples docs/chm/docs py
    add_links_between_example_programs docs/cache/python_examples docs/web py
225

226
227
    cp docs/*.gif docs/web
    cp docs/*.gif docs/chm/docs
228
229
    cp docs/ml_guide.svg docs/web
    cp docs/ml_guide.svg docs/chm/docs
230
231
    cp -r docs/guipics docs/web
    cp -r docs/guipics docs/chm/docs
232
233
234
    cp docs/*.html docs/web
    cp docs/*.html docs/chm/docs
    cp docs/*.png docs/web
235
    cp docs/*.ico docs/web
236
    cp docs/*.png docs/chm/docs
237
    cp docs/*.ico docs/chm/docs
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253

    cd docs/chm/docs || report_failure 
    htmlify_cmake dlib/CMakeLists.txt;
    htmlify_cmake examples/CMakeLists.txt;
    htmlify_cmake dlib/test/CMakeLists.txt;
    cd ../../.. || report_failure
    cd docs/web || report_failure
    htmlify_cmake dlib/CMakeLists.txt;
    htmlify_cmake examples/CMakeLists.txt;
    htmlify_cmake dlib/test/CMakeLists.txt;
    cd ../.. || report_failure

    find docs/web docs/chm -name "CMakeLists.txt" | xargs rm



254
255
256
257
258
    # generate the HTML docs
    echo Generate HTML docs from XML and XSLT style sheet
    FILES=`\ls docs/*.xml | grep -v main_menu.xml`
    for i in $FILES
    do
259

260
        # The last modified date for these files should always be the release date (regardless of when the actual xml files were modified). 
Davis King's avatar
Davis King committed
261
        if [ "${i}" = "docs/release_notes.xml" -o ${i} = "docs/old_release_notes.xml" \
262
263
             -o ${i} = "docs/change_log.xml" -o ${i} = "docs/old_change_log.xml" \
             -o ${i} = "docs/index.xml" ] 
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
        then
            DATE=$DATE_TODAY
        else
            get_last_modified_date ${i}
            DATE=$RESULT
        fi;

        #make web version
        cat docs/stylesheet.xsl | sed -e 's/"is_chm">[^<]*/"is_chm">false/' -e "s/_CURRENT_RELEASE_/$RELEASE/" -e "s/_LAST_MODIFIED_DATE_/$DATE/" \
            > docs/stylesheet.$$.xsl
        OUT_FILE=$(echo ${i} | sed -e "s/\.xml/\.html/" | sed -e "s/docs\//docs\/web\//")
        xsltproc $XSLT_OPTIONS -o $OUT_FILE docs/stylesheet.$$.xsl ${i}

        #make chm version
        cat docs/stylesheet.xsl | sed -e 's/"is_chm">[^<]*/"is_chm">true/' -e "s/_CURRENT_RELEASE_/$RELEASE/" -e "s/_LAST_MODIFIED_DATE_/$DATE/" \
            > docs/stylesheet.$$.xsl
        OUT_FILE=$(echo ${i} | sed -e "s/\.xml/\.html/" | sed -e "s/docs\//docs\/chm\/docs\//")
        xsltproc $XSLT_OPTIONS -o $OUT_FILE docs/stylesheet.$$.xsl ${i}

        rm docs/stylesheet.$$.xsl
    done
285

286
287
288
289
290
291
292
# Delete doc type header stuff
#    FILES=`find docs/chm docs/web -iname "*.html" -type f`
#    for i in $FILES
#    do
#        sed -e '/<!DOCTYPE/d' ${i} > temp.$$;
#        mv temp.$$ ${i};
#    done
293
294
295
296


    echo Generating sitemap
    cd docs/web || report_failure
297
    find . -name "*.html" |  awk '{ print "http://dlib.net" substr($1,2)}' > sitemap.txt
298
299
300
301
302
303

    # make the main index have a 301 redirect.  Use php to do this
    echo '<?php if ($_SERVER["SERVER_NAME"] != "dlib.net") { header("Location: http://dlib.net/", true, 301); exit; } ?>' > index.php
    cat index.html >> index.php
    rm index.html

304
305
306
307
308
309
310
311
312
313
    cd ../..
}


./testenv || report_failure




# build all the html documentation
314
makedocs $1
315
316
317
318
319

# now make the table of contents for the chm file
echo Generating the table of contents for the chm file
xsltproc -o docs/chm/Table\ of\ Contents.hhc docs/chm/htmlhelp_stylesheet.xsl docs/chm/toc.xml