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