blob: 659cbcd66b5c208f1fd2ace590f0d512c02dad5b [file] [log] [blame]
Martin Roth0ad5fbd2020-12-24 12:06:38 -07001#!/usr/bin/env sh
Peter Stugedad1e302008-11-22 17:13:36 +00002#
Peter Stugedad1e302008-11-22 17:13:36 +00003#
Peter Stugedad1e302008-11-22 17:13:36 +00004# 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#
Peter Stugedad1e302008-11-22 17:13:36 +000013
14# If this is left unset, try to set the version string from the highest
Peter Stuge279cdbb2009-01-26 04:10:12 +000015# revision number of the checked out files.
Peter Stugedad1e302008-11-22 17:13:36 +000016VERSION=""
17
Iru Cai69bbfac2015-12-12 01:00:57 +080018REV="`git describe --always 2>/dev/null`"
Peter Stugedad1e302008-11-22 17:13:36 +000019VERSION="${VERSION:-$REV}"
20
Andriy Gapon7df17af2009-11-28 04:54:33 +000021findprog() {
Peter Stuge279cdbb2009-01-26 04:10:12 +000022 NPARMS=$#
Peter Stugedad1e302008-11-22 17:13:36 +000023 WHAT="${1}"
24 shift
25 FROMENV="${1}"
26 shift
Peter Stuge279cdbb2009-01-26 04:10:12 +000027 printf "searching for ${WHAT} (${*})..." 1>&2
Peter Stugedad1e302008-11-22 17:13:36 +000028 test -n "${FROMENV}" && {
29 echo " using environment: ${FROMENV}" 1>&2
30 echo "${FROMENV}"
31 exit 0
32 }
Peter Stuge279cdbb2009-01-26 04:10:12 +000033 i=2
34 while test $i -lt $NPARMS; do
Peter Stugedad1e302008-11-22 17:13:36 +000035 test -z "${1}" && {
36 shift
Andriy Gapon7df17af2009-11-28 04:54:33 +000037 i=$(($i+1))
Peter Stugedad1e302008-11-22 17:13:36 +000038 continue
39 }
Peter Stuge279cdbb2009-01-26 04:10:12 +000040 FILE="`which "${1}" 2>/dev/null`"
Peter Stugedad1e302008-11-22 17:13:36 +000041 test $? -eq 0 && {
42 echo "${1}"
43 break
44 }
45 shift
Andriy Gapon7df17af2009-11-28 04:54:33 +000046 i=$(($i+1))
Peter Stugedad1e302008-11-22 17:13:36 +000047 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
Andriy Gapon7df17af2009-11-28 04:54:33 +000058trycompile() {
Peter Stuge279cdbb2009-01-26 04:10:12 +000059 NPARMS=$#
Peter Stugedad1e302008-11-22 17:13:36 +000060 WHAT="${1}"
61 shift
Peter Stuge279cdbb2009-01-26 04:10:12 +000062 printf "finding CFLAGS for ${WHAT}... " 1>&2
Peter Stugedad1e302008-11-22 17:13:36 +000063 OUT="${OUT}\n${CC} ${CFLAGS} -o .config.o -c .config.c"
Peter Stuge279cdbb2009-01-26 04:10:12 +000064 OUT="${OUT}\n`echo "${CC} ${CFLAGS} -o .config.o -c .config.c"|sh 2>&1`"
Peter Stugedad1e302008-11-22 17:13:36 +000065 test $? -eq 0 && {
66 echo " using: ${CFLAGS}" 1>&2
67 echo "${CFLAGS}"
68 exit 0
69 }
Peter Stuge279cdbb2009-01-26 04:10:12 +000070 i=1
71 while test $i -lt $NPARMS; do
Peter Stugedad1e302008-11-22 17:13:36 +000072 OUT="${OUT}\n${CC} ${CFLAGS} ${1} -o .config.o -c .config.c 2>&1"
Peter Stuge279cdbb2009-01-26 04:10:12 +000073 OUT="${OUT}\n`echo "${CC} ${CFLAGS} ${1} -o .config.o -c .config.c"|sh 2>&1`"
Peter Stugedad1e302008-11-22 17:13:36 +000074 test $? -eq 0 && {
75 echo " using: ${CFLAGS} ${1}" 1>&2
76 echo "${CFLAGS} ${1}"
77 exit 0
Stefan Reinauer14e22772010-04-27 06:56:47 +000078 }
Peter Stugedad1e302008-11-22 17:13:36 +000079 shift
Andriy Gapon7df17af2009-11-28 04:54:33 +000080 i=$(($i+1))
Peter Stugedad1e302008-11-22 17:13:36 +000081 done
82 echo "failed!" 1>&2
83 echo 1>&2
Peter Stuge279cdbb2009-01-26 04:10:12 +000084 printf "The following compiler commands were executed:" 1>&2
Peter Stugedad1e302008-11-22 17:13:36 +000085 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
Peter Stuge279cdbb2009-01-26 04:10:12 +000090 echo "CFLAGS=-I/opt/somedir/include ./configure" 1>&2
Peter Stugedad1e302008-11-22 17:13:36 +000091 echo 1>&2
92 exit 1
93}
94
Peter Stugef30a22202009-11-28 05:30:57 +000095trylink() {
Peter Stuge279cdbb2009-01-26 04:10:12 +000096 NPARMS=$#
Peter Stugedad1e302008-11-22 17:13:36 +000097 WHAT="${1}"
98 shift
Peter Stuge279cdbb2009-01-26 04:10:12 +000099 printf "finding LDFLAGS for ${WHAT}... " 1>&2
Peter Stugedad1e302008-11-22 17:13:36 +0000100 OUT="${OUT}\n${CC} -o .config .config.o ${LDFLAGS} 2>&1"
Peter Stuge279cdbb2009-01-26 04:10:12 +0000101 OUT="${OUT}\n`echo "${CC} -o .config .config.o ${LDFLAGS}"|sh 2>&1`"
Peter Stugedad1e302008-11-22 17:13:36 +0000102 test $? -eq 0 && {
103 echo " using: ${LDFLAGS}" 1>&2
104 echo "${LDFLAGS}"
105 exit 0
106 }
Peter Stuge279cdbb2009-01-26 04:10:12 +0000107 i=1
108 while test $i -lt $NPARMS; do
Peter Stugedad1e302008-11-22 17:13:36 +0000109 OUT="${OUT}\n${CC} -o .config .config.o ${LDFLAGS} ${1} 2>&1"
Peter Stuge279cdbb2009-01-26 04:10:12 +0000110 OUT="${OUT}\n`echo "${CC} -o .config .config.o ${LDFLAGS} ${1}"|sh 2>&1`"
Peter Stugedad1e302008-11-22 17:13:36 +0000111 test $? -eq 0 && {
112 echo " using: ${LDFLAGS} ${1}" 1>&2
113 echo "${LDFLAGS} ${1}"
114 exit 0
115 }
116 shift
Andriy Gapon7df17af2009-11-28 04:54:33 +0000117 i=$(($i+1))
Peter Stugedad1e302008-11-22 17:13:36 +0000118 done
119 echo "failed!" 1>&2
120 echo 1>&2
Peter Stuge279cdbb2009-01-26 04:10:12 +0000121 printf "The following linker commands were executed:" 1>&2
Peter Stugedad1e302008-11-22 17:13:36 +0000122 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
Peter Stuge279cdbb2009-01-26 04:10:12 +0000127 echo "LDFLAGS=-L/opt/somedir/lib ./configure" 1>&2
Peter Stugedad1e302008-11-22 17:13:36 +0000128 echo 1>&2
129 exit 1
130}
131
Idwer Vollering68bcc082021-01-18 16:26:50 +0100132CC=`findprog "compiler" "${CC}" clang gcc cc icc` || exit
Peter Stuge279cdbb2009-01-26 04:10:12 +0000133INSTALL=`findprog "install" "${INSTALL}" install ginstall` || exit
Peter Stugedad1e302008-11-22 17:13:36 +0000134
135test -n "$DEBUG" && myCFLAGS="-O2 -g" || myCFLAGS="-Os"
136CFLAGS="${CFLAGS} ${myCFLAGS} -Wall -Werror"
137
Peter Stuge0924dee2008-11-25 02:03:16 +0000138cat > .config.c << EOF
139#include <pci/pci.h>
140struct pci_access *pacc;
141int main(int argc, char *argv[])
142{ pacc = pci_alloc(); return 0; }
143EOF
144
Peter Stuge279cdbb2009-01-26 04:10:12 +0000145pc_CFLAGS="`pkg-config libpci --cflags 2>/dev/null`"
146pc_LDFLAGS="`pkg-config libpci --libs 2>/dev/null`"
147CFLAGS=`trycompile "libpci (from pciutils)" "${pc_CFLAGS}" "-I/usr/local/include"` || {
Peter Stuge0924dee2008-11-25 02:03:16 +0000148 rm -f .config.c
149 exit 1
150}
Stefan Reinauer9018b6e2011-03-14 09:08:27 +0000151LDFLAGS=`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 +0000152 rm -f .config.c .config.o
153 exit 1
154}
155rm -f .config.c .config.o .config
156
Peter Stugedad1e302008-11-22 17:13:36 +0000157PREFIX="${PREFIX:-/usr/local}"
158
Peter Stugedad1e302008-11-22 17:13:36 +0000159echo
160echo "configured using the following settings:"
161echo
162echo "VERSION=${VERSION}"
163echo "CC=${CC}"
164echo "CFLAGS=${CFLAGS}"
165echo "LDFLAGS=${LDFLAGS}"
166echo "INSTALL=${INSTALL}"
167echo "PREFIX=${PREFIX}"
168echo
Peter Stuge279cdbb2009-01-26 04:10:12 +0000169printf "creating Makefile..."
Peter Stugedad1e302008-11-22 17:13:36 +0000170echo "# This file was automatically generated by configure" > Makefile
171sed -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" \
Peter Stugebe89c412009-11-28 04:45:34 +0000176 -e "s#@PREFIX@#${PREFIX}#g" \
Peter Stugedad1e302008-11-22 17:13:36 +0000177 Makefile.in >> Makefile
178echo " done"
179echo