configure
1 #!/usr/bin/env sh 2 # 3 # 4 # This program is free software; you can redistribute it and/or modify 5 # it under the terms of the GNU General Public License version 2 as 6 # published by the Free Software Foundation. 7 # 8 # This program is distributed in the hope that it will be useful, 9 # but WITHOUT ANY WARRANTY; without even the implied warranty of 10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 # GNU General Public License for more details. 12 # 13 14 # If this is left unset, try to set the version string from the highest 15 # revision number of the checked out files. 16 VERSION="" 17 18 REV="`git describe --always 2>/dev/null`" 19 VERSION="${VERSION:-$REV}" 20 21 findprog() { 22 NPARMS=$# 23 WHAT="${1}" 24 shift 25 FROMENV="${1}" 26 shift 27 printf "searching for ${WHAT} (${*})..." 1>&2 28 test -n "${FROMENV}" && { 29 echo " using environment: ${FROMENV}" 1>&2 30 echo "${FROMENV}" 31 exit 0 32 } 33 i=2 34 while test $i -lt $NPARMS; do 35 test -z "${1}" && { 36 shift 37 i=$(($i+1)) 38 continue 39 } 40 FILE="`which "${1}" 2>/dev/null`" 41 test $? -eq 0 && { 42 echo "${1}" 43 break 44 } 45 shift 46 i=$(($i+1)) 47 done 48 test -z "${1}" && { 49 echo " not found!" 1>&2 50 echo 1>&2 51 echo "This is a fatal error, configure is exiting!" 1>&2 52 exit 1 53 } 54 echo " using ${FILE} in PATH" 1>&2 55 exit 0 56 } 57 58 trycompile() { 59 NPARMS=$# 60 WHAT="${1}" 61 shift 62 printf "finding CFLAGS for ${WHAT}... " 1>&2 63 OUT="${OUT}\n${CC} ${CFLAGS} -o .config.o -c .config.c" 64 OUT="${OUT}\n`echo "${CC} ${CFLAGS} -o .config.o -c .config.c"|sh 2>&1`" 65 test $? -eq 0 && { 66 echo " using: ${CFLAGS}" 1>&2 67 echo "${CFLAGS}" 68 exit 0 69 } 70 i=1 71 while test $i -lt $NPARMS; do 72 OUT="${OUT}\n${CC} ${CFLAGS} ${1} -o .config.o -c .config.c 2>&1" 73 OUT="${OUT}\n`echo "${CC} ${CFLAGS} ${1} -o .config.o -c .config.c"|sh 2>&1`" 74 test $? -eq 0 && { 75 echo " using: ${CFLAGS} ${1}" 1>&2 76 echo "${CFLAGS} ${1}" 77 exit 0 78 } 79 shift 80 i=$(($i+1)) 81 done 82 echo "failed!" 1>&2 83 echo 1>&2 84 printf "The following compiler commands were executed:" 1>&2 85 echo -e "${OUT}\n" 1>&2 86 echo "This is a fatal error, configure is exiting!" 1>&2 87 echo 1>&2 88 echo "You can try to fix this by manually setting CFLAGS in the environment before" 1>&2 89 echo "running configure. E.g.:" 1>&2 90 echo "CFLAGS=-I/opt/somedir/include ./configure" 1>&2 91 echo 1>&2 92 exit 1 93 } 94 95 trylink() { 96 NPARMS=$# 97 WHAT="${1}" 98 shift 99 printf "finding LDFLAGS for ${WHAT}... " 1>&2 100 OUT="${OUT}\n${CC} -o .config .config.o ${LDFLAGS} 2>&1" 101 OUT="${OUT}\n`echo "${CC} -o .config .config.o ${LDFLAGS}"|sh 2>&1`" 102 test $? -eq 0 && { 103 echo " using: ${LDFLAGS}" 1>&2 104 echo "${LDFLAGS}" 105 exit 0 106 } 107 i=1 108 while test $i -lt $NPARMS; do 109 OUT="${OUT}\n${CC} -o .config .config.o ${LDFLAGS} ${1} 2>&1" 110 OUT="${OUT}\n`echo "${CC} -o .config .config.o ${LDFLAGS} ${1}"|sh 2>&1`" 111 test $? -eq 0 && { 112 echo " using: ${LDFLAGS} ${1}" 1>&2 113 echo "${LDFLAGS} ${1}" 114 exit 0 115 } 116 shift 117 i=$(($i+1)) 118 done 119 echo "failed!" 1>&2 120 echo 1>&2 121 printf "The following linker commands were executed:" 1>&2 122 echo -e "${OUT}\n" 1>&2 123 echo "This is a fatal error, configure is exiting!" 1>&2 124 echo 1>&2 125 echo "You can try to fix this by manually setting LDFLAGS in the environment before" 1>&2 126 echo "running configure. E.g.:" 1>&2 127 echo "LDFLAGS=-L/opt/somedir/lib ./configure" 1>&2 128 echo 1>&2 129 exit 1 130 } 131 132 CC=`findprog "compiler" "${CC}" clang gcc cc icc` || exit 133 INSTALL=`findprog "install" "${INSTALL}" install ginstall` || exit 134 135 test -n "$DEBUG" && myCFLAGS="-O2 -g" || myCFLAGS="-Os" 136 CFLAGS="${CFLAGS} ${myCFLAGS} -Wall -Werror" 137 138 cat > .config.c << EOF 139 #include <pci/pci.h> 140 struct pci_access *pacc; 141 int main(int argc, char *argv[]) 142 { pacc = pci_alloc(); return 0; } 143 EOF 144 145 pc_CFLAGS="`pkg-config libpci --cflags 2>/dev/null`" 146 pc_LDFLAGS="`pkg-config libpci --libs 2>/dev/null`" 147 CFLAGS=`trycompile "libpci (from pciutils)" "${pc_CFLAGS}" "-I/usr/local/include"` || { 148 rm -f .config.c 149 exit 1 150 } 151 LDFLAGS=`trylink "libpci (from pciutils)" "${pc_LDFLAGS}" "-lpci -lz" "-L/usr/local/lib -lpci -lz" "-framework DirectHW -lpci -lz"` || { 152 rm -f .config.c .config.o 153 exit 1 154 } 155 rm -f .config.c .config.o .config 156 157 PREFIX="${PREFIX:-/usr/local}" 158 159 echo 160 echo "configured using the following settings:" 161 echo 162 echo "VERSION=${VERSION}" 163 echo "CC=${CC}" 164 echo "CFLAGS=${CFLAGS}" 165 echo "LDFLAGS=${LDFLAGS}" 166 echo "INSTALL=${INSTALL}" 167 echo "PREFIX=${PREFIX}" 168 echo 169 printf "creating Makefile..." 170 echo "# This file was automatically generated by configure" > Makefile 171 sed -e "s#@VERSION@#${VERSION}#g" \ 172 -e "s#@CC@#${CC}#g" \ 173 -e "s#@CFLAGS@#${CFLAGS}#g" \ 174 -e "s#@LDFLAGS@#${LDFLAGS}#g" \ 175 -e "s#@INSTALL@#${INSTALL}#g" \ 176 -e "s#@PREFIX@#${PREFIX}#g" \ 177 Makefile.in >> Makefile 178 echo " done" 179 echo