1#!/bin/sh
2#   Copyright (c) 2002 Douglas Gregor <doug.gregor -at- gmail.com>
3#
4#   Distributed under the Boost Software License, Version 1.0.
5#   (See accompanying file LICENSE_1_0.txt or copy at
6#   http://www.boost.org/LICENSE_1_0.txt)
7
8# User configuration
9# (MAINTANERS: please, keep in synch with setup_boostbook.py)
10DOCBOOK_XSL_VERSION=1.75.2
11DOCBOOK_DTD_VERSION=4.2
12FOP_VERSION=0.94
13FOP_JDK_VERSION=1.4
14# FOP_MIRROR=http://mirrors.ibiblio.org/pub/mirrors/apache/xmlgraphics/fop/binaries
15FOP_MIRROR=http://archive.apache.org/dist/xmlgraphics/fop/binaries/
16SOURCEFORGE_DOWNLOAD=http://sourceforge.net/projects/docbook/files/
17HTTP_GET_CMD="curl -O -L"
18
19# No user configuration below this point-------------------------------------
20
21# Get the DocBook XSLT Stylesheets
22DOCBOOK_XSL_TARBALL=docbook-xsl-$DOCBOOK_XSL_VERSION.tar.gz
23DOCBOOK_XSL_URL=$SOURCEFORGE_DOWNLOAD/docbook-xsl/$DOCBOOK_XSL_VERSION/$DOCBOOK_XSL_TARBALL
24if test -f $DOCBOOK_XSL_TARBALL; then
25  echo "Using existing DocBook XSLT Stylesheets (version $DOCBOOK_XSL_VERSION)."
26else
27  echo "Downloading DocBook XSLT Stylesheets version $DOCBOOK_XSL_VERSION..."
28  $HTTP_GET_CMD $DOCBOOK_XSL_URL
29fi
30
31DOCBOOK_XSL_DIR="$PWD/docbook-xsl-$DOCBOOK_XSL_VERSION"
32if test ! -d docbook-xsl-$DOCBOOK_XSL_VERSION; then
33  echo -n "Expanding DocBook XSLT Stylesheets into $DOCBOOK_XSL_DIR..."
34  gunzip -cd $DOCBOOK_XSL_TARBALL | tar xf -
35  echo "done."
36fi
37
38# Get the DocBook DTD
39DOCBOOK_DTD_ZIP=docbook-xml-$DOCBOOK_DTD_VERSION.zip
40DOCBOOK_DTD_URL=http://www.oasis-open.org/docbook/xml/$DOCBOOK_DTD_VERSION/$DOCBOOK_DTD_ZIP
41if test -f $DOCBOOK_DTD_ZIP; then
42  echo "Using existing DocBook XML DTD (version $DOCBOOK_DTD_VERSION)."
43else
44  echo "Downloading DocBook XML DTD version $DOCBOOK_DTD_VERSION..."
45  $HTTP_GET_CMD $DOCBOOK_DTD_URL
46fi
47
48DOCBOOK_DTD_DIR="$PWD/docbook-dtd-$DOCBOOK_DTD_VERSION"
49if test ! -d docbook-dtd-$DOCBOOK_DTD_VERSION; then
50  echo -n "Expanding DocBook XML DTD into $DOCBOOK_DTD_DIR... "
51  unzip -q $DOCBOOK_DTD_ZIP -d $DOCBOOK_DTD_DIR
52  echo "done."
53fi
54
55# Find xsltproc, doxygen, and java
56OLD_IFS=$IFS
57IFS=:
58for dir in $PATH; do
59  if test -f $dir/xsltproc && test -x $dir/xsltproc; then
60    XSLTPROC="$dir/xsltproc"
61  fi
62  if test -f $dir/doxygen && test -x $dir/doxygen; then
63    DOXYGEN="$dir/doxygen"
64  fi
65  if test -f $dir/java && test -x $dir/java; then
66    JAVA="$dir/java"
67  fi
68done
69IFS=$OLD_IFS
70
71# Make sure we have xsltproc
72if test ! -f "$XSLTPROC" && test ! -x "$XSLTPROC"; then
73  echo "Searching for xsltproc... NOT FOUND.";
74  echo "ERROR: Unable to find xsltproc executable."
75  echo "If you have already installed xsltproc, please set the environment"
76  echo "variable XSLTPROC to the xsltproc executable. If you do not have"
77  echo "xsltproc, you may download it from http://xmlsoft.org/XSLT/."
78  exit 0;
79else
80  echo "Searching for xsltproc... $XSLTPROC.";
81fi
82
83# Just notify the user if we haven't found doxygen.
84if test ! -f "$DOXYGEN" && test ! -x "$DOXYGEN"; then
85  echo "Searching for Doxygen... not found.";
86  echo "Warning: unable to find Doxygen executable. You will not be able to"
87  echo "  use Doxygen to generate BoostBook documentation. If you have Doxygen,"
88  echo "  please set the DOXYGEN environment variable to the path of the doxygen"
89  echo "  executable."
90  HAVE_DOXYGEN="no"
91else
92  echo "Searching for Doxygen... $DOXYGEN.";
93  HAVE_DOXYGEN="yes"
94fi
95
96# Just notify the user if we haven't found Java. Otherwise, go get FOP.
97if test ! -f "$JAVA" && test ! -x "$JAVA"; then
98  echo "Searching for Java... not found.";
99  echo "Warning: unable to find Java executable. You will not be able to"
100  echo "  generate PDF documentation. If you have Java, please set the JAVA"
101  echo "  environment variable to the path of the java executable."
102  HAVE_FOP="no"
103else
104  echo "Searching for Java... $JAVA.";
105  FOP_TARBALL="fop-$FOP_VERSION-bin-jdk$FOP_JDK_VERSION.tar.gz"
106  FOP_URL="$FOP_MIRROR/$FOP_TARBALL"
107  FOP_DIR="$PWD/fop-$FOP_VERSION"
108  FOP="$FOP_DIR/fop"
109  if test -f $FOP_TARBALL; then
110    echo "Using existing FOP distribution (version $FOP_VERSION)."
111  else
112    echo "Downloading FOP distribution version $FOP_VERSION..."
113    $HTTP_GET_CMD $FOP_URL
114  fi
115
116  if test ! -d $FOP_DIR; then
117    echo -n "Expanding FOP distribution into $FOP_DIR... ";
118    gunzip -cd $FOP_TARBALL | tar xf -
119    echo "done.";
120  fi
121  HAVE_FOP="yes"
122fi
123
124# Find the input jamfile to configure
125JAM_CONFIG_OUT="$HOME/user-config.jam"
126if test -r "$HOME/user-config.jam"; then
127  JAM_CONFIG_IN="user-config-backup.jam"
128  cp $JAM_CONFIG_OUT user-config-backup.jam
129  JAM_CONFIG_IN_TEMP="yes"
130  echo -n "Updating Boost.Jam configuration in $JAM_CONFIG_OUT... "
131
132elif test -r "$BOOST_ROOT/tools/build/user-config.jam"; then
133  JAM_CONFIG_IN="$BOOST_ROOT/tools/build/user-config.jam";
134  JAM_CONFIG_IN_TEMP="no"
135  echo -n "Writing Boost.Jam configuration to $JAM_CONFIG_OUT... "
136else
137  echo "ERROR: Please set the BOOST_ROOT environment variable to refer to your"
138  echo "Boost installation or copy user-config.jam into your home directory."
139  exit 0
140fi
141
142cat > setup_boostbook.awk <<EOF
143BEGIN { using_boostbook = 0; eaten=0 }
144
145/^\s*using boostbook/ {
146  using_boostbook = 1;
147  print "using boostbook";
148  print "  : $DOCBOOK_XSL_DIR";
149  print "  : $DOCBOOK_DTD_DIR";
150  eaten=1
151}
152
153using_boostbook==1 && /;/ { using_boostbook = 2 }
154using_boostbook==1 { eaten=1 }
155
156/^\s*using xsltproc.*$/ { eaten=1 }
157/^\s*using doxygen.*$/ { eaten=1 }
158/^\s*using fop.*$/ { eaten=1 }
159
160/^.*$/             { if (eaten == 0) print; eaten=0 }
161
162END {
163  if (using_boostbook==0) {
164    print "using boostbook";
165    print "  : $DOCBOOK_XSL_DIR";
166    print "  : $DOCBOOK_DTD_DIR";
167    print "  ;"
168  }
169  print "using xsltproc : $XSLTPROC ;"
170  if ("$HAVE_DOXYGEN" == "yes") print "using doxygen : $DOXYGEN ;";
171  if ("$HAVE_FOP" == "yes") print "using fop : $FOP : : $JAVA ;";
172}
173EOF
174
175awk -f setup_boostbook.awk $JAM_CONFIG_IN > $JAM_CONFIG_OUT
176rm -f setup_boostbook.awk
177echo "done."
178
179echo "Done! Execute \"b2\" in a documentation directory to generate"
180echo "documentation with BoostBook. If you have not already, you will need"
181echo "to compile Boost.Jam."
182