]> git.cworth.org Git - fips/blob - configure
Add support for OpenGL ES by conditionally compiling wrapper for eglSwapBuffers
[fips] / configure
1 #! /bin/sh
2
3 PROJECT=fips
4 PROJECT_BLURB="a program for monitoring performance of OpenGL applications"
5
6 # Test whether this shell is capable of parameter substring processing.
7 ( option='a/b'; : ${option#*/} ) 2>/dev/null || {
8     echo "
9 The shell interpreting '$0' is lacking some required features.
10
11 To work around this problem you may try to execute:
12
13     ksh $0 $*
14  or
15     bash $0 $*
16 "
17     exit 1
18 }
19
20 # Store original IFS value so it can be changed (and restored) in many places.
21 readonly DEFAULT_IFS="$IFS"
22
23 srcdir=$(dirname "$0")
24
25 # For a non-srcdir configure invocation (such as ../configure), create
26 # the directory structure and copy Makefiles.
27 if [ "$srcdir" != "." ]; then
28
29     for dir in . $(grep "^subdirs *=" "$srcdir"/Makefile | sed -e "s/subdirs *= *//"); do
30         mkdir -p "$dir"
31         cp "$srcdir"/"$dir"/Makefile.local "$dir"
32         cp "$srcdir"/"$dir"/Makefile "$dir"
33     done
34 fi
35
36 # Set several defaults (optionally specified by the user in
37 # environment variables)
38 CC=${CC:-gcc}
39 CFLAGS=${CFLAGS:--O2}
40 LDFLAGS=${LDFLAGS:-}
41
42 # Set the defaults for values the user can specify with command-line
43 # options.
44 PREFIX=/usr/local
45
46 usage ()
47 {
48     cat <<EOF
49 Usage: ./configure [options]...
50
51 This script configures ${PROJECT} to build on your system.
52
53 It verifies that dependencies are available, determines flags needed
54 to compile and link against various required libraries, and identifies
55 whether various system functions can be used or if locally-provided
56 replacements will be built instead.
57
58 Finally, it allows you to control various aspects of the build and
59 installation process.
60
61 First, some common variables can specified via environment variables:
62
63         CC              The C compiler to use
64         CFLAGS          Flags to pass to the C compiler
65         LDFLAGS         Flags to pass when linking
66
67 Each of these values can further be controlled by specifying them
68 later on the "make" command line.
69
70 Additionally, various options can be specified on the configure
71 command line.
72
73         --prefix=PREFIX Install files in PREFIX [$PREFIX]
74
75 By default, "make install" will install the resulting program to
76 $PREFIX/bin, documentation to $PREFIX/man, etc. You can
77 specify an installation prefix other than $PREFIX using
78 --prefix, for instance:
79
80         ./configure --prefix=\$HOME
81
82 Fine tuning of some installation directories is available:
83
84         --bindir=DIR            Install executables to DIR [PREFIX/bin]
85         --libdir=DIR            Install libraries to DIR [PREFIX/lib]
86         --mandir=DIR            Install man pages to DIR [PREFIX/share/man]
87         --sysconfdir=DIR        Read-only single-machine data [PREFIX/etc]
88
89 Additional options are accepted for compatibility with other
90 configure-script calling conventions, but don't do anything yet:
91
92         --build=<cpu>-<vendor>-<os>     Currently ignored
93         --host=<cpu>-<vendor>-<os>      Currently ignored
94         --infodir=DIR                   Currently ignored
95         --datadir=DIR                   Currently ignored
96         --localstatedir=DIR             Currently ignored
97         --libexecdir=DIR                Currently ignored
98         --disable-maintainer-mode       Currently ignored
99         --disable-dependency-tracking   Currently ignored
100
101 EOF
102 }
103
104 # Given two absolute paths ("from" and "to"), compute a relative path
105 # from "from" to "to". For example:
106 #
107 #       relative_path /foo/bar/baz /foo/qux -> ../../qux
108 relative_path ()
109 {
110     if [ $# -ne 2 ] ; then
111         echo "Internal error: relative_path requires exactly 2 arguments"
112         exit 1;
113     fi
114
115     from="$1"
116     to="$2"
117
118     # Handle trivial case up-front
119     if [ "$from" = "$to" ] ; then
120         echo ""
121     else
122         shared="$from"
123         relative=""
124
125         while [ "${to#$shared}" = "$to" ] && [ "$shared" != "." ] ; do
126             shared="$(dirname $shared)"
127             relative="..${relative:+/${relative}}"
128         done
129
130         echo "${relative:-.}${to#$shared}"
131     fi
132 }
133
134 # Parse command-line options
135 for option; do
136     if [ "${option}" = '--help' ] ; then
137         usage
138         exit 0
139     elif [ "${option%%=*}" = '--prefix' ] ; then
140         PREFIX="${option#*=}"
141     elif [ "${option%%=*}" = '--bindir' ] ; then
142         BINDIR="${option#*=}"
143     elif [ "${option%%=*}" = '--libdir' ] ; then
144         LIBDIR="${option#*=}"
145     elif [ "${option%%=*}" = '--mandir' ] ; then
146         MANDIR="${option#*=}"
147     elif [ "${option%%=*}" = '--sysconfdir' ] ; then
148         SYSCONFDIR="${option#*=}"
149     elif [ "${option%%=*}" = '--build' ] ; then
150         true
151     elif [ "${option%%=*}" = '--host' ] ; then
152         true
153     elif [ "${option%%=*}" = '--infodir' ] ; then
154         true
155     elif [ "${option%%=*}" = '--datadir' ] ; then
156         true
157     elif [ "${option%%=*}" = '--localstatedir' ] ; then
158         true
159     elif [ "${option%%=*}" = '--libexecdir' ] ; then
160         true
161     elif [ "${option}" = '--disable-maintainer-mode' ] ; then
162         true
163     elif [ "${option}" = '--disable-dependency-tracking' ] ; then
164         true
165     else
166         echo "Unrecognized option: ${option}"
167         echo "See:"
168         echo "  $0 --help"
169         echo ""
170         exit 1
171     fi
172 done
173
174 cat <<EOF
175 Welcome to ${PROJECT}, ${PROJECT_BLURB}
176
177 We hope that the process of building and installing ${PROJECT} is quick
178 and smooth.
179
180 If anything goes wrong in the configure process, you can override any
181 decisions it makes by manually editing the Makefile.config file that
182 it creates. Also please do as much as you can to figure out what could
183 be different on your machine compared to those of the ${PROJECT}
184 developers. Then, please email those details to the ${PROJECT} developers so
185 that they can hopefully make future versions of ${PROJECT} easier for you to
186 use.
187
188 We'll now investigate your system to verify that all required
189 dependencies are available:
190
191 EOF
192
193 errors=0
194
195 if pkg-config --version > /dev/null 2>&1; then
196     have_pkg_config=1
197 else
198     have_pkg_config=0
199 fi
200
201 printf "Checking for talloc development files... "
202 if pkg-config --exists talloc; then
203     printf "Yes.\n"
204     have_talloc=1
205     talloc_cflags=$(pkg-config --cflags talloc)
206     talloc_ldflags=$(pkg-config --libs talloc)
207 else
208     printf "No.\n"
209     have_talloc=0
210     talloc_cflags=
211     errors=$((errors + 1))
212 fi
213
214 printf "Checking for libelf... "
215 printf "#include <gelf.h>\nint main(void){return elf_version (EV_CURRENT);}\n" > elf-minimal.c
216 if ${CC} -o elf-minimal elf-minimal.c -lelf > /dev/null 2>&1
217 then
218     printf "Yes.\n"
219     have_libelf=1
220     libelf_cflags=
221     libelf_ldflags=-lelf
222 else
223     printf "No.\n"
224     have_libelf=0
225     libelf_cflags=
226     libelf_ldflags=
227     errors=$((errors + 1))
228 fi
229 rm -f elf-minimal elf-minimal.c
230
231 printf "Checking for OpenGL header file GL/gl.h... "
232 have_gl=0
233 if pkg-config --exists gl; then
234     printf "Yes.\n"
235     have_gl=1
236     gl_cflags=$(pkg-config --cflags gl)
237 else
238     printf "#include <GL/gl.h>\nint main(void){return 0;}\n" > gl-minimal.c
239     if ${CC} -o gl-minimal gl-minimal.c > /dev/null 2>&1
240     then
241         printf "Yes.\n"
242         have_gl=1
243     else
244         printf "No.\n"
245         errors=$((errors + 1))
246     fi
247     rm -f gl-minimal gl-minimal.c
248 fi
249
250 printf "Checking for GL window-system-binding headers:\n"
251 have_gl_winsys=0
252
253 printf "    Checking for GL/glx.h... "
254 have_glx=No
255 printf "#include <GL/glx.h>\nint main(void){return 0;}\n" > glx-minimal.c
256 if ${CC} -o glx-minimal glx-minimal.c ${gl_cflags} > /dev/null 2>&1
257 then
258     printf "Yes.\n"
259     have_gl_winsys=1
260     have_glx=Yes
261 else
262     printf "No.\n"
263 fi
264 rm -f glx-minimal glx-minimal.c
265
266 printf "    Checking for GL/egl.h... "
267 have_egl=No
268 if pkg-config --exists egl; then
269     printf "Yes.\n"
270     have_egl=Yes
271     egl_cflags=$(pkg-config --cflags egl)
272 else
273     printf "#include <GL/egl.h>\nint main(void){return 0;}\n" > egl-minimal.c
274     if ${CC} -o egl-minimal egl-minimal.c ${gl_cflags} > /dev/null 2>&1
275     then
276         printf "Yes.\n"
277         have_gl_winsys=1
278         have_egl=1
279     else
280         printf "No.\n"
281     fi
282     rm -f egl-minimal egl-minimal.c
283 fi
284
285 if [ $have_gl_winsys -eq 0 ]; then
286     errors=$((errors + 1))
287 fi
288
289 if [ $errors -gt 0 ]; then
290     cat <<EOF
291
292 *** Error: The dependencies of ${PROJECT} could not be satisfied. You will
293 need to install the following packages before being able to compile
294 ${PROJECT}:
295
296 EOF
297     if [ $have_talloc -eq 0 ]; then
298         echo "  The talloc library (including development files such as headers)"
299         echo "  http://talloc.samba.org/"
300         echo
301     fi
302     if [ $have_libelf -eq 0 ]; then
303         echo "  The libelf library (including development files such as headers)"
304         echo "  http://http://sourceforge.net/projects/elftoolchain/"
305         echo
306     fi
307     if [ $have_gl -eq 0 ]; then
308         echo "  Open GL header files (GL/gl.h)"
309         echo "  http://www.mesa3d.org/"
310         echo
311     fi
312     if [ $have_gl_winsys -eq 0 ]; then
313         echo "  OpenGL window-system-bindings header files (GL/glx.h and/or GL/egl.h)"
314         echo "  http://www.mesa3d.org/"
315         echo
316     fi
317     cat <<EOF
318 With any luck, you're using a modern, package-based operating system
319 that has all of these packages available in the distribution. In that
320 case a simple command will install everything you need. For example:
321
322 On Debian and similar systems:
323
324         sudo apt-get install libtalloc-dev libelf-dev \\
325         libgl1-mesa-dev libgles2-mesa-dev
326
327 Or on Fedora and similar systems:
328
329         sudo yum install libtalloc-devel libelf-devel \\
330         mesa-libGL-devel mesa-libGLES-devel
331
332 On other systems, similar commands can be used, but the details of the
333 package names may be different.
334
335 EOF
336     if [ $have_pkg_config -eq 0 ]; then
337 cat <<EOF
338 Note: the pkg-config program is not available. This configure script
339 uses pkg-config to find the compilation flags required to link against
340 the various libraries needed by ${PROJECT}. It's possible you simply need
341 to install pkg-config with a command such as:
342
343         sudo apt-get install pkg-config
344 Or:
345         sudo yum install pkgconfig
346
347 But if pkg-config is not available for your system, then you will need
348 to modify the configure script to manually set the cflags and ldflags
349 variables to the correct values to link against each library in each
350 case that pkg-config could not be used to determine those values.
351
352 EOF
353     fi
354 cat <<EOF
355 When you have installed the necessary dependencies, you can run
356 configure again to ensure the packages can be found, or simply run
357 "make" to compile.
358
359 EOF
360     exit 1
361 fi
362
363 printf "int main(void){return 0;}\n" > minimal.c
364
365 WARN_CFLAGS=""
366 printf "Checking for available C compiler warning flags... "
367 for flag in -Wall -Wextra -Wmissing-declarations; do
368     if ${CC} $flag -o minimal minimal.c > /dev/null 2>&1
369     then
370         WARN_CFLAGS="${WARN_CFLAGS}${WARN_CFLAGS:+ }${flag}"
371     fi
372 done
373 printf "\n\t${WARN_CFLAGS}\n"
374
375 rm -f minimal minimal.c
376
377 cat <<EOF
378
379 All required packages were found.
380
381 The following OpenGL window-system bindings will be supported:
382
383         GLX: ${have_glx}
384         EGL: ${have_egl}
385
386 You may now run the following commands to compile and install ${PROJECT}:
387
388         make
389         sudo make install
390
391 EOF
392
393 # construct the Makefile.config
394 cat > Makefile.config <<EOF
395 # This Makefile.config was automatically generated by the ./configure
396 # script of ${PROJECT}. If the configure script identified anything
397 # incorrectly, then you can edit this file to try to correct things,
398 # but be warned that if configure is run again it will destroy your
399 # changes, (and this could happen by simply calling "make" if the
400 # configure script is updated).
401
402 # The top-level directory for the source, (the directory containing
403 # the configure script). This may be different than the build
404 # directory (the current directory at the time configure was run).
405 srcdir = ${srcdir}
406
407 configure_options = $@
408
409 # We use vpath directives (rather than the VPATH variable) since the
410 # VPATH variable matches targets as well as prerequisites, (which is
411 # not useful since then a target left-over from a srcdir build would
412 # cause a target to not be built in the non-srcdir build).
413 #
414 # Also, we don't use a single "vpath % \$(srcdir)" here because we
415 # don't want the vpath to trigger for our emacs lisp compilation,
416 # (unless we first find a way to convince emacs to build the .elc
417 # target in a directory other than the directory of the .el
418 # prerequisite). In the meantime, we're actually copying in the .el
419 # files, (which is quite ugly).
420 vpath %.c \$(srcdir)
421 vpath %.cc \$(srcdir)
422 vpath %.1 \$(srcdir)
423 vpath Makefile.% \$(srcdir)
424
425 # The C compiler to use
426 CC = ${CC}
427
428 # Default FLAGS for C compiler (can be overridden by user such as "make CFLAGS=-g")
429 CFLAGS = ${CFLAGS}
430
431 # Default FLAGS for the linker (can be overridden by user such as "make LDFLAGS=-znow")
432 LDFLAGS = ${LDFLAGS}
433
434 # Flags to enable warnings when using the C compiler
435 WARN_CFLAGS=${WARN_CFLAGS}
436
437 # The prefix to which ${PROJECT} should be installed
438 prefix = ${PREFIX}
439
440 # The directory to which executables should be installed
441 bindir = ${BINDIR:=\$(prefix)/bin}
442
443 # The directory to which libraries should be installed
444 libdir = ${LIBDIR:=\$(prefix)/lib}
445
446 # The directory to which man pages should be installed
447 mandir = ${MANDIR:=\$(prefix)/share/man}
448
449 # The directory to which read-only (configuration) files should be installed
450 sysconfdir = ${SYSCONFDIR:=\$(prefix)/etc}
451
452 # Flags needed to compile and link against talloc
453 TALLOC_CFLAGS = ${talloc_cflags}
454 TALLOC_LDFLAGS = ${talloc_ldflags}
455
456 # Flags needed to compile and link against libelf
457 LIBELF_CFLAGS = ${libelf_cflags}
458 LIBELF_LDFLAGS = ${libelf_ldflags}
459
460 # Whether GLX headers are available
461 HAVE_GLX = ${have_glx}
462
463 # Flags needed to find GL and GLX header files (GL/gl.h and GL/glx.h)
464 GL_CFLAGS = ${gl_cflags}
465
466 # Whether EGL headers are available
467 HAVE_EGL = ${have_egl}
468
469 # Flags needed to find EGL header files (EGL/egl.h)
470 EGL_CFLAGS = ${egl_cflags}
471
472 # Flags needed to have linker link only to necessary libraries
473 AS_NEEDED_LDFLAGS = ${as_needed_ldflags}
474
475 # Combined flags for compiling and linking against all of the above
476 CONFIGURE_CFLAGS = \$(TALLOC_CFLAGS) \$(LIBELF_CFLAGS) \$(GL_CFLAGS) \$(EGL_CFLAGS)
477 CONFIGURE_LDFLAGS = \$(TALLOC_LDFLAGS) \$(LIBELF_LDFLAGS)
478 EOF
479
480 # construct config.h
481 cat > config.h <<EOF
482 /* Generated by configure. */
483
484 /* Relative path from ${bindir} to ${libdir} */
485 #define BINDIR_TO_LIBFIPSDIR "$(relative_path ${BINDIR} ${LIBDIR})/fips"
486 EOF