3 # TODO: backport 'distfile' to ./configure trunk
5 c_exports="program version target cflags"
7 make_exports="program version target distfile \
8 prefix libdir includedir mandir \
9 cflags ldflags ldadd libdepends \
10 sources objs deps mans headers extra_dist subdirs \
11 abi_major abi_minor abi_version \
12 cc cpp ld ln ar install diff"
17 pre_configure_hook() {
21 post_configure_hook() {
29 # Prepend $DESTDIR to installation directories
31 prefix|libdir|includedir|mandir)
32 eval "$id=\"\\\$\\\$DESTDIR\$$id\""
35 uc_id=`echo $id | $tr '[:lower:]' '[:upper:]'`;
36 eval "echo \"$uc_id=\"\$$id\"\" >> config.mk"
43 uc_id=`echo $id | $tr '[:lower:]' '[:upper:]'`;
44 eval "echo \"#define $uc_id \\\"\$$id\\\"\" >> config.h"
49 uc_id=`echo \"$1\" | $tr '[:lower:]' '[:upper:]'`;
50 eval "if [ \"\$$1\" = \"\" ] ; then $1=\"$2\" ; fi"
56 id=`echo "$arg" | sed 's/=.*//; s/^--//;'`
57 val=`echo "$arg" | sed 's/^.*=//'`
58 if [ "$val" = "" ] ; then val=1 ; fi
64 test -n "$CC" && cc="$CC"
65 test -n "$CPP" && cpp="$CPP"
66 test -n "$CPPFLAGS" && cppflags="$CPPFLAGS"
67 test -n "$CFLAGS" && cflags="$CFLAGS"
68 test -n "$LD" && ld="$LD"
69 test -n "$LN" && ld="$LN"
70 test -n "$LDFLAGS" && ldflags="$LDFLAGS"
71 test -n "$AR" && ar="$AR"
75 sym=`echo "have_$1" | sed 's,[./],_,g'`
76 uc_sym=`echo "$sym" | $tr '[:lower:]' '[:upper:]'`;
79 printf "checking for $path.. "
80 if [ -f "/usr/include/$path" ] ; then
82 echo "#define $uc_sym 1" >> config.h
87 echo "#undef $uc_sym" >> config.h
96 check_header "$header"
104 uc_symbol=`echo "HAVE_$symbol" | $tr '[:lower:]' '[:upper:]' | sed 's,[./],_,g'`
105 lc_symbol=`echo "have_$symbol" | $tr '[:upper:]' '[:lower:]' | sed 's,[./],_,g'`
107 if [ -f "$header" ] ; then
109 elif [ -f "/usr/include/$header" ] ; then
110 path="/usr/include/$header"
112 echo "*** ERROR: Cannot find <$header>"
116 printf "checking $header for $symbol.. "
117 if [ "`grep $symbol $path`" != "" ] ; then
118 eval "$lc_symbol=yes"
119 echo "#define $uc_symbol 1" >> config.h
125 echo "#undef $uc_symbol" >> config.h
131 printf "checking for a BSD-compatible install.. "
132 if [ "`uname -s`" = "SunOS" ] ; then
133 default_install=/usr/ucb/install
135 default_install=/usr/bin/install
137 finalize install "$default_install"
142 printf "checking operating system type.. "
143 default_target=`uname -s | $tr '[:upper:]' '[:lower:]'`
144 if [ "$default_target" = "sunos" ] ; then
145 default_target="solaris"
147 finalize target "$default_target"
152 printf "checking for a C compiler.. "
153 if [ "`uname -s`" = "SunOS" ] ; then
154 default_cc="/usr/sfw/bin/gcc"
156 default_cc="/usr/bin/cc"
158 finalize cc "$default_cc"
163 printf "checking for a suitable linker.. "
165 # Disabled due to problems with ld(1) under Linux
166 #if [ "`uname -s`" = "SunOS" ] ; then
167 # default_ld="/usr/sfw/bin/gld"
169 # default_ld="/usr/bin/ld"
171 #ldflags="-shared -export-dynamic -soname $program.so $ldflags"
173 # Workaround for "hidden symbol <foo> is referenced by DSO" linker error
174 # seen when compiling libdispatch.
175 # Appears to be a problem with GCC 4.0 and binutils
178 ldflags="-shared -Wl,-export-dynamic -Wl,-soname,$program.so.$abi_major -o $program.so.$abi_major.$abi_minor $ldflags"
180 finalize ld "$default_ld"
185 printf "checking for a suitable archiver.. "
186 if [ "`uname -s`" = "SunOS" ] ; then
187 default_ar="/usr/sfw/bin/gar"
189 default_ar="/usr/bin/ar"
191 finalize ar "$default_ar"
196 echo "*** ERROR *** $*"
197 rm -f config.mk $program.pc config.h
202 # TODO: Support non-GNU diff syntax
203 # TODO: Search for the command
204 printf "checking for a suitable diff(1) command.. "
205 finalize diff "diff -ruN -dEbwBp -x .svn -x .o -x config.h -x config.mk"
212 if [ ! -f "${outfile}.in" ] ; then
216 echo "Creating $outfile"
219 s,@@PROGRAM@@,$program,g;
220 s,@@VERSION@@,$version,g;
221 s,@@PREFIX@@,$prefix,g;
222 s,@@LIBDIR@@,$libdir,g;
223 s,@@INCLUDEDIR@@,$includedir,g;
224 s,@@MANDIR@@,$mandir,g;
225 s,@@LIBDEPENDS@@,$libdepends,g;
226 s,@@PKG_SUMMARY@@,$pkg_summary,g;
227 s,@@PKG_DESCRIPTION@@,$pkg_description,g;
228 s,@@LICENSE@@,$license,g;
229 s,@@AUTHOR@@,$author,g;
230 " < ${outfile}.in > $outfile
234 #######################################################################
238 #######################################################################
240 # Workaround for Solaris "Bad string" issue when LOCALE is undefined
242 test -f /usr/xpg4/bin/tr && tr="/usr/xpg4/bin/tr"
246 # Initialize the output files
248 for output_file in config.mk $program.pc
251 echo "# AUTOMATICALLY GENERATED -- DO NOT EDIT" > $output_file
254 echo "/* AUTOMATICALLY GENERATED -- DO NOT EDIT */" > config.h
266 finalize program "$program"
267 finalize version "$version"
268 finalize abi_major "$abi_major"
269 finalize abi_minor "$abi_minor"
270 finalize abi_version "$abi_major.$abi_minor"
271 finalize prefix "/usr/local"
272 finalize libdir "${prefix}/lib"
273 finalize includedir "${prefix}/include"
274 finalize mandir "${prefix}/share/man"
275 finalize cflags "$cflags"
276 finalize libdepends "$libdepends"
280 finalize ln "/bin/ln"
281 finalize distfile "$program-$version.tar.gz"
285 for header in $required_headers
287 check_header "$header" || err "$header is required, but cannot be found."
289 check_headers $optional_headers
293 objs="`echo \"$sources\" | sed 's/\.c/\.o/g'`"
295 subst_vars "$program.pc"
296 subst_vars "$program.la"
297 subst_vars "rpm.spec"
299 echo "Creating config.h"
300 export_to_c $c_exports
302 echo "Creating config.mk"
303 export_to_make "$make_exports"
305 make clean >/dev/null 2>&1