2009-11-28 05:54:33 +01:00
|
|
|
#!/bin/sh
|
2008-11-22 18:13:36 +01:00
|
|
|
#
|
|
|
|
# This file is part of msrtool.
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License version 2 as
|
|
|
|
# published by the Free Software Foundation.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
|
|
|
|
# If this is left unset, try to set the version string from the highest
|
2009-01-26 05:10:12 +01:00
|
|
|
# revision number of the checked out files.
|
2008-11-22 18:13:36 +01:00
|
|
|
VERSION=""
|
|
|
|
|
2015-12-11 18:00:57 +01:00
|
|
|
REV="`git describe --always 2>/dev/null`"
|
2008-11-22 18:13:36 +01:00
|
|
|
VERSION="${VERSION:-$REV}"
|
|
|
|
|
2009-11-28 05:54:33 +01:00
|
|
|
findprog() {
|
2009-01-26 05:10:12 +01:00
|
|
|
NPARMS=$#
|
2008-11-22 18:13:36 +01:00
|
|
|
WHAT="${1}"
|
|
|
|
shift
|
|
|
|
FROMENV="${1}"
|
|
|
|
shift
|
2009-01-26 05:10:12 +01:00
|
|
|
printf "searching for ${WHAT} (${*})..." 1>&2
|
2008-11-22 18:13:36 +01:00
|
|
|
test -n "${FROMENV}" && {
|
|
|
|
echo " using environment: ${FROMENV}" 1>&2
|
|
|
|
echo "${FROMENV}"
|
|
|
|
exit 0
|
|
|
|
}
|
2009-01-26 05:10:12 +01:00
|
|
|
i=2
|
|
|
|
while test $i -lt $NPARMS; do
|
2008-11-22 18:13:36 +01:00
|
|
|
test -z "${1}" && {
|
|
|
|
shift
|
2009-11-28 05:54:33 +01:00
|
|
|
i=$(($i+1))
|
2008-11-22 18:13:36 +01:00
|
|
|
continue
|
|
|
|
}
|
2009-01-26 05:10:12 +01:00
|
|
|
FILE="`which "${1}" 2>/dev/null`"
|
2008-11-22 18:13:36 +01:00
|
|
|
test $? -eq 0 && {
|
|
|
|
echo "${1}"
|
|
|
|
break
|
|
|
|
}
|
|
|
|
shift
|
2009-11-28 05:54:33 +01:00
|
|
|
i=$(($i+1))
|
2008-11-22 18:13:36 +01:00
|
|
|
done
|
|
|
|
test -z "${1}" && {
|
|
|
|
echo " not found!" 1>&2
|
|
|
|
echo 1>&2
|
|
|
|
echo "This is a fatal error, configure is exiting!" 1>&2
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
echo " using ${FILE} in PATH" 1>&2
|
|
|
|
exit 0
|
|
|
|
}
|
|
|
|
|
2009-11-28 05:54:33 +01:00
|
|
|
trycompile() {
|
2009-01-26 05:10:12 +01:00
|
|
|
NPARMS=$#
|
2008-11-22 18:13:36 +01:00
|
|
|
WHAT="${1}"
|
|
|
|
shift
|
2009-01-26 05:10:12 +01:00
|
|
|
printf "finding CFLAGS for ${WHAT}... " 1>&2
|
2008-11-22 18:13:36 +01:00
|
|
|
OUT="${OUT}\n${CC} ${CFLAGS} -o .config.o -c .config.c"
|
2009-01-26 05:10:12 +01:00
|
|
|
OUT="${OUT}\n`echo "${CC} ${CFLAGS} -o .config.o -c .config.c"|sh 2>&1`"
|
2008-11-22 18:13:36 +01:00
|
|
|
test $? -eq 0 && {
|
|
|
|
echo " using: ${CFLAGS}" 1>&2
|
|
|
|
echo "${CFLAGS}"
|
|
|
|
exit 0
|
|
|
|
}
|
2009-01-26 05:10:12 +01:00
|
|
|
i=1
|
|
|
|
while test $i -lt $NPARMS; do
|
2008-11-22 18:13:36 +01:00
|
|
|
OUT="${OUT}\n${CC} ${CFLAGS} ${1} -o .config.o -c .config.c 2>&1"
|
2009-01-26 05:10:12 +01:00
|
|
|
OUT="${OUT}\n`echo "${CC} ${CFLAGS} ${1} -o .config.o -c .config.c"|sh 2>&1`"
|
2008-11-22 18:13:36 +01:00
|
|
|
test $? -eq 0 && {
|
|
|
|
echo " using: ${CFLAGS} ${1}" 1>&2
|
|
|
|
echo "${CFLAGS} ${1}"
|
|
|
|
exit 0
|
2010-04-27 08:56:47 +02:00
|
|
|
}
|
2008-11-22 18:13:36 +01:00
|
|
|
shift
|
2009-11-28 05:54:33 +01:00
|
|
|
i=$(($i+1))
|
2008-11-22 18:13:36 +01:00
|
|
|
done
|
|
|
|
echo "failed!" 1>&2
|
|
|
|
echo 1>&2
|
2009-01-26 05:10:12 +01:00
|
|
|
printf "The following compiler commands were executed:" 1>&2
|
2008-11-22 18:13:36 +01:00
|
|
|
echo -e "${OUT}\n" 1>&2
|
|
|
|
echo "This is a fatal error, configure is exiting!" 1>&2
|
|
|
|
echo 1>&2
|
|
|
|
echo "You can try to fix this by manually setting CFLAGS in the environment before" 1>&2
|
|
|
|
echo "running configure. E.g.:" 1>&2
|
2009-01-26 05:10:12 +01:00
|
|
|
echo "CFLAGS=-I/opt/somedir/include ./configure" 1>&2
|
2008-11-22 18:13:36 +01:00
|
|
|
echo 1>&2
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
2009-11-28 06:30:57 +01:00
|
|
|
trylink() {
|
2009-01-26 05:10:12 +01:00
|
|
|
NPARMS=$#
|
2008-11-22 18:13:36 +01:00
|
|
|
WHAT="${1}"
|
|
|
|
shift
|
2009-01-26 05:10:12 +01:00
|
|
|
printf "finding LDFLAGS for ${WHAT}... " 1>&2
|
2008-11-22 18:13:36 +01:00
|
|
|
OUT="${OUT}\n${CC} -o .config .config.o ${LDFLAGS} 2>&1"
|
2009-01-26 05:10:12 +01:00
|
|
|
OUT="${OUT}\n`echo "${CC} -o .config .config.o ${LDFLAGS}"|sh 2>&1`"
|
2008-11-22 18:13:36 +01:00
|
|
|
test $? -eq 0 && {
|
|
|
|
echo " using: ${LDFLAGS}" 1>&2
|
|
|
|
echo "${LDFLAGS}"
|
|
|
|
exit 0
|
|
|
|
}
|
2009-01-26 05:10:12 +01:00
|
|
|
i=1
|
|
|
|
while test $i -lt $NPARMS; do
|
2008-11-22 18:13:36 +01:00
|
|
|
OUT="${OUT}\n${CC} -o .config .config.o ${LDFLAGS} ${1} 2>&1"
|
2009-01-26 05:10:12 +01:00
|
|
|
OUT="${OUT}\n`echo "${CC} -o .config .config.o ${LDFLAGS} ${1}"|sh 2>&1`"
|
2008-11-22 18:13:36 +01:00
|
|
|
test $? -eq 0 && {
|
|
|
|
echo " using: ${LDFLAGS} ${1}" 1>&2
|
|
|
|
echo "${LDFLAGS} ${1}"
|
|
|
|
exit 0
|
|
|
|
}
|
|
|
|
shift
|
2009-11-28 05:54:33 +01:00
|
|
|
i=$(($i+1))
|
2008-11-22 18:13:36 +01:00
|
|
|
done
|
|
|
|
echo "failed!" 1>&2
|
|
|
|
echo 1>&2
|
2009-01-26 05:10:12 +01:00
|
|
|
printf "The following linker commands were executed:" 1>&2
|
2008-11-22 18:13:36 +01:00
|
|
|
echo -e "${OUT}\n" 1>&2
|
|
|
|
echo "This is a fatal error, configure is exiting!" 1>&2
|
|
|
|
echo 1>&2
|
|
|
|
echo "You can try to fix this by manually setting LDFLAGS in the environment before" 1>&2
|
|
|
|
echo "running configure. E.g.:" 1>&2
|
2009-01-26 05:10:12 +01:00
|
|
|
echo "LDFLAGS=-L/opt/somedir/lib ./configure" 1>&2
|
2008-11-22 18:13:36 +01:00
|
|
|
echo 1>&2
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
2009-01-26 05:10:12 +01:00
|
|
|
CC=`findprog "compiler" "${CC}" gcc cc icc` || exit
|
|
|
|
INSTALL=`findprog "install" "${INSTALL}" install ginstall` || exit
|
2008-11-22 18:13:36 +01:00
|
|
|
|
|
|
|
test -n "$DEBUG" && myCFLAGS="-O2 -g" || myCFLAGS="-Os"
|
|
|
|
CFLAGS="${CFLAGS} ${myCFLAGS} -Wall -Werror"
|
|
|
|
|
2008-11-25 03:03:16 +01:00
|
|
|
cat > .config.c << EOF
|
|
|
|
#include <pci/pci.h>
|
|
|
|
struct pci_access *pacc;
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{ pacc = pci_alloc(); return 0; }
|
|
|
|
EOF
|
|
|
|
|
2009-01-26 05:10:12 +01:00
|
|
|
pc_CFLAGS="`pkg-config libpci --cflags 2>/dev/null`"
|
|
|
|
pc_LDFLAGS="`pkg-config libpci --libs 2>/dev/null`"
|
|
|
|
CFLAGS=`trycompile "libpci (from pciutils)" "${pc_CFLAGS}" "-I/usr/local/include"` || {
|
2008-11-25 03:03:16 +01:00
|
|
|
rm -f .config.c
|
|
|
|
exit 1
|
|
|
|
}
|
2011-03-14 10:08:27 +01:00
|
|
|
LDFLAGS=`trylink "libpci (from pciutils)" "${pc_LDFLAGS}" "-lpci -lz" "-L/usr/local/lib -lpci -lz" "-framework DirectHW -lpci -lz"` || {
|
2008-11-25 03:03:16 +01:00
|
|
|
rm -f .config.c .config.o
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
rm -f .config.c .config.o .config
|
|
|
|
|
2008-11-22 18:13:36 +01:00
|
|
|
PREFIX="${PREFIX:-/usr/local}"
|
|
|
|
|
|
|
|
echo
|
|
|
|
echo "configured using the following settings:"
|
|
|
|
echo
|
|
|
|
echo "VERSION=${VERSION}"
|
|
|
|
echo "CC=${CC}"
|
|
|
|
echo "CFLAGS=${CFLAGS}"
|
|
|
|
echo "LDFLAGS=${LDFLAGS}"
|
|
|
|
echo "INSTALL=${INSTALL}"
|
|
|
|
echo "PREFIX=${PREFIX}"
|
|
|
|
echo
|
2009-01-26 05:10:12 +01:00
|
|
|
printf "creating Makefile..."
|
2008-11-22 18:13:36 +01:00
|
|
|
echo "# This file was automatically generated by configure" > Makefile
|
|
|
|
sed -e "s#@VERSION@#${VERSION}#g" \
|
|
|
|
-e "s#@CC@#${CC}#g" \
|
|
|
|
-e "s#@CFLAGS@#${CFLAGS}#g" \
|
|
|
|
-e "s#@LDFLAGS@#${LDFLAGS}#g" \
|
|
|
|
-e "s#@INSTALL@#${INSTALL}#g" \
|
2009-11-28 05:45:34 +01:00
|
|
|
-e "s#@PREFIX@#${PREFIX}#g" \
|
2008-11-22 18:13:36 +01:00
|
|
|
Makefile.in >> Makefile
|
|
|
|
echo " done"
|
|
|
|
echo
|