Release bumped to "gts4".
[tac_plus.git] / autogen-body
1 #
2 #       autogen-body
3 #
4 #       Placed into the public domain by
5 #       Partition Surprise Team <surprise-dev@lists.sourceforge.net>
6 #
7 #       $Id$
8 #
9
10
11 # Executable code to be included from ./autogen script
12
13 # Expected variables:
14 # defaultCONFDEFS, project, want_tarZ, upload, docdir, subdirs, CLEAN_LOCAL
15 # function PREP_LOCAL
16
17 set -e
18 t=/tmp/autogen.$$
19 autogen_failed=true
20 cleaup_dir="$PWD"
21 automake_reqd=""
22 function cleanup
23 {
24   cd "$cleanup_dir"
25   rm -f "$t.*"
26   if $automake_gnu;then for i in $automake_reqd;do if [ '!' -s "$i" ];then rm -f "$i";fi;done;fi
27 }
28 EXITmsg_do=true
29 trap '
30   cleanup
31   if $autogen_failed;then
32     if $EXITmsg_do;then
33       echo -e "\n$0 failed! Try the following command to debug it: set -x"
34       EXITmsg_do=false
35       fi
36     exit 1
37     fi
38   ' EXIT
39
40 if [ "$1" = help -o "$1" = -h -o "$1" = --help ];then cat <<EOHELP
41 Beware!: "autogen" is a tool only for maintainers.
42
43 Supported parameters:
44     rpm: Build RPM packages locally (needs /usr/src/(redhat|packages)/ access)
45     rpmtest: Build RPM like "rpm" but w/o gpg/pgp signing
46     rpmup: Like rpm target but also uploads the result
47     tar: Build tar file (its basename dir-based) with only vital files incl. CVS dirs
48     clean: Standard cleanup method
49     fullclean: Like clean but even the .cvsignore files are removed
50     sym: Like clean but don't remove symbolic links, should be equal (check!)
51     copy: Behave exactly like in default mode but copy all instead of symlinks
52 $ARGS_HELP_LOCAL
53 EOHELP
54   autogen_failed=false
55   exit
56   fi
57
58
59 if [ -f "$HOME/.$project.autogen" ];then
60   . "$HOME/.$project.autogen"
61   fi
62 CONFDEFS="$defaultCONFDEFS $CONFDEFS"
63
64 function funcdo
65 {
66 local func="$1";
67
68   shift
69   if declare -f "$func" >/dev/null;then
70 local func_exit=false
71
72     "$func" "$@"
73     if $func_exit;then exit;fi
74   fi
75 }
76 funcdo ARGS_LOCAL "$@"
77
78 if expr match "$1" "rpm" >/dev/null;then
79   builds="/usr/src/redhat /usr/src/packages"
80   for b in $builds X;do
81     if test -d $b;then break;fi
82     done
83   if [ $b = X ];then
84     echo Build directory not reachable, searched: $builds
85     exit 1
86     fi
87   rm -r -f /var/tmp/$project-*-root $b/BUILD/$project-*
88   specsrc="$project.spec.m4.in"
89   if [ '!' -f "$specsrc" ];then specsrc="$project.spec.in";fi
90   CONFDEFS="`awk '/^(.*)\\$/{x=x$1" ";next}{print x$0;x=""}' <$specsrc \
91             |sed -n 's/^.*\.\/configure \(.*\)$/\1/p'`" ./autogen copy
92   make dist $project.spec
93   cp $project-*.tar.gz $b/SOURCES
94   if [ "$1" = "rpmtest" ];then SIGNIT=;else SIGNIT=--sign;fi
95   rpm -ba $SIGNIT $project.spec
96   if $want_tarZ;then make dist-tarZ;fi
97   rm $b/SOURCES/$project-*.tar.gz
98   mv $b/SRPMS/$project-*.src.rpm .
99   mv $b/RPMS/i386/$project-*.i386.rpm .
100   ls -l $project-*
101   if [ "$1" = rpmup ];then
102     echo "Uploading $[`cat $project-*|wc -c`] bytes..."
103     if [ -n "$upload" ];then
104       scp -v $project-* "$upload"
105     else
106       echo "Upload not done."
107     fi
108   fi
109   autogen_failed=false
110   exit
111 fi
112
113 function subdo
114 {
115   for i in _ $subdirs;do
116     if [ -d $i ];then
117       cd "$i"
118       ./autogen $subdir_args
119       cd ..
120       fi
121     done
122 }
123 subdir_args="${*:-dist}"
124 if [ "$subdir_args" = "copy" ];then
125   subdir_args="copy dist"
126   fi
127
128 # maintainer-clean hack is not safe, please list all files for 'rm'.
129 # When the filename doesn't contain '/', it is applied to ALL directories.
130 # Please note that files exactly in root dir MUST have ./ in the front
131 #   (to not to be considered as ALL-directories files).
132
133 CLEANFILES="
134   *~ .#*
135   *.orig *.rej
136   core
137   Makefile Makefile.in
138   TAGS tags ID
139   .deps .libs
140   *.[oa] *.l[oa]
141
142   ./errs*
143   ./intl
144   ./configure ./configure.scan
145   ./config.guess ./config.status ./config.sub ./config.log ./config.cache
146   ./config.h ./config.h.in
147   ./confdefs.h ./conftest* ./autoh[0-9]* ./confcache
148   ./stamp-h ./stamp-h.in
149   ./install-sh
150   ./aclocal.m4
151   ./missing
152   ./mkinstalldirs
153   ./libtool ./ltconfig ./ltmain.sh
154   ./ChangeLog
155   ./ABOUT-NLS ./COPYING
156   ./$project-[0-9]* ./$project-devel-[0-9]*
157   ./$project.spec ./$project.m4 ./$project.spec.m4
158   macros/macros.dep
159   po/Makefile.in.in po/POTFILES* po/cat-id-tbl.c po/cat-id-tbl.tmp po/*.gmo po/*.mo po/stamp-cat-id po/$project.pot
160
161   $CLEAN_LOCAL
162   "
163 if [ -n "$docdir" ];then
164 CLEANFILES="
165   $docdir/*.html
166   $docdir/*.info*
167   $docdir/*.txt
168   $docdir/*.tex
169   $docdir/*.sgml
170   $CLEANFILES"
171   fi
172 if [ "$1" != sym ];then CLEANFILES="$CLEANFILES `find . -type l`";fi
173 CLEANFILES="`echo "$CLEANFILES"|tr ' ' '\n'|sed 's,^\./\(.*/.*\)$,\1,'|sort|uniq|grep -v '^ *$'`"
174 true >"$t.find"
175 rm -f "$t.discard"
176 echo "$CLEANFILES"|while read -r fi;do
177   if [ "$fi" != "${fi#*/}" ];then
178        echo "$fi" >>"$t.discard"
179   else echo "-o -name $fi" >>"$t.find"
180   fi;done
181 for dirpatt in `(find . -type d '!' \( -name CVS $(sed 's,[]*?[],\\&,g' <"$t.find") \)|sort|uniq;cat "$t.discard")|sort|uniq -u`;do
182   for dir in $dirpatt;do if test -d $dir;then
183     (cd $dir
184      (echo "$CLEANFILES"                                                #ALL-dir files
185       echo "$CLEANFILES"|sed -n "s,^\\$(echo $dir|sed 's,^\./,,')/,,p"  #THIS-dir files
186       echo .cvsignore                                                   #MUST be last!
187       )|grep -v / >.cvsignore
188      if [ "$1" = "${1#tar}" ];then
189        rm -rf `
190          if [ "$1" = fullclean ];then cat .cvsignore
191          else grep -v '^\.cvsignore' <.cvsignore
192          fi`
193        fi
194      )
195     fi;done
196   done
197 rm -f "$t.find" "$t.discard"
198 if [ "$1" = tarprep ];then
199   autogen_failed=false
200   exit
201   fi
202 if [ "$1" = tar ];then
203   subdir_args=tarprep
204   subdo
205   mydir="$(basename `pwd`)"
206   cd ..
207   tar cf - \
208     $(for fi in `find "$mydir" -name .cvsignore`;do sed "s,^,--exclude=`dirname $fi`/," <$fi;done) \
209     "$mydir"
210   autogen_failed=false
211   exit
212   fi
213 if [ "$1" != "${1#*clean}" ];then
214   subdo
215   autogen_failed=false
216   exit 0
217   fi
218
219 funcdo PREP_LOCAL "$@"
220 subdo
221
222 if [ "$1" = copy ];then COPY=--copy;shift
223 else unset COPY|cat  # |cat construction is used to not fail in "set -e" state
224 fi
225
226 if test -d po;then
227   touch po/POTFILES.in
228 fi
229 aclocal_opts=""
230 if test -d macros;then
231   aclocal_opts="-I macros $aclocal_opts"
232 fi
233 aclocal $aclocal_opts
234 if $want_gettext;then
235   gettextize $COPY
236   rm -f aclocal.m4       # We delete created aclocal.m4 as it's just bug in gettextize. It shouldn't link that file here
237   aclocal $aclocal_opts  # gettextize made some changes of files which need to be reflected
238 fi
239 if $want_libtool;then
240   libtoolize $COPY
241 fi
242 autoheader
243 automake_opts=""
244 if $automake_gnu;then
245   automake_reqd="$automake_reqd ChangeLog README"
246   automake_opts="$automake_opts --gnu"
247   for i in $automake_reqd;do if [ '!' -f "$i" ];then touch "$i";fi;done
248 fi
249 automake --add-missing $COPY $automake_opts
250 cleanup
251 autoheader
252 autoconf
253
254 if [ "$1" != dist ];then
255   # shared/static switching cannot be based on maintainer-mode in configure
256   ./configure --enable-maintainer-mode --enable-shared --disable-static $CONFDEFS
257   fi
258
259 autogen_failed=false