Fri, 06 Oct 2023 21:21:10 +0200
initial commit
.hgignore | file | annotate | diff | comparison | revisions | |
DEPENDENCIES | file | annotate | diff | comparison | revisions | |
LICENSE | file | annotate | diff | comparison | revisions | |
Makefile | file | annotate | diff | comparison | revisions | |
configure | file | annotate | diff | comparison | revisions | |
make/cc.mk | file | annotate | diff | comparison | revisions | |
make/configure.vm | file | annotate | diff | comparison | revisions | |
make/project.xml | file | annotate | diff | comparison | revisions | |
make/toolchain.sh | file | annotate | diff | comparison | revisions | |
make/uwproj.xsd | file | annotate | diff | comparison | revisions | |
src/Makefile | file | annotate | diff | comparison | revisions | |
src/ascension/core.h | file | annotate | diff | comparison | revisions | |
src/ascension/utils.h | file | annotate | diff | comparison | revisions | |
src/core.c | file | annotate | diff | comparison | revisions | |
test/Makefile | file | annotate | diff | comparison | revisions | |
test/sandbox.c | file | annotate | diff | comparison | revisions |
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/.hgignore Fri Oct 06 21:21:10 2023 +0200 1.3 @@ -0,0 +1,4 @@ 1.4 +.idea/ 1.5 +nbproject/ 1.6 +build/ 1.7 +config.mk
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/DEPENDENCIES Fri Oct 06 21:21:10 2023 +0200 2.3 @@ -0,0 +1,3 @@ 2.4 +Fedora: dnf install SDL2-devel SDL2_ttf-devel glew-devel 2.5 +Arch: pacman -Sy sdl2 sdl2_ttf glew pkgconf 2.6 +FreeBSD: pkg install sdl2 sdl2_ttf glew pkgconf
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 3.2 +++ b/LICENSE Fri Oct 06 21:21:10 2023 +0200 3.3 @@ -0,0 +1,23 @@ 3.4 +Copyright 2023 Mike Becker. All rights reserved. 3.5 + 3.6 +Redistribution and use in source and binary forms, with or without 3.7 +modification, are permitted provided that the following conditions are met: 3.8 + 3.9 + 1. Redistributions of source code must retain the above copyright 3.10 + notice, this list of conditions and the following disclaimer. 3.11 + 3.12 + 2. Redistributions in binary form must reproduce the above copyright 3.13 + notice, this list of conditions and the following disclaimer in the 3.14 + documentation and/or other materials provided with the distribution. 3.15 + 3.16 +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 3.17 +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 3.18 +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 3.19 +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 3.20 +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 3.21 +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 3.22 +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 3.23 +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 3.24 +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 3.25 +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 3.26 +POSSIBILITY OF SUCH DAMAGE.
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 4.2 +++ b/Makefile Fri Oct 06 21:21:10 2023 +0200 4.3 @@ -0,0 +1,51 @@ 4.4 +# Copyright 2023 Mike Becker. All rights reserved. 4.5 +# 4.6 +# Redistribution and use in source and binary forms, with or without 4.7 +# modification, are permitted provided that the following conditions are met: 4.8 +# 4.9 +# 1. Redistributions of source code must retain the above copyright 4.10 +# notice, this list of conditions and the following disclaimer. 4.11 +# 4.12 +# 2. Redistributions in binary form must reproduce the above copyright 4.13 +# notice, this list of conditions and the following disclaimer in the 4.14 +# documentation and/or other materials provided with the distribution. 4.15 +# 4.16 +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 4.17 +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 4.18 +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 4.19 +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 4.20 +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 4.21 +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 4.22 +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 4.23 +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 4.24 +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 4.25 +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 4.26 +# POSSIBILITY OF SUCH DAMAGE. 4.27 +# 4.28 + 4.29 +all: build/test/sandbox 4.30 + 4.31 +build/test/sandbox: build/test build/lib/libascension.a config.mk FORCE 4.32 + @cd test && $(MAKE) 4.33 + 4.34 +build/lib/libascension.a: build/lib config.mk FORCE 4.35 + @cd src && $(MAKE) 4.36 + 4.37 +build/test: 4.38 + mkdir -p build/test 4.39 + 4.40 +build/lib: 4.41 + mkdir -p build/lib 4.42 + 4.43 +clean: 4.44 + rm -f -R build 4.45 + 4.46 +install: 4.47 + @echo "Not supported at the moment" 4.48 + 4.49 +config.mk: 4.50 + @echo "create config" 4.51 + @./configure 4.52 + 4.53 +FORCE: 4.54 +
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 5.2 +++ b/configure Fri Oct 06 21:21:10 2023 +0200 5.3 @@ -0,0 +1,423 @@ 5.4 +#!/bin/sh 5.5 + 5.6 +# create temporary directory 5.7 +TEMP_DIR=".tmp-`uname -n`" 5.8 +rm -Rf "$TEMP_DIR" 5.9 +if mkdir -p "$TEMP_DIR"; then 5.10 + : 5.11 +else 5.12 + echo "Cannot create tmp dir $TEMP_DIR" 5.13 + echo "Abort" 5.14 + exit 1 5.15 +fi 5.16 +touch "$TEMP_DIR/options" 5.17 +touch "$TEMP_DIR/features" 5.18 + 5.19 +# define standard variables 5.20 +PREFIX=/usr 5.21 +EPREFIX= 5.22 +BINDIR= 5.23 +SBINDIR= 5.24 +LIBDIR= 5.25 +LIBEXECDIR= 5.26 +DATADIR= 5.27 +SYSCONFDIR= 5.28 +SHAREDSTATEDIR= 5.29 +LOCALSTATEDIR= 5.30 +INCLUDEDIR= 5.31 +INFODIR= 5.32 +MANDIR= 5.33 + 5.34 +# custom variables 5.35 + 5.36 +# features 5.37 + 5.38 +# clean abort 5.39 +abort_configure() 5.40 +{ 5.41 + rm -Rf "$TEMP_DIR" 5.42 + exit 1 5.43 +} 5.44 + 5.45 +# help text 5.46 +printhelp() 5.47 +{ 5.48 + echo "Usage: $0 [OPTIONS]..." 5.49 + cat << __EOF__ 5.50 +Installation directories: 5.51 + --prefix=PREFIX path prefix for architecture-independent files 5.52 + [/usr] 5.53 + --exec-prefix=EPREFIX path prefix for architecture-dependent files 5.54 + [PREFIX] 5.55 + 5.56 + --bindir=DIR user executables [EPREFIX/bin] 5.57 + --sbindir=DIR system admin executables [EPREFIX/sbin] 5.58 + --libexecdir=DIR program executables [EPREFIX/libexec] 5.59 + --sysconfdir=DIR system configuration files [PREFIX/etc] 5.60 + --sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com] 5.61 + --localstatedir=DIR modifiable single-machine data [PREFIX/var] 5.62 + --libdir=DIR object code libraries [EPREFIX/lib] 5.63 + --includedir=DIR C header files [PREFIX/include] 5.64 + --datarootdir=DIR read-only arch.-independent data root [PREFIX/share] 5.65 + --datadir=DIR read-only architecture-independent data [DATAROOTDIR] 5.66 + --infodir=DIR info documentation [DATAROOTDIR/info] 5.67 + --mandir=DIR man documentation [DATAROOTDIR/man] 5.68 + 5.69 +__EOF__ 5.70 +} 5.71 + 5.72 +# 5.73 +# parse arguments 5.74 +# 5.75 +BUILD_TYPE="default" 5.76 +for ARG in "$@" 5.77 +do 5.78 + case "$ARG" in 5.79 + "--prefix="*) PREFIX=${ARG#--prefix=} ;; 5.80 + "--exec-prefix="*) EPREFIX=${ARG#--exec-prefix=} ;; 5.81 + "--bindir="*) BINDIR=${ARG#----bindir=} ;; 5.82 + "--sbindir="*) SBINDIR=${ARG#--sbindir=} ;; 5.83 + "--libdir="*) LIBDIR=${ARG#--libdir=} ;; 5.84 + "--libexecdir="*) LIBEXECDIR=${ARG#--libexecdir=} ;; 5.85 + "--datadir="*) DATADIR=${ARG#--datadir=} ;; 5.86 + "--sysconfdir="*) SYSCONFDIR=${ARG#--sysconfdir=} ;; 5.87 + "--sharedstatedir="*) SHAREDSTATEDIR=${ARG#--sharedstatedir=} ;; 5.88 + "--localstatedir="*) LOCALSTATEDIR=${ARG#--localstatedir=} ;; 5.89 + "--includedir="*) INCLUDEDIR=${ARG#--includedir=} ;; 5.90 + "--infodir="*) INFODIR=${ARG#--infodir=} ;; 5.91 + "--mandir"*) MANDIR=${ARG#--mandir} ;; 5.92 + "--help"*) printhelp; abort_configure ;; 5.93 + "--debug") BUILD_TYPE="debug" ;; 5.94 + "--release") BUILD_TYPE="release" ;; 5.95 + "-"*) echo "unknown option: $ARG"; abort_configure ;; 5.96 + esac 5.97 +done 5.98 + 5.99 + 5.100 +# set dir variables 5.101 +: ${EPREFIX:="$PREFIX"} 5.102 +: ${BINDIR:="$EPREFIX/bin"} 5.103 +: ${SBINDIR:="$EPREFIX/sbin"} 5.104 +: ${LIBDIR:="$EPREFIX/lib"} 5.105 +: ${LIBEXECDIR:="$EPREFIX/libexec"} 5.106 +: ${DATADIR:="$PREFIX/share"} 5.107 +: ${SYSCONFDIR:="$PREFIX/etc"} 5.108 +: ${SHAREDSTATEDIR:="$PREFIX/com"} 5.109 +: ${LOCALSTATEDIR:="$PREFIX/var"} 5.110 +: ${INCLUDEDIR:="$PREFIX/include"} 5.111 +: ${INFODIR:="$PREFIX/info"} 5.112 +: ${MANDIR:="$PREFIX/man"} 5.113 + 5.114 +# Test for availability of pkg-config 5.115 +PKG_CONFIG=`command -v pkg-config` 5.116 +: ${PKG_CONFIG:="false"} 5.117 + 5.118 +# Simple uname based platform detection 5.119 +# $PLATFORM is used for platform dependent dependency selection 5.120 +OS=`uname -s` 5.121 +OS_VERSION=`uname -r` 5.122 +printf "detect platform... " 5.123 +if [ "$OS" = "SunOS" ]; then 5.124 + PLATFORM="solaris sunos unix svr4" 5.125 +fi 5.126 +if [ "$OS" = "Linux" ]; then 5.127 + PLATFORM="linux unix" 5.128 +fi 5.129 +if [ "$OS" = "FreeBSD" ]; then 5.130 + PLATFORM="freebsd bsd unix" 5.131 +fi 5.132 +if [ "$OS" = "Darwin" ]; then 5.133 + PLATFORM="macos osx bsd unix" 5.134 +fi 5.135 +if echo "$OS" | grep -i "MINGW" > /dev/null; then 5.136 + PLATFORM="windows mingw" 5.137 +fi 5.138 +: ${PLATFORM:="unix"} 5.139 + 5.140 +PLATFORM_NAME=`echo "$PLATFORM" | cut -f1 -d' ' -` 5.141 +echo "$PLATFORM_NAME" 5.142 + 5.143 +isplatform() 5.144 +{ 5.145 + for p in $PLATFORM 5.146 + do 5.147 + if [ "$p" = "$1" ]; then 5.148 + return 0 5.149 + fi 5.150 + done 5.151 + return 1 5.152 +} 5.153 +notisplatform() 5.154 +{ 5.155 + for p in $PLATFORM 5.156 + do 5.157 + if [ "$p" = "$1" ]; then 5.158 + return 1 5.159 + fi 5.160 + done 5.161 + return 0 5.162 +} 5.163 + 5.164 + 5.165 +# generate vars.mk 5.166 +cat > "$TEMP_DIR/vars.mk" << __EOF__ 5.167 +PREFIX="$PREFIX" 5.168 +EPREFIX="$EPREFIX" 5.169 +BINDIR="$BINDIR" 5.170 +SBINDIR="$SBINDIR" 5.171 +LIBDIR="$LIBDIR" 5.172 +LIBEXECDIR="$LIBEXECDIR" 5.173 +DATADIR="$DATADIR" 5.174 +SYSCONFDIR="$SYSCONFDIR" 5.175 +SHAREDSTATEDIR="$SHAREDSTATEDIR" 5.176 +LOCALSTATEDIR="$LOCALSTATEDIR" 5.177 +INCLUDEDIR="$INCLUDEDIR" 5.178 +INFODIR="$INFODIR" 5.179 +MANDIR="$MANDIR" 5.180 +__EOF__ 5.181 +sort -u -o "$TEMP_DIR/vars.mk" "$TEMP_DIR/vars.mk" 5.182 + 5.183 + 5.184 +# toolchain detection utilities 5.185 +. make/toolchain.sh 5.186 + 5.187 +# 5.188 +# DEPENDENCIES 5.189 +# 5.190 + 5.191 +# check languages 5.192 +lang_c= 5.193 +lang_cpp= 5.194 +if detect_c_compiler ; then 5.195 + lang_c=1 5.196 +fi 5.197 + 5.198 +# create buffer for make variables required by dependencies 5.199 +echo > "$TEMP_DIR/make.mk" 5.200 + 5.201 +test_pkg_config() 5.202 +{ 5.203 + if "$PKG_CONFIG" --exists "$1" ; then : 5.204 + else return 1 ; fi 5.205 + if [ -z "$2" ] || "$PKG_CONFIG" --atleast-version="$2" "$1" ; then : 5.206 + else return 1 ; fi 5.207 + if [ -z "$3" ] || "$PKG_CONFIG" --exact-version="$3" "$1" ; then : 5.208 + else return 1 ; fi 5.209 + if [ -z "$4" ] || "$PKG_CONFIG" --max-version="$4" "$1" ; then : 5.210 + else return 1 ; fi 5.211 + return 0 5.212 +} 5.213 + 5.214 +dependency_error_sdl2_ttf() 5.215 +{ 5.216 + printf "checking for sdl2_ttf... " 5.217 + # dependency sdl2_ttf 5.218 + while true 5.219 + do 5.220 + if [ -z "$PKG_CONFIG" ]; then 5.221 + break 5.222 + fi 5.223 + if test_pkg_config "SDL2_ttf" "" "" "" ; then 5.224 + TEMP_CFLAGS="$TEMP_CFLAGS `"$PKG_CONFIG" --cflags SDL2_ttf`" 5.225 + TEMP_LDFLAGS="$TEMP_LDFLAGS `"$PKG_CONFIG" --libs SDL2_ttf`" 5.226 + else 5.227 + break 5.228 + fi 5.229 + echo yes 5.230 + return 1 5.231 + done 5.232 + 5.233 + echo no 5.234 + return 0 5.235 +} 5.236 +dependency_error_sdl2() 5.237 +{ 5.238 + printf "checking for sdl2... " 5.239 + # dependency sdl2 5.240 + while true 5.241 + do 5.242 + if [ -z "$PKG_CONFIG" ]; then 5.243 + break 5.244 + fi 5.245 + if test_pkg_config "sdl2" "" "" "" ; then 5.246 + TEMP_CFLAGS="$TEMP_CFLAGS `"$PKG_CONFIG" --cflags sdl2`" 5.247 + TEMP_LDFLAGS="$TEMP_LDFLAGS `"$PKG_CONFIG" --libs sdl2`" 5.248 + else 5.249 + break 5.250 + fi 5.251 + echo yes 5.252 + return 1 5.253 + done 5.254 + 5.255 + echo no 5.256 + return 0 5.257 +} 5.258 +dependency_error_glew() 5.259 +{ 5.260 + printf "checking for glew... " 5.261 + # dependency glew 5.262 + while true 5.263 + do 5.264 + if [ -z "$PKG_CONFIG" ]; then 5.265 + break 5.266 + fi 5.267 + if test_pkg_config "glew" "" "" "" ; then 5.268 + TEMP_CFLAGS="$TEMP_CFLAGS `"$PKG_CONFIG" --cflags glew`" 5.269 + TEMP_LDFLAGS="$TEMP_LDFLAGS `"$PKG_CONFIG" --libs glew`" 5.270 + else 5.271 + break 5.272 + fi 5.273 + echo yes 5.274 + return 1 5.275 + done 5.276 + 5.277 + echo no 5.278 + return 0 5.279 +} 5.280 +dependency_error_ucx() 5.281 +{ 5.282 + printf "checking for ucx... " 5.283 + # dependency ucx 5.284 + while true 5.285 + do 5.286 + if check_lib ucx cx/common.h > /dev/null ; then 5.287 + : 5.288 + else 5.289 + break 5.290 + fi 5.291 + TEMP_LDFLAGS="$TEMP_LDFLAGS -lucx" 5.292 + echo yes 5.293 + return 1 5.294 + done 5.295 + 5.296 + echo no 5.297 + return 0 5.298 +} 5.299 + 5.300 + 5.301 + 5.302 + 5.303 +# start collecting dependency information 5.304 +echo > "$TEMP_DIR/flags.mk" 5.305 + 5.306 +DEPENDENCIES_FAILED= 5.307 +ERROR=0 5.308 +# unnamed dependencies 5.309 +TEMP_CFLAGS= 5.310 +TEMP_CXXFLAGS= 5.311 +TEMP_LDFLAGS= 5.312 +while true 5.313 +do 5.314 + while true 5.315 + do 5.316 + if [ -z "$lang_c" ] ; then 5.317 + ERROR=1 5.318 + break 5.319 + fi 5.320 + 5.321 + break 5.322 + done 5.323 + break 5.324 +done 5.325 + 5.326 +# add general dependency flags to flags.mk 5.327 +echo "# general flags" >> "$TEMP_DIR/flags.mk" 5.328 +if [ -n "${TEMP_CFLAGS}" -a -n "$lang_c" ]; then 5.329 + echo "CFLAGS += $TEMP_CFLAGS" >> "$TEMP_DIR/flags.mk" 5.330 +fi 5.331 +if [ -n "${TEMP_CXXFLAGS}" -a -n "$lang_cpp" ]; then 5.332 + echo "CXXFLAGS += $TEMP_CXXFLAGS" >> "$TEMP_DIR/flags.mk" 5.333 +fi 5.334 +if [ -n "${TEMP_LDFLAGS}" ]; then 5.335 + echo "LDFLAGS += $TEMP_LDFLAGS" >> "$TEMP_DIR/flags.mk" 5.336 +fi 5.337 + 5.338 +# 5.339 +# OPTION VALUES 5.340 +# 5.341 + 5.342 +# 5.343 +# TARGETS 5.344 +# 5.345 + 5.346 +echo >> "$TEMP_DIR/flags.mk" 5.347 +echo "configuring target: default" 5.348 +echo "# flags for target default" >> "$TEMP_DIR/flags.mk" 5.349 +TEMP_CFLAGS= 5.350 +TEMP_CXXFLAGS= 5.351 +TEMP_LDFLAGS= 5.352 + 5.353 +if dependency_error_sdl2_ttf; then 5.354 + DEPENDENCIES_FAILED="$DEPENDENCIES_FAILED sdl2_ttf " 5.355 + ERROR=1 5.356 +fi 5.357 +if dependency_error_sdl2; then 5.358 + DEPENDENCIES_FAILED="$DEPENDENCIES_FAILED sdl2 " 5.359 + ERROR=1 5.360 +fi 5.361 +if dependency_error_glew; then 5.362 + DEPENDENCIES_FAILED="$DEPENDENCIES_FAILED glew " 5.363 + ERROR=1 5.364 +fi 5.365 +if dependency_error_ucx; then 5.366 + DEPENDENCIES_FAILED="$DEPENDENCIES_FAILED ucx " 5.367 + ERROR=1 5.368 +fi 5.369 + 5.370 +# Features 5.371 + 5.372 + 5.373 +if [ -n "${TEMP_CFLAGS}" -a -n "$lang_c" ]; then 5.374 + echo "CFLAGS += $TEMP_CFLAGS" >> "$TEMP_DIR/flags.mk" 5.375 +fi 5.376 +if [ -n "${TEMP_CXXFLAGS}" -a -n "$lang_cpp" ]; then 5.377 + echo "CXXFLAGS += $TEMP_CXXFLAGS" >> "$TEMP_DIR/flags.mk" 5.378 +fi 5.379 +if [ "$BUILD_TYPE" = "debug" ]; then 5.380 + if [ -n "$lang_c" ]; then 5.381 + echo 'CFLAGS += ${DEBUG_CC_FLAGS}' >> "$TEMP_DIR/flags.mk" 5.382 + fi 5.383 + if [ -n "$lang_cpp" ]; then 5.384 + echo 'CXXFLAGS += ${DEBUG_CXX_FLAGS}' >> "$TEMP_DIR/flags.mk" 5.385 + fi 5.386 +fi 5.387 +if [ "$BUILD_TYPE" = "release" ]; then 5.388 + if [ -n "$lang_c" ]; then 5.389 + echo 'CFLAGS += ${RELEASE_CC_FLAGS}' >> "$TEMP_DIR/flags.mk" 5.390 + fi 5.391 + if [ -n "$lang_cpp" ]; then 5.392 + echo 'CXXFLAGS += ${RELEASE_CXX_FLAGS}' >> "$TEMP_DIR/flags.mk" 5.393 + fi 5.394 +fi 5.395 +if [ -n "${TEMP_LDFLAGS}" ]; then 5.396 + echo "LDFLAGS += $TEMP_LDFLAGS" >> "$TEMP_DIR/flags.mk" 5.397 +fi 5.398 + 5.399 + 5.400 +# final result 5.401 +if [ $ERROR -ne 0 ]; then 5.402 + echo 5.403 + echo "Error: Unresolved dependencies" 5.404 + echo "$DEPENDENCIES_FAILED" 5.405 + abort_configure 5.406 +fi 5.407 + 5.408 +echo "configure finished" 5.409 +echo 5.410 +echo "Build Config:" 5.411 +echo " PREFIX: $PREFIX" 5.412 +echo " TOOLCHAIN: $TOOLCHAIN_NAME" 5.413 +echo 5.414 + 5.415 +# generate the config.mk file 5.416 +cat > "$TEMP_DIR/config.mk" << __EOF__ 5.417 +# 5.418 +# config.mk generated by configure 5.419 +# 5.420 + 5.421 +__EOF__ 5.422 +write_toolchain_defaults "$TEMP_DIR/toolchain.mk" 5.423 +cat "$TEMP_DIR/vars.mk" "$TEMP_DIR/toolchain.mk" "$TEMP_DIR/flags.mk" "$TEMP_DIR/make.mk" > config.mk 5.424 +rm -Rf "$TEMP_DIR" 5.425 + 5.426 +
6.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 6.2 +++ b/make/cc.mk Fri Oct 06 21:21:10 2023 +0200 6.3 @@ -0,0 +1,11 @@ 6.4 +# 6.5 +# cc toolchain config 6.6 +# 6.7 + 6.8 +CFLAGS = 6.9 +DEBUG_CC_FLAGS = -g 6.10 +RELEASE_CC_FLAGS = -O3 -DNDEBUG 6.11 +LDFLAGS = 6.12 + 6.13 +SHLIB_CFLAGS = -fPIC 6.14 +SHLIB_LDFLAGS = -shared 6.15 \ No newline at end of file
7.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 7.2 +++ b/make/configure.vm Fri Oct 06 21:21:10 2023 +0200 7.3 @@ -0,0 +1,609 @@ 7.4 +#!/bin/sh 7.5 + 7.6 +# create temporary directory 7.7 +TEMP_DIR=".tmp-`uname -n`" 7.8 +rm -Rf "$TEMP_DIR" 7.9 +if mkdir -p "$TEMP_DIR"; then 7.10 + : 7.11 +else 7.12 + echo "Cannot create tmp dir $TEMP_DIR" 7.13 + echo "Abort" 7.14 + exit 1 7.15 +fi 7.16 +touch "$TEMP_DIR/options" 7.17 +touch "$TEMP_DIR/features" 7.18 + 7.19 +# define standard variables 7.20 +PREFIX=/usr 7.21 +EPREFIX= 7.22 +BINDIR= 7.23 +SBINDIR= 7.24 +LIBDIR= 7.25 +LIBEXECDIR= 7.26 +DATADIR= 7.27 +SYSCONFDIR= 7.28 +SHAREDSTATEDIR= 7.29 +LOCALSTATEDIR= 7.30 +INCLUDEDIR= 7.31 +INFODIR= 7.32 +MANDIR= 7.33 + 7.34 +# custom variables 7.35 +#foreach( $var in $vars ) 7.36 +#if( $var.exec ) 7.37 +${var.varName}=`${var.value}` 7.38 +#else 7.39 +${var.varName}="${var.value}" 7.40 +#end 7.41 +#end 7.42 + 7.43 +# features 7.44 +#foreach( $feature in $features ) 7.45 +#if( ${feature.auto} ) 7.46 +${feature.varName}=auto 7.47 +#end 7.48 +#end 7.49 + 7.50 +# clean abort 7.51 +abort_configure() 7.52 +{ 7.53 + rm -Rf "$TEMP_DIR" 7.54 + exit 1 7.55 +} 7.56 + 7.57 +# help text 7.58 +printhelp() 7.59 +{ 7.60 + echo "Usage: $0 [OPTIONS]..." 7.61 + cat << __EOF__ 7.62 +Installation directories: 7.63 + --prefix=PREFIX path prefix for architecture-independent files 7.64 + [/usr] 7.65 + --exec-prefix=EPREFIX path prefix for architecture-dependent files 7.66 + [PREFIX] 7.67 + 7.68 + --bindir=DIR user executables [EPREFIX/bin] 7.69 + --sbindir=DIR system admin executables [EPREFIX/sbin] 7.70 + --libexecdir=DIR program executables [EPREFIX/libexec] 7.71 + --sysconfdir=DIR system configuration files [PREFIX/etc] 7.72 + --sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com] 7.73 + --localstatedir=DIR modifiable single-machine data [PREFIX/var] 7.74 + --libdir=DIR object code libraries [EPREFIX/lib] 7.75 + --includedir=DIR C header files [PREFIX/include] 7.76 + --datarootdir=DIR read-only arch.-independent data root [PREFIX/share] 7.77 + --datadir=DIR read-only architecture-independent data [DATAROOTDIR] 7.78 + --infodir=DIR info documentation [DATAROOTDIR/info] 7.79 + --mandir=DIR man documentation [DATAROOTDIR/man] 7.80 + 7.81 +#if( $options.size() > 0 ) 7.82 +Options: 7.83 + --debug add extra compile flags for debug builds 7.84 + --release add extra compile flags for release builds 7.85 +#foreach( $opt in $options ) 7.86 + --${opt.argument}=${opt.valuesString} 7.87 +#end 7.88 + 7.89 +#end 7.90 +#if( $features.size() > 0 ) 7.91 +Optional Features: 7.92 +#foreach( $feature in $features ) 7.93 +#if( $feature.auto ) 7.94 + --disable-${feature.arg} 7.95 +#else 7.96 + --enable-${feature.arg} 7.97 +#end 7.98 +#end 7.99 + 7.100 +#end 7.101 +__EOF__ 7.102 +} 7.103 + 7.104 +# 7.105 +# parse arguments 7.106 +# 7.107 +BUILD_TYPE="default" 7.108 +#set( $D = '$' ) 7.109 +for ARG in "$@" 7.110 +do 7.111 + case "$ARG" in 7.112 + "--prefix="*) PREFIX=${D}{ARG#--prefix=} ;; 7.113 + "--exec-prefix="*) EPREFIX=${D}{ARG#--exec-prefix=} ;; 7.114 + "--bindir="*) BINDIR=${D}{ARG#----bindir=} ;; 7.115 + "--sbindir="*) SBINDIR=${D}{ARG#--sbindir=} ;; 7.116 + "--libdir="*) LIBDIR=${D}{ARG#--libdir=} ;; 7.117 + "--libexecdir="*) LIBEXECDIR=${D}{ARG#--libexecdir=} ;; 7.118 + "--datadir="*) DATADIR=${D}{ARG#--datadir=} ;; 7.119 + "--sysconfdir="*) SYSCONFDIR=${D}{ARG#--sysconfdir=} ;; 7.120 + "--sharedstatedir="*) SHAREDSTATEDIR=${D}{ARG#--sharedstatedir=} ;; 7.121 + "--localstatedir="*) LOCALSTATEDIR=${D}{ARG#--localstatedir=} ;; 7.122 + "--includedir="*) INCLUDEDIR=${D}{ARG#--includedir=} ;; 7.123 + "--infodir="*) INFODIR=${D}{ARG#--infodir=} ;; 7.124 + "--mandir"*) MANDIR=${D}{ARG#--mandir} ;; 7.125 + "--help"*) printhelp; abort_configure ;; 7.126 + "--debug") BUILD_TYPE="debug" ;; 7.127 + "--release") BUILD_TYPE="release" ;; 7.128 + #foreach( $opt in $options ) 7.129 + "--${opt.argument}="*) ${opt.varName}=${D}{ARG#--${opt.argument}=} ;; 7.130 + #end 7.131 + #foreach( $feature in $features ) 7.132 + "--enable-${feature.arg}") ${feature.varName}=on ;; 7.133 + "--disable-${feature.arg}") unset ${feature.varName} ;; 7.134 + #end 7.135 + "-"*) echo "unknown option: $ARG"; abort_configure ;; 7.136 + esac 7.137 +done 7.138 + 7.139 +## Begin unparsed content. ** 7.140 +#[[ 7.141 +# set dir variables 7.142 +: ${EPREFIX:="$PREFIX"} 7.143 +: ${BINDIR:="$EPREFIX/bin"} 7.144 +: ${SBINDIR:="$EPREFIX/sbin"} 7.145 +: ${LIBDIR:="$EPREFIX/lib"} 7.146 +: ${LIBEXECDIR:="$EPREFIX/libexec"} 7.147 +: ${DATADIR:="$PREFIX/share"} 7.148 +: ${SYSCONFDIR:="$PREFIX/etc"} 7.149 +: ${SHAREDSTATEDIR:="$PREFIX/com"} 7.150 +: ${LOCALSTATEDIR:="$PREFIX/var"} 7.151 +: ${INCLUDEDIR:="$PREFIX/include"} 7.152 +: ${INFODIR:="$PREFIX/info"} 7.153 +: ${MANDIR:="$PREFIX/man"} 7.154 + 7.155 +# Test for availability of pkg-config 7.156 +PKG_CONFIG=`command -v pkg-config` 7.157 +: ${PKG_CONFIG:="false"} 7.158 + 7.159 +# Simple uname based platform detection 7.160 +# $PLATFORM is used for platform dependent dependency selection 7.161 +OS=`uname -s` 7.162 +OS_VERSION=`uname -r` 7.163 +printf "detect platform... " 7.164 +if [ "$OS" = "SunOS" ]; then 7.165 + PLATFORM="solaris sunos unix svr4" 7.166 +fi 7.167 +if [ "$OS" = "Linux" ]; then 7.168 + PLATFORM="linux unix" 7.169 +fi 7.170 +if [ "$OS" = "FreeBSD" ]; then 7.171 + PLATFORM="freebsd bsd unix" 7.172 +fi 7.173 +if [ "$OS" = "Darwin" ]; then 7.174 + PLATFORM="macos osx bsd unix" 7.175 +fi 7.176 +if echo "$OS" | grep -i "MINGW" > /dev/null; then 7.177 + PLATFORM="windows mingw" 7.178 +fi 7.179 +: ${PLATFORM:="unix"} 7.180 + 7.181 +PLATFORM_NAME=`echo "$PLATFORM" | cut -f1 -d' ' -` 7.182 +echo "$PLATFORM_NAME" 7.183 + 7.184 +isplatform() 7.185 +{ 7.186 + for p in $PLATFORM 7.187 + do 7.188 + if [ "$p" = "$1" ]; then 7.189 + return 0 7.190 + fi 7.191 + done 7.192 + return 1 7.193 +} 7.194 +notisplatform() 7.195 +{ 7.196 + for p in $PLATFORM 7.197 + do 7.198 + if [ "$p" = "$1" ]; then 7.199 + return 1 7.200 + fi 7.201 + done 7.202 + return 0 7.203 +} 7.204 +]]# 7.205 +## End of unparsed content ** 7.206 + 7.207 +# generate vars.mk 7.208 +cat > "$TEMP_DIR/vars.mk" << __EOF__ 7.209 +PREFIX="$PREFIX" 7.210 +EPREFIX="$EPREFIX" 7.211 +BINDIR="$BINDIR" 7.212 +SBINDIR="$SBINDIR" 7.213 +LIBDIR="$LIBDIR" 7.214 +LIBEXECDIR="$LIBEXECDIR" 7.215 +DATADIR="$DATADIR" 7.216 +SYSCONFDIR="$SYSCONFDIR" 7.217 +SHAREDSTATEDIR="$SHAREDSTATEDIR" 7.218 +LOCALSTATEDIR="$LOCALSTATEDIR" 7.219 +INCLUDEDIR="$INCLUDEDIR" 7.220 +INFODIR="$INFODIR" 7.221 +MANDIR="$MANDIR" 7.222 +#foreach( $var in $vars ) 7.223 +${var.varName}="${D}${var.varName}" 7.224 +#end 7.225 +__EOF__ 7.226 +sort -u -o "$TEMP_DIR/vars.mk" "$TEMP_DIR/vars.mk" 7.227 + 7.228 + 7.229 +# toolchain detection utilities 7.230 +. make/toolchain.sh 7.231 + 7.232 +# 7.233 +# DEPENDENCIES 7.234 +# 7.235 + 7.236 +# check languages 7.237 +lang_c= 7.238 +lang_cpp= 7.239 +#foreach( $lang in $languages ) 7.240 +if detect_${lang}_compiler ; then 7.241 + lang_${lang}=1 7.242 +fi 7.243 +#end 7.244 + 7.245 +# create buffer for make variables required by dependencies 7.246 +echo > "$TEMP_DIR/make.mk" 7.247 + 7.248 +test_pkg_config() 7.249 +{ 7.250 + if "$PKG_CONFIG" --exists "$1" ; then : 7.251 + else return 1 ; fi 7.252 + if [ -z "$2" ] || "$PKG_CONFIG" --atleast-version="$2" "$1" ; then : 7.253 + else return 1 ; fi 7.254 + if [ -z "$3" ] || "$PKG_CONFIG" --exact-version="$3" "$1" ; then : 7.255 + else return 1 ; fi 7.256 + if [ -z "$4" ] || "$PKG_CONFIG" --max-version="$4" "$1" ; then : 7.257 + else return 1 ; fi 7.258 + return 0 7.259 +} 7.260 + 7.261 +#foreach( $dependency in $namedDependencies ) 7.262 +dependency_error_${dependency.id}() 7.263 +{ 7.264 + printf "checking for ${dependency.name}... " 7.265 + #foreach( $sub in $dependency.subdependencies ) 7.266 + # dependency $sub.fullName 7.267 + while true 7.268 + do 7.269 + #if( $sub.platform ) 7.270 + if notisplatform "${sub.platform}"; then 7.271 + break 7.272 + fi 7.273 + #end 7.274 + #foreach( $np in $sub.notList ) 7.275 + if isplatform "${np}"; then 7.276 + break 7.277 + fi 7.278 + #end 7.279 + #foreach( $lang in $sub.lang ) 7.280 + if [ -z "$lang_${lang}" ] ; then 7.281 + break 7.282 + fi 7.283 + #end 7.284 + #if( $sub.pkgconfig.size() > 0 ) 7.285 + if [ -z "$PKG_CONFIG" ]; then 7.286 + break 7.287 + fi 7.288 + #end 7.289 + #foreach( $test in $sub.tests ) 7.290 + if $test > /dev/null ; then 7.291 + : 7.292 + else 7.293 + break 7.294 + fi 7.295 + #end 7.296 + #foreach( $pkg in $sub.pkgconfig ) 7.297 + if test_pkg_config "$pkg.name" "$pkg.atleast" "$pkg.exact" "$pkg.max" ; then 7.298 + TEMP_CFLAGS="$TEMP_CFLAGS `"$PKG_CONFIG" --cflags $pkg.name`" 7.299 + TEMP_LDFLAGS="$TEMP_LDFLAGS `"$PKG_CONFIG" --libs $pkg.name`" 7.300 + else 7.301 + break 7.302 + fi 7.303 + #end 7.304 + #foreach( $flags in $sub.flags ) 7.305 + #if( $flags.exec ) 7.306 + if tmp_flags=`$flags.value` ; then 7.307 + TEMP_$flags.varName="$TEMP_$flags.varName $tmp_flags" 7.308 + else 7.309 + break 7.310 + fi 7.311 + #else 7.312 + TEMP_$flags.varName="$TEMP_$flags.varName $flags.value" 7.313 + #end 7.314 + #end 7.315 + #if ( $sub.make.length() > 0 ) 7.316 + cat >> $TEMP_DIR/make.mk << __EOF__ 7.317 +# Dependency: $dependency.name 7.318 +$sub.make 7.319 +__EOF__ 7.320 + #end 7.321 + echo yes 7.322 + return 1 7.323 + done 7.324 + 7.325 + #end 7.326 + echo no 7.327 + return 0 7.328 +} 7.329 +#end 7.330 + 7.331 + 7.332 + 7.333 + 7.334 +# start collecting dependency information 7.335 +echo > "$TEMP_DIR/flags.mk" 7.336 + 7.337 +DEPENDENCIES_FAILED= 7.338 +ERROR=0 7.339 +#if( $dependencies.size() > 0 ) 7.340 +# unnamed dependencies 7.341 +TEMP_CFLAGS= 7.342 +TEMP_CXXFLAGS= 7.343 +TEMP_LDFLAGS= 7.344 +#foreach( $dependency in $dependencies ) 7.345 +while true 7.346 +do 7.347 + #if( $dependency.platform ) 7.348 + if notisplatform "${dependency.platform}"; then 7.349 + break 7.350 + fi 7.351 + #end 7.352 + #foreach( $np in $dependency.notList ) 7.353 + if isplatform "${np}"; then 7.354 + break 7.355 + fi 7.356 + #end 7.357 + while true 7.358 + do 7.359 + #foreach( $lang in $dependency.lang ) 7.360 + if [ -z "$lang_${lang}" ] ; then 7.361 + ERROR=1 7.362 + break 7.363 + fi 7.364 + #end 7.365 + #if( $dependency.pkgconfig.size() > 0 ) 7.366 + if [ -z "$PKG_CONFIG" ]; then 7.367 + ERROR=1 7.368 + break 7.369 + fi 7.370 + #end 7.371 + #foreach( $pkg in $dependency.pkgconfig ) 7.372 + printf "checking for pkg-config package $pkg.name... " 7.373 + if test_pkg_config "$pkg.name" "$pkg.atleast" "$pkg.exact" "$pkg.max" ; then 7.374 + echo yes 7.375 + TEMP_CFLAGS="$TEMP_CFLAGS `"$PKG_CONFIG" --cflags $pkg.name`" 7.376 + TEMP_LDFLAGS="$TEMP_LDFLAGS `"$PKG_CONFIG" --libs $pkg.name`" 7.377 + else 7.378 + echo no 7.379 + ERROR=1 7.380 + break 7.381 + fi 7.382 + #end 7.383 + 7.384 + #foreach( $flags in $dependency.flags ) 7.385 + #if( $flags.exec ) 7.386 + $flags.value > /dev/null 7.387 + if tmp_flags=`$flags.value` ; then 7.388 + TEMP_$flags.varName="$TEMP_$flags.varName $tmp_flags" 7.389 + else 7.390 + ERROR=1 7.391 + break 7.392 + fi 7.393 + #else 7.394 + TEMP_$flags.varName="$TEMP_$flags.varName $flags.value" 7.395 + #end 7.396 + #end 7.397 + #if ( $dependency.make.length() > 0 ) 7.398 + cat >> "$TEMP_DIR/make.mk" << __EOF__ 7.399 +$dependency.make 7.400 +__EOF__ 7.401 + #end 7.402 + break 7.403 + done 7.404 + break 7.405 +done 7.406 +#end 7.407 + 7.408 +# add general dependency flags to flags.mk 7.409 +echo "# general flags" >> "$TEMP_DIR/flags.mk" 7.410 +if [ -n "${TEMP_CFLAGS}" -a -n "$lang_c" ]; then 7.411 + echo "CFLAGS += $TEMP_CFLAGS" >> "$TEMP_DIR/flags.mk" 7.412 +fi 7.413 +if [ -n "${TEMP_CXXFLAGS}" -a -n "$lang_cpp" ]; then 7.414 + echo "CXXFLAGS += $TEMP_CXXFLAGS" >> "$TEMP_DIR/flags.mk" 7.415 +fi 7.416 +if [ -n "${TEMP_LDFLAGS}" ]; then 7.417 + echo "LDFLAGS += $TEMP_LDFLAGS" >> "$TEMP_DIR/flags.mk" 7.418 +fi 7.419 +#end 7.420 + 7.421 +# 7.422 +# OPTION VALUES 7.423 +# 7.424 +#foreach( $opt in $options ) 7.425 +#foreach( $val in $opt.values ) 7.426 +${val.func}() 7.427 +{ 7.428 + VERR=0 7.429 + #foreach( $dep in $val.dependencies ) 7.430 + if dependency_error_$dep ; then 7.431 + VERR=1 7.432 + fi 7.433 + #end 7.434 + if [ $VERR -ne 0 ]; then 7.435 + return 1 7.436 + fi 7.437 + #foreach( $def in $val.defines ) 7.438 + TEMP_CFLAGS="$TEMP_CFLAGS ${def.toFlags()}" 7.439 + TEMP_CXXFLAGS="$TEMP_CXXFLAGS ${def.toFlags()}" 7.440 + #end 7.441 + #if( $val.hasMake() ) 7.442 + cat >> "$TEMP_DIR/make.mk" << __EOF__ 7.443 +$val.make 7.444 +__EOF__ 7.445 + #end 7.446 + return 0 7.447 +} 7.448 +#end 7.449 +#end 7.450 + 7.451 +# 7.452 +# TARGETS 7.453 +# 7.454 + 7.455 +#foreach( $target in $targets ) 7.456 +echo >> "$TEMP_DIR/flags.mk" 7.457 +#if ( $target.name ) 7.458 +echo "configuring target: $target.name" 7.459 +echo "# flags for target $target.name" >> "$TEMP_DIR/flags.mk" 7.460 +#else 7.461 +echo "configuring global target" 7.462 +echo "# flags for unnamed target" >> "$TEMP_DIR/flags.mk" 7.463 +#end 7.464 +TEMP_CFLAGS= 7.465 +TEMP_CXXFLAGS= 7.466 +TEMP_LDFLAGS= 7.467 + 7.468 +#foreach( $dependency in $target.dependencies ) 7.469 +if dependency_error_$dependency; then 7.470 + DEPENDENCIES_FAILED="$DEPENDENCIES_FAILED ${dependency} " 7.471 + ERROR=1 7.472 +fi 7.473 +#end 7.474 + 7.475 +# Features 7.476 +#foreach( $feature in $target.features ) 7.477 +if [ -n "${D}${feature.varName}" ]; then 7.478 +#foreach( $dependency in $feature.dependencies ) 7.479 + # check dependency 7.480 + if dependency_error_$dependency ; then 7.481 + # "auto" features can fail and are just disabled in this case 7.482 + if [ "${D}${feature.varName}" = "auto" ]; then 7.483 + DISABLE_${feature.varName}=1 7.484 + else 7.485 + DEPENDENCIES_FAILED="$DEPENDENCIES_FAILED ${dependency} " 7.486 + ERROR=1 7.487 + fi 7.488 + fi 7.489 +#end 7.490 + if [ -n "$DISABLE_${feature.varName}" ]; then 7.491 + unset ${feature.varName} 7.492 + fi 7.493 +fi 7.494 +#end 7.495 + 7.496 +#foreach( $opt in $target.options ) 7.497 +# Option: --${opt.argument} 7.498 +if [ -z "${D}${opt.varName}" ]; then 7.499 + echo "auto-detecting option '${opt.argument}'" 7.500 + SAVED_ERROR="$ERROR" 7.501 + SAVED_DEPENDENCIES_FAILED="$DEPENDENCIES_FAILED" 7.502 + ERROR=1 7.503 + while true 7.504 + do 7.505 + #foreach( $optdef in $opt.defaults ) 7.506 + #if( $optdef.platform ) 7.507 + if isplatform "$optdef.platform"; then 7.508 + #end 7.509 + if $optdef.func ; then 7.510 + echo " ${opt.argument}: ${optdef.valueName}" >> "$TEMP_DIR/options" 7.511 + ERROR=0 7.512 + break 7.513 + fi 7.514 + #if( $optdef.platform ) 7.515 + fi 7.516 + #end 7.517 + #end 7.518 + break 7.519 + done 7.520 + if [ $ERROR -ne 0 ]; then 7.521 + SAVED_ERROR=1 7.522 + SAVED_DEPENDENCIES_FAILED="option '${opt.argument}' $SAVED_DEPENDENCIES_FAILED" 7.523 + fi 7.524 + ERROR="$SAVED_ERROR" 7.525 + DEPENDENCIES_FAILED="$SAVED_DEPENDENCIES_FAILED" 7.526 +else 7.527 + echo "checking option ${opt.argument} = ${D}${opt.varName}" 7.528 + if false; then 7.529 + false 7.530 + #foreach( $optval in $opt.values ) 7.531 + elif [ "${D}${opt.varName}" = "${optval.value}" ]; then 7.532 + echo " ${opt.argument}: ${D}${opt.varName}" >> $TEMP_DIR/options 7.533 + if $optval.func ; then 7.534 + : 7.535 + else 7.536 + ERROR=1 7.537 + DEPENDENCIES_FAILED="option '${opt.argument}' $DEPENDENCIES_FAILED" 7.538 + fi 7.539 + #end 7.540 + fi 7.541 +fi 7.542 +#end 7.543 + 7.544 +if [ -n "${TEMP_CFLAGS}" -a -n "$lang_c" ]; then 7.545 + echo "${target.cFlags} += $TEMP_CFLAGS" >> "$TEMP_DIR/flags.mk" 7.546 +fi 7.547 +if [ -n "${TEMP_CXXFLAGS}" -a -n "$lang_cpp" ]; then 7.548 + echo "${target.cxxFlags} += $TEMP_CXXFLAGS" >> "$TEMP_DIR/flags.mk" 7.549 +fi 7.550 +if [ "$BUILD_TYPE" = "debug" ]; then 7.551 + if [ -n "$lang_c" ]; then 7.552 + echo '${target.cFlags} += ${DEBUG_CC_FLAGS}' >> "$TEMP_DIR/flags.mk" 7.553 + fi 7.554 + if [ -n "$lang_cpp" ]; then 7.555 + echo '${target.cxxFlags} += ${DEBUG_CXX_FLAGS}' >> "$TEMP_DIR/flags.mk" 7.556 + fi 7.557 +fi 7.558 +if [ "$BUILD_TYPE" = "release" ]; then 7.559 + if [ -n "$lang_c" ]; then 7.560 + echo '${target.cFlags} += ${RELEASE_CC_FLAGS}' >> "$TEMP_DIR/flags.mk" 7.561 + fi 7.562 + if [ -n "$lang_cpp" ]; then 7.563 + echo '${target.cxxFlags} += ${RELEASE_CXX_FLAGS}' >> "$TEMP_DIR/flags.mk" 7.564 + fi 7.565 +fi 7.566 +if [ -n "${TEMP_LDFLAGS}" ]; then 7.567 + echo "${target.ldFlags} += $TEMP_LDFLAGS" >> "$TEMP_DIR/flags.mk" 7.568 +fi 7.569 + 7.570 +#end 7.571 + 7.572 +# final result 7.573 +if [ $ERROR -ne 0 ]; then 7.574 + echo 7.575 + echo "Error: Unresolved dependencies" 7.576 + echo "$DEPENDENCIES_FAILED" 7.577 + abort_configure 7.578 +fi 7.579 + 7.580 +echo "configure finished" 7.581 +echo 7.582 +echo "Build Config:" 7.583 +echo " PREFIX: $PREFIX" 7.584 +echo " TOOLCHAIN: $TOOLCHAIN_NAME" 7.585 +#if ( $options.size() > 0 ) 7.586 +echo "Options:" 7.587 +cat "$TEMP_DIR/options" 7.588 +#end 7.589 +#if ( $features.size() > 0 ) 7.590 +echo "Features:" 7.591 +#foreach( $feature in $features ) 7.592 +if [ -n "${D}${feature.varName}" ]; then 7.593 +echo " $feature.name: on" 7.594 +else 7.595 +echo " $feature.name: off" 7.596 +fi 7.597 +#end 7.598 +#end 7.599 +echo 7.600 + 7.601 +# generate the config.mk file 7.602 +cat > "$TEMP_DIR/config.mk" << __EOF__ 7.603 +# 7.604 +# config.mk generated by configure 7.605 +# 7.606 + 7.607 +__EOF__ 7.608 +write_toolchain_defaults "$TEMP_DIR/toolchain.mk" 7.609 +cat "$TEMP_DIR/vars.mk" "$TEMP_DIR/toolchain.mk" "$TEMP_DIR/flags.mk" "$TEMP_DIR/make.mk" > config.mk 7.610 +rm -Rf "$TEMP_DIR" 7.611 + 7.612 +
8.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 8.2 +++ b/make/project.xml Fri Oct 06 21:21:10 2023 +0200 8.3 @@ -0,0 +1,24 @@ 8.4 +<?xml version="1.0" encoding="UTF-8"?> 8.5 +<project xmlns="http://unixwork.de/uwproj"> 8.6 + <dependency> 8.7 + <lang>c</lang> 8.8 + </dependency> 8.9 + 8.10 + <dependency name="ucx"> 8.11 + <test>check_lib ucx cx/common.h</test> 8.12 + <ldflags>-lucx</ldflags> 8.13 + </dependency> 8.14 + 8.15 + <dependency name="sdl2"> 8.16 + <pkgconfig>sdl2</pkgconfig> 8.17 + </dependency> 8.18 + 8.19 + <dependency name="sdl2_ttf"> 8.20 + <pkgconfig>SDL2_ttf</pkgconfig> 8.21 + </dependency> 8.22 + 8.23 + <dependency name="glew"> 8.24 + <pkgconfig>glew</pkgconfig> 8.25 + </dependency> 8.26 +</project> 8.27 +
9.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 9.2 +++ b/make/toolchain.sh Fri Oct 06 21:21:10 2023 +0200 9.3 @@ -0,0 +1,186 @@ 9.4 +#!/bin/sh 9.5 +# 9.6 +# toolchain detection 9.7 +# 9.8 + 9.9 +C_COMPILERS="gcc clang suncc cc" 9.10 +CPP_COMPILERS="g++ clang++ sunCC CC" 9.11 +unset TOOLCHAIN_NAME 9.12 +unset TOOLCHAIN_CC 9.13 +unset TOOLCHAIN_CXX 9.14 + 9.15 +check_c_compiler() 9.16 +{ 9.17 + cat > "$TEMP_DIR/test.c" << __EOF__ 9.18 +/* test file */ 9.19 +#include <stdio.h> 9.20 +int main(int argc, char **argv) { 9.21 +#if defined(__clang__) 9.22 + printf("clang\n"); 9.23 +#elif defined(__GNUC__) 9.24 + printf("gcc\n"); 9.25 +#elif defined(__sun) 9.26 + printf("suncc\n"); 9.27 +#else 9.28 + printf("unknown\n"); 9.29 +#endif 9.30 + return 0; 9.31 +} 9.32 +__EOF__ 9.33 + rm -f "$TEMP_DIR/checkcc" 9.34 + $1 -o "$TEMP_DIR/checkcc" $CFLAGS $LDFLAGS "$TEMP_DIR/test.c" 2> /dev/null 9.35 +} 9.36 + 9.37 +check_cpp_compiler() 9.38 +{ 9.39 + cat > "$TEMP_DIR/test.cpp" << __EOF__ 9.40 +/* test file */ 9.41 +#include <iostream> 9.42 +int main(int argc, char **argv) { 9.43 +#if defined(__clang__) 9.44 + std::cout << "clang" << std::endl; 9.45 +#elif defined(__GNUC__) 9.46 + std::cout << "gcc" << std::endl; 9.47 +#elif defined(__sun) 9.48 + std::cout << "suncc" << std::endl; 9.49 +#else 9.50 + std::cout << "cc" << std::endl; 9.51 +#endif 9.52 + return 0; 9.53 +} 9.54 +__EOF__ 9.55 + rm -f "$TEMP_DIR/checkcc" 9.56 + $1 -o "$TEMP_DIR/checkcc" $CXXFLAGS $LDFLAGS "$TEMP_DIR/test.cpp" 2> /dev/null 9.57 +} 9.58 + 9.59 +create_libtest_source() 9.60 +{ 9.61 + # $1: filename 9.62 + # $2: optional include 9.63 + cat > "$TEMP_DIR/$1" << __EOF__ 9.64 +/* libtest file */ 9.65 +int main(int argc, char **argv) { 9.66 + return 0; 9.67 +} 9.68 +__EOF__ 9.69 + if [ -n "$2" ]; then 9.70 + echo "#include <$2>" >> "$TEMP_DIR/$1" 9.71 + fi 9.72 +} 9.73 + 9.74 +check_c_lib() 9.75 +{ 9.76 + # $1: libname 9.77 + # $2: optional include 9.78 + if [ -z "$TOOLCHAIN_CC" ]; then 9.79 + return 1 9.80 + fi 9.81 + create_libtest_source "test.c" "$2" 9.82 + rm -f "$TEMP_DIR/checklib" 9.83 + $TOOLCHAIN_CC -o "$TEMP_DIR/checklib" $CFLAGS $LDFLAGS "-l$1" "$TEMP_DIR/test.c" 2> /dev/null 9.84 +} 9.85 + 9.86 +check_cpp_lib() 9.87 +{ 9.88 + # $1: libname 9.89 + # $2: optional include 9.90 + if [ -z "$TOOLCHAIN_CXX" ]; then 9.91 + return 1 9.92 + fi 9.93 + create_libtest_source "test.cpp" "$2" 9.94 + rm -f "$TEMP_DIR/checklib" 9.95 + $TOOLCHAIN_CXX -o "$TEMP_DIR/checklib" $CXXFLAGS $LDFLAGS "-l$1" "$TEMP_DIR/test.cpp" 2> /dev/null 9.96 +} 9.97 + 9.98 +check_lib() 9.99 +{ 9.100 + # $1: libname 9.101 + # $2: optional include 9.102 + if [ -n "$TOOLCHAIN_CC" ]; then 9.103 + check_c_lib "$1" "$2" 9.104 + elif [ -n "$TOOLCHAIN_CXX" ]; then 9.105 + check_cpp_lib "$1" "$2" 9.106 + fi 9.107 +} 9.108 + 9.109 +detect_c_compiler() 9.110 +{ 9.111 + if [ -n "$TOOLCHAIN_CC" ]; then 9.112 + return 0 9.113 + fi 9.114 + printf "detect C compiler... " 9.115 + if [ -n "$CC" ]; then 9.116 + if check_c_compiler "$CC"; then 9.117 + TOOLCHAIN_CC=$CC 9.118 + TOOLCHAIN_NAME=`"$TEMP_DIR/checkcc"` 9.119 + echo "$CC" 9.120 + return 0 9.121 + else 9.122 + echo "$CC is not a working C compiler" 9.123 + return 1 9.124 + fi 9.125 + else 9.126 + for COMP in $C_COMPILERS 9.127 + do 9.128 + if check_c_compiler "$COMP"; then 9.129 + TOOLCHAIN_CC=$COMP 9.130 + TOOLCHAIN_NAME=`"$TEMP_DIR/checkcc"` 9.131 + echo "$COMP" 9.132 + return 0 9.133 + fi 9.134 + done 9.135 + echo "not found" 9.136 + return 1 9.137 + fi 9.138 +} 9.139 + 9.140 +detect_cpp_compiler() 9.141 +{ 9.142 + if [ -n "$TOOLCHAIN_CXX" ]; then 9.143 + return 0 9.144 + fi 9.145 + printf "detect C++ compiler... " 9.146 + 9.147 + if [ -n "$CXX" ]; then 9.148 + if check_cpp_compiler "$CXX"; then 9.149 + TOOLCHAIN_CXX=$CXX 9.150 + TOOLCHAIN_NAME=`"$TEMP_DIR/checkcc"` 9.151 + echo "$CXX" 9.152 + return 0 9.153 + else 9.154 + echo "$CXX is not a working C++ compiler" 9.155 + return 1 9.156 + fi 9.157 + else 9.158 + for COMP in $CPP_COMPILERS 9.159 + do 9.160 + if check_cpp_compiler "$COMP"; then 9.161 + TOOLCHAIN_CXX=$COMP 9.162 + TOOLCHAIN_NAME=`"$TEMP_DIR/checkcc"` 9.163 + echo "$COMP" 9.164 + return 0 9.165 + fi 9.166 + done 9.167 + echo "${TOOLCHAIN_CXX:-"not found"}" 9.168 + return 1 9.169 + fi 9.170 +} 9.171 + 9.172 +write_toolchain_defaults() 9.173 +{ 9.174 + echo "# toolchain" >> "$1" 9.175 + if [ -n "$TOOLCHAIN_CC" ]; then 9.176 + echo "CC = ${TOOLCHAIN_CC}" >> "$1" 9.177 + fi 9.178 + if [ -n "$TOOLCHAIN_CXX" ]; then 9.179 + echo "CXX = ${TOOLCHAIN_CXX}" >> "$1" 9.180 + fi 9.181 + echo >> "$1" 9.182 + if [ -f "make/${TOOLCHAIN_NAME}.mk" ]; then 9.183 + cat "make/${TOOLCHAIN_NAME}.mk" >> "$1" 9.184 + elif [ -f "make/cc.mk" ]; then 9.185 + cat "make/cc.mk" >> "$1" 9.186 + else 9.187 + echo "!!! WARNING !!! Default toolchain flags not found. Configuration might be incomplete." 9.188 + fi 9.189 +}
10.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 10.2 +++ b/make/uwproj.xsd Fri Oct 06 21:21:10 2023 +0200 10.3 @@ -0,0 +1,131 @@ 10.4 +<?xml version="1.0" encoding="UTF-8"?> 10.5 +<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" 10.6 + xmlns="http://unixwork.de/uwproj" 10.7 + targetNamespace="http://unixwork.de/uwproj" 10.8 + elementFormDefault="qualified" 10.9 + version="0.1" 10.10 +> 10.11 + <xs:element name="project" type="ProjectType"/> 10.12 + 10.13 + <xs:complexType name="ProjectType"> 10.14 + <xs:sequence> 10.15 + <xs:element name="config" type="ConfigType" minOccurs="0"/> 10.16 + <xs:element name="dependency" type="DependencyType" minOccurs="0" maxOccurs="unbounded"/> 10.17 + <xs:element name="target" type="TargetType" minOccurs="0" maxOccurs="unbounded"/> 10.18 + </xs:sequence> 10.19 + </xs:complexType> 10.20 + 10.21 + <xs:complexType name="ConfigType"> 10.22 + <xs:sequence> 10.23 + <xs:element name="var" type="ConfigVarType" minOccurs="0" maxOccurs="unbounded"/> 10.24 + </xs:sequence> 10.25 + </xs:complexType> 10.26 + 10.27 + <xs:complexType name="ConfigVarType"> 10.28 + <xs:simpleContent> 10.29 + <xs:extension base="xs:string"> 10.30 + <xs:attribute name="name" type="xs:string" use="required"/> 10.31 + <xs:attribute name="exec" type="xs:boolean" default="false"/> 10.32 + </xs:extension> 10.33 + </xs:simpleContent> 10.34 + </xs:complexType> 10.35 + 10.36 + <xs:complexType name="PkgConfigType"> 10.37 + <xs:simpleContent> 10.38 + <xs:extension base="xs:string"> 10.39 + <xs:attribute name="atleast" type="xs:string"/> 10.40 + <xs:attribute name="exact" type="xs:string"/> 10.41 + <xs:attribute name="max" type="xs:string"/> 10.42 + </xs:extension> 10.43 + </xs:simpleContent> 10.44 + </xs:complexType> 10.45 + 10.46 + <xs:simpleType name="LangType"> 10.47 + <xs:restriction base="xs:string"> 10.48 + <xs:enumeration value="c"/> 10.49 + <xs:enumeration value="cpp"/> 10.50 + </xs:restriction> 10.51 + </xs:simpleType> 10.52 + 10.53 + <xs:complexType name="DependencyType"> 10.54 + <xs:choice minOccurs="0" maxOccurs="unbounded"> 10.55 + <xs:element name="lang" type="LangType"/> 10.56 + <xs:element name="cflags" type="FlagsType"/> 10.57 + <xs:element name="cxxflags" type="FlagsType"/> 10.58 + <xs:element name="ldflags" type="FlagsType"/> 10.59 + <xs:element name="pkgconfig" type="PkgConfigType"/> 10.60 + <xs:element name="test" type="xs:string"/> 10.61 + <xs:element name="make" type="xs:string"/> 10.62 + </xs:choice> 10.63 + <xs:attribute name="name" type="xs:string"/> 10.64 + <xs:attribute name="platform" type="xs:string"/> 10.65 + <xs:attribute name="not" type="xs:string"/> 10.66 + </xs:complexType> 10.67 + 10.68 + <xs:complexType name="FlagsType"> 10.69 + <xs:simpleContent> 10.70 + <xs:extension base="xs:string"> 10.71 + <xs:attribute name="exec" type="xs:boolean" default="false"/> 10.72 + </xs:extension> 10.73 + </xs:simpleContent> 10.74 + </xs:complexType> 10.75 + 10.76 + <xs:complexType name="TargetType"> 10.77 + <xs:choice minOccurs="0" maxOccurs="unbounded"> 10.78 + <xs:element name="feature" type="FeatureType"/> 10.79 + <xs:element name="option" type="OptionType"/> 10.80 + <xs:element name="define" type="DefineType"/> 10.81 + <xs:element name="dependencies" type="DependenciesType"/> 10.82 + <xs:element name="alldependencies"> 10.83 + <xs:complexType/> 10.84 + </xs:element> 10.85 + </xs:choice> 10.86 + <xs:attribute name="name" type="xs:string"/> 10.87 + </xs:complexType> 10.88 + 10.89 + <xs:complexType name="FeatureType"> 10.90 + <xs:choice minOccurs="0" maxOccurs="unbounded"> 10.91 + <xs:group ref="TargetDataGroup"/> 10.92 + </xs:choice> 10.93 + <xs:attribute name="name" type="xs:string" use="required"/> 10.94 + <xs:attribute name="arg" type="xs:string"/> 10.95 + <xs:attribute name="default" type="xs:boolean" default="false"/> 10.96 + </xs:complexType> 10.97 + 10.98 + <xs:complexType name="OptionType"> 10.99 + <xs:sequence> 10.100 + <xs:element name="value" type="OptionValueType" minOccurs="0" maxOccurs="unbounded"/> 10.101 + <xs:element name="default" type="OptionDefaultType" minOccurs="0" maxOccurs="unbounded"/> 10.102 + </xs:sequence> 10.103 + <xs:attribute name="arg" type="xs:string"/> 10.104 + </xs:complexType> 10.105 + 10.106 + <xs:complexType name="OptionValueType"> 10.107 + <xs:choice minOccurs="0" maxOccurs="unbounded"> 10.108 + <xs:group ref="TargetDataGroup"/> 10.109 + </xs:choice> 10.110 + <xs:attribute name="str" type="xs:string" use="required"/> 10.111 + </xs:complexType> 10.112 + 10.113 + <xs:complexType name="OptionDefaultType"> 10.114 + <xs:attribute name="value" type="xs:string" use="required"/> 10.115 + <xs:attribute name="platform" type="xs:string"/> 10.116 + </xs:complexType> 10.117 + 10.118 + <xs:group name="TargetDataGroup"> 10.119 + <xs:choice> 10.120 + <xs:element name="define" type="DefineType" minOccurs="0" maxOccurs="unbounded"/> 10.121 + <xs:element name="dependencies" type="DependenciesType" minOccurs="0" maxOccurs="unbounded"/> 10.122 + <xs:element name="make" type="xs:string" minOccurs="0" maxOccurs="unbounded"/> 10.123 + </xs:choice> 10.124 + </xs:group> 10.125 + 10.126 + <xs:complexType name="DefineType"> 10.127 + <xs:attribute name="name" type="xs:string" use="required"/> 10.128 + <xs:attribute name="value" type="xs:string"/> 10.129 + </xs:complexType> 10.130 + 10.131 + <xs:simpleType name="DependenciesType"> 10.132 + <xs:restriction base="xs:string"/> 10.133 + </xs:simpleType> 10.134 +</xs:schema> 10.135 \ No newline at end of file
11.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 11.2 +++ b/src/Makefile Fri Oct 06 21:21:10 2023 +0200 11.3 @@ -0,0 +1,46 @@ 11.4 +# Copyright 2023 Mike Becker. All rights reserved. 11.5 +# 11.6 +# Redistribution and use in source and binary forms, with or without 11.7 +# modification, are permitted provided that the following conditions are met: 11.8 +# 11.9 +# 1. Redistributions of source code must retain the above copyright 11.10 +# notice, this list of conditions and the following disclaimer. 11.11 +# 11.12 +# 2. Redistributions in binary form must reproduce the above copyright 11.13 +# notice, this list of conditions and the following disclaimer in the 11.14 +# documentation and/or other materials provided with the distribution. 11.15 +# 11.16 +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 11.17 +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 11.18 +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 11.19 +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 11.20 +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 11.21 +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 11.22 +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 11.23 +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 11.24 +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 11.25 +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 11.26 +# POSSIBILITY OF SUCH DAMAGE. 11.27 +# 11.28 + 11.29 +include ../config.mk 11.30 + 11.31 +BUILD_DIR=../build/lib 11.32 + 11.33 +SRC = core.c 11.34 + 11.35 +OBJ = $(SRC:%.c=$(BUILD_DIR)/%.o) 11.36 + 11.37 +all: $(BUILD_DIR)/libascension.a FORCE 11.38 + echo "You have successfully ascended." 11.39 + 11.40 +$(BUILD_DIR)/libascension.a: $(OBJ) 11.41 + echo "Creating library..." 11.42 + $(AR) $(ARFLAGS) $@ $^ 11.43 + 11.44 +FORCE: 11.45 + 11.46 +$(BUILD_DIR)/core.o: core.c ascension/core.h ascension/utils.h 11.47 + echo "Compiling $<" 11.48 + $(CC) -o $@ $(CFLAGS) -c $< 11.49 +
12.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 12.2 +++ b/src/ascension/core.h Fri Oct 06 21:21:10 2023 +0200 12.3 @@ -0,0 +1,157 @@ 12.4 +/* 12.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 12.6 + * Copyright 2023 Mike Becker. All rights reserved. 12.7 + * 12.8 + * Redistribution and use in source and binary forms, with or without 12.9 + * modification, are permitted provided that the following conditions are met: 12.10 + * 12.11 + * 1. Redistributions of source code must retain the above copyright 12.12 + * notice, this list of conditions and the following disclaimer. 12.13 + * 12.14 + * 2. Redistributions in binary form must reproduce the above copyright 12.15 + * notice, this list of conditions and the following disclaimer in the 12.16 + * documentation and/or other materials provided with the distribution. 12.17 + * 12.18 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 12.19 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 12.20 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 12.21 + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 12.22 + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 12.23 + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 12.24 + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 12.25 + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 12.26 + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 12.27 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 12.28 + * POSSIBILITY OF SUCH DAMAGE. 12.29 + */ 12.30 + 12.31 +#ifndef ASCENSION_CORE_H 12.32 +#define ASCENSION_CORE_H 12.33 + 12.34 +#include <SDL2/SDL.h> 12.35 +#include <SDL2/SDL_ttf.h> 12.36 +#include <GL/glew.h> 12.37 + 12.38 +#include <cx/string.h> 12.39 +#include <cx/buffer.h> 12.40 +#include <cx/list.h> 12.41 + 12.42 +#ifdef __cplusplus 12.43 +extern "C" { 12.44 +#endif 12.45 + 12.46 +/** The flag for the overall initialized state. */ 12.47 +#define ASC_FLAG_INITILIZED 0x01u 12.48 + 12.49 +/** Flag is set, when error buffer contains new error information. */ 12.50 +#define ASC_FLAG_HAS_ERROR 0x02u 12.51 + 12.52 +/** Flag is set, when SDL wants to quit the application. */ 12.53 +#define ASC_FLAG_QUIT 0x80000000u 12.54 + 12.55 +typedef struct AscContext { 12.56 + CxBuffer error_buffer; 12.57 + CxList *windows; 12.58 + unsigned int flags; 12.59 +} AscContext; 12.60 + 12.61 +/** Global ascension context. */ 12.62 +extern AscContext asc_context; 12.63 + 12.64 +typedef struct AscWindowSettings { 12.65 + int depth_size; 12.66 + int vsync; 12.67 + int width; 12.68 + int height; 12.69 + int fullscreen; 12.70 + int gl_major_version; 12.71 + int gl_minor_version; 12.72 + char const* title; 12.73 +} AscWindowSettings; 12.74 + 12.75 +typedef struct AscWindow { 12.76 + SDL_Window* window; 12.77 + SDL_GLContext glctx; 12.78 + Uint32 id; 12.79 + int width; 12.80 + int height; 12.81 +} AscWindow; 12.82 + 12.83 +void asc_context_initialize(void); 12.84 +void asc_context_destroy(void); 12.85 + 12.86 +static inline bool asc_test_flag(unsigned int reg, int flag) { 12.87 + return (reg & flag) == flag; 12.88 +} 12.89 + 12.90 +static inline void asc_set_flag(unsigned int *reg, int flag) { 12.91 + *reg |= flag; 12.92 +} 12.93 + 12.94 +static inline void asc_clear_flag(unsigned int *reg, int flag) { 12.95 + *reg &= ~flag; 12.96 +} 12.97 + 12.98 +void asc_error_cxstr(cxstring text); 12.99 +void asc_error_cchar(char const* text); 12.100 +void asc_error_cuchar(unsigned char const* text); 12.101 + 12.102 +#define asc_error(text) _Generic((text), \ 12.103 + char const*: asc_error_cchar, \ 12.104 + unsigned char const*: asc_error_cuchar, \ 12.105 + char*: asc_error_cchar, \ 12.106 + unsigned char*: asc_error_cuchar, \ 12.107 + cxstring: asc_error_cxstr)(text) 12.108 + 12.109 +bool asc_has_error(void); 12.110 +char const* asc_get_error(void); 12.111 +void asc_clear_error(void); 12.112 + 12.113 +/** 12.114 + * Dispatches events and synchronizes all initialized windows. 12.115 + * 12.116 + * @return false, if one of the events is a QUIT event, true otherwise 12.117 + */ 12.118 +bool asc_loop_next(void); 12.119 + 12.120 +/** 12.121 + * Initializes the settings structure with default values. 12.122 + * 12.123 + * @param settings an uninitialized settings object 12.124 + */ 12.125 +void asc_window_settings_init_defaults(AscWindowSettings* settings); 12.126 + 12.127 +/** 12.128 + * Creates and initializes a new window and a corresponding OpenGL context. 12.129 + * 12.130 + * @param window the window structure 12.131 + * @param settings the settings to be used for initialization 12.132 + */ 12.133 +void asc_window_initialize(AscWindow* window, AscWindowSettings const* settings); 12.134 + 12.135 +/** 12.136 + * Destroys the window and its OpenGL context. 12.137 + * 12.138 + * Still alive windows will also be destroyed by asc_context_destroy() 12.139 + * automatically. 12.140 + * 12.141 + * @param window the window 12.142 + */ 12.143 +void asc_window_destroy(AscWindow* window); 12.144 + 12.145 +/** 12.146 + * Swaps buffers and adjusts the viewport to the current window size. 12.147 + * 12.148 + * This function is automatically invoked for all initialized windows 12.149 + * by asc_loop_next(). You usually do not need to call this function manually. 12.150 + * 12.151 + * @param window the window 12.152 + */ 12.153 +void asc_window_sync(AscWindow const *window); 12.154 + 12.155 +#ifdef __cplusplus 12.156 +} // extern "C" 12.157 +#endif 12.158 + 12.159 +#endif /* ASCENSION_CORE_H */ 12.160 +
13.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 13.2 +++ b/src/ascension/utils.h Fri Oct 06 21:21:10 2023 +0200 13.3 @@ -0,0 +1,48 @@ 13.4 +/* 13.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 13.6 + * Copyright 2023 Mike Becker. All rights reserved. 13.7 + * 13.8 + * Redistribution and use in source and binary forms, with or without 13.9 + * modification, are permitted provided that the following conditions are met: 13.10 + * 13.11 + * 1. Redistributions of source code must retain the above copyright 13.12 + * notice, this list of conditions and the following disclaimer. 13.13 + * 13.14 + * 2. Redistributions in binary form must reproduce the above copyright 13.15 + * notice, this list of conditions and the following disclaimer in the 13.16 + * documentation and/or other materials provided with the distribution. 13.17 + * 13.18 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 13.19 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 13.20 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 13.21 + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 13.22 + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 13.23 + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 13.24 + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 13.25 + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 13.26 + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 13.27 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 13.28 + * POSSIBILITY OF SUCH DAMAGE. 13.29 + */ 13.30 + 13.31 +#ifndef ASCENSION_UTILS_H 13.32 +#define ASCENSION_UTILS_H 13.33 + 13.34 +#include <stdbool.h> 13.35 +#include <stdio.h> 13.36 + 13.37 +#ifdef __cplusplus 13.38 +extern "C" { 13.39 +#endif 13.40 + 13.41 +#ifdef NDEBUG 13.42 +#define asc_dprintf(...) 13.43 +#else 13.44 +#define asc_dprintf(...) printf(__VA_ARGS__); putchar('\n') 13.45 +#endif 13.46 + 13.47 +#ifdef __cplusplus 13.48 +} // extern "C" 13.49 +#endif 13.50 + 13.51 +#endif // ASCENSION_UTILS_H 13.52 \ No newline at end of file
14.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 14.2 +++ b/src/core.c Fri Oct 06 21:21:10 2023 +0200 14.3 @@ -0,0 +1,285 @@ 14.4 +/* 14.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 14.6 + * Copyright 2023 Mike Becker. All rights reserved. 14.7 + * 14.8 + * Redistribution and use in source and binary forms, with or without 14.9 + * modification, are permitted provided that the following conditions are met: 14.10 + * 14.11 + * 1. Redistributions of source code must retain the above copyright 14.12 + * notice, this list of conditions and the following disclaimer. 14.13 + * 14.14 + * 2. Redistributions in binary form must reproduce the above copyright 14.15 + * notice, this list of conditions and the following disclaimer in the 14.16 + * documentation and/or other materials provided with the distribution. 14.17 + * 14.18 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 14.19 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 14.20 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 14.21 + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 14.22 + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 14.23 + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 14.24 + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 14.25 + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 14.26 + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 14.27 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 14.28 + * POSSIBILITY OF SUCH DAMAGE. 14.29 + */ 14.30 + 14.31 +#include "ascension/core.h" 14.32 +#include "ascension/utils.h" 14.33 + 14.34 +#include <cx/linked_list.h> 14.35 +#include <cx/printf.h> 14.36 + 14.37 +static void asc_gl_debug_callback( 14.38 + GLenum source, GLenum type, GLuint id, GLenum severity, 14.39 + GLsizei length, const GLchar* message, 14.40 + const void* userParam 14.41 +) { 14.42 + cxmutstr buf = cx_asprintf( 14.43 + "source = %d, id = %u, type = %d, severity= %d, message = %.*s", 14.44 + source, id, type, severity, length, message); 14.45 + if (type == GL_DEBUG_TYPE_ERROR) { 14.46 + asc_error(buf.ptr); 14.47 + } else { 14.48 + asc_dprintf("GL debug: %*.s", (int)buf.length, buf.ptr); 14.49 + } 14.50 + cx_strfree(&buf); 14.51 +} 14.52 + 14.53 +AscContext asc_context; 14.54 + 14.55 +// forward declarations 14.56 +static void asc_window_destroy_impl(AscWindow* window); 14.57 + 14.58 +void asc_context_initialize(void) { 14.59 + if (asc_test_flag(asc_context.flags, ASC_FLAG_INITILIZED)) 14.60 + return; 14.61 + asc_clear_flag(&asc_context.flags, ASC_FLAG_HAS_ERROR); 14.62 + 14.63 + // initialize error buffer 14.64 + cxBufferInit( 14.65 + &asc_context.error_buffer, 14.66 + NULL, 14.67 + 256, 14.68 + NULL, 14.69 + CX_BUFFER_AUTO_EXTEND 14.70 + ); 14.71 + 14.72 + // initialize lists 14.73 + asc_context.windows = cxLinkedListCreateSimple(CX_STORE_POINTERS); 14.74 + asc_context.windows->simple_destructor = 14.75 + (cx_destructor_func)asc_window_destroy_impl; 14.76 + 14.77 + // initialize SDL 14.78 + if (SDL_Init(SDL_INIT_VIDEO) < 0) { 14.79 + asc_error(SDL_GetError()); 14.80 + } else { 14.81 + if (TTF_Init() < 0) { 14.82 + asc_error(TTF_GetError()); 14.83 + } 14.84 + } 14.85 + SDL_ClearError(); 14.86 + asc_set_flag(&asc_context.flags, ASC_FLAG_INITILIZED); 14.87 + asc_dprintf("Ascension context initialized."); 14.88 +} 14.89 + 14.90 +void asc_context_destroy(void) { 14.91 + // destroy lists 14.92 + cxListDestroy(asc_context.windows); 14.93 + 14.94 + // quit SDL 14.95 + if (TTF_WasInit()) 14.96 + TTF_Quit(); 14.97 + SDL_Quit(); 14.98 + 14.99 + // destroy the error buffer 14.100 + cxBufferDestroy(&asc_context.error_buffer); 14.101 + asc_context.flags = 0; 14.102 + asc_dprintf("Ascension context destroyed."); 14.103 +} 14.104 + 14.105 +void asc_error_cchar(char const* text) { 14.106 + asc_error_cxstr(cx_str(text)); 14.107 +} 14.108 + 14.109 +void asc_error_cuchar(unsigned char const* text) { 14.110 + asc_error_cxstr(cx_str((char const*)text)); 14.111 +} 14.112 + 14.113 +void asc_error_cxstr(cxstring text) { 14.114 + if (text.length == 0) return; 14.115 + 14.116 + // write error to debug output 14.117 + asc_dprintf("ERROR: %*.s", (int)text.length, text.ptr); 14.118 + 14.119 + // write error to buffer 14.120 + CxBuffer* buf = &asc_context.error_buffer; 14.121 + cxBufferWrite(text.ptr, 1, text.length, buf); 14.122 + cxBufferPut(buf, '\n'); 14.123 + 14.124 + asc_set_flag(&asc_context.flags, ASC_FLAG_HAS_ERROR); 14.125 +} 14.126 + 14.127 +bool asc_has_error(void) { 14.128 + return asc_test_flag(asc_context.flags, ASC_FLAG_HAS_ERROR); 14.129 +} 14.130 + 14.131 +char const* asc_get_error(void) { 14.132 + // we zero-terminate the current buffer contents before providing them 14.133 + cxBufferPut(&asc_context.error_buffer, 0); 14.134 + --asc_context.error_buffer.pos; 14.135 + --asc_context.error_buffer.size; 14.136 + return asc_context.error_buffer.space; 14.137 +} 14.138 + 14.139 +void asc_clear_error(void) { 14.140 + cxBufferClear(&asc_context.error_buffer); 14.141 + asc_clear_flag(&asc_context.flags, ASC_FLAG_HAS_ERROR); 14.142 +} 14.143 + 14.144 +static void asc_event_window_resized(Uint32 id, Sint32 width, Sint32 height) { 14.145 + CxIterator iter = cxListIterator(asc_context.windows); 14.146 + cx_foreach(AscWindow*, w, iter) { 14.147 + if (w->id == id) { 14.148 + w->width = width; 14.149 + w->height = height; 14.150 + return; 14.151 + } 14.152 + } 14.153 +} 14.154 + 14.155 +bool asc_loop_next(void) { 14.156 + // dispatch SDL events 14.157 + SDL_Event event; 14.158 + while (SDL_PollEvent(&event)) { 14.159 + switch (event.type) { 14.160 + case SDL_QUIT:return false; 14.161 + case SDL_WINDOWEVENT: { 14.162 + if (event.window.type == SDL_WINDOWEVENT_RESIZED) 14.163 + asc_event_window_resized( 14.164 + event.window.windowID, 14.165 + event.window.data1, 14.166 + event.window.data2 14.167 + ); 14.168 + break; 14.169 + } 14.170 + case SDL_KEYDOWN: 14.171 + // TODO: remove this code and implement key press map instead 14.172 + if (event.key.keysym.sym == SDLK_ESCAPE) 14.173 + return false; 14.174 + break; 14.175 + case SDL_KEYUP: 14.176 + // TODO: implement key press map 14.177 + break; 14.178 + } 14.179 + } 14.180 + 14.181 + // sync the windows 14.182 + CxMutIterator windows = cxListMutIterator(asc_context.windows); 14.183 + cx_foreach(AscWindow*, w, windows) { 14.184 + asc_window_sync(w); 14.185 + } 14.186 + return true; 14.187 +} 14.188 + 14.189 +void asc_window_settings_init_defaults(AscWindowSettings* settings) { 14.190 + settings->depth_size = 24; 14.191 + settings->vsync = 1; 14.192 + settings->width = 800; 14.193 + settings->height = 600; 14.194 + settings->fullscreen = 0; 14.195 + settings->gl_major_version = 3; 14.196 + settings->gl_minor_version = 3; 14.197 + settings->title = "Ascended Window"; 14.198 +} 14.199 + 14.200 +void asc_window_initialize(AscWindow* window, AscWindowSettings const* settings) { 14.201 + Uint32 flags = SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN; 14.202 + flags |= settings->fullscreen ? SDL_WINDOW_FULLSCREEN_DESKTOP : SDL_WINDOW_RESIZABLE; 14.203 + 14.204 + window->window = SDL_CreateWindow( 14.205 + settings->title, 14.206 + SDL_WINDOWPOS_CENTERED, 14.207 + SDL_WINDOWPOS_CENTERED, 14.208 + settings->width, 14.209 + settings->height, 14.210 + flags 14.211 + ); 14.212 + if (window->window == NULL) { 14.213 + asc_error(SDL_GetError()); 14.214 + return; 14.215 + } 14.216 + 14.217 + window->id = SDL_GetWindowID(window->window); 14.218 + SDL_GetWindowSize(window->window, &window->width, &window->height); 14.219 + 14.220 + SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); 14.221 + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, settings->gl_major_version); 14.222 + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, settings->gl_minor_version); 14.223 + SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, settings->depth_size); 14.224 + SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); 14.225 + window->glctx = SDL_GL_CreateContext(window->window); 14.226 + if (window->glctx == NULL) { 14.227 + asc_dprintf("Creating GL context failed for window %u", window->id); 14.228 + } else { 14.229 + glewExperimental = GL_TRUE; 14.230 + GLenum err = glewInit(); 14.231 + if (err == GLEW_OK) { 14.232 + SDL_GL_SetSwapInterval(settings->vsync); 14.233 + glEnable(GL_DEPTH_TEST); 14.234 + glEnable(GL_BLEND); 14.235 + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 14.236 + glEnable(GL_DEBUG_OUTPUT); 14.237 + glDebugMessageCallback(asc_gl_debug_callback, NULL); 14.238 + asc_dprintf("Window %u initialized", window->id); 14.239 + cxListAdd(asc_context.windows, window); 14.240 + return; 14.241 + } else { 14.242 + asc_error(glewGetErrorString(err)); 14.243 + } 14.244 + } 14.245 + 14.246 + // cleanup on error 14.247 + if (window->glctx != NULL) { 14.248 + SDL_GL_DeleteContext(window->glctx); 14.249 + } 14.250 + window->glctx = NULL; 14.251 + SDL_DestroyWindow(window->window); 14.252 + window->window = NULL; 14.253 + window->id = 0; 14.254 +} 14.255 + 14.256 +void asc_window_destroy_impl(AscWindow* window) { 14.257 + // destory the GL context and the window 14.258 + if (window->glctx != NULL) { 14.259 + SDL_GL_DeleteContext(window->glctx); 14.260 + } 14.261 + if (window->window != NULL) { 14.262 + SDL_DestroyWindow(window->window); 14.263 + } 14.264 + 14.265 + // clean the data 14.266 + asc_dprintf("Window %u and its OpenGL context destroyed.", window->id); 14.267 + memset(window, 0, sizeof(AscWindow)); 14.268 +} 14.269 + 14.270 +void asc_window_destroy(AscWindow* window) { 14.271 + // find the window in the context and remove it 14.272 + CxMutIterator iter = cxListMutIterator(asc_context.windows); 14.273 + cx_foreach(AscWindow*, w, iter) { 14.274 + if (w == window) { 14.275 + asc_dprintf("Window %u removed from context.", window->id); 14.276 + cxIteratorFlagRemoval(iter); 14.277 + } 14.278 + } 14.279 + asc_window_destroy_impl(window); 14.280 +} 14.281 + 14.282 +void asc_window_sync(AscWindow const* window) { 14.283 + SDL_GL_MakeCurrent(window->window, window->glctx); 14.284 + SDL_GL_SwapWindow(window->window); 14.285 + glViewport(0, 0, window->width, window->height); 14.286 + glClearColor(0.0f, 0.0f, 0.0f, 1.0f); 14.287 + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 14.288 +}
15.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 15.2 +++ b/test/Makefile Fri Oct 06 21:21:10 2023 +0200 15.3 @@ -0,0 +1,43 @@ 15.4 +# Copyright 2023 Mike Becker. All rights reserved. 15.5 +# 15.6 +# Redistribution and use in source and binary forms, with or without 15.7 +# modification, are permitted provided that the following conditions are met: 15.8 +# 15.9 +# 1. Redistributions of source code must retain the above copyright 15.10 +# notice, this list of conditions and the following disclaimer. 15.11 +# 15.12 +# 2. Redistributions in binary form must reproduce the above copyright 15.13 +# notice, this list of conditions and the following disclaimer in the 15.14 +# documentation and/or other materials provided with the distribution. 15.15 +# 15.16 +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15.17 +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15.18 +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 15.19 +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 15.20 +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 15.21 +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 15.22 +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 15.23 +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 15.24 +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 15.25 +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 15.26 +# POSSIBILITY OF SUCH DAMAGE. 15.27 +# 15.28 + 15.29 +include ../config.mk 15.30 + 15.31 +BUILD_DIR=../build/test 15.32 +LIB_ASCENSION=../build/lib/libascension.a 15.33 +CFLAGS += -I../src 15.34 + 15.35 +all: $(BUILD_DIR)/sandbox FORCE 15.36 + @echo "Sandbox demo successfully built." 15.37 + 15.38 +$(BUILD_DIR)/sandbox: $(BUILD_DIR)/sandbox.o $(LIB_ASCENSION) 15.39 + echo "Linking executable..." 15.40 + $(CC) $(LDFLAGS) -o $@ $^ 15.41 + 15.42 +$(BUILD_DIR)/sandbox.o: sandbox.c ../src/ascension/core.h 15.43 + echo "Compiling $<" 15.44 + $(CC) -o $@ $(CFLAGS) -c $< 15.45 + 15.46 +FORCE:
16.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 16.2 +++ b/test/sandbox.c Fri Oct 06 21:21:10 2023 +0200 16.3 @@ -0,0 +1,66 @@ 16.4 +/* 16.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 16.6 + * Copyright 2023 Mike Becker. All rights reserved. 16.7 + * 16.8 + * Redistribution and use in source and binary forms, with or without 16.9 + * modification, are permitted provided that the following conditions are met: 16.10 + * 16.11 + * 1. Redistributions of source code must retain the above copyright 16.12 + * notice, this list of conditions and the following disclaimer. 16.13 + * 16.14 + * 2. Redistributions in binary form must reproduce the above copyright 16.15 + * notice, this list of conditions and the following disclaimer in the 16.16 + * documentation and/or other materials provided with the distribution. 16.17 + * 16.18 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16.19 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16.20 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 16.21 + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 16.22 + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 16.23 + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 16.24 + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 16.25 + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 16.26 + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 16.27 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 16.28 + * POSSIBILITY OF SUCH DAMAGE. 16.29 + */ 16.30 + 16.31 +#include "ascension/core.h" 16.32 + 16.33 +#include <unistd.h> 16.34 + 16.35 +static bool show_message_box_on_error(SDL_Window* window) { 16.36 + if (asc_has_error()) { 16.37 + SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, 16.38 + "Fatal Error", 16.39 + asc_get_error(), 16.40 + window); 16.41 + asc_clear_error(); 16.42 + return true; 16.43 + } else { 16.44 + return false; 16.45 + } 16.46 +} 16.47 + 16.48 +int main(int argc, char** argv) { 16.49 + asc_context_initialize(); 16.50 + if (show_message_box_on_error(NULL)) return 1; 16.51 + 16.52 + AscWindowSettings settings; 16.53 + asc_window_settings_init_defaults(&settings); 16.54 + settings.title = "Sandbox Application"; 16.55 + 16.56 + AscWindow window; 16.57 + asc_window_initialize(&window, &settings); 16.58 + 16.59 + while (asc_loop_next()) { 16.60 + // quit application on any error 16.61 + if (show_message_box_on_error(window.window)) break; 16.62 + 16.63 + 16.64 + } 16.65 + 16.66 + asc_context_destroy(); 16.67 + return 0; 16.68 +} 16.69 +