]> Dogcows Code - chaz/yoink/blob - configure
need the configure script
[chaz/yoink] / configure
1 #!/bin/sh
2
3 #
4 # Yoink
5 # Execute this file to configure the build system.
6 #
7
8 PACKAGE="Yoink"
9 VERSION="0.1"
10 BUGREPORT="chaz@dogcows.com"
11
12
13 showhelp()
14 {
15 cat <<"END"
16
17 This script prepares Yoink for building on your system.
18 Usage: ./configure [OPTION]... [VAR=VALUE]...
19
20 Basic configuration:
21 -h, --help display this help and exit
22 --host=HOST cross-compile program to run on HOST
23
24 --prefix=DIR base directory to install program
25 --bindir=DIR directory to install executables
26 --libdir=DIR directory to install libraries
27 --datadir=DIR directory to install shared data files
28 --mandir=DIR directory to install manual pages
29
30 Program options:
31 --enable-debug include debugging symbols and code paths
32 --enable-double-precision use doubles instead of floats
33 --enable-profile compile in gprof profiling instructions
34 --enable-extra-warnings make the gcc compiler give more warnings
35 --enable-link-sh try to decrease the number of direct dependencies
36 --enable-clock_gettime use clock_gettime() instead of SDL
37 --enable-threads use threads for concurrency where appropriate
38 --enable-hotloading monitor assets and reload them when they change
39
40 --with-gtk use gtk2 modal dialogs
41 --with-qt4 use qt4 modal dialogs; overridden by --with-gtk
42
43 END
44 }
45
46 . "build/functions.sh"
47
48
49 #
50 # Perform a quick sanity check.
51 #
52
53 test -f configure -a -f Makefile || die <<"END"
54 You must `cd' to the project root directory where the Makefile resides.
55 END
56
57
58 #
59 # Define some default values.
60 #
61
62 CC=""
63 CXX=""
64 AR=""
65 RANLIB=""
66
67 CFLAGS="-g -O2"
68 CXXFLAGS="$CFLAGS"
69 LDFLAGS=""
70 LIBS=""
71
72 prefix='/usr/local'
73 bindir='$prefix/bin'
74 libdir='$prefix/lib'
75 datadir='$prefix/share/yoink'
76 mandir='$prefix/share/man'
77
78 host=$(./build/config.guess)
79 althost=$(./build/config.sub $host)
80 cross_compile="no"
81
82
83 #
84 # Parse the command-line options.
85 #
86
87 for opt in "$@"
88 do
89 case $opt in
90 -h|--help)
91 showhelp
92 exit 0
93 ;;
94
95 --host=*)
96 host=$(parse_argument host $opt)
97 cross_compile="yes"
98 ;;
99 --prefix=*)
100 prefix=$(parse_argument prefix $opt)
101 ;;
102 --bindir=*)
103 bindir=$(parse_argument bindir $opt)
104 ;;
105 --libdir=*)
106 libdir=$(parse_argument libdir $opt)
107 ;;
108 --datadir=*)
109 datadir=$(parse_argument datadir $opt)
110 ;;
111 --mandir=*)
112 mandir=$(parse_argument mandir $opt)
113 ;;
114
115 --enable-debug)
116 cflags="$cflags -O0 -Wall -Wno-uninitialized"
117 define "DEBUG"
118 ;;
119 --enable-double-precision)
120 define "USE_DOUBLE_PRECISION"
121 ;;
122 --enable-profile)
123 cflags="$cflags -pg"
124 define "PROFILING_ENABLED"
125 ;;
126 --enable-extra-warnings)
127 cflags="$cflags -Wextra -Wno-unused-parameter"
128 ;;
129 --enable-link-sh)
130 link_sh=yes
131 ;;
132 --enable-clock_gettime)
133 clock_gettime=yes
134 ;;
135 --enable-threads)
136 define "USE_THREADS"
137 ;;
138 --enable-hotloading)
139 define "USE_HOTLOADING"
140 ;;
141 --with-gtk)
142 gtk=yes
143 ;;
144 --with-qt4)
145 qt4=yes
146 ;;
147 *)
148 if echo "$opt" | grep -q '^[A-Za-z0-9_]*=.*'
149 then
150 export "$opt"
151 else
152 echo "warning: unknown option: $opt"
153 fi
154 ;;
155 esac
156 done
157
158
159 #
160 # Evaluate any dependent paths.
161 #
162
163 eval bindir="$bindir"
164 eval datadir="$datadir"
165 eval libdir="$libdir"
166 eval mandir="$mandir"
167
168 is_defined "DEBUG" || define "NDEBUG"
169
170 export PKG_CONFIG_PATH="$libdir/pkgconfig:$PKG_CONFIG_PATH"
171
172 define_string "YOINK_DATADIR" "$datadir"
173
174
175 #
176 # Determine the target platform.
177 #
178
179 case $host in
180 *mingw32*) HOST=win32 ;;
181 *netbsd*) HOST=netbsd ;;
182 esac
183
184
185 #
186 # Define the check functions.
187 #
188
189 # Run a command and return its exit code. If the third argument is given,
190 # stdin will be read and written to the specified file before the command
191 # is executed. If the command creates any files inside the current
192 # directory, they will be removed automatically.
193 # $1 The command to run.
194 # $2 The arguments to be passed to the command.
195 # $3 Optional filename where stdin will be written.
196 check_run_command()
197 {
198 tmpdir=$(mktemp -d "tmp-XXXXXXXX") || die "could not create temp directory"
199 cd $tmpdir || die "could not enter temp directory"
200
201 if test "x$3" != x
202 then
203 while read line
204 do
205 echo $line
206 done >$3
207 fi
208
209 saved_ifs=$IFS
210 IFS=:
211 for path in $PATH
212 do
213 if test -x "$path/$1"
214 then
215 eval "$1 $2" 2>&1 >/dev/null
216 exit_code=$?
217
218 cd ..
219 rm -rf $tmpdir
220 IFS=$saved_ifs
221 return $exit_code
222 fi
223 done
224
225 cd ..
226 rm -rf $tmpdir
227 IFS=$saved_ifs
228 return 1
229 }
230
231
232 #
233 # Do some common checks.
234 #
235
236 if test "x$cross_compile" = xno
237 then
238 # If we are not cross-compiling, we also want to consider tools without
239 # host prefixes.
240 extra_cc="gcc cc"
241 extra_cxx="g++ c++"
242 extra_ar="ar"
243 extra_ranlib="ranlib"
244 extra_windres="windres"
245 fi
246
247 for exe in $CC $host-gcc $host-cc $althost-gcc $althost-cc $extra_cc
248 do
249 if check_run_command "$exe" "test.c" "test.c" <<"END"
250 #include <stdio.h>
251 int main()
252 {
253 printf("Hello world!\n");
254 return 0;
255 }
256 END
257 then
258 CC="$exe"
259 break
260 fi
261 done
262
263 for exe in $CXX $host-g++ $host-c++ $althost-g++ $althost-c++ $extra_cxx
264 do
265 if check_run_command "$exe" "test.cpp" "test.cpp" <<"END"
266 #include <iostream>
267 int main()
268 {
269 std::cout << "Hello world!" << std::endl;
270 return 0;
271 }
272 END
273 then
274 CXX="$exe"
275 break
276 fi
277 done
278
279 for exe in $AR $host-ar $althost-ar $extra_ar
280 do
281 if check_run_command "$exe" "--version"
282 then
283 AR="$exe"
284 break
285 fi
286 done
287
288 for exe in $RANLIB $host-ranlib $althost-ranlib $extra_ranlib
289 do
290 if check_run_command "$exe" "--version"
291 then
292 RANLIB="$exe"
293 break
294 fi
295 done
296
297 if test x$HOST = xwin32
298 then
299 for exe in $WINDRES $host-windres $althost-windres $extra_windres
300 do
301 if check_run_command "$exe" "--version"
302 then
303 WINDRES="$exe"
304 break
305 fi
306 done
307 fi
308
309 if test "x$CC" = x -o "x$CXX" = x -o "x$AR" = x -o "x$RANLIB" = x
310 then
311 die <<END
312 A working version of one or more of these required tools is missing:
313 CC = $CC
314 CXX = $CXX
315 AR = $AR
316 RANLIB = $RANLIB
317 END
318 fi
319
320
321 #
322 # Check for the libraries we need.
323 #
324
325 deps="sdl gl glu libpng openal vorbisfile lua"
326
327 if test x$gtk = xyes
328 then
329 deps="$deps gtk+-2.0"
330 elif test x$qt4 = xyes
331 then
332 deps="$deps QtGui"
333 fi
334
335 pc_cflags=$(pkg-config --cflags $deps)
336 CFLAGS="$CFLAGS $pc_cflags"
337 CXXFLAGS="$CXXFLAGS $pc_cflags"
338
339 pc_ldflags=$(pkg-config --libs-only-L $deps)
340 LDFLAGS="$LDFLAGS $pc_ldflags"
341
342 pc_libs=$(pkg-config --libs-only-l $deps)
343 LIBS="$LIBS $pc_libs"
344
345 # Windows sockets are in libws2_32.
346 if test x$HOST = xwin32
347 then
348 LIBS="$LIBS -lws2_32"
349 EXEEXT=".exe"
350 fi
351
352
353 #
354 # Find the game resources to install.
355 #
356
357 #data_files=$(echo $(find . -name "*.lua" \
358 #-o -name "*.ogg" \
359 #-o -name "*.png" \
360 #-o -name "yoinkrc"))
361 # FIXME: doesn't work yet
362
363
364 #
365 # Define version components needed by src/yoink.rc.
366 #
367
368 vmajor=$(echo $VERSION | cut -d. -f1)
369 vminor=$(echo $VERSION | cut -d. -f2)
370 vrevis=$(echo $VERSION | cut -d. -f3)
371
372 define "VERSION_MAJOR" "${vmajor:-0}"
373 define "VERSION_MINOR" "${vminor:-0}"
374 define "VERSION_REVISION" "${vrevis:-0}"
375
376
377 #
378 # Determine and define the git revision.
379 #
380
381 if githead=$(git log -n1 --date=short --pretty=format:"%h (%ad)")
382 then
383 define_string "YOINK_GITHEAD" "$githead"
384 fi
385
386
387 #
388 # Finalize the compiler flags, linker flags, and library list.
389 #
390
391 define_string "PACKAGE" "$PACKAGE"
392 define_string "PACKAGE_NAME" "$PACKAGE"
393 define_string "VERSION" "$VERSION"
394 define_string "PACKAGE_VERSION" "$VERSION"
395 define_string "PACKAGE_STRING" "$PACKAGE $VERSION"
396 define_string "PACKAGE_BUGREPORT" "$BUGREPORT"
397
398 CFLAGS=$(echo $CFLAGS $cflags $defines)
399 CXXFLAGS=$(echo $CXXFLAGS $cflags $defines)
400 LDFLAGS=$(echo $LDFLAGS)
401 LIBS=$(echo $LIBS)
402
403
404 #
405 # All done; output the configuration file.
406 #
407
408 cat >config.mk <<END
409
410 HOST = $HOST
411
412 CC = $CC
413 CXX = $CXX
414 AR = $AR
415 RANLIB = $RANLIB
416 WINDRES = $WINDRES
417
418 CFLAGS = $CFLAGS
419 CXXFLAGS = $CXXFLAGS
420 LDFLAGS = $LDFLAGS
421 LIBS = $LIBS
422
423 prefix = $prefix
424 bindir = $bindir
425 datadir = $datadir
426 libdir = $libdir
427 mandir = $mandir
428
429 EXEEXT = $EXEEXT
430
431 END
432
433
434 echo ""
435 echo " Configuration complete! Review your configuration in \`config.mk'":
436 echo ""
437 cat config.mk | grep -e "^prefix" \
438 -e "^datadir" \
439 -e "^CXX" \
440 -e "^CXXFLAGS" \
441 -e "^LDFLAGS" \
442 -e "^LIBS"
443 echo ""
444 echo " To finish the installation, type:"
445 echo " make"
446 echo " make install"
447 echo ""
448
This page took 0.055181 seconds and 5 git commands to generate.