1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351
|
#!/bin/sh
#
# Copyright (c) 2009-2011 Mark Heily <mark@heily.com>
#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#
makeconf_version="$Revision: 10 $"
c_exports="program version target api cflags"
make_exports="program version target api distfile basedir \
prefix bindir sbindir libdir includedir mandir \
cflags ldflags ldadd libdepends \
sources objs deps mans headers extra_dist subdirs \
abi_major abi_minor abi_version \
cc cpp ld ln ar install diff"
required_headers=
optional_headers=
pre_configure_hook() {
return
}
post_configure_hook() {
return
}
export_to_make() {
for id in $*
do
uc_id=`echo $id | $tr '[:lower:]' '[:upper:]'`;
eval "echo \"$uc_id=\"\$$id\"\" >> config.mk"
done
}
export_to_c() {
for id in $*
do
uc_id=`echo $id | $tr '[:lower:]' '[:upper:]'`;
eval "echo \"#define $uc_id \\\"\$$id\\\"\" >> config.h"
done
}
finalize() {
uc_id=`echo \"$1\" | $tr '[:lower:]' '[:upper:]'`;
eval "if [ \"\$$1\" = \"\" ] ; then $1=\"$2\" ; fi"
}
process_argv() {
for arg in $*
do
if [ "$arg" = "--makeconf-version" ] ; then
echo $makeconf_version | sed 's/[^0-9.]//g'
exit 0
fi
id=`echo "$arg" | sed 's/=.*//; s/^--//;'`
val=`echo "$arg" | sed 's/^.*=//'`
if [ "$val" = "" ] ; then val=1 ; fi
eval "$id=\"$val\""
done
}
process_env() {
test -n "$CC" && cc="$CC"
test -n "$CPP" && cpp="$CPP"
test -n "$CPPFLAGS" && cppflags="$CPPFLAGS"
test -n "$CFLAGS" && cflags="$CFLAGS"
test -n "$LD" && ld="$LD"
test -n "$LN" && ld="$LN"
test -n "$LDFLAGS" && ldflags="$LDFLAGS"
test -n "$AR" && ar="$AR"
basedir=`pwd`
}
check_header() {
sym=`echo "have_$1" | sed 's,[./],_,g'`
uc_sym=`echo "$sym" | $tr '[:lower:]' '[:upper:]'`;
path=$1
printf "checking for $path.. "
if [ -f "/usr/include/$path" ] ; then
echo "yes"
echo "#define $uc_sym 1" >> config.h
eval "$sym=yes"
return 0
else
echo "no"
echo "#undef $uc_sym" >> config.h
eval "$sym=no"
return 1
fi
}
# Determine the path to an executable binary
check_binary() {
id=$1
shift
for path in $*
do
test -f $path
if [ $? = 0 ] ; then
eval "$id=\"$path\""
return
fi
done
echo "not found"
return
}
check_headers() {
for header in $*
do
check_header "$header"
done
}
check_symbol() {
header=$1
symbol=$2
uc_symbol=`echo "HAVE_$symbol" | $tr '[:lower:]' '[:upper:]' | sed 's,[./],_,g'`
lc_symbol=`echo "have_$symbol" | $tr '[:upper:]' '[:lower:]' | sed 's,[./],_,g'`
if [ -f "$header" ] ; then
path="$header"
elif [ -f "/usr/include/$header" ] ; then
path="/usr/include/$header"
else
echo "*** ERROR: Cannot find <$header>"
exit 1
fi
printf "checking $header for $symbol.. "
if [ "`grep $symbol $path`" != "" ] ; then
eval "$lc_symbol=yes"
echo "#define $uc_symbol 1" >> config.h
echo "yes"
return 0
else
eval "$lc_symbol=no"
echo "no"
echo "#undef $uc_symbol" >> config.h
return 1
fi
}
check_install() {
printf "checking for a BSD-compatible install.. "
if [ "`uname -s`" = "SunOS" ] ; then
default_install=/usr/ucb/install
else
default_install=/usr/bin/install
fi
finalize install "$default_install"
echo "$install"
}
check_target() {
printf "checking operating system type.. "
default_target=`uname -s | $tr '[:upper:]' '[:lower:]'`
default_api="posix"
case "$default_target" in
sunos)
default_target="solaris"
;;
"gnu/kfreebsd")
default_target="freebsd"
;;
mingw*)
default_target="windows"
default_api="windows"
;;
esac
finalize target "$default_target"
finalize api "$default_api"
echo "$api"
}
check_compiler() {
printf "checking for a C compiler.. "
check_binary default_cc "$cc" "`which $cc 2>/dev/null`" "/usr/bin/cc" "/usr/bin/gcc" "/usr/sfw/bin/gcc" "`which gcc 2>/dev/null`"
finalize cc "$default_cc"
# test -x "$cc" || err "Unable to locate a C compiler"
echo "$cc"
}
check_linker() {
printf "checking for a suitable linker.. "
# Workaround for "hidden symbol <foo> is referenced by DSO" linker error
# seen when compiling libdispatch.
# Appears to be a problem with GCC 4.0 and binutils
#
default_ld="$cc"
ldflags="-o $program.so.$abi_major.$abi_minor $ldflags"
# FIXME: port to solaris
if [ "$target" = "linux" ] ; then
ldflags="$ldflags -Wl,-export-dynamic -Wl,-soname,$program.so.$abi_major"
fi
if [ "$target" = "solaris" ] ; then
ldflags="$ldflags"
fi
finalize ld "$default_ld"
echo "$ld"
}
check_archiver() {
printf "checking for a suitable archiver.. "
if [ "`uname -s`" = "SunOS" -a "`uname -v | grep Nexenta`" = "" ] ; then
default_ar="/usr/sfw/bin/gar"
else
default_ar="/usr/bin/ar"
fi
finalize ar "$default_ar"
echo "$ar"
}
err() {
echo "*** ERROR *** $*"
rm -f config.mk $program.pc config.h
exit 1
}
check_diff() {
# TODO: Support non-GNU diff syntax
# TODO: Search for the command
printf "checking for a suitable diff(1) command.. "
finalize diff "diff -ruN -dEbwBp -x .svn -x .o -x config.h -x config.mk"
echo "found"
}
subst_vars() {
outfile=$1
if [ ! -f "${outfile}.in" ] ; then
return
fi
echo "Creating $outfile"
rm -f $outfile
sed -e "
s,@@CWD@@,`pwd`,g;
s,@@PROGRAM@@,$program,g;
s,@@VERSION@@,$version,g;
s,@@PREFIX@@,$prefix,g;
s,@@LIBDIR@@,$libdir,g;
s,@@INCLUDEDIR@@,$includedir,g;
s,@@MANDIR@@,$mandir,g;
s,@@LIBDEPENDS@@,$libdepends,g;
s,@@PKG_SUMMARY@@,$pkg_summary,g;
s,@@RPM_DATE@@,`date +'%a %b %d %Y'`,g;
s,@@PKG_DESCRIPTION@@,$pkg_description,g;
s,@@LICENSE@@,$license,g;
s,@@AUTHOR@@,$author,g;
" < ${outfile}.in > $outfile
chmod 400 $outfile
}
#######################################################################
#
# MAIN()
#
#######################################################################
# Workaround for Solaris "Bad string" issue when LOCALE is undefined
tr="/usr/bin/tr"
test -f /usr/xpg4/bin/tr && tr="/usr/xpg4/bin/tr"
. ./config.inc
# Initialize the output files
#
for output_file in config.mk
do
rm -f $output_file
echo "# AUTOMATICALLY GENERATED -- DO NOT EDIT" > $output_file
done
if [ "$sources" != "" ] ; then
rm -f config.h
echo "/* AUTOMATICALLY GENERATED -- DO NOT EDIT */" > config.h
fi
process_argv "$*"
process_env
check_target
check_compiler
check_linker
check_archiver
check_install
check_diff
finalize program "$program"
finalize version "$version"
finalize abi_major "$abi_major"
finalize abi_minor "$abi_minor"
finalize abi_version "$abi_major.$abi_minor"
finalize prefix "/usr/local"
finalize bindir "\\\$(PREFIX)/bin"
finalize sbindir "\\\$(PREFIX)/sbin"
finalize libdir "\\\$(PREFIX)/lib"
finalize includedir "\\\$(PREFIX)/include"
finalize mandir "\\\$(PREFIX)/share/man"
finalize cflags "$cflags"
finalize libdepends "$libdepends"
finalize ldadd ""
finalize ldflags ""
finalize deps ""
finalize ln "`which ln`"
finalize distfile "$program-$version.tar.gz"
pre_configure_hook
for header in $required_headers
do
check_header "$header" || err "$header is required, but cannot be found."
done
check_headers $optional_headers
post_configure_hook
objs="`echo \"$sources\" | sed 's/\.c/\.o/g'`"
subst_vars "$program.pc"
subst_vars "$program.la"
subst_vars "rpm.spec"
if [ "$sources" != "" ] ; then
echo "Creating config.h"
export_to_c $c_exports
fi
echo "Creating config.mk"
export_to_make "$make_exports"
|