71826a5ef7ab3eb416943e3375bef507f883c8c7
[synfig.git] / synfig-core / trunk / bootstrap
1 #! /bin/sh
2 #
3 # Sinfg Bootstrap Script
4 # $Id: bootstrap,v 1.2 2005/01/10 07:40:26 darco Exp $
5
6 # This script creates the configure script and Makefile.in files,
7 # and also fixes a few things in both to ensure a smooth build
8 # on all compilers and platforms.
9 #
10
11 # Grab the current directory and move to our own
12 CURR_DIR=$(pwd)
13 cd $(dirname $0)
14
15 # Environment Variables
16 BOOTSTRAP_NAME=$(basename $0)
17 CONFIG_DIR=$(pwd)/config
18
19 # Automake,Autoconf, and Libtool versions that we require
20 #AUTOCONF_VERSION=2.5
21 #AUTOMAKE_VERSION=1.6
22 #LIBTOOL_VERSION=1.4
23 export WANT_AUTOMAKE=1.8
24 #export WANT_LIBTOOL_VER=1.5
25 export WANT_AUTOCONF_2_5=1
26 export WANT_AUTOCONF=2.5
27
28 . $CONFIG_DIR/build.cfg
29
30 SED_SCRIPT="
31 s/@PACKAGE@/$PACKAGE/g;
32 s/@PACKAGE_NAME@/$PACKAGE_NAME/g;
33 s/@PACKAGE_BUGREPORT@/$PACKAGE_BUGREPORT/g;
34 s/@PACKAGE_TARNAME@/$PACKAGE_TARNAME/g;
35 s/@PACKAGE_VERSION@/$PACKAGE_VERSION/g;
36 s/@VERSION@/$VERSION/g;
37 s/@API_VERSION@/$API_VERSION/g;
38 s/@VERSION_MAJ@/$VERSION_MAJ/g;
39 s/@VERSION_MIN@/$VERSION_MIN/g;
40 s/@VERSION_REV@/$VERSION_REV/g;
41 s/@VERSION_REL@/$VERSION_REL/g;
42 s/@CFLAGS@//g;
43 "
44
45 # Define the output function
46 output () {
47         echo $BOOTSTRAP_NAME: $*
48 }
49
50 # Define the cleanup function
51 cleanup () {
52         output Cleaning up...
53         rm -fr config.cache autom4te*.cache configure.in $TEMPFILE
54 }
55
56 output Prepairing build environment for $PACKAGE-$VERSION...
57
58 # Look for the CVS directory. If we don't find it, we need to
59 # ask the user if they know what they are doing.
60 ( test -d CVS || test -d .svn ) ||
61 {
62         output warning: This shell script is intended for those
63         output warning: who either know what they are doing or
64         output warning: or downloaded this program from the CVS
65         output warning: repository. See README for more details.
66         output warning: To avoid seeing this message in the future,
67         output warning: create an empty directory called 'CVS'.
68         output Waiting for 15 seconds...
69         sleep 15
70 }
71
72 # Create the temporary file
73 output Creating temporary file...
74 TEMPFILE=`mktemp /tmp/$BOOTSTRAP_NAME.XXXXXX` ||
75 {
76         output ERROR: Unable to create temporary file!
77         exit 1
78 }
79
80 # Check for autoconf
81 (which autoconf > /dev/null 2>&1 ) ||
82 {
83         output error: 'Could not find GNU autoconf!'
84         output You need to download and install GNU autoconf v2.52 or higher.
85         output '<ftp://ftp.gnu.org/gnu/autoconf/>'
86         cleanup;
87         exit 1
88 }
89
90 # Check autoconf version
91 output Using $(autoconf --version | grep utoconf)
92 autoconf --version | grep -q "$AUTOCONF_VERSION" ||
93 {
94         output warning: Unexpected version of GNU Autoconf "(expected $AUTOCONF_VERSION)"
95         output warning: *** Bootstrap process may fail!
96 }
97
98 # Check for automake
99 (which automake > /dev/null 2>&1 ) ||
100 {
101         output error: 'Could not find GNU automake!'
102         output You need to download and install GNU automake v1.5 or higher.
103         output '<ftp://ftp.gnu.org/gnu/automake/>'
104         cleanup;
105         exit 1
106 }
107
108 # Check automake version
109 output Using $(automake --version | grep utomake)
110 automake --version | grep -q "$AUTOMAKE_VERSION" ||
111 {
112         output warning: Unexpected version of GNU Automake "(expected $AUTOMAKE_VERSION)"
113         output warning: *** Bootstrap process may fail!
114 }
115
116 # Check for libtool
117 (which libtool > /dev/null 2>&1 ) ||
118 {
119         output error: 'Could not find GNU libtool!'
120         output You need to download and install GNU libtool v1.4 or higher.
121         output '<ftp://ftp.gnu.org/gnu/libtool/>'
122         exit 1
123 }
124
125 # Check libtool version
126 echo $BOOTSTRAP_NAME: Using $(libtoolize --version | grep ibtool)
127 libtoolize --version | grep -q "$LIBTOOL_VERSION" ||
128 {
129         output warning: Unexpected version of GNU Libtool "(expected $LIBTOOL_VERSION)"
130         output warning: *** Bootstrap process may fail!
131 }
132
133 # Versions of libtool prior to 1.4.2 have a seriously broken libltdl.
134 # If we are using this broken version, we need to patch it.
135 libtoolize --version | grep -q -e "1.4.2" -e "1.4.1" -e "1.4 " && PATCH_LTDL=1
136
137 RECONFIG_LTDL=1
138
139 for FILENAME in doxygen.cfg pkgconfig.pc project.spec ; do {
140 output Creating $FILENAME...
141 sed "$SED_SCRIPT" < $CONFIG_DIR/$FILENAME.in > $FILENAME;
142 } ; done
143
144 output Renaming pkgconfig.pc to $PACKAGE_TARNAME.pc.in...
145 mv pkgconfig.pc "$PACKAGE_TARNAME.pc.in"
146
147 output Renaming project.spec to $PACKAGE-$VERSION.spec...
148 mv project.spec "$PACKAGE-$VERSION.spec"
149
150 output Finishing up $PACKAGE-$VERSION.spec...
151 echo %changelog >> "$PACKAGE-$VERSION.spec"
152 cat NEWS >> "$PACKAGE-$VERSION.spec"
153
154 output Creating configure.in from configure.ac...
155 sed "$SED_SCRIPT" < $CONFIG_DIR/configure.ac > configure.in;
156
157 output Setting up build environment...
158
159 # Set the shell to output what we are doing
160 set -x
161
162 # Create all of the build environment files
163 (
164         libtoolize -c -f --ltdl &&
165         aclocal -I $CONFIG_DIR $ACLOCAL_FLAGS &&
166         autoheader &&
167         autoconf -o configure &&
168         automake --foreign --add-missing --copy --include-deps &&
169         true
170 ) ||
171 {
172         # Something went wrong...
173         set +x
174         output Failure.
175         cleanup;
176         exit 1
177 }
178
179 # Turn off echoing of commands
180 set +x
181
182 # Reconfigure the LTDL, if necessary
183 [ $RECONFIG_LTDL"x" != "x" ] && (
184         output Reconfiguring LTDL...
185         set -x
186         (
187                 cd libltdl &&
188                 ( echo "AC_CONFIG_AUX_DIR(../config)" >> configure.[ai][cn] ) &&
189                 aclocal -I $CONFIG_DIR &&
190                 autoheader &&
191                 autoconf &&
192                 automake --foreign --add-missing --copy
193         ) ||
194         {
195                 # Something went wrong...
196                 set +x
197                 output Failure.
198                 cleanup;
199                 exit 1
200         }
201         set +x
202 )
203
204 # If this is the broken version of LTDL, then patch it
205 [ $PATCH_LTDL"x" != "x" ] && (
206         output Patching LTDL...
207         sed "
208                 s/handle || /(handle \&\& handle->loader) || /;
209                 s/errors > 0) \&\& file_not_found ())/errors > 0) \&\& !file_not_found ())/;
210                 s/(!handle)/(!handle || !handle->loader)/;
211                 s/ access (filename, R_OK)/ !access (filename, R_OK)/;
212         " < libltdl/ltdl.c > $TEMPFILE && cp $TEMPFILE libltdl/ltdl.c
213         sed "
214                 s/DLL_EXPORT/LTDL_DLL_EXPORT/;
215         " < libltdl/ltdl.h > $TEMPFILE && cp $TEMPFILE libltdl/ltdl.h
216 )
217
218 (
219 output Patching libtool...
220 patch config/ltmain.sh config/ltmain.patch
221 ) || true
222 false && {
223         # Something went wrong...
224         set +x
225         output Failure.
226         cleanup;
227         exit 1
228 }
229
230 #echo '#define LTDL_SHLIB_EXT   ".so"' >> libltdl/config-h.in
231 #echo '
232 #ifdef WIN32
233 #define LTDL_SHLIB_EXT  ".dll"
234 #else
235 #if __APPLE__
236 #define LTDL_SHLIB_EXT  ".so"
237 #else
238 #define LTDL_SHLIB_EXT  ".la"
239 #endif
240 #endif ' >> libltdl/config-h.in
241
242 # output Patching configure script to look for gcc3...
243 # sed "
244 # s/g++ c++/g++3 g++ c++/;
245 # s/gcc cc/gcc3 gcc cc/;
246 # s:"'${prefix}/include'":"'${prefix}/include/sinfg'":;
247 # s:PREFIX/include:PREFIX/include/ETL:;
248 # " < configure > $TEMPFILE
249 # cp $TEMPFILE configure
250
251 # Patch the Makefile.in files
252 for filename in $(find Makefile.in src -name Makefile.in) ; do {
253         echo $BOOTSTRAP_NAME: Patching $filename
254         (
255                 cp $filename $TEMPFILE &&
256                 sed "
257                         # Remove brain-dead include path
258                         s;-I. ;;
259                         
260                         # Gosh... I can't remember why I did this one...
261                         # Everything seems to work, so I'll leave it in.
262                         s;-I"'$(srcdir)'" ;-I"'$(top_srcdir)'" ;
263
264                         # Tell the configure script where it's origin realy is
265                         s;configure.in;config/configure.ac;
266                 " < $TEMPFILE > $filename
267         ) ||
268         {
269                 # Patch failure
270                 output Failure. Unable to patch $filename.
271                 cleanup;
272                 exit 1
273         }
274 }; done
275
276 output Creating Makefile...
277 ( echo "
278 all:
279         ./configure --enable-maintainer-mode
280         make all
281         
282 install:
283         ./configure --enable-maintainer-mode
284         make install
285         
286 check:
287         ./configure --enable-maintainer-mode
288         make check
289
290 distcheck:
291         ./configure --enable-maintainer-mode
292         make check
293         
294 dist:
295         ./configure --enable-maintainer-mode
296         make dist
297
298 docs: doxygen.cfg
299         doxygen doxygen.cfg
300
301 " ) > Makefile
302
303 output Complete.
304
305 cleanup;
306
307 # Move back to the current directory
308 cd $CURR_DIR
309
310 make -C src/synfig/proto