tools: add a pre-commit check for the python code
[gtk-doc.git] / gtkdocize.in
bloba688fc322d81bfd9306bad8d3fb9531d3d685521
1 #!/bin/sh
3 progname=`echo "$0" | sed 's%^.*/%%'`
5 PROGRAM=gtkdocize
6 PACKAGE=@PACKAGE@
7 VERSION=@VERSION@
9 prefix=@prefix@
10 datarootdir=@datarootdir@
11 datadir=@datadir@
13 # options
14 copy=no
15 makefile=gtk-doc.make
16 flavour=no-tmpl
18 # mini help
19 usage="\
20 usage: $progname [ --copy ] [ --docdir DIR ] [ --flavour {legacy|legacy-flat|no-tmpl|no-tmpl-flat} ] [ --srcdir DIR ]"
22 # Find the srcdir early (and ignore a srcdir set in configure).
23 # https://bugzilla.gnome.org/show_bug.cgi?id=707426
24 args="$*"
25 while test $# -gt 0; do
26 case "$1" in
27 --srcdir)
28 shift
29 srcdir="$1"
30 shift ;;
31 --srcdir=*)
32 srcdir=`expr "X$1" : '[^=]*=\(.*\)'`
33 shift ;;
35 shift ;;
36 esac
37 done
38 set - $args
40 # assume working directory if srcdir is not set
41 test "$srcdir" || srcdir=.
42 test "$docdir" || docdir="$srcdir"
44 # detect configure script
45 no_configure_found=0
46 if test -f "$srcdir"/configure.ac; then
47 configure="$srcdir"/configure.ac
48 elif test -f "$srcdir"/configure.in; then
49 configure="$srcdir"/configure.in
50 else
51 no_configure_found=1
54 # check configure script for GTK_DOC_CHECK macro
55 no_gtk_doc_check_found=0
56 if test $no_configure_found -eq 0; then
57 macro=`grep '^GTK_DOC_CHECK' $configure 2>/dev/null`
58 if test $? -eq 0; then
59 # GTK_DOC_CHECK([1.14],[--flavour no-tmpl])
60 params=`echo $macro | sed -e 's/^GTK_DOC_CHECK(\ *\(.*\)).*$/\1/'`
61 if echo $params | grep -q '^.*\,\ *\[\{0,1\}'; then
62 extra_options=`echo $params | sed -e 's/^.*\,\ *\[\{0,1\}\([^]]*\)\]\{0,1\}\ *$/\1/'`
63 #echo >&2 "DEBUG: adding extra options [$extra_options] to [$*]"
64 set - $* $GTKDOCIZE_FLAGS $extra_options
65 else
66 set - $* $GTKDOCIZE_FLAGS
68 else
69 no_gtk_doc_check_found=1;
73 while test $# -gt 0; do
74 #echo >&2 "DEBUG: parsing args [$1]";
75 case "$1" in
76 --help)
77 echo "$usage"
78 exit 0 ;;
79 --version)
80 echo "$PROGRAM ($PACKAGE) $VERSION"
81 exit 0 ;;
82 --copy)
83 copy=yes
84 shift ;;
85 --docdir)
86 shift
87 docdir="$1"
88 shift ;;
89 --docdir=*)
90 docdir=`expr "X$1" : '[^=]*=\(.*\)'`
91 shift ;;
92 --flavour)
93 shift
94 flavour="$1"
95 shift ;;
96 --flavour=*)
97 flavour=`expr "X$1" : '[^=]*=\(.*\)'`
98 shift ;;
99 --srcdir)
100 shift
101 # srcdir was set earlier.
102 shift ;;
103 --srcdir=*)
104 # srcdir was set earlier.
105 shift ;;
107 echo "$progname: unrecognised option '$1'" 1>&2
108 echo "$usage" 1>&2
109 exit 1 ;;
111 echo "$progname: too many arguments" 1>&2
112 echo "$usage" 1>&2
113 exit 1 ;;
114 esac
115 done
117 case "$flavour" in
118 legacy-flat|no-tmpl-flat)
119 makefile=gtk-doc.flat.make
121 legacy|no-tmpl)
124 echo "$progname: invalid value for --flavour" 1>&2
125 echo "$usage" 1>&2
126 exit 1 ;;
127 esac
129 if test $no_configure_found -eq 1; then
130 echo "$progname: neither configure.ac nor configure.in exist" 1>&2
131 exit 1
133 if test $no_gtk_doc_check_found -eq 1; then
134 echo "$progname: GTK_DOC_CHECK not called in $configure" 1>&2
135 exit 1
138 # If the AC_CONFIG_MACRO_DIR() macro is used, copy gtk-doc.m4 from our
139 # prefix to that directory. This makes sure that the M4 macro used
140 # matches the the automake fragment.
141 # If AC_CONFIG_MACRO_DIR is not used, the macro won't be copied, and
142 # the correct flags must be passed to aclocal for it to find the macro.
143 m4dir="$srcdir"/`autoconf 2>/dev/null --trace 'AC_CONFIG_MACRO_DIR:$1' "$configure"`
144 if test -n "$m4dir"; then
145 rm -f $m4dir/gtk-doc.m4
146 if test "$copy" = yes; then
147 cp -f $datadir/aclocal/gtk-doc.m4 $m4dir/ ||
148 exit 1
149 else
150 ln -sf $datadir/aclocal/gtk-doc.m4 $m4dir/ ||
151 cp -f $datadir/aclocal/gtk-doc.m4 $m4dir/ ||
152 exit 1
156 rm -f $docdir/gtk-doc.make
157 if test "$copy" = yes; then
158 cp -f $datadir/gtk-doc/data/$makefile $docdir/gtk-doc.make ||
159 exit 1
160 else
161 ln -sf $datadir/gtk-doc/data/$makefile $docdir/gtk-doc.make ||
162 cp -f $datadir/gtk-doc/data/$makefile $docdir/gtk-doc.make ||
163 exit 1