]> git.cworth.org Git - fips/blob - configure
Add the ability to execute a program.
[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 LIBDIR=
46
47 usage ()
48 {
49     cat <<EOF
50 Usage: ./configure [options]...
51
52 This script configures ${PROJECT} to build on your system.
53
54 It verifies that dependencies are available, determines flags needed
55 to compile and link against various required libraries, and identifies
56 whether various system functions can be used or if locally-provided
57 replacements will be built instead.
58
59 Finally, it allows you to control various aspects of the build and
60 installation process.
61
62 First, some common variables can specified via environment variables:
63
64         CC              The C compiler to use
65         CFLAGS          Flags to pass to the C compiler
66         LDFLAGS         Flags to pass when linking
67
68 Each of these values can further be controlled by specifying them
69 later on the "make" command line.
70
71 Additionally, various options can be specified on the configure
72 command line.
73
74         --prefix=PREFIX Install files in PREFIX [$PREFIX]
75
76 By default, "make install" will install the resulting program to
77 $PREFIX/bin, documentation to $PREFIX/man, etc. You can
78 specify an installation prefix other than $PREFIX using
79 --prefix, for instance:
80
81         ./configure --prefix=\$HOME
82
83 Fine tuning of some installation directories is available:
84
85         --libdir=DIR            Install libraries to DIR [PREFIX/lib]
86         --includedir=DIR        Install header files to DIR [PREFIX/include]
87         --mandir=DIR            Install man pages to DIR [PREFIX/share/man]
88         --sysconfdir=DIR        Read-only single-machine data [PREFIX/etc]
89
90 Additional options are accepted for compatibility with other
91 configure-script calling conventions, but don't do anything yet:
92
93         --build=<cpu>-<vendor>-<os>     Currently ignored
94         --host=<cpu>-<vendor>-<os>      Currently ignored
95         --infodir=DIR                   Currently ignored
96         --datadir=DIR                   Currently ignored
97         --localstatedir=DIR             Currently ignored
98         --libexecdir=DIR                Currently ignored
99         --disable-maintainer-mode       Currently ignored
100         --disable-dependency-tracking   Currently ignored
101
102 EOF
103 }
104
105 # Parse command-line options
106 for option; do
107     if [ "${option}" = '--help' ] ; then
108         usage
109         exit 0
110     elif [ "${option%%=*}" = '--prefix' ] ; then
111         PREFIX="${option#*=}"
112     elif [ "${option%%=*}" = '--libdir' ] ; then
113         LIBDIR="${option#*=}"
114     elif [ "${option%%=*}" = '--includedir' ] ; then
115         INCLUDEDIR="${option#*=}"
116     elif [ "${option%%=*}" = '--mandir' ] ; then
117         MANDIR="${option#*=}"
118     elif [ "${option%%=*}" = '--sysconfdir' ] ; then
119         SYSCONFDIR="${option#*=}"
120     elif [ "${option%%=*}" = '--build' ] ; then
121         true
122     elif [ "${option%%=*}" = '--host' ] ; then
123         true
124     elif [ "${option%%=*}" = '--infodir' ] ; then
125         true
126     elif [ "${option%%=*}" = '--datadir' ] ; then
127         true
128     elif [ "${option%%=*}" = '--localstatedir' ] ; then
129         true
130     elif [ "${option%%=*}" = '--libexecdir' ] ; then
131         true
132     elif [ "${option}" = '--disable-maintainer-mode' ] ; then
133         true
134     elif [ "${option}" = '--disable-dependency-tracking' ] ; then
135         true
136     else
137         echo "Unrecognized option: ${option}"
138         echo "See:"
139         echo "  $0 --help"
140         echo ""
141         exit 1
142     fi
143 done
144
145 # We set this value early, (rather than just while printing the
146 # Makefile.config file later like most values), because we need to
147 # actually investigate this value compared to the ldconfig_paths value
148 # below.
149 if [ -z "$LIBDIR" ] ; then
150     libdir_expanded="${PREFIX}/lib"
151 else
152     # very non-general variable expansion
153     libdir_expanded=`echo "$LIBDIR" | sed "s|\\${prefix}|${PREFIX}|g; s|\\$prefix/|${PREFIX}/|; s|//*|/|g"`
154 fi
155
156 cat <<EOF
157 Welcome to ${PROJECT}, ${PROJECT_BLURB}
158
159 We hope that the process of building and installing ${PROJECT} is quick
160 and smooth.
161
162 If anything goes wrong in the configure process, you can override any
163 decisions it makes by manually editing the Makefile.config file that
164 it creates. Also please do as much as you can to figure out what could
165 be different on your machine compared to those of the ${PROJECT}
166 developers. Then, please email those details to the ${PROJECT} developers so
167 that they can hopefully make future versions of ${PROJECT} easier for you to
168 use.
169
170 We'll now investigate your system to verify that all required
171 dependencies are available:
172
173 EOF
174
175 errors=0
176
177 if pkg-config --version > /dev/null 2>&1; then
178     have_pkg_config=1
179 else
180     have_pkg_config=0
181 fi
182
183 printf "Checking for talloc development files... "
184 if pkg-config --exists talloc; then
185     printf "Yes.\n"
186     have_talloc=1
187     talloc_cflags=$(pkg-config --cflags talloc)
188     talloc_ldflags=$(pkg-config --libs talloc)
189 else
190     printf "No.\n"
191     have_talloc=0
192     talloc_cflags=
193     errors=$((errors + 1))
194 fi
195
196 libdir_in_ldconfig=0
197
198 printf "Checking which platform we are on... "
199 uname=`uname`
200 if [ $uname = "Darwin" ] ; then
201     printf "Mac OS X.\n"
202     platform=MACOSX
203     linker_resolves_library_dependencies=0
204 elif [ $uname = "SunOS" ] ; then
205     printf "Solaris.\n"
206     platform=SOLARIS
207     linker_resolves_library_dependencies=0
208 elif [ $uname = "FreeBSD" ] ; then
209     printf "FreeBSD.\n"
210     platform=FREEBSD
211     linker_resolves_library_dependencies=0
212 elif [ $uname = "OpenBSD" ] ; then
213     printf "OpenBSD.\n"
214     platform=OPENBSD
215     linker_resolves_library_dependencies=0
216 elif [ $uname = "Linux" ] || [ $uname = "GNU" ] ; then
217     printf "$uname\n"
218     platform="$uname"
219     linker_resolves_library_dependencies=1
220
221     printf "Checking for $libdir_expanded in ldconfig... "
222     ldconfig_paths=$(/sbin/ldconfig -N -X -v 2>/dev/null | sed -n -e 's,^\(/.*\):\( (.*)\)\?$,\1,p')
223     # Separate ldconfig_paths only on newline (not on any potential
224     # embedded space characters in any filenames). Note, we use a
225     # literal newline in the source here rather than something like:
226     #
227     #   IFS=$(printf '\n')
228     #
229     # because the shell's command substitution deletes any trailing newlines.
230     IFS="
231 "
232     for path in $ldconfig_paths; do
233         if [ "$path" = "$libdir_expanded" ]; then
234             libdir_in_ldconfig=1
235         fi
236     done
237     IFS=$DEFAULT_IFS
238     if [ "$libdir_in_ldconfig" = '0' ]; then
239         printf "No (will set RPATH)\n"
240     else
241         printf "Yes\n"
242     fi
243 else
244     printf "Unknown.\n"
245     cat <<EOF
246
247 *** Warning: Unknown platform. ${PROJECT} might or might not build correctly.
248
249 EOF
250 fi
251
252 if [ $errors -gt 0 ]; then
253     cat <<EOF
254
255 *** Error: The dependencies of ${PROJECT} could not be satisfied. You will
256 need to install the following packages before being able to compile
257 ${PROJECT}:
258
259 EOF
260     if [ $have_talloc -eq 0 ]; then
261         echo "  The talloc library (including development files such as headers)"
262         echo "  http://talloc.samba.org/"
263         echo
264     fi
265     cat <<EOF
266 With any luck, you're using a modern, package-based operating system
267 that has all of these packages available in the distribution. In that
268 case a simple command will install everything you need. For example:
269
270 On Debian and similar systems:
271
272         sudo apt-get install libtalloc-dev
273
274 Or on Fedora and similar systems:
275
276         sudo yum install libtalloc-devel
277
278 On other systems, similar commands can be used, but the details of the
279 package names may be different.
280
281 EOF
282     if [ $have_pkg_config -eq 0 ]; then
283 cat <<EOF
284 Note: the pkg-config program is not available. This configure script
285 uses pkg-config to find the compilation flags required to link against
286 the various libraries needed by ${PROJECT}. It's possible you simply need
287 to install pkg-config with a command such as:
288
289         sudo apt-get install pkg-config
290 Or:
291         sudo yum install pkgconfig
292
293 But if pkg-config is not available for your system, then you will need
294 to modify the configure script to manually set the cflags and ldflags
295 variables to the correct values to link against each library in each
296 case that pkg-config could not be used to determine those values.
297
298 EOF
299     fi
300 cat <<EOF
301 When you have installed the necessary dependencies, you can run
302 configure again to ensure the packages can be found, or simply run
303 "make" to compile.
304
305 EOF
306     exit 1
307 fi
308
309 printf "int main(void){return 0;}\n" > minimal.c
310
311 WARN_CFLAGS=""
312 printf "Checking for available C compiler warning flags... "
313 for flag in -Wall -Wextra -Wmissing-declarations; do
314     if ${CC} $flag -o minimal minimal.c > /dev/null 2>&1
315     then
316         WARN_CFLAGS="${WARN_CFLAGS}${WARN_CFLAGS:+ }${flag}"
317     fi
318 done
319 printf "\n\t${WARN_CFLAGS}\n"
320
321 rm -f minimal minimal.c
322
323 cat <<EOF
324
325 All required packages were found. You may now run the following
326 commands to compile and install ${PROJECT}:
327
328         make
329         sudo make install
330
331 EOF
332
333 # construct the Makefile.config
334 cat > Makefile.config <<EOF
335 # This Makefile.config was automatically generated by the ./configure
336 # script of ${PROJECT}. If the configure script identified anything
337 # incorrectly, then you can edit this file to try to correct things,
338 # but be warned that if configure is run again it will destroy your
339 # changes, (and this could happen by simply calling "make" if the
340 # configure script is updated).
341
342 # The top-level directory for the source, (the directory containing
343 # the configure script). This may be different than the build
344 # directory (the current directory at the time configure was run).
345 srcdir = ${srcdir}
346
347 configure_options = $@
348
349 # We use vpath directives (rather than the VPATH variable) since the
350 # VPATH variable matches targets as well as prerequisites, (which is
351 # not useful since then a target left-over from a srcdir build would
352 # cause a target to not be built in the non-srcdir build).
353 #
354 # Also, we don't use a single "vpath % \$(srcdir)" here because we
355 # don't want the vpath to trigger for our emacs lisp compilation,
356 # (unless we first find a way to convince emacs to build the .elc
357 # target in a directory other than the directory of the .el
358 # prerequisite). In the meantime, we're actually copying in the .el
359 # files, (which is quite ugly).
360 vpath %.c \$(srcdir)
361 vpath %.cc \$(srcdir)
362 vpath %.1 \$(srcdir)
363 vpath Makefile.% \$(srcdir)
364
365 # The C compiler to use
366 CC = ${CC}
367
368 # Default FLAGS for C compiler (can be overridden by user such as "make CFLAGS=-g")
369 CFLAGS = ${CFLAGS}
370
371 # Default FLAGS for the linker (can be overridden by user such as "make LDFLAGS=-znow")
372 LDFLAGS = ${LDFLAGS} -ldl
373
374 # Flags to enable warnings when using the C compiler
375 WARN_CFLAGS=${WARN_CFLAGS}
376
377 # The prefix to which ${PROJECT} should be installed
378 # Note: If you change this value here, be sure to ensure that the
379 # LIBDIR_IN_LDCONFIG value below is still set correctly.
380 prefix = ${PREFIX}
381
382 # The directory to which libraries should be installed
383 # Note: If you change this value here, be sure to ensure that the
384 # LIBDIR_IN_LDCONFIG value below is still set correctly.
385 libdir = ${LIBDIR:=\$(prefix)/lib}
386
387 # Whether libdir is in a path configured into ldconfig
388 LIBDIR_IN_LDCONFIG = ${libdir_in_ldconfig}
389
390 # The directory to which header files should be installed
391 includedir = ${INCLUDEDIR:=\$(prefix)/include}
392
393 # The directory to which man pages should be installed
394 mandir = ${MANDIR:=\$(prefix)/share/man}
395
396 # The directory to which read-only (configuration) files should be installed
397 sysconfdir = ${SYSCONFDIR:=\$(prefix)/etc}
398
399 # Supported platforms (so far) are: LINUX, MACOSX, SOLARIS, FREEBSD, OPENBSD
400 PLATFORM = ${platform}
401
402 # Whether the linker will automatically resolve the dependency of one
403 # library on another (if not, then linking a binary requires linking
404 # directly against both)
405 LINKER_RESOLVES_LIBRARY_DEPENDENCIES = ${linker_resolves_library_dependencies}
406
407 # Flags needed to compile and link against talloc
408 TALLOC_CFLAGS = ${talloc_cflags}
409 TALLOC_LDFLAGS = ${talloc_ldflags}
410
411 # Flags needed to have linker link only to necessary libraries
412 AS_NEEDED_LDFLAGS = ${as_needed_ldflags}
413
414 # Combined flags for compiling and linking against all of the above
415 CONFIGURE_CFLAGS = \$(TALLOC_CFLAGS)
416 CONFIGURE_LDFLAGS = \$(TALLOC_LDFLAGS)
417 EOF