google/butterfly: add cpu/gpu pwm backlight register values
[coreboot.git] / util / msrtool / configure
blob0606f4b8b984bad9a70f7bfc921779e4d57e3105
1 #!/bin/sh
3 # This file is part of msrtool.
5 # Copyright (c) 2008, 2009 Peter Stuge <peter@stuge.se>
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.
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.
17 # If this is left unset, try to set the version string from the highest
18 # revision number of the checked out files.
19 VERSION=""
21 REV="`git describe --always 2>/dev/null`"
22 VERSION="${VERSION:-$REV}"
24 findprog() {
25 NPARMS=$#
26 WHAT="${1}"
27 shift
28 FROMENV="${1}"
29 shift
30 printf "searching for ${WHAT} (${*})..." 1>&2
31 test -n "${FROMENV}" && {
32 echo " using environment: ${FROMENV}" 1>&2
33 echo "${FROMENV}"
34 exit 0
36 i=2
37 while test $i -lt $NPARMS; do
38 test -z "${1}" && {
39 shift
40 i=$(($i+1))
41 continue
43 FILE="`which "${1}" 2>/dev/null`"
44 test $? -eq 0 && {
45 echo "${1}"
46 break
48 shift
49 i=$(($i+1))
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
57 echo " using ${FILE} in PATH" 1>&2
58 exit 0
61 trycompile() {
62 NPARMS=$#
63 WHAT="${1}"
64 shift
65 printf "finding CFLAGS for ${WHAT}... " 1>&2
66 OUT="${OUT}\n${CC} ${CFLAGS} -o .config.o -c .config.c"
67 OUT="${OUT}\n`echo "${CC} ${CFLAGS} -o .config.o -c .config.c"|sh 2>&1`"
68 test $? -eq 0 && {
69 echo " using: ${CFLAGS}" 1>&2
70 echo "${CFLAGS}"
71 exit 0
73 i=1
74 while test $i -lt $NPARMS; do
75 OUT="${OUT}\n${CC} ${CFLAGS} ${1} -o .config.o -c .config.c 2>&1"
76 OUT="${OUT}\n`echo "${CC} ${CFLAGS} ${1} -o .config.o -c .config.c"|sh 2>&1`"
77 test $? -eq 0 && {
78 echo " using: ${CFLAGS} ${1}" 1>&2
79 echo "${CFLAGS} ${1}"
80 exit 0
82 shift
83 i=$(($i+1))
84 done
85 echo "failed!" 1>&2
86 echo 1>&2
87 printf "The following compiler commands were executed:" 1>&2
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
93 echo "CFLAGS=-I/opt/somedir/include ./configure" 1>&2
94 echo 1>&2
95 exit 1
98 trylink() {
99 NPARMS=$#
100 WHAT="${1}"
101 shift
102 printf "finding LDFLAGS for ${WHAT}... " 1>&2
103 OUT="${OUT}\n${CC} -o .config .config.o ${LDFLAGS} 2>&1"
104 OUT="${OUT}\n`echo "${CC} -o .config .config.o ${LDFLAGS}"|sh 2>&1`"
105 test $? -eq 0 && {
106 echo " using: ${LDFLAGS}" 1>&2
107 echo "${LDFLAGS}"
108 exit 0
111 while test $i -lt $NPARMS; do
112 OUT="${OUT}\n${CC} -o .config .config.o ${LDFLAGS} ${1} 2>&1"
113 OUT="${OUT}\n`echo "${CC} -o .config .config.o ${LDFLAGS} ${1}"|sh 2>&1`"
114 test $? -eq 0 && {
115 echo " using: ${LDFLAGS} ${1}" 1>&2
116 echo "${LDFLAGS} ${1}"
117 exit 0
119 shift
120 i=$(($i+1))
121 done
122 echo "failed!" 1>&2
123 echo 1>&2
124 printf "The following linker commands were executed:" 1>&2
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
130 echo "LDFLAGS=-L/opt/somedir/lib ./configure" 1>&2
131 echo 1>&2
132 exit 1
135 CC=`findprog "compiler" "${CC}" gcc cc icc` || exit
136 INSTALL=`findprog "install" "${INSTALL}" install ginstall` || exit
138 test -n "$DEBUG" && myCFLAGS="-O2 -g" || myCFLAGS="-Os"
139 CFLAGS="${CFLAGS} ${myCFLAGS} -Wall -Werror"
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; }
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"` || {
151 rm -f .config.c
152 exit 1
154 LDFLAGS=`trylink "libpci (from pciutils)" "${pc_LDFLAGS}" "-lpci -lz" "-L/usr/local/lib -lpci -lz" "-framework DirectHW -lpci -lz"` || {
155 rm -f .config.c .config.o
156 exit 1
158 rm -f .config.c .config.o .config
160 PREFIX="${PREFIX:-/usr/local}"
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
172 printf "creating Makefile..."
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" \
179 -e "s#@PREFIX@#${PREFIX}#g" \
180 Makefile.in >> Makefile
181 echo " done"
182 echo