Changed g_critical to g_error for glib1.2 support
[silc.git] / prepare
1 #! /bin/sh
2 #
3 #  prepare
4 #
5 #  Author: Pekka Riikonen <priikone@silcnet.org>
6 #
7 #  Copyright (C) 2000 - 2002 Pekka Riikonen
8 #
9 #  This program is free software; you can redistribute it and/or modify
10 #  it under the terms of the GNU General Public License as published by
11 #  the Free Software Foundation; version 2 of the License.
12 #
13 #  This program is distributed in the hope that it will be useful,
14 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
15 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 #  GNU General Public License for more details.
17 #
18
19 #
20 # Prepares SILC source tree for configuration and compilation. This is
21 # done only after checkout from CVS. This is only for developers of SILC
22 # and will never appear in public distribution. When creating distributions
23 # this is always run first. After the distribution is created all
24 # temporary files (including these prepare* scripts) are removed.
25 #
26
27 #
28 # Usage: ./prepare [<distribution> <package version>]
29 #
30 # If <package version> is omitted <base version> is used as package
31 # version.  The package version appears in the package name and in those
32 # distributions that used the SILC_DIST_VERSION_STRING define in the
33 # code.  The base version is the SILC_VERSION_STRING define.
34 #
35
36 #
37 # SILC Distribution versions. Set here or give the version on the command
38 # line as argument.
39 #
40 SILC_VERSION=0.9.12                     # Base version
41
42 #############################################################################
43
44 #############################################################################
45 # Functions
46
47 #
48 # Creates the main configure script from the configure.ad fragments in
49 # the source tree.
50 #
51 # Arguments: ad_make_configure <main_configure_file>
52 #
53 ad_make_configure()
54 {
55   rm -f configure.in
56
57   cfs=`find . -name configure\*\.ad`
58   for i in $cfs
59   do
60     if test "x$i" = "x$1"; then
61       continue
62     fi
63     cat $i >> configure.ad.cfs
64   done
65
66   if test -f configure.ad.cfs; then
67     sed '/AD_INCLUDE_CONFIGURE/ r configure.ad.cfs' $1 > configure.in.tmp
68     sed -e "/AD_INCLUDE_CONFIGURE/s///" configure.in.tmp > configure.in
69     rm -f configure.ad.cfs configure.in.tmp
70   else
71     cp $1 configure.in
72   fi
73 }
74
75
76 #############################################################################
77
78 echo "Preparing SILC source tree for configuration and compilation..."
79
80 distribution=$1
81 if test "$distribution" = ""; then
82   distribution="toolkit";
83 fi
84
85 dist_version=$2
86 if test "$dist_version" = ""; then
87   dist_version=$SILC_VERSION
88 fi
89
90
91 echo "Preparing $distribution distribution version $dist_version"
92
93 #
94 # Go though the subdirs and create the Makefile.ams from the
95 # Makefile.am.pre files.
96 #
97 subdirs=`grep "$distribution"_SUBDIRS= distributions |cut -d=  -f2`
98 ed=`grep "$distribution"_EXTRA_DIST= distributions |cut -d=  -f2`
99 sed -e "/SILC_DISTRIBUTION_EXTRA/s,,$ed," Makefile.am.pre >Makefile.am
100 path=`pwd`
101 for i in $subdirs
102 do
103   cd $i
104   sub=`grep "$distribution"_SUBDIRS_"$i"= $path/distributions |cut -d=  -f2`
105   if test "$sub" = ""; then
106     cd $path
107     continue;
108   fi
109   if [ -f Makefile.am.pre ]; then
110     sed -e "/SILC_DISTRIBUTION_SUBDIRS/s//$sub/" -e "/SILC_DISTRIBUTION_SUBDIRS/s//$sub/" Makefile.am.pre >Makefile.am 2>/dev/null
111   fi
112   cd $path
113 done
114 cd $path
115
116
117 #
118 # Replace version string, package name and distribution infos, and create 
119 # the actual configure.in
120 #
121 echo "# Automatically generated by ./prepare from configure.in.pre. Do not edit!" >configure.in2
122 sed -e "/SILC_DISTRIBUTION_SUBDIRS/s//$subdirs/" -e "/SILC_VERSION/s//$dist_version/" -e "/SILC_PACKAGE/s//silc-"$distribution"/" configure.in.pre >>configure.in2
123
124 #
125 # Create also the acconfig.h for the distribution. Note that this sets
126 # also dist labels for distributions that are not defined.
127 #
128 cp acconfig.h.pre acconfig.h
129 dists=`grep DISTRIBUTIONS= distributions |cut -d=  -f2`
130 touch am_cond
131 for i in $dists
132 do
133   dl=`grep "$i"_DISTLABEL= distributions |cut -d=  -f2`
134   echo "#undef $dl" >>acconfig.h
135   if test "$i" = "$distribution"; then
136     echo "AM_CONDITIONAL($dl, test xtrue = xtrue)" >>am_cond
137   else
138     echo "AM_CONDITIONAL($dl, test xtrue = xfalse)" >>am_cond
139   fi
140 done
141
142 sed '/SILC_DIST_DEFINE/ r am_cond' configure.in2 >configure.in3
143 dl=`grep "$distribution"_DISTLABEL= distributions |cut -d=  -f2`
144 sed -e "/SILC_DIST_DEFINE/s//$dl/" configure.in3 >configure.in4
145 ad_make_configure ./configure.in4
146 rm -f configure.in2 configure.in3 configure.in4 am_cond
147
148
149 #
150 # Prepare the Makefile.defines
151 #
152 cp Makefile.defines.pre Makefile.defines.in
153 cp Makefile.defines_int.pre Makefile.defines_int.in
154 cp Makefile.defines.in irssi
155 cp Makefile.defines_int.in irssi
156
157 aclocal
158 autoconf
159 autoheader >/dev/null 2>/dev/null
160 libtoolize --automake --copy
161 automake
162
163 file=includes/version_internal.h
164 echo "/* Automatically generated by ./prepare */" >$file
165 echo "#define SILC_VERSION_STRING \"$dist_version\"" >>$file
166 echo "#define SILC_DIST_VERSION_STRING \"$dist_version\"" >>$file
167 echo "#define SILC_PROTOCOL_VERSION_STRING \"SILC-1.2-$dist_version $distribution\"" >>$file
168 echo "#define SILC_NAME \"SILC $distribution\"" >>$file
169
170 # preparing irssi
171 echo "Preparing irssi"
172 file=irssi/irssi-version.h.in
173 touch $file
174 cd irssi
175 sh autogen.sh 2>/dev/null 1>/dev/null
176 cd ..
177 version_date=`date +%Y%m%d`
178 echo "/* automatically created by autogen.sh */" > $file
179 echo "#define IRSSI_VERSION \"$dist_version (Irssi base: @VERSION@ - SILC base: SILC $dist_version)\"" >>$file
180 echo "#define IRSSI_VERSION_DATE $version_date" >> $file
181 echo "#define IRSSI_VERSION_TIME $version_date" >> $file
182
183 echo "Done, now run ./configure and make."