summaryrefslogtreecommitdiff
path: root/gtkdoc-mkpdf.in
blob: f221f05b0995521866b359f0564b220090b35a03 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#!/bin/sh
#

usage() {
cat <<EOF
gtkdoc-mkpdf version @VERSION@ - generate documentation in pdf format

--verbose               Print extra output while processing
--path=SEARCH_PATH      Extra source directories
--imgdir=DIR            Extra image directories
MODULE                  Name of the doc module being parsed
DRIVER_FILE             File containing the toplevel DocBook file.
--version               Print the version of this program
--help                  Print this help
EOF
}

#echo "args $0\n";

cleanexit() {
    rm -f $module.fo
    exit 1
}

# parse options, ignore unknown options for future extensions

verbose="0"
searchpath=
uninstalled=no
imgdirs=
while true; do
    case "X$1" in
        X--version) echo "@VERSION@"; exit 0;;
        X--help) usage; exit 0;;
        X--uninstalled) uninstalled=yes; shift;;
        X--verbose) verbose="1"; shift;;
        X--path=*) searchpath=`echo "$1" | sed s/.*=//`; shift;;
        X--imgdir=*) imgdirs="$imgdirs -I `echo "$1" | sed s/.*=//`"; shift;;
        X--*) shift;;
        X*) break;;
    esac
done

if test $# -lt 2; then
    usage 1>&2
    exit 1
fi

module="$1"
shift
document="$1"
shift

quiet="1"
if test $verbose = "1"; then
    quiet="0"
fi

if test $uninstalled = yes; then
      # this does not work from buiddir!=srcdir
      # we could try this
      # MAKE_SCRDIR=$(abs_srcdir) MAKE_BUILDDIR=$(abs_builddir) gtkdoc-mkpdf ...
      gtkdocdir=`dirname $0`
      #echo "uninstalled, gtkdocdir=$gtkdocdir"
else
      # the first two are needed to resolve datadir
      prefix=@prefix@
      datarootdir=@datarootdir@
      gtkdocdir=@datadir@/gtk-doc/data
fi

if head -n 1 $document | grep "<?xml" > /dev/null; then
    is_xml=true
    path_option='--path'
else
    is_xml=false
    path_option='--directory'
fi

# we could do "$path_option $PWD "
# to avoid needing rewriting entities that are copied from the header
# into docs under xml
if test "X$searchpath" = "X"; then
    path_arg=
else
    path_arg="$path_option $searchpath"
fi

if $is_xml; then
  if test -n "@DBLATEX@"; then
      # extra options to consider
      # -I FIG_PATH
      # -V is useful for debugging
      # -T db2latex : different style
      # -d : keep transient files (for debugging)
      # -P abc.def=$quiet : once the stylesheets have a quiet mode
      # xsltproc is already called with --xinclude
      # does not work: --xslt-opts "$path_arg --nonet $@"
      dblatex_options="-o $module.pdf $imgdirs \"$document\""
      #echo "calling: @DBLATEX@ $dblatex_options"
      if test $verbose = "0"; then
          @DBLATEX@ 2>&1 --help | grep  >/dev/null "\-\-quiet"
          if test "$?" = "0"; then
            dblatex_options="--quiet $dblatex_options";
          fi;
          @DBLATEX@ 2>&1 >/dev/null $dblatex_options | grep -v 'programlisting or screen'
      else
          { @DBLATEX@ 2>&1 >&3 $dblatex_options | grep -v 'programlisting or screen' >&2; } 3>&1
      fi
  else
    if test -n "@FOP@"; then
        @XSLTPROC@ $path_arg --nonet --xinclude \
            --stringparam gtkdoc.bookname $module \
            --stringparam gtkdoc.version "@VERSION@" \
            --stringparam chunk.quietly $quiet \
            --stringparam chunker.output.quiet $quiet \
            "$@" -o $module.fo $gtkdocdir/gtk-doc-fo.xsl "$document" || cleanexit $?
        # fop dies too easily :(
        # @FOP@ $module.fo $module.pdf
    else
      echo "dblatex or fop must be installed to use gtkdoc-mkpdf." >&2
      cleanexit 1
    fi
  fi
else
    # not very good output
    # also for xxx-docs.sgml it will produce xxx-docs.pdf
    docbook2pdf -e no-valid "$document"
fi

echo "timestamp" > pdf.stamp
cleanexit 0