| 1 |
#!/bin/bash |
| 2 |
. bash_helper_functions |
| 3 |
|
| 4 |
report_failure () |
| 5 |
{ |
| 6 |
echo " **** failed to complete **** " |
| 7 |
exit 1 |
| 8 |
} |
| 9 |
|
| 10 |
htmlify_python_file () |
| 11 |
{ |
| 12 |
pygmentize -f html -O full,style=vs $1 > $1.html |
| 13 |
} |
| 14 |
|
| 15 |
|
| 16 |
add_links_between_example_programs() |
| 17 |
{ |
| 18 |
EXT=$3 |
| 19 |
# Get the list of example program filenames |
| 20 |
pushd $1 > /dev/null |
| 21 |
FILES=`ls *.$EXT` |
| 22 |
popd > /dev/null |
| 23 |
|
| 24 |
# Now run sed on all the htmlified example programs to add the links between them. |
| 25 |
for f in $FILES |
| 26 |
do |
| 27 |
#escape the . in the filename |
| 28 |
escaped_name=`echo $f | sed -e 's/\./\\\./g'` |
| 29 |
pushd $1 > /dev/null |
| 30 |
# get a list of all the html example files that contain the name |
| 31 |
matching_html_files=`grep -e "\b$escaped_name\b" -l *.$EXT | sed -e "s/\.$EXT\b/.$EXT.html/g"` |
| 32 |
popd > /dev/null |
| 33 |
|
| 34 |
# now actually run sed to add the links |
| 35 |
pushd $2 > /dev/null |
| 36 |
if [ -n "$matching_html_files" ] |
| 37 |
then |
| 38 |
sed -i -e "s/\b$escaped_name\b/<a href=\"$escaped_name.html\">$escaped_name<\/a>/g" $matching_html_files |
| 39 |
fi |
| 40 |
popd > /dev/null |
| 41 |
done |
| 42 |
|
| 43 |
} |
| 44 |
|
| 45 |
htmlify_cmake () |
| 46 |
{ |
| 47 |
echo "<html><head><title>" > $1.html; |
| 48 |
echo $1 >> $1.html; |
| 49 |
echo "</title></head><body bgcolor='white'><pre>" >> $1.html; |
| 50 |
|
| 51 |
# line 1: make comments green |
| 52 |
# line 2: add links into the add_subdirectory directives |
| 53 |
# line 3: make literal quotes red |
| 54 |
# line 4: make the directives show up blue |
| 55 |
# line 5: make variable names show up purple |
| 56 |
sed -e "s/^\([ ]*#.*\)/<font color='#009900'>\1<\/font>/" \ |
| 57 |
-e "s/add_subdirectory\([ ]*\)(\([ ]*\)\([^ ]*\)\([ ]*\)\([^ )]*\)/add_subdirectory\1(\2\3\4<a href='\3\/CMakeLists.txt.html'>\5<\/a>/" \ |
| 58 |
-e "s/\"\([^\"]*\)\"/\"<font color='#CC0000'>\1<\/font>\"/g" \ |
| 59 |
-e "s/^\([ ]*[^( ]*[ ]*\)(/<font color='blue'>\1<\/font>(/" \ |
| 60 |
-e "s/{\([^}]*\)}/\{<font color='#BB00BB'>\1<\/font>}/g" \ |
| 61 |
$1 >> $1.html; |
| 62 |
|
| 63 |
echo "</pre></body></html>" >> $1.html; |
| 64 |
} |
| 65 |
|
| 66 |
htmlify_python() |
| 67 |
{ |
| 68 |
FILES=`\ls $1/*.py` |
| 69 |
for i in $FILES |
| 70 |
do |
| 71 |
htmlify_python_file ${i} |
| 72 |
rm ${i} |
| 73 |
done |
| 74 |
} |
| 75 |
|
| 76 |
|
| 77 |
makedocs () |
| 78 |
{ |
| 79 |
|
| 80 |
REVNUM_FILE=.logger_revnum |
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
LOGGER_REVNUM=`cat $REVNUM_FILE` |
| 85 |
|
| 86 |
XSLT_OPTIONS="--nodtdattr --nonet --novalid" |
| 87 |
DATE_TODAY=`date --date= "+%b %d, %Y"`; |
| 88 |
|
| 89 |
|
| 90 |
if [ "$1" = "makerel" ] |
| 91 |
then |
| 92 |
RELEASE=${MAJOR_NUM}.${MINOR_NUM} |
| 93 |
else |
| 94 |
RELEASE=${MAJOR_NUM}.${MINOR_NUM}.${PATCH_NUM} |
| 95 |
fi; |
| 96 |
|
| 97 |
# get XML versions of the change logs |
| 98 |
echo Getting the git change logs for $LOGGER_REVNUM..HEAD |
| 99 |
git_logs_as_xml $LOGGER_REVNUM..HEAD docs/git-logs.xml || report_failure |
| 100 |
|
| 101 |
# grab a clean copy of the repository |
| 102 |
rm -rf docs/cache |
| 103 |
rm -rf docs/web |
| 104 |
rm -rf docs/chm/docs |
| 105 |
cd .. |
| 106 |
mkdir -p docs/docs/cache |
| 107 |
git archive HEAD | tar -xC docs/docs/cache |
| 108 |
cd docs |
| 109 |
rm -rf docs/cache/docs |
| 110 |
|
| 111 |
CHANGESET_ID=`git log -1 --pretty=format:%H` |
| 112 |
echo "#ifndef DLIB_REVISION_H" > docs/cache/dlib/revision.h |
| 113 |
echo "// Version: " $RELEASE >> docs/cache/dlib/revision.h |
| 114 |
echo "// Date: " `date` >> docs/cache/dlib/revision.h |
| 115 |
echo "// Git Changeset ID: " $CHANGESET_ID >> docs/cache/dlib/revision.h |
| 116 |
echo "#define DLIB_MAJOR_VERSION " $MAJOR_NUM >> docs/cache/dlib/revision.h |
| 117 |
echo "#define DLIB_MINOR_VERSION " $MINOR_NUM >> docs/cache/dlib/revision.h |
| 118 |
echo "#define DLIB_PATCH_VERSION " $PATCH_NUM >> docs/cache/dlib/revision.h |
| 119 |
echo "#endif" >> docs/cache/dlib/revision.h |
| 120 |
|
| 121 |
|
| 122 |
rm -rf docs/web |
| 123 |
rm -rf docs/chm/docs |
| 124 |
mkdir docs/web |
| 125 |
mkdir docs/chm/docs |
| 126 |
|
| 127 |
echo Creating HTML version of the source |
| 128 |
htmlify --title "dlib C++ Library - " -i docs/cache -o htmltemp.$$ |
| 129 |
add_links_between_example_programs docs/cache/examples htmltemp.$$/examples cpp |
| 130 |
|
| 131 |
echo Copying files around... |
| 132 |
cp -r htmltemp.$$/dlib docs/web |
| 133 |
cp -r htmltemp.$$/dlib docs/chm/docs |
| 134 |
cp -r htmltemp.$$/examples/* docs/web |
| 135 |
cp -r htmltemp.$$/examples/* docs/chm/docs |
| 136 |
rm -rf htmltemp.$$ |
| 137 |
|
| 138 |
# create python docs unless you say ./makedocs fast |
| 139 |
if [ "$1" != "fast" ] |
| 140 |
then |
| 141 |
cd .. |
| 142 |
python setup.py build || report_failure |
| 143 |
python setup.py build_sphinx -c docs/docs/python --build-dir docs/sphinx.$$ || report_failure |
| 144 |
# sphinx will read in the _dlib_pybind11 module and use that to name everything. But that's |
| 145 |
# not what we want, so we rename that to dlib everywhere. You would think sphinx would be |
| 146 |
# able to deal with the dlib/__init__.py file and this wouldn't be necessary, but that |
| 147 |
# doesn't seem to be the case. |
| 148 |
find docs/sphinx.$$ -type f | xargs sed -i -e "s/_dlib_pybind11/dlib/g" |
| 149 |
cd docs |
| 150 |
cp -r sphinx.$$/html docs/web/python |
| 151 |
mv sphinx.$$/html docs/chm/docs/python |
| 152 |
rm -rf sphinx.$$ |
| 153 |
fi; |
| 154 |
|
| 155 |
|
| 156 |
cp docs/cache/dlib/test/makefile docs/web/dlib/test |
| 157 |
cp docs/cache/dlib/test/makefile docs/chm/docs/dlib/test |
| 158 |
|
| 159 |
cp docs/cache/dlib/test/CMakeLists.txt docs/web/dlib/test |
| 160 |
cp docs/cache/dlib/test/CMakeLists.txt docs/chm/docs/dlib/test |
| 161 |
cp docs/cache/dlib/CMakeLists.txt docs/web/dlib |
| 162 |
cp docs/cache/dlib/CMakeLists.txt docs/chm/docs/dlib |
| 163 |
mkdir docs/web/examples || report_failure |
| 164 |
cp docs/cache/examples/CMakeLists.txt docs/web/examples |
| 165 |
mkdir docs/chm/docs/examples || report_failure |
| 166 |
cp docs/cache/examples/CMakeLists.txt docs/chm/docs/examples |
| 167 |
cp docs/cache/python_examples/*.py docs/chm/docs/ |
| 168 |
cp docs/cache/python_examples/*.py docs/web/ |
| 169 |
|
| 170 |
htmlify_python docs/chm/docs/ |
| 171 |
htmlify_python docs/web/ |
| 172 |
add_links_between_example_programs docs/cache/python_examples docs/chm/docs py |
| 173 |
add_links_between_example_programs docs/cache/python_examples docs/web py |
| 174 |
|
| 175 |
cp docs/*.gif docs/web |
| 176 |
cp docs/*.gif docs/chm/docs |
| 177 |
cp docs/ml_guide.svg docs/web |
| 178 |
cp docs/ml_guide.svg docs/chm/docs |
| 179 |
cp -r docs/guipics docs/web |
| 180 |
cp -r docs/guipics docs/chm/docs |
| 181 |
cp -r docs/images docs/web |
| 182 |
cp -r docs/images docs/chm/docs |
| 183 |
cp docs/*.html docs/web |
| 184 |
cp docs/*.html docs/chm/docs |
| 185 |
cp docs/*.css docs/web |
| 186 |
cp docs/*.css docs/chm/docs |
| 187 |
cp docs/*.js docs/web |
| 188 |
cp docs/*.js docs/chm/docs |
| 189 |
cp docs/*.png docs/web |
| 190 |
cp docs/*.pdf docs/web |
| 191 |
cp docs/*.jpg docs/web |
| 192 |
cp docs/*.webm docs/web |
| 193 |
cp docs/*.ico docs/web |
| 194 |
cp docs/*.png docs/chm/docs |
| 195 |
cp docs/*.pdf docs/chm/docs |
| 196 |
cp docs/*.jpg docs/chm/docs |
| 197 |
cp docs/*.webm docs/chm/docs |
| 198 |
cp docs/*.ico docs/chm/docs |
| 199 |
|
| 200 |
cd docs/chm/docs || report_failure |
| 201 |
htmlify_cmake dlib/CMakeLists.txt; |
| 202 |
htmlify_cmake examples/CMakeLists.txt; |
| 203 |
htmlify_cmake dlib/test/CMakeLists.txt; |
| 204 |
cd ../../.. || report_failure |
| 205 |
cd docs/web || report_failure |
| 206 |
htmlify_cmake dlib/CMakeLists.txt; |
| 207 |
htmlify_cmake examples/CMakeLists.txt; |
| 208 |
htmlify_cmake dlib/test/CMakeLists.txt; |
| 209 |
cd ../.. || report_failure |
| 210 |
|
| 211 |
find docs/web docs/chm -name "CMakeLists.txt" | xargs rm |
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
# generate the HTML docs |
| 216 |
echo Generate HTML docs from XML and XSLT style sheet |
| 217 |
FILES=`\ls docs/*.xml | grep -v main_menu.xml` |
| 218 |
for i in $FILES |
| 219 |
do |
| 220 |
|
| 221 |
# The last modified date for these files should always be the release date (regardless of when the actual xml files were modified). |
| 222 |
if [ "${i}" = "docs/release_notes.xml" -o ${i} = "docs/old_release_notes.xml" \ |
| 223 |
-o ${i} = "docs/change_log.xml" -o ${i} = "docs/index.xml" ] |
| 224 |
then |
| 225 |
DATE=$DATE_TODAY |
| 226 |
else |
| 227 |
get_last_modified_date ${i} |
| 228 |
DATE=$RESULT |
| 229 |
fi; |
| 230 |
|
| 231 |
#make web version |
| 232 |
cat docs/stylesheet.xsl | sed -e 's/"is_chm">[^<]*/"is_chm">false/' -e "s/_CURRENT_RELEASE_/$RELEASE/" -e "s/_LAST_MODIFIED_DATE_/$DATE/" \ |
| 233 |
> docs/stylesheet.$$.xsl |
| 234 |
OUT_FILE=$(echo ${i} | sed -e "s/\.xml/\.html/" | sed -e "s/docs\//docs\/web\//") |
| 235 |
xsltproc $XSLT_OPTIONS -o $OUT_FILE docs/stylesheet.$$.xsl ${i} |
| 236 |
|
| 237 |
#make chm version |
| 238 |
cat docs/stylesheet.xsl | sed -e 's/"is_chm">[^<]*/"is_chm">true/' -e "s/_CURRENT_RELEASE_/$RELEASE/" -e "s/_LAST_MODIFIED_DATE_/$DATE/" \ |
| 239 |
> docs/stylesheet.$$.xsl |
| 240 |
OUT_FILE=$(echo ${i} | sed -e "s/\.xml/\.html/" | sed -e "s/docs\//docs\/chm\/docs\//") |
| 241 |
xsltproc $XSLT_OPTIONS -o $OUT_FILE docs/stylesheet.$$.xsl ${i} |
| 242 |
|
| 243 |
rm docs/stylesheet.$$.xsl |
| 244 |
done |
| 245 |
|
| 246 |
# Delete doc type header stuff |
| 247 |
# FILES=`find docs/chm docs/web -iname "*.html" -type f` |
| 248 |
# for i in $FILES |
| 249 |
# do |
| 250 |
# sed -e '/<!DOCTYPE/d' ${i} > temp.$$; |
| 251 |
# mv temp.$$ ${i}; |
| 252 |
# done |
| 253 |
|
| 254 |
|
| 255 |
echo Generating sitemap |
| 256 |
cd docs/web || report_failure |
| 257 |
find . -name "*.html" | awk '{ print "http://dlib.net" substr($1,2)}' > sitemap.txt |
| 258 |
|
| 259 |
# make the main index have a 301 redirect. Use php to do this |
| 260 |
echo '<?php if ($_SERVER["SERVER_NAME"] != "dlib.net") { header("Location: http://dlib.net/", true, 301); exit; } ?>' > index.php |
| 261 |
cat index.html >> index.php |
| 262 |
rm index.html |
| 263 |
|
| 264 |
cd ../.. |
| 265 |
} |
| 266 |
|
| 267 |
|
| 268 |
./testenv || report_failure |
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
# build all the html documentation |
| 274 |
makedocs $1 |
| 275 |
|
| 276 |
# now make the table of contents for the chm file |
| 277 |
echo Generating the table of contents for the chm file |
| 278 |
xsltproc -o docs/chm/Table\ of\ Contents.hhc docs/chm/htmlhelp_stylesheet.xsl docs/chm/toc.xml |
| 279 |
|