]> git.cworth.org Git - glenv/blob - configure
Share common code for numeric glGet functions
[glenv] / configure
1 #! /bin/sh
2
3 PROJECT=glenv
4 PROJECT_BLURB="run an OpenGL program in a modified environment"
5
6 srcdir=$(dirname "$0")
7
8 # For a non-srcdir configure invocation (such as ../configure), create
9 # the directory structure and copy Makefiles.
10 if [ "$srcdir" != "." ]; then
11
12     for dir in . $(grep "^subdirs *=" "$srcdir"/Makefile | sed -e "s/subdirs *= *//"); do
13         mkdir -p "$dir"
14         cp "$srcdir"/"$dir"/Makefile.local "$dir"
15         cp "$srcdir"/"$dir"/Makefile "$dir"
16     done
17 fi
18
19 # Set several defaults (optionally specified by the user in
20 # environment variables)
21 CC=${CC:-gcc}
22 CFLAGS=${CFLAGS:--O2}
23 LDFLAGS=${LDFLAGS:-}
24
25 # Set the defaults for values the user can specify with command-line
26 # options.
27 PREFIX=/usr/local
28
29 usage ()
30 {
31     cat <<EOF
32 Usage: ./configure [options]...
33
34 This script configures ${PROJECT} to build on your system.
35
36 It verifies that dependencies are available, determines flags needed
37 to compile and link against various required libraries, and identifies
38 whether various system functions can be used or if locally-provided
39 replacements will be built instead.
40
41 Finally, it allows you to control various aspects of the build and
42 installation process.
43
44 First, some common variables can specified via environment variables:
45
46         CC              The C compiler to use
47         CFLAGS          Flags to pass to the C compiler
48         LDFLAGS         Flags to pass when linking
49
50 Each of these values can further be controlled by specifying them
51 later on the "make" command line.
52
53 Additionally, various options can be specified on the configure
54 command line.
55
56         --prefix=PREFIX Install files in PREFIX [$PREFIX]
57
58 By default, "make install" will install the resulting program to
59 $PREFIX/bin, documentation to $PREFIX/man, etc. You can
60 specify an installation prefix other than $PREFIX using
61 --prefix, for instance:
62
63         ./configure --prefix=\$HOME
64
65 Fine tuning of some installation directories is available:
66
67         --bindir=DIR            Install executables to DIR [PREFIX/bin]
68         --libdir=DIR            Install libraries to DIR [PREFIX/lib]
69         --mandir=DIR            Install man pages to DIR [PREFIX/share/man]
70         --sysconfdir=DIR        Read-only single-machine data [PREFIX/etc]
71
72 Additional options are accepted for compatibility with other
73 configure-script calling conventions, but don't do anything yet:
74
75         --build=<cpu>-<vendor>-<os>     Currently ignored
76         --host=<cpu>-<vendor>-<os>      Currently ignored
77         --infodir=DIR                   Currently ignored
78         --datadir=DIR                   Currently ignored
79         --localstatedir=DIR             Currently ignored
80         --libexecdir=DIR                Currently ignored
81         --disable-maintainer-mode       Currently ignored
82         --disable-dependency-tracking   Currently ignored
83
84 EOF
85 }
86
87 # Parse command-line options
88 for option; do
89     if [ "${option}" = '--help' ] ; then
90         usage
91         exit 0
92     elif [ "${option%%=*}" = '--prefix' ] ; then
93         PREFIX="${option#*=}"
94     elif [ "${option%%=*}" = '--bindir' ] ; then
95         BINDIR="${option#*=}"
96     elif [ "${option%%=*}" = '--libdir' ] ; then
97         LIBDIR="${option#*=}"
98     elif [ "${option%%=*}" = '--mandir' ] ; then
99         MANDIR="${option#*=}"
100     elif [ "${option%%=*}" = '--sysconfdir' ] ; then
101         SYSCONFDIR="${option#*=}"
102     elif [ "${option%%=*}" = '--build' ] ; then
103         true
104     elif [ "${option%%=*}" = '--host' ] ; then
105         true
106     elif [ "${option%%=*}" = '--infodir' ] ; then
107         true
108     elif [ "${option%%=*}" = '--datadir' ] ; then
109         true
110     elif [ "${option%%=*}" = '--localstatedir' ] ; then
111         true
112     elif [ "${option%%=*}" = '--libexecdir' ] ; then
113         true
114     elif [ "${option}" = '--disable-maintainer-mode' ] ; then
115         true
116     elif [ "${option}" = '--disable-dependency-tracking' ] ; then
117         true
118     else
119         echo "Unrecognized option: ${option}"
120         echo "See:"
121         echo "  $0 --help"
122         echo ""
123         exit 1
124     fi
125 done
126
127 printf "Checking for working C compiler (${CC})... "
128 printf "int main(void){return 42;}\n" > minimal.c
129 if ${CC} -o minimal minimal.c > /dev/null 2>&1
130 then
131     printf "Yes.\n"
132 else
133     printf "No.\n"
134     cat <<EOF
135
136 *** Error: No functioning C compiler found. Either set the CC environment
137 to a working C compiler, or else install gcc:
138
139         http://gcc.gnu.org/
140
141 You may be able to install gcc with a command such as:
142
143         sudo apt-get install build-essential
144     or:
145         sudo yum install make automake gcc gcc-c++ kernel-devel
146
147 EOF
148
149 exit 1
150
151 fi
152
153 WARN_CFLAGS=""
154 printf "Checking for available C compiler warning flags:\n"
155 for flag in -Wall -Wextra -Wmissing-declarations -Werror=attributes; do
156     if ${CC} $flag -o minimal minimal.c > /dev/null 2>&1
157     then
158         WARN_CFLAGS="${WARN_CFLAGS}${WARN_CFLAGS:+ }${flag}"
159     fi
160 done
161 printf "\t${WARN_CFLAGS}\n"
162
163 rm -f minimal minimal.c
164
165 printf "#include <features.h>\nint main(void){return 0;}\n" > arch-minimal.c
166
167 printf "Checking for machine-dependent compiler support:\n"
168
169 printf "        Compiler can create 32-bit binaries... "
170 have_m32=Yes
171 if ${CC} -m32 -o arch-minimal arch-minimal.c > /dev/null 2>&1
172 then
173     printf "Yes.\n"
174 else
175     printf "No.\n"
176     have_m32=No
177 fi
178
179 printf "        Compiler can create 64-bit binaries... "
180 have_m64=Yes
181 if ${CC} -m64 -o arch-minimal arch-minimal.c > /dev/null 2>&1
182 then
183     printf "Yes.\n"
184 else
185     printf "No.\n"
186     have_m64=No
187 fi
188
189 if [ "$have_m32" = "No" ] || [ "$have_m64" = "No" ]; then
190     cat <<EOF
191
192 * Warning: Cannot create both 32 and 64-bit glenv libraries. Glenv will not
193            support applications of the non-native size. Fixing this may be
194            as simple as running a command such as:
195
196                 sudo apt-get install gcc-multilib
197 EOF
198 fi
199
200 rm -f arch-minimal arch-minimal.c
201
202 errors=0
203
204 printf "Checking for pkg-config... "
205 if pkg-config --version > /dev/null 2>&1; then
206     printf "Yes.\n"
207 else
208     printf "No.\n"
209     cat <<EOF
210
211 *** Error: This configure script requires pkg-config to find the
212 compilation flags required to link against the various libraries
213 needed by ${PROJECT}. The pkg-config program can be obtained from:
214
215         http://www.freedesktop.org/wiki/Software/pkg-config/
216
217 Or you may be able install it with a command such as:
218
219         sudo apt-get install pkg-config
220     or:
221         sudo yum install pkgconfig
222
223 EOF
224
225 exit 1
226
227 fi
228
229 printf "Checking for glaze... "
230 if pkg-config --exists glaze; then
231     printf "Yes.\n"
232     have_glazec=1
233     glaze_cflags=$(pkg-config --cflags glaze)
234     glaze_ldflags=$(pkg-config --libs glaze)
235 else
236     printf "No.\n"
237     have_glaze=0
238     errors=$((errors + 1))
239 fi
240
241 if [ $errors -gt 0 ]; then
242     cat <<EOF
243
244 *** Error: The dependencies of ${PROJECT} could not be satisfied. You will
245 need to install the following packages before being able to compile
246 ${PROJECT}:
247
248 EOF
249     if [ $have_glaze -eq 0 ]; then
250         echo "  The glaze library"
251         echo "  git://git.cworth.org/git/glaze/"
252         echo
253     fi
254
255     exit 1
256 fi
257
258 # construct the Makefile.config
259 cat > Makefile.config <<EOF
260 # This Makefile.config was automatically generated by the ./configure
261 # script of ${PROJECT}. If the configure script identified anything
262 # incorrectly, then you can edit this file to try to correct things,
263 # but be warned that if configure is run again it will destroy your
264 # changes, (and this could happen by simply calling "make" if the
265 # configure script is updated).
266
267 # The top-level directory for the source, (the directory containing
268 # the configure script). This may be different than the build
269 # directory (the current directory at the time configure was run).
270 srcdir = ${srcdir}
271
272 configure_options = $@
273
274 # We use vpath directives (rather than the VPATH variable) since the
275 # VPATH variable matches targets as well as prerequisites, (which is
276 # not useful since then a target left-over from a srcdir build would
277 # cause a target to not be built in the non-srcdir build).
278 vpath % \$(srcdir)
279
280 # The C compiler to use
281 CC = ${CC}
282
283 # Default FLAGS for C compiler (can be overridden by user such as "make CFLAGS=-g")
284 CFLAGS = ${CFLAGS}
285
286 # Default FLAGS for the linker (can be overridden by user such as "make LDFLAGS=-znow")
287 LDFLAGS = ${LDFLAGS}
288
289 # Flags to enable warnings when using the C compiler
290 WARN_CFLAGS = ${WARN_CFLAGS}
291
292 # The prefix to which ${PROJECT} should be installed
293 PREFIX = ${PREFIX}
294
295 # The directory to which executables should be installed
296 BINDIR = ${BINDIR:-\$(PREFIX)/bin}
297
298 # The directory to which libraries should be installed
299 LIBDIR = ${LIBDIR:-\$(PREFIX)/lib}
300
301 # The directory to which headers should be installed
302 INCLUDEDIR = ${INCLUDEDIR:-\$(PREFIX)/include}
303
304 # Whether compiler can create 32 or 64-bit binaries
305 COMPILER_SUPPORTS_32 = ${have_m32}
306 COMPILER_SUPPORTS_64 = ${have_m64}
307
308 # Flags needed to compile and link against Glaze
309 GLAZE_CFLAGS = ${glaze_cflags}
310 GLAZE_LDFLAGS = ${glaze_ldflags}
311
312 EOF
313
314 cat <<EOF
315
316 You may now run the following commands to compile and install ${PROJECT}:
317
318         make
319         sudo make install
320
321 EOF