Andriy Gapon | 7df17af | 2009-11-28 04:54:33 +0000 | [diff] [blame] | 1 | #!/bin/sh |
Peter Stuge | dad1e30 | 2008-11-22 17:13:36 +0000 | [diff] [blame] | 2 | # |
| 3 | # This file is part of msrtool. |
| 4 | # |
Peter Stuge | be89c41 | 2009-11-28 04:45:34 +0000 | [diff] [blame] | 5 | # Copyright (c) 2008, 2009 Peter Stuge <peter@stuge.se> |
Peter Stuge | dad1e30 | 2008-11-22 17:13:36 +0000 | [diff] [blame] | 6 | # |
| 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 |
| 18 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 19 | # |
| 20 | |
| 21 | # If this is left unset, try to set the version string from the highest |
Peter Stuge | 279cdbb | 2009-01-26 04:10:12 +0000 | [diff] [blame] | 22 | # revision number of the checked out files. |
Peter Stuge | dad1e30 | 2008-11-22 17:13:36 +0000 | [diff] [blame] | 23 | VERSION="" |
| 24 | |
Peter Stuge | 279cdbb | 2009-01-26 04:10:12 +0000 | [diff] [blame] | 25 | REV="`svnversion -c . 2>/dev/null | sed 's,.*:,,' 2>/dev/null`" |
Peter Stuge | dad1e30 | 2008-11-22 17:13:36 +0000 | [diff] [blame] | 26 | VERSION="${VERSION:-$REV}" |
| 27 | |
Andriy Gapon | 7df17af | 2009-11-28 04:54:33 +0000 | [diff] [blame] | 28 | findprog() { |
Peter Stuge | 279cdbb | 2009-01-26 04:10:12 +0000 | [diff] [blame] | 29 | NPARMS=$# |
Peter Stuge | dad1e30 | 2008-11-22 17:13:36 +0000 | [diff] [blame] | 30 | WHAT="${1}" |
| 31 | shift |
| 32 | FROMENV="${1}" |
| 33 | shift |
Peter Stuge | 279cdbb | 2009-01-26 04:10:12 +0000 | [diff] [blame] | 34 | printf "searching for ${WHAT} (${*})..." 1>&2 |
Peter Stuge | dad1e30 | 2008-11-22 17:13:36 +0000 | [diff] [blame] | 35 | test -n "${FROMENV}" && { |
| 36 | echo " using environment: ${FROMENV}" 1>&2 |
| 37 | echo "${FROMENV}" |
| 38 | exit 0 |
| 39 | } |
Peter Stuge | 279cdbb | 2009-01-26 04:10:12 +0000 | [diff] [blame] | 40 | i=2 |
| 41 | while test $i -lt $NPARMS; do |
Peter Stuge | dad1e30 | 2008-11-22 17:13:36 +0000 | [diff] [blame] | 42 | test -z "${1}" && { |
| 43 | shift |
Andriy Gapon | 7df17af | 2009-11-28 04:54:33 +0000 | [diff] [blame] | 44 | i=$(($i+1)) |
Peter Stuge | dad1e30 | 2008-11-22 17:13:36 +0000 | [diff] [blame] | 45 | continue |
| 46 | } |
Peter Stuge | 279cdbb | 2009-01-26 04:10:12 +0000 | [diff] [blame] | 47 | FILE="`which "${1}" 2>/dev/null`" |
Peter Stuge | dad1e30 | 2008-11-22 17:13:36 +0000 | [diff] [blame] | 48 | test $? -eq 0 && { |
| 49 | echo "${1}" |
| 50 | break |
| 51 | } |
| 52 | shift |
Andriy Gapon | 7df17af | 2009-11-28 04:54:33 +0000 | [diff] [blame] | 53 | i=$(($i+1)) |
Peter Stuge | dad1e30 | 2008-11-22 17:13:36 +0000 | [diff] [blame] | 54 | 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 Gapon | 7df17af | 2009-11-28 04:54:33 +0000 | [diff] [blame] | 65 | trycompile() { |
Peter Stuge | 279cdbb | 2009-01-26 04:10:12 +0000 | [diff] [blame] | 66 | NPARMS=$# |
Peter Stuge | dad1e30 | 2008-11-22 17:13:36 +0000 | [diff] [blame] | 67 | WHAT="${1}" |
| 68 | shift |
Peter Stuge | 279cdbb | 2009-01-26 04:10:12 +0000 | [diff] [blame] | 69 | printf "finding CFLAGS for ${WHAT}... " 1>&2 |
Peter Stuge | dad1e30 | 2008-11-22 17:13:36 +0000 | [diff] [blame] | 70 | OUT="${OUT}\n${CC} ${CFLAGS} -o .config.o -c .config.c" |
Peter Stuge | 279cdbb | 2009-01-26 04:10:12 +0000 | [diff] [blame] | 71 | OUT="${OUT}\n`echo "${CC} ${CFLAGS} -o .config.o -c .config.c"|sh 2>&1`" |
Peter Stuge | dad1e30 | 2008-11-22 17:13:36 +0000 | [diff] [blame] | 72 | test $? -eq 0 && { |
| 73 | echo " using: ${CFLAGS}" 1>&2 |
| 74 | echo "${CFLAGS}" |
| 75 | exit 0 |
| 76 | } |
Peter Stuge | 279cdbb | 2009-01-26 04:10:12 +0000 | [diff] [blame] | 77 | i=1 |
| 78 | while test $i -lt $NPARMS; do |
Peter Stuge | dad1e30 | 2008-11-22 17:13:36 +0000 | [diff] [blame] | 79 | OUT="${OUT}\n${CC} ${CFLAGS} ${1} -o .config.o -c .config.c 2>&1" |
Peter Stuge | 279cdbb | 2009-01-26 04:10:12 +0000 | [diff] [blame] | 80 | OUT="${OUT}\n`echo "${CC} ${CFLAGS} ${1} -o .config.o -c .config.c"|sh 2>&1`" |
Peter Stuge | dad1e30 | 2008-11-22 17:13:36 +0000 | [diff] [blame] | 81 | test $? -eq 0 && { |
| 82 | echo " using: ${CFLAGS} ${1}" 1>&2 |
| 83 | echo "${CFLAGS} ${1}" |
| 84 | exit 0 |
| 85 | } |
| 86 | shift |
Andriy Gapon | 7df17af | 2009-11-28 04:54:33 +0000 | [diff] [blame] | 87 | i=$(($i+1)) |
Peter Stuge | dad1e30 | 2008-11-22 17:13:36 +0000 | [diff] [blame] | 88 | done |
| 89 | echo "failed!" 1>&2 |
| 90 | echo 1>&2 |
Peter Stuge | 279cdbb | 2009-01-26 04:10:12 +0000 | [diff] [blame] | 91 | printf "The following compiler commands were executed:" 1>&2 |
Peter Stuge | dad1e30 | 2008-11-22 17:13:36 +0000 | [diff] [blame] | 92 | 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 Stuge | 279cdbb | 2009-01-26 04:10:12 +0000 | [diff] [blame] | 97 | echo "CFLAGS=-I/opt/somedir/include ./configure" 1>&2 |
Peter Stuge | dad1e30 | 2008-11-22 17:13:36 +0000 | [diff] [blame] | 98 | echo 1>&2 |
| 99 | exit 1 |
| 100 | } |
| 101 | |
Peter Stuge | f30a2220 | 2009-11-28 05:30:57 +0000 | [diff] [blame] | 102 | trylink() { |
Peter Stuge | 279cdbb | 2009-01-26 04:10:12 +0000 | [diff] [blame] | 103 | NPARMS=$# |
Peter Stuge | dad1e30 | 2008-11-22 17:13:36 +0000 | [diff] [blame] | 104 | WHAT="${1}" |
| 105 | shift |
Peter Stuge | 279cdbb | 2009-01-26 04:10:12 +0000 | [diff] [blame] | 106 | printf "finding LDFLAGS for ${WHAT}... " 1>&2 |
Peter Stuge | dad1e30 | 2008-11-22 17:13:36 +0000 | [diff] [blame] | 107 | OUT="${OUT}\n${CC} -o .config .config.o ${LDFLAGS} 2>&1" |
Peter Stuge | 279cdbb | 2009-01-26 04:10:12 +0000 | [diff] [blame] | 108 | OUT="${OUT}\n`echo "${CC} -o .config .config.o ${LDFLAGS}"|sh 2>&1`" |
Peter Stuge | dad1e30 | 2008-11-22 17:13:36 +0000 | [diff] [blame] | 109 | test $? -eq 0 && { |
| 110 | echo " using: ${LDFLAGS}" 1>&2 |
| 111 | echo "${LDFLAGS}" |
| 112 | exit 0 |
| 113 | } |
Peter Stuge | 279cdbb | 2009-01-26 04:10:12 +0000 | [diff] [blame] | 114 | i=1 |
| 115 | while test $i -lt $NPARMS; do |
Peter Stuge | dad1e30 | 2008-11-22 17:13:36 +0000 | [diff] [blame] | 116 | OUT="${OUT}\n${CC} -o .config .config.o ${LDFLAGS} ${1} 2>&1" |
Peter Stuge | 279cdbb | 2009-01-26 04:10:12 +0000 | [diff] [blame] | 117 | OUT="${OUT}\n`echo "${CC} -o .config .config.o ${LDFLAGS} ${1}"|sh 2>&1`" |
Peter Stuge | dad1e30 | 2008-11-22 17:13:36 +0000 | [diff] [blame] | 118 | test $? -eq 0 && { |
| 119 | echo " using: ${LDFLAGS} ${1}" 1>&2 |
| 120 | echo "${LDFLAGS} ${1}" |
| 121 | exit 0 |
| 122 | } |
| 123 | shift |
Andriy Gapon | 7df17af | 2009-11-28 04:54:33 +0000 | [diff] [blame] | 124 | i=$(($i+1)) |
Peter Stuge | dad1e30 | 2008-11-22 17:13:36 +0000 | [diff] [blame] | 125 | done |
| 126 | echo "failed!" 1>&2 |
| 127 | echo 1>&2 |
Peter Stuge | 279cdbb | 2009-01-26 04:10:12 +0000 | [diff] [blame] | 128 | printf "The following linker commands were executed:" 1>&2 |
Peter Stuge | dad1e30 | 2008-11-22 17:13:36 +0000 | [diff] [blame] | 129 | 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 Stuge | 279cdbb | 2009-01-26 04:10:12 +0000 | [diff] [blame] | 134 | echo "LDFLAGS=-L/opt/somedir/lib ./configure" 1>&2 |
Peter Stuge | dad1e30 | 2008-11-22 17:13:36 +0000 | [diff] [blame] | 135 | echo 1>&2 |
| 136 | exit 1 |
| 137 | } |
| 138 | |
Peter Stuge | 279cdbb | 2009-01-26 04:10:12 +0000 | [diff] [blame] | 139 | CC=`findprog "compiler" "${CC}" gcc cc icc` || exit |
| 140 | INSTALL=`findprog "install" "${INSTALL}" install ginstall` || exit |
Peter Stuge | dad1e30 | 2008-11-22 17:13:36 +0000 | [diff] [blame] | 141 | |
| 142 | test -n "$DEBUG" && myCFLAGS="-O2 -g" || myCFLAGS="-Os" |
| 143 | CFLAGS="${CFLAGS} ${myCFLAGS} -Wall -Werror" |
| 144 | |
Peter Stuge | 0924dee | 2008-11-25 02:03:16 +0000 | [diff] [blame] | 145 | cat > .config.c << EOF |
| 146 | #include <pci/pci.h> |
| 147 | struct pci_access *pacc; |
| 148 | int main(int argc, char *argv[]) |
| 149 | { pacc = pci_alloc(); return 0; } |
| 150 | EOF |
| 151 | |
Peter Stuge | 279cdbb | 2009-01-26 04:10:12 +0000 | [diff] [blame] | 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"` || { |
Peter Stuge | 0924dee | 2008-11-25 02:03:16 +0000 | [diff] [blame] | 155 | rm -f .config.c |
| 156 | exit 1 |
| 157 | } |
Stefan Reinauer | 37f3935 | 2009-09-01 10:03:01 +0000 | [diff] [blame] | 158 | LDFLAGS=`trylink "libpci (from pciutils)" "${pc_LDFLAGS}" "-lpci -lz" "-L/usr/local/lib -lpci -lz" "-framework DirectIO -lpci -lz"` || { |
Peter Stuge | 0924dee | 2008-11-25 02:03:16 +0000 | [diff] [blame] | 159 | rm -f .config.c .config.o |
| 160 | exit 1 |
| 161 | } |
| 162 | rm -f .config.c .config.o .config |
| 163 | |
Peter Stuge | dad1e30 | 2008-11-22 17:13:36 +0000 | [diff] [blame] | 164 | PREFIX="${PREFIX:-/usr/local}" |
| 165 | |
Peter Stuge | dad1e30 | 2008-11-22 17:13:36 +0000 | [diff] [blame] | 166 | echo |
| 167 | echo "configured using the following settings:" |
| 168 | echo |
| 169 | echo "VERSION=${VERSION}" |
| 170 | echo "CC=${CC}" |
| 171 | echo "CFLAGS=${CFLAGS}" |
| 172 | echo "LDFLAGS=${LDFLAGS}" |
| 173 | echo "INSTALL=${INSTALL}" |
| 174 | echo "PREFIX=${PREFIX}" |
| 175 | echo |
Peter Stuge | 279cdbb | 2009-01-26 04:10:12 +0000 | [diff] [blame] | 176 | printf "creating Makefile..." |
Peter Stuge | dad1e30 | 2008-11-22 17:13:36 +0000 | [diff] [blame] | 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" \ |
Peter Stuge | be89c41 | 2009-11-28 04:45:34 +0000 | [diff] [blame] | 183 | -e "s#@PREFIX@#${PREFIX}#g" \ |
Peter Stuge | dad1e30 | 2008-11-22 17:13:36 +0000 | [diff] [blame] | 184 | Makefile.in >> Makefile |
| 185 | echo " done" |
| 186 | echo |