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.
17 # If this is left unset, try to set the version string from the highest
18 # revision number of the checked out files.
21 REV
="`git describe --always 2>/dev/null`"
22 VERSION
="${VERSION:-$REV}"
30 printf "searching for ${WHAT} (${*})..." 1>&2
31 test -n "${FROMENV}" && {
32 echo " using environment: ${FROMENV}" 1>&2
37 while test $i -lt $NPARMS; do
43 FILE
="`which "${1}" 2>/dev/null`"
52 echo " not found!" 1>&2
54 echo "This is a fatal error, configure is exiting!" 1>&2
57 echo " using ${FILE} in PATH" 1>&2
65 printf "finding CFLAGS for ${WHAT}... " 1>&2
66 OUT
="${OUT}\n${CC} ${CFLAGS} -o .config.o -c .config.c"
67 OUT
="${OUT}\n`echo "${CC} ${CFLAGS} -o .config.o -c .config.c"|sh
2>&1`"
69 echo " using: ${CFLAGS}" 1>&2
74 while test $i -lt $NPARMS; do
75 OUT="${OUT}\n${CC} ${CFLAGS} ${1} -o .config.o -c .config.c 2>&1"
76 OUT="${OUT}\n`echo "${CC} ${CFLAGS} ${1} -o .config.o -c .config.c"|sh 2>&1`"
78 echo " using
: ${CFLAGS} ${1}" 1>&2
87 printf "The following compiler commands were executed
:" 1>&2
88 echo -e "${OUT}\n" 1>&2
89 echo "This is a fatal error
, configure is exiting
!" 1>&2
91 echo "You can try to fix this by manually setting CFLAGS
in the environment before
" 1>&2
92 echo "running configure. E.g.
:" 1>&2
93 echo "CFLAGS
=-I/opt
/somedir
/include .
/configure
" 1>&2
102 printf "finding LDFLAGS
for ${WHAT}...
" 1>&2
103 OUT="${OUT}\n${CC} -o .config .config.o ${LDFLAGS} 2>&1"
104 OUT="${OUT}\n`echo "${CC} -o .config .config.o ${LDFLAGS}"|sh 2>&1`"
106 echo " using: ${LDFLAGS}" 1>&2
111 while test $i -lt $NPARMS; do
112 OUT
="${OUT}\n${CC} -o .config .config.o ${LDFLAGS} ${1} 2>&1"
113 OUT
="${OUT}\n`echo "${CC} -o .config .config.o ${LDFLAGS} ${1}"|sh
2>&1`"
115 echo " using: ${LDFLAGS} ${1}" 1>&2
116 echo "${LDFLAGS} ${1}"
124 printf "The following linker commands were executed:" 1>&2
125 echo -e "${OUT}\n" 1>&2
126 echo "This is a fatal error, configure is exiting!" 1>&2
128 echo "You can try to fix this by manually setting LDFLAGS in the environment before" 1>&2
129 echo "running configure. E.g.:" 1>&2
130 echo "LDFLAGS=-L/opt/somedir/lib ./configure" 1>&2
135 CC=`findprog
"compiler" "${CC}" gcc cc icc
` || exit
136 INSTALL=`findprog
"install" "${INSTALL}" install ginstall
` || exit
138 test -n "$DEBUG" && myCFLAGS="-O2 -g" || myCFLAGS="-Os"
139 CFLAGS="${CFLAGS} ${myCFLAGS} -Wall -Werror"
141 cat > .config.c << EOF
143 struct pci_access *pacc;
144 int main(int argc, char *argv[])
145 { pacc = pci_alloc(); return 0; }
148 pc_CFLAGS="`pkg-config libpci
--cflags 2>/dev
/null
`"
149 pc_LDFLAGS="`pkg-config libpci
--libs 2>/dev
/null
`"
150 CFLAGS=`trycompile
"libpci (from pciutils)" "${pc_CFLAGS}" "-I/usr/local/include"` || {
154 LDFLAGS=`trylink
"libpci (from pciutils)" "${pc_LDFLAGS}" "-lpci -lz" "-L/usr/local/lib -lpci -lz" "-framework DirectHW -lpci -lz"` || {
155 rm -f .config.c .config.o
158 rm -f .config.c .config.o .config
160 PREFIX="${PREFIX:-/usr/local}"
163 echo "configured using the following settings:"
165 echo "VERSION=${VERSION}"
167 echo "CFLAGS=${CFLAGS}"
168 echo "LDFLAGS=${LDFLAGS}"
169 echo "INSTALL=${INSTALL}"
170 echo "PREFIX=${PREFIX}"
172 printf "creating Makefile..."
173 echo "# This file was automatically generated by configure" > Makefile
174 sed -e "s#@VERSION@#${VERSION}#g" \
175 -e "s#@CC@#${CC}#g" \
176 -e "s#@CFLAGS@#${CFLAGS}#g" \
177 -e "s#@LDFLAGS@#${LDFLAGS}#g" \
178 -e "s#@INSTALL@#${INSTALL}#g" \
179 -e "s#@PREFIX@#${PREFIX}#g" \
180 Makefile.in >> Makefile