161 lines · bash
1#!/bin/bash2#===-- 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-exception7#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.txt17# * Ubuntu:18# * apt-get install doxygen \19# ninja-build graphviz texlive-font-utils20# * pip install --user -r ./llvm/docs/requirements.txt21#===------------------------------------------------------------------------===#22 23set -e24 25builddir=docs-build26srcdir=$(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=$144 proj_dir=$245 output=${project}_doxygen-$release46 47 mv $builddir/$proj_dir/docs/doxygen/html $output48 tar -cJf $output.tar.xz $output49}50 51 52while [ $# -gt 0 ]; do53 case $1 in54 -release )55 shift56 release=$157 ;;58 -srcdir )59 shift60 custom_srcdir=$161 ;;62 -no-doxygen )63 no_doxygen="yes"64 ;;65 -no-sphinx )66 no_sphinx="yes"67 ;;68 * )69 echo "unknown option: $1"70 usage71 exit 172 ;;73 esac74 shift75done76 77if [ -n "$release" -a -n "$custom_srcdir" ]; then78 echo "error: Cannot specify both -srcdir and -release options"79 exit 180fi81 82if [ -n "$custom_srcdir" ]; then83 srcdir="$custom_srcdir"84fi85 86# Set default source directory if one is not supplied87if [ -n "$release" ]; then88 git_ref=llvmorg-$release89 if [ -d llvm-project ]; then90 echo "error llvm-project directory already exists"91 exit 192 fi93 mkdir -p llvm-project94 pushd llvm-project95 curl -L https://github.com/llvm/llvm-project/archive/$git_ref.tar.gz | tar --strip-components=1 -xzf -96 popd97 srcdir="./llvm-project/llvm"98fi99 100if [ "$no_doxygen" == "yes" ] && [ "$no_sphinx" == "yes" ]; then101 echo "You can't specify both -no-doxygen and -no-sphinx, we have nothing to build then!"102 exit 1103fi104 105if [ "$no_sphinx" != "yes" ]; then106 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"109else110 echo "Sphinx: disabled"111fi112 113if [ "$no_doxygen" != "yes" ]; then114 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"117else118 echo "Doxygen: disabled"119fi120 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_flag127 128ninja -C $builddir $sphinx_targets $doxygen_targets129 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=OFF134 135ninja -C $builddir/runtimes-doc \136 docs-libcxx-html \137 138if [ "$no_doxygen" != "yes" ]; then139 package_doxygen llvm .140 package_doxygen clang tools/clang141 package_doxygen clang-tools-extra tools/clang/tools/extra142 package_doxygen flang tools/flang143fi144 145if [ "$no_sphinx" == "yes" ]; then146 exit 0147fi148 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/; do152 mkdir -p $html_dir/$d153 mv $builddir/$d/html/* $html_dir/$d/154done155 156# Keep the documentation for the runtimes under /projects/ to avoid breaking existing links.157for d in libcxx/docs/; do158 mkdir -p $html_dir/projects/$d159 mv $builddir/runtimes-doc/$d/html/* $html_dir/projects/$d/160done161