]> git.cworth.org Git - fips/blob - configure
Add explicit link to libpthread, to work around debugging issues
[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 printf "Checking for pkg-config... "
196 if pkg-config --version > /dev/null 2>&1; then
197     printf "Yes.\n"
198 else
199     printf "No.\n"
200     cat <<EOF
201
202 *** Error: This configure script requires pkg-config to find the
203 compilation flags required to link against the various libraries
204 needed by ${PROJECT}. The pkg-config program can be obtained from:
205
206         http://www.freedesktop.org/wiki/Software/pkg-config/
207
208 Or you may be able install it with a command such as:
209
210         sudo apt-get install pkg-config
211     or:
212         sudo yum install pkgconfig
213
214 EOF
215
216 exit 1
217
218 fi
219
220 printf "Checking for working C compiler (${CC})... "
221 printf "int main(void){return 42;}\n" > minimal.c
222 if ${CC} -o minimal minimal.c > /dev/null 2>&1
223 then
224     printf "Yes.\n"
225 else
226     printf "No.\n"
227     cat <<EOF
228
229 *** Error: No functioning C compiler found. Either set the CC environment
230 to a working C compiler, or else install gcc:
231
232         http://gcc.gnu.org/
233
234 You may be able to install gcc with a command such as:
235
236         sudo apt-get install build-essential
237     or:
238         sudo yum install make automake gcc gcc-c++ kernel-devel
239
240 EOF
241
242 exit 1
243
244 fi
245
246 printf "Checking for libtalloc... "
247 if pkg-config --exists talloc; then
248     printf "Yes.\n"
249     have_talloc=1
250     talloc_cflags=$(pkg-config --cflags talloc)
251     talloc_ldflags=$(pkg-config --libs talloc)
252 else
253     printf "No.\n"
254     have_talloc=0
255     talloc_cflags=
256     errors=$((errors + 1))
257 fi
258
259 printf "Checking for libelf... "
260 printf "#include <gelf.h>\nint main(void){return elf_version (EV_CURRENT);}\n" > elf-minimal.c
261 if ${CC} -o elf-minimal elf-minimal.c -lelf > /dev/null 2>&1
262 then
263     printf "Yes.\n"
264     have_libelf=1
265     libelf_cflags=
266     libelf_ldflags=-lelf
267 else
268     printf "No.\n"
269     have_libelf=0
270     libelf_cflags=
271     libelf_ldflags=
272     errors=$((errors + 1))
273 fi
274 rm -f elf-minimal elf-minimal.c
275
276 printf "Checking for GL/gl.h... "
277 have_gl=0
278 if pkg-config --exists gl; then
279     printf "Yes.\n"
280     have_gl=1
281     gl_cflags=$(pkg-config --cflags gl)
282     gl_ldflags=$(pkg-config --libs gl)
283 else
284     printf"No.\n"
285     have_gl=0
286     errors=$((errors + 1))
287 fi
288
289 printf "Checking for GL window-system-binding headers:\n"
290 have_gl_winsys=0
291
292 printf "        Checking for GL/glx.h... "
293 have_glx=No
294 printf "#include <GL/glx.h>\nint main(void){return 0;}\n" > glx-minimal.c
295 if ${CC} -o glx-minimal glx-minimal.c ${gl_cflags} > /dev/null 2>&1
296 then
297     printf "Yes.\n"
298     have_gl_winsys=1
299     have_glx=Yes
300 else
301     printf "No.\n"
302 fi
303 rm -f glx-minimal glx-minimal.c
304
305 if [ $have_gl_winsys -eq 0 ]; then
306     errors=$((errors + 1))
307 fi
308
309 printf "        Checking for X11... "
310 have_x11=No
311 if pkg-config --exists x11; then
312   printf "Yes.\n"
313   have_x11=Yes
314   x11_cflags=$(pkg-config --cflags x11)
315   x11_ldflags=$(pkg-config --libs x11)
316 else
317   printf "No.\n"
318 fi
319
320 printf "        Checking for EGL/egl.h... "
321 have_egl=No
322 if pkg-config --exists egl; then
323     printf "Yes.\n"
324     have_egl=Yes
325     egl_cflags=$(pkg-config --cflags egl)
326     egl_ldflags=$(pkg-config --libs egl)
327 else
328     printf "No.\n"
329 fi
330
331 printf "        Checking for GLESv2... "
332 have_glesv2=No
333 if pkg-config --exists glesv2; then
334     printf "Yes.\n"
335     have_glesv2=Yes
336     glesv2_cflags=$(pkg-config --cflags glesv2)
337     glesv2_ldflags=$(pkg-config --libs glesv2)
338 else
339     printf "No.\n"
340 fi
341
342 printf "int main(void){return 0;}\n" > minimal.c
343
344 WARN_CFLAGS=""
345 printf "Checking for available C compiler warning flags:\n"
346 for flag in -Wall -Wextra -Wmissing-declarations; do
347     if ${CC} $flag -o minimal minimal.c > /dev/null 2>&1
348     then
349         WARN_CFLAGS="${WARN_CFLAGS}${WARN_CFLAGS:+ }${flag}"
350     fi
351 done
352 printf "\t${WARN_CFLAGS}\n"
353
354 rm -f minimal minimal.c
355
356 printf "#include <features.h>\nint main(void){return 0;}\n" > arch-minimal.c
357
358 printf "Checking for machine-dependent compiler support:\n"
359
360 printf "        Compiler can create 32-bit binaries... "
361 have_m32=Yes
362 if ${CC} -m32 -o arch-minimal arch-minimal.c > /dev/null 2>&1
363 then
364     printf "Yes.\n"
365 else
366     printf "No.\n"
367     have_m32=No
368 fi
369
370 printf "        Compiler can create 64-bit binaries... "
371 have_m64=Yes
372 if ${CC} -m64 -o arch-minimal arch-minimal.c > /dev/null 2>&1
373 then
374     printf "Yes.\n"
375 else
376     printf "No.\n"
377     have_m64=No
378 fi
379
380 if [ "$have_m32" = "No" ] || [ "$have_m64" = "No" ]; then
381     cat <<EOF
382
383 * Warning: Cannot create both 32 and 64-bit fips libraries. Fips will not
384            support applications of the non-native size. Fixing this may be
385            as simple as running a command such as:
386
387                 sudo apt-get install gcc-multilib
388 EOF
389 fi
390
391 rm -f arch-minimal arch-minimal.c
392
393 if [ $errors -gt 0 ]; then
394     cat <<EOF
395
396 *** Error: The dependencies of ${PROJECT} could not be satisfied. You will
397 need to install the following packages before being able to compile
398 ${PROJECT}:
399
400 EOF
401     if [ $have_talloc -eq 0 ]; then
402         echo "  The talloc library (including development files such as headers)"
403         echo "  http://talloc.samba.org/"
404         echo
405     fi
406     if [ $have_libelf -eq 0 ]; then
407         echo "  The libelf library (including development files such as headers)"
408         echo "  http://http://sourceforge.net/projects/elftoolchain/"
409         echo
410     fi
411     if [ $have_gl -eq 0 ]; then
412         echo "  Open GL header files (GL/gl.h)"
413         echo "  http://www.mesa3d.org/"
414         echo
415     fi
416     if [ $have_gl_winsys -eq 0 ]; then
417         echo "  OpenGL window-system-bindings header files (GL/glx.h and/or GL/egl.h)"
418         echo "  http://www.mesa3d.org/"
419         echo
420     fi
421     cat <<EOF
422 With any luck, you're using a modern, package-based operating system
423 that has all of these packages available in the distribution. In that
424 case a simple command will install everything you need. For example:
425
426 On Debian and similar systems:
427
428         sudo apt-get install libtalloc-dev libelf-dev \\
429         libgl1-mesa-dev libgles2-mesa-dev
430
431 Or on Fedora and similar systems:
432
433         sudo yum install libtalloc-devel libelf-devel \\
434         mesa-libGL-devel mesa-libGLES-devel
435
436 On other systems, similar commands can be used, but the details of the
437 package names may be different.
438
439 When you have installed the necessary dependencies, you can run
440 configure again to ensure the packages can be found, or simply run
441 "make" to compile.
442
443 EOF
444     exit 1
445 fi
446
447 cat <<EOF
448
449 All required packages were found.
450
451 The following OpenGL window-system bindings will be supported:
452
453         GLX: ${have_glx}
454         EGL: ${have_egl}
455
456 You may now run the following commands to compile and install ${PROJECT}:
457
458         make
459         sudo make install
460
461 EOF
462
463 # construct the Makefile.config
464 cat > Makefile.config <<EOF
465 # This Makefile.config was automatically generated by the ./configure
466 # script of ${PROJECT}. If the configure script identified anything
467 # incorrectly, then you can edit this file to try to correct things,
468 # but be warned that if configure is run again it will destroy your
469 # changes, (and this could happen by simply calling "make" if the
470 # configure script is updated).
471
472 # The top-level directory for the source, (the directory containing
473 # the configure script). This may be different than the build
474 # directory (the current directory at the time configure was run).
475 srcdir = ${srcdir}
476
477 configure_options = $@
478
479 # We use vpath directives (rather than the VPATH variable) since the
480 # VPATH variable matches targets as well as prerequisites, (which is
481 # not useful since then a target left-over from a srcdir build would
482 # cause a target to not be built in the non-srcdir build).
483 #
484 # Also, we don't use a single "vpath % \$(srcdir)" here because we
485 # don't want the vpath to trigger for our emacs lisp compilation,
486 # (unless we first find a way to convince emacs to build the .elc
487 # target in a directory other than the directory of the .el
488 # prerequisite). In the meantime, we're actually copying in the .el
489 # files, (which is quite ugly).
490 vpath %.c \$(srcdir)
491 vpath %.cc \$(srcdir)
492 vpath %.1 \$(srcdir)
493 vpath Makefile.% \$(srcdir)
494
495 # The C compiler to use
496 CC = ${CC}
497
498 # Default FLAGS for C compiler (can be overridden by user such as "make CFLAGS=-g")
499 CFLAGS = ${CFLAGS}
500
501 # Default FLAGS for the linker (can be overridden by user such as "make LDFLAGS=-znow")
502 LDFLAGS = ${LDFLAGS}
503
504 # Flags to enable warnings when using the C compiler
505 WARN_CFLAGS=${WARN_CFLAGS}
506
507 # The prefix to which ${PROJECT} should be installed
508 prefix = ${PREFIX}
509
510 # The directory to which executables should be installed
511 bindir = ${BINDIR:=\$(prefix)/bin}
512
513 # The directory to which libraries should be installed
514 libdir = ${LIBDIR:=\$(prefix)/lib}
515
516 # The directory to which man pages should be installed
517 mandir = ${MANDIR:=\$(prefix)/share/man}
518
519 # The directory to which read-only (configuration) files should be installed
520 sysconfdir = ${SYSCONFDIR:=\$(prefix)/etc}
521
522 # Whether compiler can create 32 or 64-bit binaries
523 COMPILER_SUPPORTS_32 = ${have_m32}
524 COMPILER_SUPPORTS_64 = ${have_m64}
525
526 # Flags needed to compile and link against talloc
527 TALLOC_CFLAGS = ${talloc_cflags}
528 TALLOC_LDFLAGS = ${talloc_ldflags}
529
530 # Flags needed to compile and link against libelf
531 LIBELF_CFLAGS = ${libelf_cflags}
532 LIBELF_LDFLAGS = ${libelf_ldflags}
533
534 # Whether GLX headers are available
535 HAVE_GLX = ${have_glx}
536
537 # Flags needed to compile and link against libGL
538 GL_CFLAGS = ${gl_cflags}
539 GL_LDFLAGS = ${gl_ldflags}
540
541 # Whether X11 headers and library are available
542 HAVE_X11 = ${have_x11}
543
544 # Flags needed to compile and link against libX11
545 X11_CLFLAGS = ${x11_cflags}
546 X11_LDFLAGS = ${x11_ldflags}
547
548 # Whether EGL headers are available
549 HAVE_EGL = ${have_egl}
550
551 # Flags needed to find EGL header files (EGL/egl.h)
552 EGL_CFLAGS = ${egl_cflags}
553 EGL_LDFLAGS = ${egl_ldflags}
554
555 # Whether GLESv2 headers and library are available
556 HAVE_GLESV2 = ${have_glesv2}
557
558 # Flags needed to compile and link against GLESv2
559 GLESV2_CFLAGS = ${glesv2_cflags}
560 GLESV2_LDFLAGS = ${glesv2_ldflags}
561
562 # Flags needed to have linker link only to necessary libraries
563 AS_NEEDED_LDFLAGS = ${as_needed_ldflags}
564 EOF
565
566 # construct config.h
567 cat > config.h <<EOF
568 /* Generated by configure. */
569
570 /* Relative path from ${BINDIR} to ${LIBDIR}/fips */
571 #define BINDIR_TO_LIBFIPSDIR "$(relative_path ${BINDIR} ${LIBDIR})/fips"
572 EOF