|
1 #!/bin/sh |
|
2 |
|
3 # create temporary directory |
|
4 TEMP_DIR=".tmp-`uname -n`" |
|
5 rm -Rf "$TEMP_DIR" |
|
6 if mkdir -p "$TEMP_DIR"; then |
|
7 : |
|
8 else |
|
9 echo "Cannot create tmp dir $TEMP_DIR" |
|
10 echo "Abort" |
|
11 exit 1 |
|
12 fi |
|
13 touch "$TEMP_DIR/options" |
|
14 touch "$TEMP_DIR/features" |
|
15 |
|
16 # define standard variables |
|
17 PREFIX=/usr |
|
18 EPREFIX= |
|
19 BINDIR= |
|
20 SBINDIR= |
|
21 LIBDIR= |
|
22 LIBEXECDIR= |
|
23 DATADIR= |
|
24 SYSCONFDIR= |
|
25 SHAREDSTATEDIR= |
|
26 LOCALSTATEDIR= |
|
27 INCLUDEDIR= |
|
28 INFODIR= |
|
29 MANDIR= |
|
30 |
|
31 # custom variables |
|
32 |
|
33 # features |
|
34 |
|
35 # clean abort |
|
36 abort_configure() |
|
37 { |
|
38 rm -Rf "$TEMP_DIR" |
|
39 exit 1 |
|
40 } |
|
41 |
|
42 # help text |
|
43 printhelp() |
|
44 { |
|
45 echo "Usage: $0 [OPTIONS]..." |
|
46 cat << __EOF__ |
|
47 Installation directories: |
|
48 --prefix=PREFIX path prefix for architecture-independent files |
|
49 [/usr] |
|
50 --exec-prefix=EPREFIX path prefix for architecture-dependent files |
|
51 [PREFIX] |
|
52 |
|
53 --bindir=DIR user executables [EPREFIX/bin] |
|
54 --sbindir=DIR system admin executables [EPREFIX/sbin] |
|
55 --libexecdir=DIR program executables [EPREFIX/libexec] |
|
56 --sysconfdir=DIR system configuration files [PREFIX/etc] |
|
57 --sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com] |
|
58 --localstatedir=DIR modifiable single-machine data [PREFIX/var] |
|
59 --libdir=DIR object code libraries [EPREFIX/lib] |
|
60 --includedir=DIR C header files [PREFIX/include] |
|
61 --datarootdir=DIR read-only arch.-independent data root [PREFIX/share] |
|
62 --datadir=DIR read-only architecture-independent data [DATAROOTDIR] |
|
63 --infodir=DIR info documentation [DATAROOTDIR/info] |
|
64 --mandir=DIR man documentation [DATAROOTDIR/man] |
|
65 |
|
66 __EOF__ |
|
67 } |
|
68 |
|
69 # |
|
70 # parse arguments |
|
71 # |
|
72 BUILD_TYPE="default" |
|
73 for ARG in "$@" |
|
74 do |
|
75 case "$ARG" in |
|
76 "--prefix="*) PREFIX=${ARG#--prefix=} ;; |
|
77 "--exec-prefix="*) EPREFIX=${ARG#--exec-prefix=} ;; |
|
78 "--bindir="*) BINDIR=${ARG#----bindir=} ;; |
|
79 "--sbindir="*) SBINDIR=${ARG#--sbindir=} ;; |
|
80 "--libdir="*) LIBDIR=${ARG#--libdir=} ;; |
|
81 "--libexecdir="*) LIBEXECDIR=${ARG#--libexecdir=} ;; |
|
82 "--datadir="*) DATADIR=${ARG#--datadir=} ;; |
|
83 "--sysconfdir="*) SYSCONFDIR=${ARG#--sysconfdir=} ;; |
|
84 "--sharedstatedir="*) SHAREDSTATEDIR=${ARG#--sharedstatedir=} ;; |
|
85 "--localstatedir="*) LOCALSTATEDIR=${ARG#--localstatedir=} ;; |
|
86 "--includedir="*) INCLUDEDIR=${ARG#--includedir=} ;; |
|
87 "--infodir="*) INFODIR=${ARG#--infodir=} ;; |
|
88 "--mandir"*) MANDIR=${ARG#--mandir} ;; |
|
89 "--help"*) printhelp; abort_configure ;; |
|
90 "--debug") BUILD_TYPE="debug" ;; |
|
91 "--release") BUILD_TYPE="release" ;; |
|
92 "-"*) echo "unknown option: $ARG"; abort_configure ;; |
|
93 esac |
|
94 done |
|
95 |
|
96 |
|
97 # set dir variables |
|
98 : ${EPREFIX:="$PREFIX"} |
|
99 : ${BINDIR:="$EPREFIX/bin"} |
|
100 : ${SBINDIR:="$EPREFIX/sbin"} |
|
101 : ${LIBDIR:="$EPREFIX/lib"} |
|
102 : ${LIBEXECDIR:="$EPREFIX/libexec"} |
|
103 : ${DATADIR:="$PREFIX/share"} |
|
104 : ${SYSCONFDIR:="$PREFIX/etc"} |
|
105 : ${SHAREDSTATEDIR:="$PREFIX/com"} |
|
106 : ${LOCALSTATEDIR:="$PREFIX/var"} |
|
107 : ${INCLUDEDIR:="$PREFIX/include"} |
|
108 : ${INFODIR:="$PREFIX/info"} |
|
109 : ${MANDIR:="$PREFIX/man"} |
|
110 |
|
111 # Test for availability of pkg-config |
|
112 PKG_CONFIG=`command -v pkg-config` |
|
113 : ${PKG_CONFIG:="false"} |
|
114 |
|
115 # Simple uname based platform detection |
|
116 # $PLATFORM is used for platform dependent dependency selection |
|
117 OS=`uname -s` |
|
118 OS_VERSION=`uname -r` |
|
119 printf "detect platform... " |
|
120 if [ "$OS" = "SunOS" ]; then |
|
121 PLATFORM="solaris sunos unix svr4" |
|
122 fi |
|
123 if [ "$OS" = "Linux" ]; then |
|
124 PLATFORM="linux unix" |
|
125 fi |
|
126 if [ "$OS" = "FreeBSD" ]; then |
|
127 PLATFORM="freebsd bsd unix" |
|
128 fi |
|
129 if [ "$OS" = "Darwin" ]; then |
|
130 PLATFORM="macos osx bsd unix" |
|
131 fi |
|
132 if echo "$OS" | grep -i "MINGW" > /dev/null; then |
|
133 PLATFORM="windows mingw" |
|
134 fi |
|
135 : ${PLATFORM:="unix"} |
|
136 |
|
137 PLATFORM_NAME=`echo "$PLATFORM" | cut -f1 -d' ' -` |
|
138 echo "$PLATFORM_NAME" |
|
139 |
|
140 isplatform() |
|
141 { |
|
142 for p in $PLATFORM |
|
143 do |
|
144 if [ "$p" = "$1" ]; then |
|
145 return 0 |
|
146 fi |
|
147 done |
|
148 return 1 |
|
149 } |
|
150 notisplatform() |
|
151 { |
|
152 for p in $PLATFORM |
|
153 do |
|
154 if [ "$p" = "$1" ]; then |
|
155 return 1 |
|
156 fi |
|
157 done |
|
158 return 0 |
|
159 } |
|
160 |
|
161 |
|
162 # generate vars.mk |
|
163 cat > "$TEMP_DIR/vars.mk" << __EOF__ |
|
164 PREFIX="$PREFIX" |
|
165 EPREFIX="$EPREFIX" |
|
166 BINDIR="$BINDIR" |
|
167 SBINDIR="$SBINDIR" |
|
168 LIBDIR="$LIBDIR" |
|
169 LIBEXECDIR="$LIBEXECDIR" |
|
170 DATADIR="$DATADIR" |
|
171 SYSCONFDIR="$SYSCONFDIR" |
|
172 SHAREDSTATEDIR="$SHAREDSTATEDIR" |
|
173 LOCALSTATEDIR="$LOCALSTATEDIR" |
|
174 INCLUDEDIR="$INCLUDEDIR" |
|
175 INFODIR="$INFODIR" |
|
176 MANDIR="$MANDIR" |
|
177 __EOF__ |
|
178 sort -u -o "$TEMP_DIR/vars.mk" "$TEMP_DIR/vars.mk" |
|
179 |
|
180 |
|
181 # toolchain detection utilities |
|
182 . make/toolchain.sh |
|
183 |
|
184 # |
|
185 # DEPENDENCIES |
|
186 # |
|
187 |
|
188 # check languages |
|
189 lang_c= |
|
190 lang_cpp= |
|
191 if detect_c_compiler ; then |
|
192 lang_c=1 |
|
193 fi |
|
194 |
|
195 # create buffer for make variables required by dependencies |
|
196 echo > "$TEMP_DIR/make.mk" |
|
197 |
|
198 test_pkg_config() |
|
199 { |
|
200 if "$PKG_CONFIG" --exists "$1" ; then : |
|
201 else return 1 ; fi |
|
202 if [ -z "$2" ] || "$PKG_CONFIG" --atleast-version="$2" "$1" ; then : |
|
203 else return 1 ; fi |
|
204 if [ -z "$3" ] || "$PKG_CONFIG" --exact-version="$3" "$1" ; then : |
|
205 else return 1 ; fi |
|
206 if [ -z "$4" ] || "$PKG_CONFIG" --max-version="$4" "$1" ; then : |
|
207 else return 1 ; fi |
|
208 return 0 |
|
209 } |
|
210 |
|
211 dependency_error_sdl2_ttf() |
|
212 { |
|
213 printf "checking for sdl2_ttf... " |
|
214 # dependency sdl2_ttf |
|
215 while true |
|
216 do |
|
217 if [ -z "$PKG_CONFIG" ]; then |
|
218 break |
|
219 fi |
|
220 if test_pkg_config "SDL2_ttf" "" "" "" ; then |
|
221 TEMP_CFLAGS="$TEMP_CFLAGS `"$PKG_CONFIG" --cflags SDL2_ttf`" |
|
222 TEMP_LDFLAGS="$TEMP_LDFLAGS `"$PKG_CONFIG" --libs SDL2_ttf`" |
|
223 else |
|
224 break |
|
225 fi |
|
226 echo yes |
|
227 return 1 |
|
228 done |
|
229 |
|
230 echo no |
|
231 return 0 |
|
232 } |
|
233 dependency_error_sdl2() |
|
234 { |
|
235 printf "checking for sdl2... " |
|
236 # dependency sdl2 |
|
237 while true |
|
238 do |
|
239 if [ -z "$PKG_CONFIG" ]; then |
|
240 break |
|
241 fi |
|
242 if test_pkg_config "sdl2" "" "" "" ; then |
|
243 TEMP_CFLAGS="$TEMP_CFLAGS `"$PKG_CONFIG" --cflags sdl2`" |
|
244 TEMP_LDFLAGS="$TEMP_LDFLAGS `"$PKG_CONFIG" --libs sdl2`" |
|
245 else |
|
246 break |
|
247 fi |
|
248 echo yes |
|
249 return 1 |
|
250 done |
|
251 |
|
252 echo no |
|
253 return 0 |
|
254 } |
|
255 dependency_error_glew() |
|
256 { |
|
257 printf "checking for glew... " |
|
258 # dependency glew |
|
259 while true |
|
260 do |
|
261 if [ -z "$PKG_CONFIG" ]; then |
|
262 break |
|
263 fi |
|
264 if test_pkg_config "glew" "" "" "" ; then |
|
265 TEMP_CFLAGS="$TEMP_CFLAGS `"$PKG_CONFIG" --cflags glew`" |
|
266 TEMP_LDFLAGS="$TEMP_LDFLAGS `"$PKG_CONFIG" --libs glew`" |
|
267 else |
|
268 break |
|
269 fi |
|
270 echo yes |
|
271 return 1 |
|
272 done |
|
273 |
|
274 echo no |
|
275 return 0 |
|
276 } |
|
277 dependency_error_ucx() |
|
278 { |
|
279 printf "checking for ucx... " |
|
280 # dependency ucx |
|
281 while true |
|
282 do |
|
283 if check_lib ucx cx/common.h > /dev/null ; then |
|
284 : |
|
285 else |
|
286 break |
|
287 fi |
|
288 TEMP_LDFLAGS="$TEMP_LDFLAGS -lucx" |
|
289 echo yes |
|
290 return 1 |
|
291 done |
|
292 |
|
293 echo no |
|
294 return 0 |
|
295 } |
|
296 |
|
297 |
|
298 |
|
299 |
|
300 # start collecting dependency information |
|
301 echo > "$TEMP_DIR/flags.mk" |
|
302 |
|
303 DEPENDENCIES_FAILED= |
|
304 ERROR=0 |
|
305 # unnamed dependencies |
|
306 TEMP_CFLAGS= |
|
307 TEMP_CXXFLAGS= |
|
308 TEMP_LDFLAGS= |
|
309 while true |
|
310 do |
|
311 while true |
|
312 do |
|
313 if [ -z "$lang_c" ] ; then |
|
314 ERROR=1 |
|
315 break |
|
316 fi |
|
317 |
|
318 break |
|
319 done |
|
320 break |
|
321 done |
|
322 |
|
323 # add general dependency flags to flags.mk |
|
324 echo "# general flags" >> "$TEMP_DIR/flags.mk" |
|
325 if [ -n "${TEMP_CFLAGS}" -a -n "$lang_c" ]; then |
|
326 echo "CFLAGS += $TEMP_CFLAGS" >> "$TEMP_DIR/flags.mk" |
|
327 fi |
|
328 if [ -n "${TEMP_CXXFLAGS}" -a -n "$lang_cpp" ]; then |
|
329 echo "CXXFLAGS += $TEMP_CXXFLAGS" >> "$TEMP_DIR/flags.mk" |
|
330 fi |
|
331 if [ -n "${TEMP_LDFLAGS}" ]; then |
|
332 echo "LDFLAGS += $TEMP_LDFLAGS" >> "$TEMP_DIR/flags.mk" |
|
333 fi |
|
334 |
|
335 # |
|
336 # OPTION VALUES |
|
337 # |
|
338 |
|
339 # |
|
340 # TARGETS |
|
341 # |
|
342 |
|
343 echo >> "$TEMP_DIR/flags.mk" |
|
344 echo "configuring target: default" |
|
345 echo "# flags for target default" >> "$TEMP_DIR/flags.mk" |
|
346 TEMP_CFLAGS= |
|
347 TEMP_CXXFLAGS= |
|
348 TEMP_LDFLAGS= |
|
349 |
|
350 if dependency_error_sdl2_ttf; then |
|
351 DEPENDENCIES_FAILED="$DEPENDENCIES_FAILED sdl2_ttf " |
|
352 ERROR=1 |
|
353 fi |
|
354 if dependency_error_sdl2; then |
|
355 DEPENDENCIES_FAILED="$DEPENDENCIES_FAILED sdl2 " |
|
356 ERROR=1 |
|
357 fi |
|
358 if dependency_error_glew; then |
|
359 DEPENDENCIES_FAILED="$DEPENDENCIES_FAILED glew " |
|
360 ERROR=1 |
|
361 fi |
|
362 if dependency_error_ucx; then |
|
363 DEPENDENCIES_FAILED="$DEPENDENCIES_FAILED ucx " |
|
364 ERROR=1 |
|
365 fi |
|
366 |
|
367 # Features |
|
368 |
|
369 |
|
370 if [ -n "${TEMP_CFLAGS}" -a -n "$lang_c" ]; then |
|
371 echo "CFLAGS += $TEMP_CFLAGS" >> "$TEMP_DIR/flags.mk" |
|
372 fi |
|
373 if [ -n "${TEMP_CXXFLAGS}" -a -n "$lang_cpp" ]; then |
|
374 echo "CXXFLAGS += $TEMP_CXXFLAGS" >> "$TEMP_DIR/flags.mk" |
|
375 fi |
|
376 if [ "$BUILD_TYPE" = "debug" ]; then |
|
377 if [ -n "$lang_c" ]; then |
|
378 echo 'CFLAGS += ${DEBUG_CC_FLAGS}' >> "$TEMP_DIR/flags.mk" |
|
379 fi |
|
380 if [ -n "$lang_cpp" ]; then |
|
381 echo 'CXXFLAGS += ${DEBUG_CXX_FLAGS}' >> "$TEMP_DIR/flags.mk" |
|
382 fi |
|
383 fi |
|
384 if [ "$BUILD_TYPE" = "release" ]; then |
|
385 if [ -n "$lang_c" ]; then |
|
386 echo 'CFLAGS += ${RELEASE_CC_FLAGS}' >> "$TEMP_DIR/flags.mk" |
|
387 fi |
|
388 if [ -n "$lang_cpp" ]; then |
|
389 echo 'CXXFLAGS += ${RELEASE_CXX_FLAGS}' >> "$TEMP_DIR/flags.mk" |
|
390 fi |
|
391 fi |
|
392 if [ -n "${TEMP_LDFLAGS}" ]; then |
|
393 echo "LDFLAGS += $TEMP_LDFLAGS" >> "$TEMP_DIR/flags.mk" |
|
394 fi |
|
395 |
|
396 |
|
397 # final result |
|
398 if [ $ERROR -ne 0 ]; then |
|
399 echo |
|
400 echo "Error: Unresolved dependencies" |
|
401 echo "$DEPENDENCIES_FAILED" |
|
402 abort_configure |
|
403 fi |
|
404 |
|
405 echo "configure finished" |
|
406 echo |
|
407 echo "Build Config:" |
|
408 echo " PREFIX: $PREFIX" |
|
409 echo " TOOLCHAIN: $TOOLCHAIN_NAME" |
|
410 echo |
|
411 |
|
412 # generate the config.mk file |
|
413 cat > "$TEMP_DIR/config.mk" << __EOF__ |
|
414 # |
|
415 # config.mk generated by configure |
|
416 # |
|
417 |
|
418 __EOF__ |
|
419 write_toolchain_defaults "$TEMP_DIR/toolchain.mk" |
|
420 cat "$TEMP_DIR/vars.mk" "$TEMP_DIR/toolchain.mk" "$TEMP_DIR/flags.mk" "$TEMP_DIR/make.mk" > config.mk |
|
421 rm -Rf "$TEMP_DIR" |
|
422 |
|
423 |