1*4c3eb207Smrg#!/bin/sh 2*4c3eb207Smrg 3*4c3eb207Smrg# Generate HTML documentation from GCC Texinfo docs. 4*4c3eb207Smrg# 5*4c3eb207Smrg# If you want to run this on a machine different from gcc.gnu.org, you 6*4c3eb207Smrg# may need to adjust GITROOT and WWWBASE below (or override them via the 7*4c3eb207Smrg# environment). 8*4c3eb207Smrg 9*4c3eb207Smrgset -e 10*4c3eb207Smrg 11*4c3eb207Smrg# Run this from /tmp. 12*4c3eb207SmrgGITROOT=${GITROOT:-"/git/gcc.git"} 13*4c3eb207Smrgexport GITROOT 14*4c3eb207Smrg 15*4c3eb207SmrgPATH=/usr/local/bin:$PATH 16*4c3eb207Smrg 17*4c3eb207SmrgMANUALS="cpp 18*4c3eb207Smrg cppinternals 19*4c3eb207Smrg fastjar 20*4c3eb207Smrg gcc 21*4c3eb207Smrg gccgo 22*4c3eb207Smrg gccint 23*4c3eb207Smrg gcj 24*4c3eb207Smrg gfortran 25*4c3eb207Smrg gfc-internals 26*4c3eb207Smrg gnat_ugn 27*4c3eb207Smrg gnat-style 28*4c3eb207Smrg gnat_rm 29*4c3eb207Smrg libgomp 30*4c3eb207Smrg libitm 31*4c3eb207Smrg libquadmath 32*4c3eb207Smrg libiberty 33*4c3eb207Smrg porting" 34*4c3eb207Smrg 35*4c3eb207SmrgCSS=/gcc.css 36*4c3eb207Smrg 37*4c3eb207SmrgWWWBASE=${WWWBASE:-"/www/gcc/htdocs"} 38*4c3eb207SmrgWWWBASE_PREFORMATTED=/www/gcc/htdocs-preformatted 39*4c3eb207SmrgWWWPREPROCESS='/www/gcc/bin/preprocess -r' 40*4c3eb207Smrg 41*4c3eb207Smrg# Process options -rrelease and -ddirectory 42*4c3eb207SmrgRELEASE="" 43*4c3eb207SmrgSUBDIR="" 44*4c3eb207Smrg 45*4c3eb207Smrgwhile [ $# -gt 0 ]; do 46*4c3eb207Smrg case $1 in 47*4c3eb207Smrg -r*) 48*4c3eb207Smrg if [ -n "$RELEASE" ]; then 49*4c3eb207Smrg echo "Multiple releases specified" >&2 50*4c3eb207Smrg exit 1 51*4c3eb207Smrg fi 52*4c3eb207Smrg RELEASE="${1#-r}" 53*4c3eb207Smrg if [ -z "$RELEASE" ]; then 54*4c3eb207Smrg shift 55*4c3eb207Smrg RELEASE="$1" 56*4c3eb207Smrg if [ -z "$RELEASE" ]; then 57*4c3eb207Smrg echo "No release specified with -r" >&2 58*4c3eb207Smrg exit 1 59*4c3eb207Smrg fi 60*4c3eb207Smrg fi 61*4c3eb207Smrg ;; 62*4c3eb207Smrg -d*) 63*4c3eb207Smrg if [ -n "$SUBDIR" ]; then 64*4c3eb207Smrg echo "Multiple subdirectories specified" >&2 65*4c3eb207Smrg exit 1 66*4c3eb207Smrg fi 67*4c3eb207Smrg SUBDIR="${1#-d}" 68*4c3eb207Smrg if [ -z "$SUBDIR" ]; then 69*4c3eb207Smrg shift 70*4c3eb207Smrg SUBDIR="$1" 71*4c3eb207Smrg if [ -z "$SUBDIR" ]; then 72*4c3eb207Smrg echo "No subdirectory specified with -d" >&2 73*4c3eb207Smrg exit 1 74*4c3eb207Smrg fi 75*4c3eb207Smrg fi 76*4c3eb207Smrg ;; 77*4c3eb207Smrg *) 78*4c3eb207Smrg echo "Unknown argument \"$1\"" >&2 79*4c3eb207Smrg exit 1 80*4c3eb207Smrg ;; 81*4c3eb207Smrg esac 82*4c3eb207Smrg shift 83*4c3eb207Smrgdone 84*4c3eb207Smrg 85*4c3eb207Smrgif [ -n "$RELEASE" ] && [ -z "$SUBDIR" ]; then 86*4c3eb207Smrg echo "Release specified without subdirectory" >&2 87*4c3eb207Smrg exit 1 88*4c3eb207Smrgfi 89*4c3eb207Smrg 90*4c3eb207Smrgif [ -z "$SUBDIR" ]; then 91*4c3eb207Smrg DOCSDIR=$WWWBASE/onlinedocs 92*4c3eb207Smrgelse 93*4c3eb207Smrg DOCSDIR=$WWWBASE/onlinedocs/$SUBDIR 94*4c3eb207Smrgfi 95*4c3eb207Smrg 96*4c3eb207Smrgif [ ! -d $WWWBASE ]; then 97*4c3eb207Smrg echo "WWW base directory \"$WWWBASE\" does not exist." >&2 98*4c3eb207Smrg exit 1 99*4c3eb207Smrgfi 100*4c3eb207Smrg 101*4c3eb207Smrgif [ ! -d $DOCSDIR ]; then 102*4c3eb207Smrg mkdir $DOCSDIR 103*4c3eb207Smrg chmod g+w $DOCSDIR 104*4c3eb207Smrgfi 105*4c3eb207Smrg 106*4c3eb207Smrgif [ -z "$RELEASE" ]; then 107*4c3eb207Smrg RELEASE=master 108*4c3eb207Smrgfi 109*4c3eb207Smrg 110*4c3eb207SmrgWORKDIR=/tmp/gcc-doc-update.$$ 111*4c3eb207Smrg 112*4c3eb207Smrgrm -rf $WORKDIR 113*4c3eb207Smrgmkdir $WORKDIR 114*4c3eb207Smrgcd $WORKDIR 115*4c3eb207Smrgif [ "$RELEASE" = "master" ]; then 116*4c3eb207Smrg git clone -q $GITROOT gcc 117*4c3eb207Smrgelse 118*4c3eb207Smrg git clone -q -b releases/gcc-$RELEASE $GITROOT gcc 119*4c3eb207Smrgfi 120*4c3eb207Smrgrm -rf gcc/.git 121*4c3eb207Smrg 122*4c3eb207Smrg# Remove all unwanted files. This is needed to avoid packaging all the 123*4c3eb207Smrg# sources instead of only documentation sources. 124*4c3eb207Smrg# Note that we have to preserve gcc/jit/docs since the jit docs are 125*4c3eb207Smrg# not .texi files (Makefile, .rst and .png), and the jit docs use 126*4c3eb207Smrg# include directives to pull in content from jit/jit-common.h and 127*4c3eb207Smrg# jit/notes.txt, so we have to preserve those also. 128*4c3eb207Smrgfind gcc -type f \( -name '*.texi' \ 129*4c3eb207Smrg -o -path gcc/gcc/doc/install.texi2html \ 130*4c3eb207Smrg -o -path gcc/gcc/doc/include/texinfo.tex \ 131*4c3eb207Smrg -o -path gcc/gcc/BASE-VER \ 132*4c3eb207Smrg -o -path gcc/gcc/DEV-PHASE \ 133*4c3eb207Smrg -o -path "gcc/gcc/ada/doc/gnat_ugn/*.png" \ 134*4c3eb207Smrg -o -path "gcc/gcc/jit/docs/*" \ 135*4c3eb207Smrg -o -path "gcc/gcc/jit/jit-common.h" \ 136*4c3eb207Smrg -o -path "gcc/gcc/jit/notes.txt" \ 137*4c3eb207Smrg -o -print0 \) | xargs -0 rm -f 138*4c3eb207Smrg 139*4c3eb207Smrg# Build a tarball of the sources. 140*4c3eb207Smrgtar cf docs-sources.tar gcc 141*4c3eb207Smrg 142*4c3eb207Smrg# The directory to pass to -I; this is the one with texinfo.tex 143*4c3eb207Smrg# and fdl.texi. 144*4c3eb207Smrgincludedir=gcc/gcc/doc/include 145*4c3eb207Smrg 146*4c3eb207Smrg# Generate gcc-vers.texi. 147*4c3eb207Smrg( 148*4c3eb207Smrg echo "@set version-GCC $(cat gcc/gcc/BASE-VER)" 149*4c3eb207Smrg if [ "$(cat gcc/gcc/DEV-PHASE)" = "experimental" ]; then 150*4c3eb207Smrg echo "@set DEVELOPMENT" 151*4c3eb207Smrg else 152*4c3eb207Smrg echo "@clear DEVELOPMENT" 153*4c3eb207Smrg fi 154*4c3eb207Smrg echo "@set srcdir $WORKDIR/gcc/gcc" 155*4c3eb207Smrg echo "@set VERSION_PACKAGE (GCC)" 156*4c3eb207Smrg echo "@set BUGURL @uref{http://gcc.gnu.org/bugs/}" 157*4c3eb207Smrg) > $includedir/gcc-vers.texi 158*4c3eb207Smrg 159*4c3eb207Smrg# Generate libquadmath-vers.texi. 160*4c3eb207Smrgecho "@set BUGURL @uref{http://gcc.gnu.org/bugs/}" \ 161*4c3eb207Smrg > $includedir/libquadmath-vers.texi 162*4c3eb207Smrg 163*4c3eb207Smrg# Now convert the relevant files from texi to HTML, PDF and PostScript. 164*4c3eb207Smrgfor file in $MANUALS; do 165*4c3eb207Smrg filename=`find . -name ${file}.texi` 166*4c3eb207Smrg if [ "${filename}" ]; then 167*4c3eb207Smrg includes="-I ${includedir} -I `dirname ${filename}`" 168*4c3eb207Smrg if [ "$file" = "gnat_ugn" ]; then 169*4c3eb207Smrg includes="$includes -I gcc/gcc/ada -I gcc/gcc/ada/doc/gnat_ugn" 170*4c3eb207Smrg fi 171*4c3eb207Smrg makeinfo --html --css-ref $CSS $includes -o ${file} ${filename} 172*4c3eb207Smrg tar cf ${file}-html.tar ${file}/*.html 173*4c3eb207Smrg texi2dvi $includes -o ${file}.dvi ${filename} </dev/null >/dev/null && dvips -o ${file}.ps ${file}.dvi 174*4c3eb207Smrg texi2pdf $includes -o ${file}.pdf ${filename} </dev/null 175*4c3eb207Smrg mkdir -p $DOCSDIR/$file 176*4c3eb207Smrg fi 177*4c3eb207Smrgdone 178*4c3eb207Smrg 179*4c3eb207Smrg# The jit is a special-case, using sphinx rather than texinfo. 180*4c3eb207Smrg# Specifically, the jit docs need sphinx 1.0 or later. 181*4c3eb207Smrg# 182*4c3eb207Smrg# The jit/docs Makefile uses the executable $(SPHINXBUILD), 183*4c3eb207Smrg# defaulting to "sphinx-build". 184*4c3eb207Smrg# 185*4c3eb207Smrg# sphinx is packaged in Fedora and EPEL 6 within "python-sphinx", 186*4c3eb207Smrg# in RHEL 8 within "python3-sphinx", 187*4c3eb207Smrg# and in openSUSE within "python-Sphinx". 188*4c3eb207Smrg# 189*4c3eb207Smrg# For EPEL6, python-sphinx is sphinx 0.6.6, which is missing various 190*4c3eb207Smrg# directives (e.g. ":c:macro:"), so we need the variant 191*4c3eb207Smrg# python-sphinx10 package. The latter installs its executable as 192*4c3eb207Smrg# /usr/bin/sphinx-1.0-build 193*4c3eb207Smrg# so we needed to override SPHINXBUILD with this when invoking "make". 194*4c3eb207Smrgpushd gcc/gcc/jit/docs 195*4c3eb207Smrgmake html || true 196*4c3eb207Smrgpopd 197*4c3eb207Smrgcp -a gcc/gcc/jit/docs/_build/html jit 198*4c3eb207Smrgmkdir -p $DOCSDIR/jit 199*4c3eb207Smrg 200*4c3eb207Smrg# Work around makeinfo generated file names and references with 201*4c3eb207Smrg# "_002d" instead of "-". 202*4c3eb207Smrgfind . -name '*.html' | while read f; do 203*4c3eb207Smrg # Do this for the contents of each file. 204*4c3eb207Smrg sed -i -e 's/_002d/-/g' "$f" 205*4c3eb207Smrg # And rename files if necessary. 206*4c3eb207Smrg ff=`echo $f | sed -e 's/_002d/-/g'`; 207*4c3eb207Smrg if [ "$f" != "$ff" ]; then 208*4c3eb207Smrg printf "Renaming %s to %s\n" "$f" "$ff" 209*4c3eb207Smrg mv "$f" "$ff" 210*4c3eb207Smrg fi 211*4c3eb207Smrgdone 212*4c3eb207Smrg 213*4c3eb207Smrg# Then build a gzipped copy of each of the resulting .html, .ps and .tar files 214*4c3eb207Smrgfor file in */*.html *.ps *.pdf *.tar; do 215*4c3eb207Smrg cat $file | gzip --best > $file.gz 216*4c3eb207Smrgdone 217*4c3eb207Smrg 218*4c3eb207Smrg# On the 15th of the month, wipe all the old files from the 219*4c3eb207Smrg# web server. 220*4c3eb207Smrgtoday=`date +%d` 221*4c3eb207Smrgif test $today = 15; then 222*4c3eb207Smrg find $DOCSDIR -type f -maxdepth 1 -print | grep -v index.html | xargs rm 223*4c3eb207Smrg for m in $MANUALS; do 224*4c3eb207Smrg rm -f $DOCSDIR/$m/*.html $DOCSDIR/$m/*.html.gz 225*4c3eb207Smrg done 226*4c3eb207Smrgfi 227*4c3eb207Smrg 228*4c3eb207Smrg# And copy the resulting files to the web server 229*4c3eb207Smrgfor file in */*.html *.ps *.pdf *.tar; do 230*4c3eb207Smrg if [ -f $DOCSDIR/$file ]; then 231*4c3eb207Smrg cat $DOCSDIR/$file | 232*4c3eb207Smrg sed -e '/^<meta name=generator/d' \ 233*4c3eb207Smrg -e '/^%DVIPSSource:/d' > file1 234*4c3eb207Smrg fi 235*4c3eb207Smrg cat $file | 236*4c3eb207Smrg sed -e '/^<meta name=generator/d' \ 237*4c3eb207Smrg -e '/^%DVIPSSource:/d' > file2 238*4c3eb207Smrg if cmp -s file1 file2; then 239*4c3eb207Smrg : 240*4c3eb207Smrg else 241*4c3eb207Smrg cp $file $DOCSDIR/$file 242*4c3eb207Smrg cp $file.gz $DOCSDIR/$file.gz 243*4c3eb207Smrg fi 244*4c3eb207Smrgdone 245*4c3eb207Smrg 246*4c3eb207Smrg# Again, the jit is a special case, with nested subdirectories 247*4c3eb207Smrg# below "jit", and with some non-HTML files (.png images from us, 248*4c3eb207Smrg# plus .css and .js supplied by sphinx, and source files, renamed 249*4c3eb207Smrg# from .rst to .txt). 250*4c3eb207Smrgfind jit \ 251*4c3eb207Smrg -name "*.html" -o -name "*.png" \ 252*4c3eb207Smrg -o -name "*.css" -o -name "*.js" \ 253*4c3eb207Smrg -o -name "*.txt" | 254*4c3eb207Smrg while read file ; do 255*4c3eb207Smrg # Note that $file here will contain path fragments beginning 256*4c3eb207Smrg # with "jit/", e.g. "jit/cp/topics/functions.html" 257*4c3eb207Smrg mkdir -p $(dirname $DOCSDIR/$file) 258*4c3eb207Smrg cp $file $DOCSDIR/$file 259*4c3eb207Smrg done 260*4c3eb207Smrg 261*4c3eb207Smrgcd $DOCSDIR 262*4c3eb207Smrg 263*4c3eb207Smrg# Finally, generate the installation documentation 264*4c3eb207Smrgif [ "$RELEASE" = "master" ]; then 265*4c3eb207Smrg SOURCEDIR=$WORKDIR/gcc/gcc/doc 266*4c3eb207Smrg DESTDIR=$WWWBASE_PREFORMATTED/install 267*4c3eb207Smrg export SOURCEDIR 268*4c3eb207Smrg export DESTDIR 269*4c3eb207Smrg $WORKDIR/gcc/gcc/doc/install.texi2html 270*4c3eb207Smrg 271*4c3eb207Smrg # Preprocess the entire web site, not just the install docs! 272*4c3eb207Smrg echo "Invoking $WWWPREPROCESS" 273*4c3eb207Smrg $WWWPREPROCESS |grep -v '^ Warning: Keeping' 274*4c3eb207Smrgfi 275*4c3eb207Smrg 276*4c3eb207Smrg# Clean up behind us. 277*4c3eb207Smrg 278*4c3eb207Smrgrm -rf $WORKDIR 279