xref: /llvm-project/llvm/utils/release/build-docs.sh (revision b7ff03206d668cd5a620a9d4e1b22ea112ed56e3)
1#!/bin/bash
2#===-- build-docs.sh - Tag the LLVM release candidates ---------------------===#
3#
4# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5# See https://llvm.org/LICENSE.txt for license information.
6# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7#
8#===------------------------------------------------------------------------===#
9#
10# Build documentation for LLVM releases.
11#
12# Required Packages:
13# * Fedora:
14#   * dnf install doxygen texlive-epstopdf ghostscript \
15#                 ninja-build gcc-c++
16#   * pip install --user -r ./llvm/docs/requirements.txt
17# * Ubuntu:
18#   * apt-get install doxygen \
19#             ninja-build graphviz texlive-font-utils
20#   * pip install --user -r ./llvm/docs/requirements.txt
21#===------------------------------------------------------------------------===#
22
23set -e
24
25builddir=docs-build
26srcdir=$(readlink -f $(dirname "$(readlink -f "$0")")/../..)
27
28usage() {
29  echo "Build the documentation for an LLVM release.  This only needs to be "
30  echo "done for -final releases."
31  echo "usage: `basename $0`"
32  echo " "
33  echo " -release <num> Fetch the tarball for release <num> and build the "
34  echo "                documentation from that source."
35  echo " -srcdir  <dir> Path to llvm source directory with CMakeLists.txt"
36  echo "                (optional) default: $srcdir"
37  echo " -no-doxygen    Don't build Doxygen docs"
38  echo " -no-sphinx     Don't build Spinx docs"
39}
40
41package_doxygen() {
42
43  project=$1
44  proj_dir=$2
45  output=${project}_doxygen-$release
46
47  mv $builddir/$proj_dir/docs/doxygen/html $output
48  tar -cJf $output.tar.xz $output
49}
50
51
52while [ $# -gt 0 ]; do
53  case $1 in
54    -release )
55      shift
56      release=$1
57      ;;
58    -srcdir )
59      shift
60      custom_srcdir=$1
61      ;;
62    -no-doxygen )
63      no_doxygen="yes"
64      ;;
65    -no-sphinx )
66      no_sphinx="yes"
67      ;;
68    * )
69      echo "unknown option: $1"
70      usage
71      exit 1
72      ;;
73   esac
74   shift
75done
76
77if [ -n "$release" -a -n "$custom_srcdir" ]; then
78  echo "error: Cannot specify both -srcdir and -release options"
79  exit 1
80fi
81
82if [ -n "$custom_srcdir" ]; then
83  srcdir="$custom_srcdir"
84fi
85
86# Set default source directory if one is not supplied
87if [ -n "$release" ]; then
88  git_ref=llvmorg-$release
89  if [ -d llvm-project ]; then
90    echo "error llvm-project directory already exists"
91    exit 1
92  fi
93  mkdir -p llvm-project
94  pushd llvm-project
95  curl -L https://github.com/llvm/llvm-project/archive/$git_ref.tar.gz | tar --strip-components=1 -xzf -
96  popd
97  srcdir="./llvm-project/llvm"
98fi
99
100if [ "$no_doxygen" == "yes" ] && [ "$no_sphinx" == "yes" ]; then
101  echo "You can't specify both -no-doxygen and -no-sphinx, we have nothing to build then!"
102  exit 1
103fi
104
105if [ "$no_sphinx" != "yes" ]; then
106  echo "Sphinx: enabled"
107  sphinx_targets="docs-clang-html docs-clang-tools-html docs-flang-html docs-lld-html docs-llvm-html docs-polly-html"
108  sphinx_flag=" -DLLVM_ENABLE_SPHINX=ON -DSPHINX_WARNINGS_AS_ERRORS=OFF"
109else
110  echo "Sphinx: disabled"
111fi
112
113if [ "$no_doxygen" != "yes" ]; then
114  echo "Doxygen: enabled"
115  doxygen_targets="$docs_target doxygen-clang doxygen-clang-tools doxygen-flang doxygen-llvm doxygen-mlir doxygen-polly"
116  doxygen_flag=" -DLLVM_ENABLE_DOXYGEN=ON -DLLVM_DOXYGEN_SVG=ON"
117else
118   echo "Doxygen: disabled"
119fi
120
121cmake -G Ninja $srcdir -B $builddir \
122               -DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra;lld;polly;flang" \
123               -DCMAKE_BUILD_TYPE=Release \
124               -DLLVM_BUILD_DOCS=ON \
125               $sphinx_flag \
126               $doxygen_flag
127
128ninja -C $builddir $sphinx_targets $doxygen_targets
129
130cmake -G Ninja $srcdir/../runtimes -B $builddir/runtimes-doc \
131               -DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi;libunwind" \
132               -DLLVM_ENABLE_SPHINX=ON \
133               -DSPHINX_WARNINGS_AS_ERRORS=OFF
134
135ninja -C $builddir/runtimes-doc \
136               docs-libcxx-html \
137
138if [ "$no_doxygen" != "yes" ]; then
139  package_doxygen llvm .
140  package_doxygen clang tools/clang
141  package_doxygen clang-tools-extra tools/clang/tools/extra
142  package_doxygen flang tools/flang
143fi
144
145if [ "$no_sphinx" == "yes" ]; then
146  exit 0
147fi
148
149html_dir=$builddir/html-export/
150
151for d in docs/ tools/clang/docs/ tools/lld/docs/ tools/clang/tools/extra/docs/ tools/polly/docs/ tools/flang/docs/; do
152  mkdir -p $html_dir/$d
153  mv $builddir/$d/html/* $html_dir/$d/
154done
155
156# Keep the documentation for the runtimes under /projects/ to avoid breaking existing links.
157for d in libcxx/docs/; do
158  mkdir -p $html_dir/projects/$d
159  mv $builddir/runtimes-doc/$d/html/* $html_dir/projects/$d/
160done
161