3 # This file is part of msrtool.
5 # Copyright (c) 2008, 2009 Peter Stuge <peter@stuge.se>
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License version 2 as
9 # published by the Free Software Foundation.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 # If this is left unset, try to set the version string from the highest
22 # revision number of the checked out files.
25 REV="`svnversion -c . 2>/dev/null | sed 's,.*:,,' 2>/dev/null`"
26 VERSION="${VERSION:-$REV}"
34 printf "searching for ${WHAT} (${*})..." 1>&2
35 test -n "${FROMENV}" && {
36 echo " using environment: ${FROMENV}" 1>&2
41 while test $i -lt $NPARMS; do
47 FILE="`which "${1}" 2>/dev/null`"
56 echo " not found!" 1>&2
58 echo "This is a fatal error, configure is exiting!" 1>&2
61 echo " using ${FILE} in PATH" 1>&2
69 printf "finding CFLAGS for ${WHAT}... " 1>&2
70 OUT="${OUT}\n${CC} ${CFLAGS} -o .config.o -c .config.c"
71 OUT="${OUT}\n`echo "${CC} ${CFLAGS} -o .config.o -c .config.c"|sh 2>&1`"
73 echo " using: ${CFLAGS}" 1>&2
78 while test $i -lt $NPARMS; do
79 OUT="${OUT}\n${CC} ${CFLAGS} ${1} -o .config.o -c .config.c 2>&1"
80 OUT="${OUT}\n`echo "${CC} ${CFLAGS} ${1} -o .config.o -c .config.c"|sh 2>&1`"
82 echo " using: ${CFLAGS} ${1}" 1>&2
91 printf "The following compiler commands were executed:" 1>&2
92 echo -e "${OUT}\n" 1>&2
93 echo "This is a fatal error, configure is exiting!" 1>&2
95 echo "You can try to fix this by manually setting CFLAGS in the environment before" 1>&2
96 echo "running configure. E.g.:" 1>&2
97 echo "CFLAGS=-I/opt/somedir/include ./configure" 1>&2
106 printf "finding LDFLAGS for ${WHAT}... " 1>&2
107 OUT="${OUT}\n${CC} -o .config .config.o ${LDFLAGS} 2>&1"
108 OUT="${OUT}\n`echo "${CC} -o .config .config.o ${LDFLAGS}"|sh 2>&1`"
110 echo " using: ${LDFLAGS}" 1>&2
115 while test $i -lt $NPARMS; do
116 OUT="${OUT}\n${CC} -o .config .config.o ${LDFLAGS} ${1} 2>&1"
117 OUT="${OUT}\n`echo "${CC} -o .config .config.o ${LDFLAGS} ${1}"|sh 2>&1`"
119 echo " using: ${LDFLAGS} ${1}" 1>&2
120 echo "${LDFLAGS} ${1}"
128 printf "The following linker commands were executed:" 1>&2
129 echo -e "${OUT}\n" 1>&2
130 echo "This is a fatal error, configure is exiting!" 1>&2
132 echo "You can try to fix this by manually setting LDFLAGS in the environment before" 1>&2
133 echo "running configure. E.g.:" 1>&2
134 echo "LDFLAGS=-L/opt/somedir/lib ./configure" 1>&2
139 CC=`findprog "compiler" "${CC}" gcc cc icc` || exit
140 INSTALL=`findprog "install" "${INSTALL}" install ginstall` || exit
142 test -n "$DEBUG" && myCFLAGS="-O2 -g" || myCFLAGS="-Os"
143 CFLAGS="${CFLAGS} ${myCFLAGS} -Wall -Werror"
145 cat > .config.c << EOF
147 struct pci_access *pacc;
148 int main(int argc, char *argv[])
149 { pacc = pci_alloc(); return 0; }
152 pc_CFLAGS="`pkg-config libpci --cflags 2>/dev/null`"
153 pc_LDFLAGS="`pkg-config libpci --libs 2>/dev/null`"
154 CFLAGS=`trycompile "libpci (from pciutils)" "${pc_CFLAGS}" "-I/usr/local/include"` || {
158 LDFLAGS=`trylink "libpci (from pciutils)" "${pc_LDFLAGS}" "-lpci -lz" "-L/usr/local/lib -lpci -lz" "-framework DirectHW -lpci -lz"` || {
159 rm -f .config.c .config.o
162 rm -f .config.c .config.o .config
164 PREFIX="${PREFIX:-/usr/local}"
167 echo "configured using the following settings:"
169 echo "VERSION=${VERSION}"
171 echo "CFLAGS=${CFLAGS}"
172 echo "LDFLAGS=${LDFLAGS}"
173 echo "INSTALL=${INSTALL}"
174 echo "PREFIX=${PREFIX}"
176 printf "creating Makefile..."
177 echo "# This file was automatically generated by configure" > Makefile
178 sed -e "s#@VERSION@#${VERSION}#g" \
179 -e "s#@CC@#${CC}#g" \
180 -e "s#@CFLAGS@#${CFLAGS}#g" \
181 -e "s#@LDFLAGS@#${LDFLAGS}#g" \
182 -e "s#@INSTALL@#${INSTALL}#g" \
183 -e "s#@PREFIX@#${PREFIX}#g" \
184 Makefile.in >> Makefile