]> git.cworth.org Git - fips/blob - configure
configure: Tighten up the text on a couple of messages
[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 libtalloc... "
221 if pkg-config --exists talloc; then
222     printf "Yes.\n"
223     have_talloc=1
224     talloc_cflags=$(pkg-config --cflags talloc)
225     talloc_ldflags=$(pkg-config --libs talloc)
226 else
227     printf "No.\n"
228     have_talloc=0
229     talloc_cflags=
230     errors=$((errors + 1))
231 fi
232
233 printf "Checking for libelf... "
234 printf "#include <gelf.h>\nint main(void){return elf_version (EV_CURRENT);}\n" > elf-minimal.c
235 if ${CC} -o elf-minimal elf-minimal.c -lelf > /dev/null 2>&1
236 then
237     printf "Yes.\n"
238     have_libelf=1
239     libelf_cflags=
240     libelf_ldflags=-lelf
241 else
242     printf "No.\n"
243     have_libelf=0
244     libelf_cflags=
245     libelf_ldflags=
246     errors=$((errors + 1))
247 fi
248 rm -f elf-minimal elf-minimal.c
249
250 printf "Checking for GL/gl.h... "
251 have_gl=0
252 if pkg-config --exists gl; then
253     printf "Yes.\n"
254     have_gl=1
255     gl_cflags=$(pkg-config --cflags gl)
256 else
257     printf "#include <GL/gl.h>\nint main(void){return 0;}\n" > gl-minimal.c
258     if ${CC} -o gl-minimal gl-minimal.c > /dev/null 2>&1
259     then
260         printf "Yes.\n"
261         have_gl=1
262     else
263         printf "No.\n"
264         errors=$((errors + 1))
265     fi
266     rm -f gl-minimal gl-minimal.c
267 fi
268
269 printf "Checking for GL window-system-binding headers:\n"
270 have_gl_winsys=0
271
272 printf "    Checking for GL/glx.h... "
273 have_glx=No
274 printf "#include <GL/glx.h>\nint main(void){return 0;}\n" > glx-minimal.c
275 if ${CC} -o glx-minimal glx-minimal.c ${gl_cflags} > /dev/null 2>&1
276 then
277     printf "Yes.\n"
278     have_gl_winsys=1
279     have_glx=Yes
280 else
281     printf "No.\n"
282 fi
283 rm -f glx-minimal glx-minimal.c
284
285 printf "    Checking for GL/egl.h... "
286 have_egl=No
287 if pkg-config --exists egl; then
288     printf "Yes.\n"
289     have_egl=Yes
290     egl_cflags=$(pkg-config --cflags egl)
291 else
292     printf "#include <GL/egl.h>\nint main(void){return 0;}\n" > egl-minimal.c
293     if ${CC} -o egl-minimal egl-minimal.c ${gl_cflags} > /dev/null 2>&1
294     then
295         printf "Yes.\n"
296         have_gl_winsys=1
297         have_egl=1
298     else
299         printf "No.\n"
300     fi
301     rm -f egl-minimal egl-minimal.c
302 fi
303
304 if [ $have_gl_winsys -eq 0 ]; then
305     errors=$((errors + 1))
306 fi
307
308 if [ $errors -gt 0 ]; then
309     cat <<EOF
310
311 *** Error: The dependencies of ${PROJECT} could not be satisfied. You will
312 need to install the following packages before being able to compile
313 ${PROJECT}:
314
315 EOF
316     if [ $have_talloc -eq 0 ]; then
317         echo "  The talloc library (including development files such as headers)"
318         echo "  http://talloc.samba.org/"
319         echo
320     fi
321     if [ $have_libelf -eq 0 ]; then
322         echo "  The libelf library (including development files such as headers)"
323         echo "  http://http://sourceforge.net/projects/elftoolchain/"
324         echo
325     fi
326     if [ $have_gl -eq 0 ]; then
327         echo "  Open GL header files (GL/gl.h)"
328         echo "  http://www.mesa3d.org/"
329         echo
330     fi
331     if [ $have_gl_winsys -eq 0 ]; then
332         echo "  OpenGL window-system-bindings header files (GL/glx.h and/or GL/egl.h)"
333         echo "  http://www.mesa3d.org/"
334         echo
335     fi
336     cat <<EOF
337 With any luck, you're using a modern, package-based operating system
338 that has all of these packages available in the distribution. In that
339 case a simple command will install everything you need. For example:
340
341 On Debian and similar systems:
342
343         sudo apt-get install libtalloc-dev libelf-dev \\
344         libgl1-mesa-dev libgles2-mesa-dev
345
346 Or on Fedora and similar systems:
347
348         sudo yum install libtalloc-devel libelf-devel \\
349         mesa-libGL-devel mesa-libGLES-devel
350
351 On other systems, similar commands can be used, but the details of the
352 package names may be different.
353
354 When you have installed the necessary dependencies, you can run
355 configure again to ensure the packages can be found, or simply run
356 "make" to compile.
357
358 EOF
359     exit 1
360 fi
361
362 printf "int main(void){return 0;}\n" > minimal.c
363
364 WARN_CFLAGS=""
365 printf "Checking for available C compiler warning flags... "
366 for flag in -Wall -Wextra -Wmissing-declarations; do
367     if ${CC} $flag -o minimal minimal.c > /dev/null 2>&1
368     then
369         WARN_CFLAGS="${WARN_CFLAGS}${WARN_CFLAGS:+ }${flag}"
370     fi
371 done
372 printf "\n\t${WARN_CFLAGS}\n"
373
374 rm -f minimal minimal.c
375
376 cat <<EOF
377
378 All required packages were found.
379
380 The following OpenGL window-system bindings will be supported:
381
382         GLX: ${have_glx}
383         EGL: ${have_egl}
384
385 You may now run the following commands to compile and install ${PROJECT}:
386
387         make
388         sudo make install
389
390 EOF
391
392 # construct the Makefile.config
393 cat > Makefile.config <<EOF
394 # This Makefile.config was automatically generated by the ./configure
395 # script of ${PROJECT}. If the configure script identified anything
396 # incorrectly, then you can edit this file to try to correct things,
397 # but be warned that if configure is run again it will destroy your
398 # changes, (and this could happen by simply calling "make" if the
399 # configure script is updated).
400
401 # The top-level directory for the source, (the directory containing
402 # the configure script). This may be different than the build
403 # directory (the current directory at the time configure was run).
404 srcdir = ${srcdir}
405
406 configure_options = $@
407
408 # We use vpath directives (rather than the VPATH variable) since the
409 # VPATH variable matches targets as well as prerequisites, (which is
410 # not useful since then a target left-over from a srcdir build would
411 # cause a target to not be built in the non-srcdir build).
412 #
413 # Also, we don't use a single "vpath % \$(srcdir)" here because we
414 # don't want the vpath to trigger for our emacs lisp compilation,
415 # (unless we first find a way to convince emacs to build the .elc
416 # target in a directory other than the directory of the .el
417 # prerequisite). In the meantime, we're actually copying in the .el
418 # files, (which is quite ugly).
419 vpath %.c \$(srcdir)
420 vpath %.cc \$(srcdir)
421 vpath %.1 \$(srcdir)
422 vpath Makefile.% \$(srcdir)
423
424 # The C compiler to use
425 CC = ${CC}
426
427 # Default FLAGS for C compiler (can be overridden by user such as "make CFLAGS=-g")
428 CFLAGS = ${CFLAGS}
429
430 # Default FLAGS for the linker (can be overridden by user such as "make LDFLAGS=-znow")
431 LDFLAGS = ${LDFLAGS}
432
433 # Flags to enable warnings when using the C compiler
434 WARN_CFLAGS=${WARN_CFLAGS}
435
436 # The prefix to which ${PROJECT} should be installed
437 prefix = ${PREFIX}
438
439 # The directory to which executables should be installed
440 bindir = ${BINDIR:=\$(prefix)/bin}
441
442 # The directory to which libraries should be installed
443 libdir = ${LIBDIR:=\$(prefix)/lib}
444
445 # The directory to which man pages should be installed
446 mandir = ${MANDIR:=\$(prefix)/share/man}
447
448 # The directory to which read-only (configuration) files should be installed
449 sysconfdir = ${SYSCONFDIR:=\$(prefix)/etc}
450
451 # Flags needed to compile and link against talloc
452 TALLOC_CFLAGS = ${talloc_cflags}
453 TALLOC_LDFLAGS = ${talloc_ldflags}
454
455 # Flags needed to compile and link against libelf
456 LIBELF_CFLAGS = ${libelf_cflags}
457 LIBELF_LDFLAGS = ${libelf_ldflags}
458
459 # Whether GLX headers are available
460 HAVE_GLX = ${have_glx}
461
462 # Flags needed to find GL and GLX header files (GL/gl.h and GL/glx.h)
463 GL_CFLAGS = ${gl_cflags}
464
465 # Whether EGL headers are available
466 HAVE_EGL = ${have_egl}
467
468 # Flags needed to find EGL header files (EGL/egl.h)
469 EGL_CFLAGS = ${egl_cflags}
470
471 # Flags needed to have linker link only to necessary libraries
472 AS_NEEDED_LDFLAGS = ${as_needed_ldflags}
473
474 # Combined flags for compiling and linking against all of the above
475 CONFIGURE_CFLAGS = \$(TALLOC_CFLAGS) \$(LIBELF_CFLAGS) \$(GL_CFLAGS) \$(EGL_CFLAGS)
476 CONFIGURE_LDFLAGS = \$(TALLOC_LDFLAGS) \$(LIBELF_LDFLAGS)
477 EOF
478
479 # construct config.h
480 cat > config.h <<EOF
481 /* Generated by configure. */
482
483 /* Relative path from ${bindir} to ${libdir} */
484 #define BINDIR_TO_LIBFIPSDIR "$(relative_path ${BINDIR} ${LIBDIR})/fips"
485 EOF