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