blob: f627a6541f2918d928accd4d983727835196dde6 [file] [log] [blame]
Peter Stugedad1e302008-11-22 17:13:36 +00001#!/bin/sh
2#
3# This file is part of msrtool.
4#
5# Copyright (c) 2008 Peter Stuge <peter@stuge.se>
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
22# revision number of the checked out files later.
23VERSION=""
24
25REV="$(svnversion -c . 2>/dev/null)"; REV="${REV/*:}"
26VERSION="${VERSION:-$REV}"
27
28function findprog() {
29 local WHAT FROMENV FILE
30 WHAT="${1}"
31 shift
32 FROMENV="${1}"
33 shift
34 echo -n "searching for ${WHAT} (${*})..." 1>&2
35 test -n "${FROMENV}" && {
36 echo " using environment: ${FROMENV}" 1>&2
37 echo "${FROMENV}"
38 exit 0
39 }
40 for parm in $(seq 0 $#); do
41 test -z "${1}" && {
42 shift
43 continue
44 }
45 FILE="$(which "${1}" 2>/dev/null)"
46 test $? -eq 0 && {
47 echo "${1}"
48 break
49 }
50 shift
51 done
52 test -z "${1}" && {
53 echo " not found!" 1>&2
54 echo 1>&2
55 echo "This is a fatal error, configure is exiting!" 1>&2
56 exit 1
57 }
58 echo " using ${FILE} in PATH" 1>&2
59 exit 0
60}
61
62function trycompile() {
63 local WHAT OUT
64 WHAT="${1}"
65 shift
66 echo -n "finding CFLAGS for ${WHAT}... " 1>&2
67 OUT="${OUT}\n${CC} ${CFLAGS} -o .config.o -c .config.c"
68 OUT="${OUT}\n$(${CC} ${CFLAGS} -o .config.o -c .config.c 2>&1)"
69 test $? -eq 0 && {
70 echo " using: ${CFLAGS}" 1>&2
71 echo "${CFLAGS}"
72 exit 0
73 }
74 for parm in $(seq 1 $#); do
75 OUT="${OUT}\n${CC} ${CFLAGS} ${1} -o .config.o -c .config.c 2>&1"
76 OUT="${OUT}\n$(${CC} ${CFLAGS} ${1} -o .config.o -c .config.c 2>&1)"
77 test $? -eq 0 && {
78 echo " using: ${CFLAGS} ${1}" 1>&2
79 echo "${CFLAGS} ${1}"
80 exit 0
81 }
82 shift
83 done
84 echo "failed!" 1>&2
85 echo 1>&2
86 echo -n "The following compiler commands were executed:" 1>&2
87 echo -e "${OUT}\n" 1>&2
88 echo "This is a fatal error, configure is exiting!" 1>&2
89 echo 1>&2
90 echo "You can try to fix this by manually setting CFLAGS in the environment before" 1>&2
91 echo "running configure. E.g.:" 1>&2
92 echo "CFLAGS=-I/opt/somedir/include ${0}" 1>&2
93 echo 1>&2
94 exit 1
95}
96
97function trylink() {
98 local WHAT OUT
99 WHAT="${1}"
100 shift
101 echo -n "finding LDFLAGS for ${WHAT}... " 1>&2
102 OUT="${OUT}\n${CC} -o .config .config.o ${LDFLAGS} 2>&1"
103 OUT="${OUT}\n$(${CC} -o .config .config.o ${LDFLAGS} 2>&1)"
104 test $? -eq 0 && {
105 echo " using: ${LDFLAGS}" 1>&2
106 echo "${LDFLAGS}"
107 exit 0
108 }
109 for parm in $(seq 1 $#); do
110 OUT="${OUT}\n${CC} -o .config .config.o ${LDFLAGS} ${1} 2>&1"
111 OUT="${OUT}\n$(${CC} -o .config .config.o ${LDFLAGS} ${1} 2>&1)"
112 test $? -eq 0 && {
113 echo " using: ${LDFLAGS} ${1}" 1>&2
114 echo "${LDFLAGS} ${1}"
115 exit 0
116 }
117 shift
118 done
119 echo "failed!" 1>&2
120 echo 1>&2
121 echo -n "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 ${0}" 1>&2
128 echo 1>&2
129 exit 1
130}
131
132CC=$(findprog "compiler" "${CC}" gcc cc icc) || exit
133INSTALL=$(findprog "install" "${INSTALL}" install ginstall) || exit
134
135test -n "$DEBUG" && myCFLAGS="-O2 -g" || myCFLAGS="-Os"
136CFLAGS="${CFLAGS} ${myCFLAGS} -Wall -Werror"
137
138PREFIX="${PREFIX:-/usr/local}"
139
140OS_ARCH=$(uname)
141
142echo
143echo "configured using the following settings:"
144echo
145echo "VERSION=${VERSION}"
146echo "CC=${CC}"
147echo "CFLAGS=${CFLAGS}"
148echo "LDFLAGS=${LDFLAGS}"
149echo "INSTALL=${INSTALL}"
150echo "PREFIX=${PREFIX}"
151echo
152echo -n "creating Makefile..."
153echo "# This file was automatically generated by configure" > Makefile
154sed -e "s#@VERSION@#${VERSION}#g" \
155 -e "s#@CC@#${CC}#g" \
156 -e "s#@CFLAGS@#${CFLAGS}#g" \
157 -e "s#@LDFLAGS@#${LDFLAGS}#g" \
158 -e "s#@INSTALL@#${INSTALL}#g" \
159 -e "s#@PREFIX@#/usr/local#g" \
160 Makefile.in >> Makefile
161echo " done"
162echo