blob: 1d11a464b97ff9eff033d7c40d8c8c4ed35a2c6d [file] [log] [blame]
Andriy Gapon7df17af2009-11-28 04:54:33 +00001#!/bin/sh
Peter Stugedad1e302008-11-22 17:13:36 +00002#
3# This file is part of msrtool.
4#
Peter Stugebe89c412009-11-28 04:45:34 +00005# Copyright (c) 2008, 2009 Peter Stuge <peter@stuge.se>
Peter Stugedad1e302008-11-22 17:13:36 +00006#
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.
10#
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.
15#
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
Paul Menzela46a7122013-02-23 18:37:27 +010018# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Peter Stugedad1e302008-11-22 17:13:36 +000019#
20
21# If this is left unset, try to set the version string from the highest
Peter Stuge279cdbb2009-01-26 04:10:12 +000022# revision number of the checked out files.
Peter Stugedad1e302008-11-22 17:13:36 +000023VERSION=""
24
Peter Stuge279cdbb2009-01-26 04:10:12 +000025REV="`svnversion -c . 2>/dev/null | sed 's,.*:,,' 2>/dev/null`"
Peter Stugedad1e302008-11-22 17:13:36 +000026VERSION="${VERSION:-$REV}"
27
Andriy Gapon7df17af2009-11-28 04:54:33 +000028findprog() {
Peter Stuge279cdbb2009-01-26 04:10:12 +000029 NPARMS=$#
Peter Stugedad1e302008-11-22 17:13:36 +000030 WHAT="${1}"
31 shift
32 FROMENV="${1}"
33 shift
Peter Stuge279cdbb2009-01-26 04:10:12 +000034 printf "searching for ${WHAT} (${*})..." 1>&2
Peter Stugedad1e302008-11-22 17:13:36 +000035 test -n "${FROMENV}" && {
36 echo " using environment: ${FROMENV}" 1>&2
37 echo "${FROMENV}"
38 exit 0
39 }
Peter Stuge279cdbb2009-01-26 04:10:12 +000040 i=2
41 while test $i -lt $NPARMS; do
Peter Stugedad1e302008-11-22 17:13:36 +000042 test -z "${1}" && {
43 shift
Andriy Gapon7df17af2009-11-28 04:54:33 +000044 i=$(($i+1))
Peter Stugedad1e302008-11-22 17:13:36 +000045 continue
46 }
Peter Stuge279cdbb2009-01-26 04:10:12 +000047 FILE="`which "${1}" 2>/dev/null`"
Peter Stugedad1e302008-11-22 17:13:36 +000048 test $? -eq 0 && {
49 echo "${1}"
50 break
51 }
52 shift
Andriy Gapon7df17af2009-11-28 04:54:33 +000053 i=$(($i+1))
Peter Stugedad1e302008-11-22 17:13:36 +000054 done
55 test -z "${1}" && {
56 echo " not found!" 1>&2
57 echo 1>&2
58 echo "This is a fatal error, configure is exiting!" 1>&2
59 exit 1
60 }
61 echo " using ${FILE} in PATH" 1>&2
62 exit 0
63}
64
Andriy Gapon7df17af2009-11-28 04:54:33 +000065trycompile() {
Peter Stuge279cdbb2009-01-26 04:10:12 +000066 NPARMS=$#
Peter Stugedad1e302008-11-22 17:13:36 +000067 WHAT="${1}"
68 shift
Peter Stuge279cdbb2009-01-26 04:10:12 +000069 printf "finding CFLAGS for ${WHAT}... " 1>&2
Peter Stugedad1e302008-11-22 17:13:36 +000070 OUT="${OUT}\n${CC} ${CFLAGS} -o .config.o -c .config.c"
Peter Stuge279cdbb2009-01-26 04:10:12 +000071 OUT="${OUT}\n`echo "${CC} ${CFLAGS} -o .config.o -c .config.c"|sh 2>&1`"
Peter Stugedad1e302008-11-22 17:13:36 +000072 test $? -eq 0 && {
73 echo " using: ${CFLAGS}" 1>&2
74 echo "${CFLAGS}"
75 exit 0
76 }
Peter Stuge279cdbb2009-01-26 04:10:12 +000077 i=1
78 while test $i -lt $NPARMS; do
Peter Stugedad1e302008-11-22 17:13:36 +000079 OUT="${OUT}\n${CC} ${CFLAGS} ${1} -o .config.o -c .config.c 2>&1"
Peter Stuge279cdbb2009-01-26 04:10:12 +000080 OUT="${OUT}\n`echo "${CC} ${CFLAGS} ${1} -o .config.o -c .config.c"|sh 2>&1`"
Peter Stugedad1e302008-11-22 17:13:36 +000081 test $? -eq 0 && {
82 echo " using: ${CFLAGS} ${1}" 1>&2
83 echo "${CFLAGS} ${1}"
84 exit 0
Stefan Reinauer14e22772010-04-27 06:56:47 +000085 }
Peter Stugedad1e302008-11-22 17:13:36 +000086 shift
Andriy Gapon7df17af2009-11-28 04:54:33 +000087 i=$(($i+1))
Peter Stugedad1e302008-11-22 17:13:36 +000088 done
89 echo "failed!" 1>&2
90 echo 1>&2
Peter Stuge279cdbb2009-01-26 04:10:12 +000091 printf "The following compiler commands were executed:" 1>&2
Peter Stugedad1e302008-11-22 17:13:36 +000092 echo -e "${OUT}\n" 1>&2
93 echo "This is a fatal error, configure is exiting!" 1>&2
94 echo 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
Peter Stuge279cdbb2009-01-26 04:10:12 +000097 echo "CFLAGS=-I/opt/somedir/include ./configure" 1>&2
Peter Stugedad1e302008-11-22 17:13:36 +000098 echo 1>&2
99 exit 1
100}
101
Peter Stugef30a22202009-11-28 05:30:57 +0000102trylink() {
Peter Stuge279cdbb2009-01-26 04:10:12 +0000103 NPARMS=$#
Peter Stugedad1e302008-11-22 17:13:36 +0000104 WHAT="${1}"
105 shift
Peter Stuge279cdbb2009-01-26 04:10:12 +0000106 printf "finding LDFLAGS for ${WHAT}... " 1>&2
Peter Stugedad1e302008-11-22 17:13:36 +0000107 OUT="${OUT}\n${CC} -o .config .config.o ${LDFLAGS} 2>&1"
Peter Stuge279cdbb2009-01-26 04:10:12 +0000108 OUT="${OUT}\n`echo "${CC} -o .config .config.o ${LDFLAGS}"|sh 2>&1`"
Peter Stugedad1e302008-11-22 17:13:36 +0000109 test $? -eq 0 && {
110 echo " using: ${LDFLAGS}" 1>&2
111 echo "${LDFLAGS}"
112 exit 0
113 }
Peter Stuge279cdbb2009-01-26 04:10:12 +0000114 i=1
115 while test $i -lt $NPARMS; do
Peter Stugedad1e302008-11-22 17:13:36 +0000116 OUT="${OUT}\n${CC} -o .config .config.o ${LDFLAGS} ${1} 2>&1"
Peter Stuge279cdbb2009-01-26 04:10:12 +0000117 OUT="${OUT}\n`echo "${CC} -o .config .config.o ${LDFLAGS} ${1}"|sh 2>&1`"
Peter Stugedad1e302008-11-22 17:13:36 +0000118 test $? -eq 0 && {
119 echo " using: ${LDFLAGS} ${1}" 1>&2
120 echo "${LDFLAGS} ${1}"
121 exit 0
122 }
123 shift
Andriy Gapon7df17af2009-11-28 04:54:33 +0000124 i=$(($i+1))
Peter Stugedad1e302008-11-22 17:13:36 +0000125 done
126 echo "failed!" 1>&2
127 echo 1>&2
Peter Stuge279cdbb2009-01-26 04:10:12 +0000128 printf "The following linker commands were executed:" 1>&2
Peter Stugedad1e302008-11-22 17:13:36 +0000129 echo -e "${OUT}\n" 1>&2
130 echo "This is a fatal error, configure is exiting!" 1>&2
131 echo 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
Peter Stuge279cdbb2009-01-26 04:10:12 +0000134 echo "LDFLAGS=-L/opt/somedir/lib ./configure" 1>&2
Peter Stugedad1e302008-11-22 17:13:36 +0000135 echo 1>&2
136 exit 1
137}
138
Peter Stuge279cdbb2009-01-26 04:10:12 +0000139CC=`findprog "compiler" "${CC}" gcc cc icc` || exit
140INSTALL=`findprog "install" "${INSTALL}" install ginstall` || exit
Peter Stugedad1e302008-11-22 17:13:36 +0000141
142test -n "$DEBUG" && myCFLAGS="-O2 -g" || myCFLAGS="-Os"
143CFLAGS="${CFLAGS} ${myCFLAGS} -Wall -Werror"
144
Peter Stuge0924dee2008-11-25 02:03:16 +0000145cat > .config.c << EOF
146#include <pci/pci.h>
147struct pci_access *pacc;
148int main(int argc, char *argv[])
149{ pacc = pci_alloc(); return 0; }
150EOF
151
Peter Stuge279cdbb2009-01-26 04:10:12 +0000152pc_CFLAGS="`pkg-config libpci --cflags 2>/dev/null`"
153pc_LDFLAGS="`pkg-config libpci --libs 2>/dev/null`"
154CFLAGS=`trycompile "libpci (from pciutils)" "${pc_CFLAGS}" "-I/usr/local/include"` || {
Peter Stuge0924dee2008-11-25 02:03:16 +0000155 rm -f .config.c
156 exit 1
157}
Stefan Reinauer9018b6e2011-03-14 09:08:27 +0000158LDFLAGS=`trylink "libpci (from pciutils)" "${pc_LDFLAGS}" "-lpci -lz" "-L/usr/local/lib -lpci -lz" "-framework DirectHW -lpci -lz"` || {
Peter Stuge0924dee2008-11-25 02:03:16 +0000159 rm -f .config.c .config.o
160 exit 1
161}
162rm -f .config.c .config.o .config
163
Peter Stugedad1e302008-11-22 17:13:36 +0000164PREFIX="${PREFIX:-/usr/local}"
165
Peter Stugedad1e302008-11-22 17:13:36 +0000166echo
167echo "configured using the following settings:"
168echo
169echo "VERSION=${VERSION}"
170echo "CC=${CC}"
171echo "CFLAGS=${CFLAGS}"
172echo "LDFLAGS=${LDFLAGS}"
173echo "INSTALL=${INSTALL}"
174echo "PREFIX=${PREFIX}"
175echo
Peter Stuge279cdbb2009-01-26 04:10:12 +0000176printf "creating Makefile..."
Peter Stugedad1e302008-11-22 17:13:36 +0000177echo "# This file was automatically generated by configure" > Makefile
178sed -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" \
Peter Stugebe89c412009-11-28 04:45:34 +0000183 -e "s#@PREFIX@#${PREFIX}#g" \
Peter Stugedad1e302008-11-22 17:13:36 +0000184 Makefile.in >> Makefile
185echo " done"
186echo