You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
400 lines
9.0 KiB
400 lines
9.0 KiB
#!/bin/sh
|
|
#
|
|
# Copyright © 2009-2011 Samy Al Bahra.
|
|
# Copyright © 2011 Devon H. O'Dell <devon.odell@gmail.com>
|
|
# All rights reserved.
|
|
#
|
|
# Redistribution and use in source and binary forms, with or without
|
|
# modification, are permitted provided that the following conditions
|
|
# are met:
|
|
# 1. Redistributions of source code must retain the above copyright
|
|
# notice, this list of conditions and the following disclaimer.
|
|
# 2. Redistributions in binary form must reproduce the above copyright
|
|
# notice, this list of conditions and the following disclaimer in the
|
|
# documentation and/or other materials provided with the distribution.
|
|
#
|
|
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
# SUCH DAMAGE.
|
|
#
|
|
|
|
REQUIRE_HEADER="stdbool.h stdint.h"
|
|
GENERATE_FILE="build/ck.build"
|
|
|
|
EXIT_SUCCESS=0
|
|
EXIT_FAILURE=1
|
|
|
|
MAINTAINER='sbahra@repnop.org'
|
|
VERSION='0.0.6'
|
|
VERSION_MAJOR='0'
|
|
BUILD="$PWD/build/ck.build"
|
|
PREFIX=${PREFIX:-"/usr/local"}
|
|
|
|
export CFLAGS
|
|
export PREFIX
|
|
LC_ALL=C
|
|
export LC_ALL
|
|
|
|
if test -n "${BASH_VERSION+set}" && (set -o posix) >/dev/null 2>&1; then
|
|
set -o posix
|
|
fi
|
|
|
|
trap epilog 1 2 3 6
|
|
|
|
epilog()
|
|
{
|
|
rm -f .1.c .1
|
|
}
|
|
|
|
assert()
|
|
{
|
|
|
|
if test "$#" -eq 2; then
|
|
fail=$2
|
|
print=true
|
|
elif test "$#" -eq 3; then
|
|
fail=$3
|
|
print=echo
|
|
else
|
|
echo "Usage: assert <test> <fail string> or assert <test> <success string> <fail string>" 1>&2
|
|
exit $EXIT_FAILURE
|
|
fi
|
|
|
|
if test -z "$1"; then
|
|
echo "failed [$fail]"
|
|
exit $EXIT_FAILURE
|
|
else
|
|
${print} "success [$1]"
|
|
fi
|
|
}
|
|
|
|
generate()
|
|
{
|
|
sed -e "s#@PROFILE@#$PROFILE#g" \
|
|
-e "s#@VERSION@#$VERSION#g" \
|
|
-e "s#@VERSION_MAJOR@#$VERSION_MAJOR#g" \
|
|
-e "s#@CC@#$CC#g" \
|
|
-e "s#@CFLAGS@#$CFLAGS#g" \
|
|
-e "s#@HEADERS@#$HEADERS#g" \
|
|
-e "s#@LIBRARY@#$LIBRARY#g" \
|
|
-e "s#@PREFIX@#$PREFIX#g" \
|
|
-e "s#@LD@#$LD#g" \
|
|
-e "s#@LDFLAGS@#$LDFLAGS#g" \
|
|
-e "s#@PTHREAD_CFLAGS@#$PTHREAD_CFLAGS#g" \
|
|
$1 > $2
|
|
}
|
|
|
|
generate_stdout()
|
|
{
|
|
|
|
echo
|
|
echo " PROFILE = $PROFILE"
|
|
echo " CC = $CC"
|
|
echo " COMPILER = $COMPILER"
|
|
echo " CFLAGS = $CFLAGS"
|
|
echo " PTHREAD_CFLAGS = $PTHREAD_CFLAGS"
|
|
echo " LD = $LD"
|
|
echo " LDFLAGS = $LDFLAGS"
|
|
echo
|
|
echo "Headers will be installed in $HEADERS"
|
|
echo "Libraries will be installed in $LIBRARY"
|
|
}
|
|
|
|
for option in $*; do
|
|
value=`echo "$option" | sed -e 's/^[^=]*=\(.*\)/\1/'`
|
|
|
|
case "$option" in
|
|
--help)
|
|
echo "Usage: ./configure [OPTIONS]"
|
|
echo
|
|
echo "The following options may be used for cross-building."
|
|
echo " --profile=N Use custom build profile (use in conjunction with \$CC)"
|
|
echo
|
|
echo "The following options may be used to modify installation behavior."
|
|
echo " --includedir=N Headers directory (default is ${PREFIX}/include)"
|
|
echo " --libdir=N Libraries directory (default is ${PREFIX}/lib)"
|
|
echo " --prefix=N Installs library files in N (default is $PREFIX)"
|
|
echo
|
|
echo "The following environment variables may be used:"
|
|
echo " CC C compiler command"
|
|
echo " CFLAGS C compiler flags"
|
|
echo
|
|
echo "Report bugs to ${MAINTAINER}."
|
|
exit $EXIT_SUCCESS
|
|
;;
|
|
--profile=*)
|
|
PROFILE=$value
|
|
;;
|
|
--prefix=*)
|
|
PREFIX=$value
|
|
;;
|
|
--includedir=*)
|
|
HEADERS=$value
|
|
;;
|
|
--libdir=*)
|
|
LIBRARY=$value
|
|
;;
|
|
*)
|
|
echo "./configure [--help]"
|
|
exit $EXIT_FAILURE
|
|
;;
|
|
esac
|
|
done
|
|
|
|
HEADERS=${HEADERS:-"${PREFIX}/include"}
|
|
LIBRARY=${LIBRARY:-"${PREFIX}/lib"}
|
|
|
|
if test "$PROFILE"; then
|
|
printf "Using user-specified profile....."
|
|
|
|
if test -z "$CC"; then
|
|
echo "failed [specify compiler]"
|
|
exit $EXIT_FAILURE
|
|
fi
|
|
|
|
if test ! -f build/ck.build.$PROFILE; then
|
|
echo "failed [$PROFILE]"
|
|
exit $EXIT_FAILURE
|
|
fi
|
|
|
|
echo "success [$PROFILE]"
|
|
printf "Generating build files..........."
|
|
generate build/ck.build.in build/ck.build
|
|
generate build/regressions.build.in build/regressions.build
|
|
generate build/ck.pc.in build/ck.pc
|
|
generate Makefile.in Makefile
|
|
echo "success"
|
|
generate_stdout
|
|
exit $EXIT_SUCCESS
|
|
fi
|
|
|
|
printf "Detecting operating system......."
|
|
SYSTEM=`uname -s 2> /dev/null`
|
|
case "$SYSTEM" in
|
|
"SunOS")
|
|
SYSTEM=solaris
|
|
;;
|
|
"Linux"|"uClinux")
|
|
SYSTEM=linux
|
|
;;
|
|
"FreeBSD"|"GNU/kFreeBSD")
|
|
SYSTEM=freebsd
|
|
;;
|
|
"NetBSD")
|
|
SYSTEM=netbsd
|
|
;;
|
|
"OpenBSD")
|
|
SYSTEM=openbsd
|
|
;;
|
|
"DragonFly")
|
|
SYSTEM=dragonflybsd
|
|
;;
|
|
"Darwin")
|
|
SYSTEM=darwin
|
|
;;
|
|
*)
|
|
SYSTEM=
|
|
;;
|
|
esac
|
|
|
|
assert "$SYSTEM" "$SYSTEM" "unsupported"
|
|
|
|
printf "Detecting machine architecture..."
|
|
PLATFORM=`uname -m 2> /dev/null`
|
|
case $PLATFORM in
|
|
"macppc"|"Power Macintosh"|"powerpc")
|
|
PLATFORM=ppc32
|
|
ENVIRONMENT=32
|
|
assert "$PLATFORM $ENVIRONMENT" "$PLATFORM $ENVIRONMENT" "unsupported"
|
|
;;
|
|
"sun4u"|"sun4v"|"sparc64")
|
|
PLATFORM=sparcv9
|
|
ENVIRONMENT=64
|
|
LDFLAGS="-m64 $LDFLAGS"
|
|
;;
|
|
i386|i486|i586|i686|i586_i686|pentium*|athlon*|k5|k6|k6_2|k6_3)
|
|
case $SYSTEM in
|
|
darwin)
|
|
ENVIRONMENT=64
|
|
PLATFORM=x86_64
|
|
;;
|
|
freebsd)
|
|
PLATFORM=x86
|
|
ENVIRONMENT=32
|
|
|
|
# FreeBSD doesn't give us a nice way to determine the CPU
|
|
# class of the running system, reporting any 32-bit x86
|
|
# architecture as i386. 486 is its minimum supported CPU
|
|
# class and cmpxchg8b was implemented first in i586.
|
|
dmesg | grep -q "486-class"
|
|
if test "$?" -eq 0; then
|
|
assert "" "" "Must have an i586 class or higher CPU"
|
|
fi
|
|
|
|
# FreeBSD still generates code for 486-class CPUs as its
|
|
# default 32-bit target, but we need 586 at the least.
|
|
echo "$CFLAGS" | grep -q 'march='
|
|
if test "$?" -ne 0; then
|
|
# Needed for cmpxchg8b
|
|
CFLAGS="$CFLAGS -march=i586"
|
|
fi
|
|
;;
|
|
linux)
|
|
case $PLATFORM in
|
|
i386|i486)
|
|
assert "" "" "Must have an i586 class or higher CPU"
|
|
;;
|
|
esac
|
|
|
|
PLATFORM=x86
|
|
ENVIRONMENT=32
|
|
;;
|
|
|
|
*)
|
|
PLATFORM=x86
|
|
ENVIRONMENT=32
|
|
assert "$PLATFORM $ENVIRONMENT" "$PLATFORM $ENVIRONMENT" "unsupported"
|
|
;;
|
|
esac
|
|
;;
|
|
"amd64"|"x86_64")
|
|
PLATFORM=x86_64
|
|
ENVIRONMENT=64
|
|
LDFLAGS="-m64 $LDFLAGS"
|
|
;;
|
|
"i86pc")
|
|
ISA=`isainfo -n 2> /dev/null || echo i386`
|
|
case "$ISA" in
|
|
"amd64")
|
|
PLATFORM=x86_64
|
|
ENVIRONMENT=64
|
|
;;
|
|
*)
|
|
PLATFORM=x86
|
|
ENVIRONMENT=32
|
|
assert "$PLATFORM $ENVIRONMENT" "$PLATFORM $ENVIRONMENT" "unsupported"
|
|
;;
|
|
esac
|
|
;;
|
|
"ppc64")
|
|
PLATFORM=ppc64
|
|
ENVIRONMENT=64
|
|
;;
|
|
*)
|
|
PLATFORM=
|
|
;;
|
|
esac
|
|
|
|
assert "$PLATFORM" "$PLATFORM" "unsupported"
|
|
|
|
# Platform will be used as a macro.
|
|
PROFILE="${PROFILE:-$PLATFORM}"
|
|
PLATFORM="__${PLATFORM}__"
|
|
|
|
printf "Finding suitable compiler........"
|
|
|
|
# `which` on Solaris sucks
|
|
pathsearch()
|
|
{
|
|
what=$1
|
|
oldFS="$IFS"
|
|
IFS=":"
|
|
for d in $PATH ; do
|
|
if test -x "$d/$what" ; then
|
|
echo "$d/$what";
|
|
IFS="$oldFS"
|
|
return
|
|
fi
|
|
done
|
|
IFS="$oldFS"
|
|
}
|
|
|
|
CC=`pathsearch "${CC:-cc}"`
|
|
if test -z "$CC" -o ! -x "$CC"; then
|
|
CC=`pathsearch "${CC:-gcc}"`
|
|
fi
|
|
assert "$CC" "not found"
|
|
|
|
# Make sure GCC 4.X, the only supported compiler, is being used.
|
|
cat << EOF > .1.c
|
|
#include <stdio.h>
|
|
int main(void) {
|
|
#if defined(__GNUC__) && (__GNUC__ >= 4)
|
|
puts("gcc");
|
|
return (0);
|
|
#elif defined(__SUNPRO_C) && (__SUNPRO_C >= 0x5110)
|
|
puts("suncc");
|
|
return (0);
|
|
#else
|
|
return (1);
|
|
#endif
|
|
}
|
|
EOF
|
|
|
|
$CC -o .1 .1.c
|
|
COMPILER=`./.1`
|
|
r=$?
|
|
rm -f .1.c .1
|
|
|
|
if test "$r" -ne 0; then
|
|
assert "" "update compiler"
|
|
else
|
|
echo "success [$CC]"
|
|
fi
|
|
|
|
if test "$COMPILER" = "suncc"; then
|
|
LD=/bin/ld
|
|
LDFLAGS="-G -z text -h libck.so.$VERSION_MAJOR $LDFLAGS"
|
|
CFLAGS="-xO5 $CFLAGS"
|
|
PTHREAD_CFLAGS="-mt -lpthread"
|
|
elif test "$COMPILER" = "gcc"; then
|
|
LD=$CC
|
|
if test "$SYSTEM" = "darwin"; then
|
|
CC_WL_OPT="-install_name"
|
|
else
|
|
CC_WL_OPT="-soname"
|
|
fi
|
|
LDFLAGS="-shared -fPIC -Wl,$CC_WL_OPT,libck.so.$VERSION_MAJOR $LDFLAGS"
|
|
CFLAGS="-D_XOPEN_SOURCE=600 -D_BSD_SOURCE -std=gnu99 -pedantic -Wall -W -Wundef -Wendif-labels -Wshadow -Wpointer-arith -Wbad-function-cast -Wcast-align -Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes -Wnested-externs -Winline -Wdisabled-optimization -fstrict-aliasing -O2 -pipe -Wno-parentheses $CFLAGS"
|
|
PTHREAD_CFLAGS="-pthread"
|
|
else
|
|
assert "" "unknown compiler"
|
|
fi
|
|
|
|
for i in $REQUIRE_HEADER; do
|
|
printf "Checking header file usability..."
|
|
|
|
cat << EOF > .1.c
|
|
#include <$i>
|
|
int main(void){return(0);}
|
|
EOF
|
|
$CC -o .1 .1.c 2> /dev/null
|
|
hf_s=$?
|
|
|
|
rm -f .1 .1.c
|
|
if test $hf_s -eq 0; then
|
|
echo "success [$i]"
|
|
else
|
|
echo "failed [$i]"
|
|
exit $EXIT_FAILURE
|
|
fi
|
|
done
|
|
|
|
printf "Generating build files..........."
|
|
|
|
generate build/ck.build.in build/ck.build
|
|
generate build/regressions.build.in build/regressions.build
|
|
generate build/ck.pc.in build/ck.pc
|
|
generate Makefile.in Makefile
|
|
|
|
echo "success"
|
|
generate_stdout
|