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 | # |
Peter Stuge | dad1e30 | 2008-11-22 17:13:36 +0000 | [diff] [blame] | 16 | |
| 17 | # 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] | 18 | # revision number of the checked out files. |
Peter Stuge | dad1e30 | 2008-11-22 17:13:36 +0000 | [diff] [blame] | 19 | VERSION="" |
| 20 | |
Peter Stuge | 279cdbb | 2009-01-26 04:10:12 +0000 | [diff] [blame] | 21 | REV="`svnversion -c . 2>/dev/null | sed 's,.*:,,' 2>/dev/null`" |
Peter Stuge | dad1e30 | 2008-11-22 17:13:36 +0000 | [diff] [blame] | 22 | VERSION="${VERSION:-$REV}" |
| 23 | |
Andriy Gapon | 7df17af | 2009-11-28 04:54:33 +0000 | [diff] [blame] | 24 | findprog() { |
Peter Stuge | 279cdbb | 2009-01-26 04:10:12 +0000 | [diff] [blame] | 25 | NPARMS=$# |
Peter Stuge | dad1e30 | 2008-11-22 17:13:36 +0000 | [diff] [blame] | 26 | WHAT="${1}" |
| 27 | shift |
| 28 | FROMENV="${1}" |
| 29 | shift |
Peter Stuge | 279cdbb | 2009-01-26 04:10:12 +0000 | [diff] [blame] | 30 | printf "searching for ${WHAT} (${*})..." 1>&2 |
Peter Stuge | dad1e30 | 2008-11-22 17:13:36 +0000 | [diff] [blame] | 31 | test -n "${FROMENV}" && { |
| 32 | echo " using environment: ${FROMENV}" 1>&2 |
| 33 | echo "${FROMENV}" |
| 34 | exit 0 |
| 35 | } |
Peter Stuge | 279cdbb | 2009-01-26 04:10:12 +0000 | [diff] [blame] | 36 | i=2 |
| 37 | while test $i -lt $NPARMS; do |
Peter Stuge | dad1e30 | 2008-11-22 17:13:36 +0000 | [diff] [blame] | 38 | test -z "${1}" && { |
| 39 | shift |
Andriy Gapon | 7df17af | 2009-11-28 04:54:33 +0000 | [diff] [blame] | 40 | i=$(($i+1)) |
Peter Stuge | dad1e30 | 2008-11-22 17:13:36 +0000 | [diff] [blame] | 41 | continue |
| 42 | } |
Peter Stuge | 279cdbb | 2009-01-26 04:10:12 +0000 | [diff] [blame] | 43 | FILE="`which "${1}" 2>/dev/null`" |
Peter Stuge | dad1e30 | 2008-11-22 17:13:36 +0000 | [diff] [blame] | 44 | test $? -eq 0 && { |
| 45 | echo "${1}" |
| 46 | break |
| 47 | } |
| 48 | shift |
Andriy Gapon | 7df17af | 2009-11-28 04:54:33 +0000 | [diff] [blame] | 49 | i=$(($i+1)) |
Peter Stuge | dad1e30 | 2008-11-22 17:13:36 +0000 | [diff] [blame] | 50 | done |
| 51 | test -z "${1}" && { |
| 52 | echo " not found!" 1>&2 |
| 53 | echo 1>&2 |
| 54 | echo "This is a fatal error, configure is exiting!" 1>&2 |
| 55 | exit 1 |
| 56 | } |
| 57 | echo " using ${FILE} in PATH" 1>&2 |
| 58 | exit 0 |
| 59 | } |
| 60 | |
Andriy Gapon | 7df17af | 2009-11-28 04:54:33 +0000 | [diff] [blame] | 61 | trycompile() { |
Peter Stuge | 279cdbb | 2009-01-26 04:10:12 +0000 | [diff] [blame] | 62 | NPARMS=$# |
Peter Stuge | dad1e30 | 2008-11-22 17:13:36 +0000 | [diff] [blame] | 63 | WHAT="${1}" |
| 64 | shift |
Peter Stuge | 279cdbb | 2009-01-26 04:10:12 +0000 | [diff] [blame] | 65 | printf "finding CFLAGS for ${WHAT}... " 1>&2 |
Peter Stuge | dad1e30 | 2008-11-22 17:13:36 +0000 | [diff] [blame] | 66 | OUT="${OUT}\n${CC} ${CFLAGS} -o .config.o -c .config.c" |
Peter Stuge | 279cdbb | 2009-01-26 04:10:12 +0000 | [diff] [blame] | 67 | 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] | 68 | test $? -eq 0 && { |
| 69 | echo " using: ${CFLAGS}" 1>&2 |
| 70 | echo "${CFLAGS}" |
| 71 | exit 0 |
| 72 | } |
Peter Stuge | 279cdbb | 2009-01-26 04:10:12 +0000 | [diff] [blame] | 73 | i=1 |
| 74 | while test $i -lt $NPARMS; do |
Peter Stuge | dad1e30 | 2008-11-22 17:13:36 +0000 | [diff] [blame] | 75 | 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] | 76 | 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] | 77 | test $? -eq 0 && { |
| 78 | echo " using: ${CFLAGS} ${1}" 1>&2 |
| 79 | echo "${CFLAGS} ${1}" |
| 80 | exit 0 |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 81 | } |
Peter Stuge | dad1e30 | 2008-11-22 17:13:36 +0000 | [diff] [blame] | 82 | shift |
Andriy Gapon | 7df17af | 2009-11-28 04:54:33 +0000 | [diff] [blame] | 83 | i=$(($i+1)) |
Peter Stuge | dad1e30 | 2008-11-22 17:13:36 +0000 | [diff] [blame] | 84 | done |
| 85 | echo "failed!" 1>&2 |
| 86 | echo 1>&2 |
Peter Stuge | 279cdbb | 2009-01-26 04:10:12 +0000 | [diff] [blame] | 87 | printf "The following compiler commands were executed:" 1>&2 |
Peter Stuge | dad1e30 | 2008-11-22 17:13:36 +0000 | [diff] [blame] | 88 | echo -e "${OUT}\n" 1>&2 |
| 89 | echo "This is a fatal error, configure is exiting!" 1>&2 |
| 90 | echo 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 |
Peter Stuge | 279cdbb | 2009-01-26 04:10:12 +0000 | [diff] [blame] | 93 | echo "CFLAGS=-I/opt/somedir/include ./configure" 1>&2 |
Peter Stuge | dad1e30 | 2008-11-22 17:13:36 +0000 | [diff] [blame] | 94 | echo 1>&2 |
| 95 | exit 1 |
| 96 | } |
| 97 | |
Peter Stuge | f30a2220 | 2009-11-28 05:30:57 +0000 | [diff] [blame] | 98 | trylink() { |
Peter Stuge | 279cdbb | 2009-01-26 04:10:12 +0000 | [diff] [blame] | 99 | NPARMS=$# |
Peter Stuge | dad1e30 | 2008-11-22 17:13:36 +0000 | [diff] [blame] | 100 | WHAT="${1}" |
| 101 | shift |
Peter Stuge | 279cdbb | 2009-01-26 04:10:12 +0000 | [diff] [blame] | 102 | printf "finding LDFLAGS for ${WHAT}... " 1>&2 |
Peter Stuge | dad1e30 | 2008-11-22 17:13:36 +0000 | [diff] [blame] | 103 | OUT="${OUT}\n${CC} -o .config .config.o ${LDFLAGS} 2>&1" |
Peter Stuge | 279cdbb | 2009-01-26 04:10:12 +0000 | [diff] [blame] | 104 | 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] | 105 | test $? -eq 0 && { |
| 106 | echo " using: ${LDFLAGS}" 1>&2 |
| 107 | echo "${LDFLAGS}" |
| 108 | exit 0 |
| 109 | } |
Peter Stuge | 279cdbb | 2009-01-26 04:10:12 +0000 | [diff] [blame] | 110 | i=1 |
| 111 | while test $i -lt $NPARMS; do |
Peter Stuge | dad1e30 | 2008-11-22 17:13:36 +0000 | [diff] [blame] | 112 | OUT="${OUT}\n${CC} -o .config .config.o ${LDFLAGS} ${1} 2>&1" |
Peter Stuge | 279cdbb | 2009-01-26 04:10:12 +0000 | [diff] [blame] | 113 | 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] | 114 | test $? -eq 0 && { |
| 115 | echo " using: ${LDFLAGS} ${1}" 1>&2 |
| 116 | echo "${LDFLAGS} ${1}" |
| 117 | exit 0 |
| 118 | } |
| 119 | shift |
Andriy Gapon | 7df17af | 2009-11-28 04:54:33 +0000 | [diff] [blame] | 120 | i=$(($i+1)) |
Peter Stuge | dad1e30 | 2008-11-22 17:13:36 +0000 | [diff] [blame] | 121 | done |
| 122 | echo "failed!" 1>&2 |
| 123 | echo 1>&2 |
Peter Stuge | 279cdbb | 2009-01-26 04:10:12 +0000 | [diff] [blame] | 124 | printf "The following linker commands were executed:" 1>&2 |
Peter Stuge | dad1e30 | 2008-11-22 17:13:36 +0000 | [diff] [blame] | 125 | echo -e "${OUT}\n" 1>&2 |
| 126 | echo "This is a fatal error, configure is exiting!" 1>&2 |
| 127 | echo 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 |
Peter Stuge | 279cdbb | 2009-01-26 04:10:12 +0000 | [diff] [blame] | 130 | echo "LDFLAGS=-L/opt/somedir/lib ./configure" 1>&2 |
Peter Stuge | dad1e30 | 2008-11-22 17:13:36 +0000 | [diff] [blame] | 131 | echo 1>&2 |
| 132 | exit 1 |
| 133 | } |
| 134 | |
Peter Stuge | 279cdbb | 2009-01-26 04:10:12 +0000 | [diff] [blame] | 135 | CC=`findprog "compiler" "${CC}" gcc cc icc` || exit |
| 136 | INSTALL=`findprog "install" "${INSTALL}" install ginstall` || exit |
Peter Stuge | dad1e30 | 2008-11-22 17:13:36 +0000 | [diff] [blame] | 137 | |
| 138 | test -n "$DEBUG" && myCFLAGS="-O2 -g" || myCFLAGS="-Os" |
| 139 | CFLAGS="${CFLAGS} ${myCFLAGS} -Wall -Werror" |
| 140 | |
Peter Stuge | 0924dee | 2008-11-25 02:03:16 +0000 | [diff] [blame] | 141 | cat > .config.c << EOF |
| 142 | #include <pci/pci.h> |
| 143 | struct pci_access *pacc; |
| 144 | int main(int argc, char *argv[]) |
| 145 | { pacc = pci_alloc(); return 0; } |
| 146 | EOF |
| 147 | |
Peter Stuge | 279cdbb | 2009-01-26 04:10:12 +0000 | [diff] [blame] | 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"` || { |
Peter Stuge | 0924dee | 2008-11-25 02:03:16 +0000 | [diff] [blame] | 151 | rm -f .config.c |
| 152 | exit 1 |
| 153 | } |
Stefan Reinauer | 9018b6e | 2011-03-14 09:08:27 +0000 | [diff] [blame] | 154 | LDFLAGS=`trylink "libpci (from pciutils)" "${pc_LDFLAGS}" "-lpci -lz" "-L/usr/local/lib -lpci -lz" "-framework DirectHW -lpci -lz"` || { |
Peter Stuge | 0924dee | 2008-11-25 02:03:16 +0000 | [diff] [blame] | 155 | rm -f .config.c .config.o |
| 156 | exit 1 |
| 157 | } |
| 158 | rm -f .config.c .config.o .config |
| 159 | |
Peter Stuge | dad1e30 | 2008-11-22 17:13:36 +0000 | [diff] [blame] | 160 | PREFIX="${PREFIX:-/usr/local}" |
| 161 | |
Peter Stuge | dad1e30 | 2008-11-22 17:13:36 +0000 | [diff] [blame] | 162 | echo |
| 163 | echo "configured using the following settings:" |
| 164 | echo |
| 165 | echo "VERSION=${VERSION}" |
| 166 | echo "CC=${CC}" |
| 167 | echo "CFLAGS=${CFLAGS}" |
| 168 | echo "LDFLAGS=${LDFLAGS}" |
| 169 | echo "INSTALL=${INSTALL}" |
| 170 | echo "PREFIX=${PREFIX}" |
| 171 | echo |
Peter Stuge | 279cdbb | 2009-01-26 04:10:12 +0000 | [diff] [blame] | 172 | printf "creating Makefile..." |
Peter Stuge | dad1e30 | 2008-11-22 17:13:36 +0000 | [diff] [blame] | 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" \ |
Peter Stuge | be89c41 | 2009-11-28 04:45:34 +0000 | [diff] [blame] | 179 | -e "s#@PREFIX@#${PREFIX}#g" \ |
Peter Stuge | dad1e30 | 2008-11-22 17:13:36 +0000 | [diff] [blame] | 180 | Makefile.in >> Makefile |
| 181 | echo " done" |
| 182 | echo |