From 3d00d8a155be29dd003d03bdc95eef5cdd6d6c67 Mon Sep 17 00:00:00 2001 From: Mitya Selivanov Date: Thu, 7 Dec 2023 17:45:58 +0100 Subject: Update build script --- build_and_test.sh | 148 +++++++++++++++++++++++++++++++----------------------- source/kit/file.c | 4 ++ 2 files changed, 90 insertions(+), 62 deletions(-) diff --git a/build_and_test.sh b/build_and_test.sh index a25cd32..bcb10c6 100644 --- a/build_and_test.sh +++ b/build_and_test.sh @@ -1,7 +1,8 @@ -if [ ! -d "build" ]; then - mkdir build -fi +# +# General build instructions +# +FOLDER=build_gcc OS=Linux COMPILE=gcc COMPILEPP=g++ @@ -13,22 +14,35 @@ FLAG_EXE="-o " LINK_FLAGS= if [ "$2" = "gcc" ]; then + FOLDER=build_gcc COMPILE=gcc COMPILEPP=g++ elif [ "$2" = "clang" ]; then + FOLDER=build_clang COMPILE=clang COMPILEPP=clang++ elif [ "$2" = "msvc" ]; then + FOLDER=build_msvc COMPILE=cl.exe COMPILEPP=cl.exe OBJ_POSTFIX=.obj FLAG_OBJ="-c -Fo" FLAG_EXE="-Fe" +elif [ "$2" = "emcc" ]; then + FOLDER=build_emcc + COMPILE=emcc + COMPILEPP=em++ + EXE_POSTFIX=.js + LINK_FLAGS="-sFULL_ES3=1" elif [ "$2" != "" ]; then echo "Unknown C compiler" exit 1 fi +if [ "$3" != "" ]; then + FOLDER="$3" +fi + if [ "$2" != "" ]; then if command -v $COMPILE >/dev/null 2>&1; then echo "C compiler found" @@ -38,86 +52,96 @@ if [ "$2" != "" ]; then fi fi -case $(uname | tr '[:upper:]' '[:lower:]') in - *darwin*) - OS=macOS - if [ "$2" = "" ]; then - if command -v clang >/dev/null 2>&1; then - echo "C compiler found - Clang" - COMPILE=clang - COMPILEPP=clang++ - elif command -v gcc >/dev/null 2>&1; then - echo "C compiler found - GCC" - else - echo "C compiler not found" - exit 1 +if [ "$COMPILE" != "emcc" ]; then + case $(uname | tr '[:upper:]' '[:lower:]') in + *darwin*) + OS=macOS + if [ "$2" = "" ]; then + if command -v clang >/dev/null 2>&1; then + echo "C compiler found - Clang" + COMPILE=clang + COMPILEPP=clang++ + elif command -v gcc >/dev/null 2>&1; then + echo "C compiler found - GCC" + else + echo "C compiler not found" + exit 1 + fi fi - fi - ;; - *msys*|*cygwin*|*mingw*|*nt*|*win*) - OS=Windows - EXE_POSTFIX=.exe - if [ "$2" = "" ]; then - if command -v cl.exe >/dev/null 2>&1; then - echo "C compiler found - MSVC" - COMPILE=cl.exe - COMPILEPP=cl.exe - OBJ_POSTFIX=.obj - FLAG_OBJ="-c -Fo" - FLAG_EXE="-Fe" - elif command -v gcc >/dev/null 2>&1; then - echo "C compiler found - GCC" - elif command -v clang >/dev/null 2>&1; then - echo "C compiler found - Clang" - COMPILE=clang - COMPILEPP=clang++ - else - echo "C compiler not found" - exit 1 + ;; + *msys*|*cygwin*|*mingw*|*nt*|*win*) + OS=Windows + EXE_POSTFIX=.exe + if [ "$2" = "" ]; then + if command -v cl.exe >/dev/null 2>&1; then + echo "C compiler found - MSVC" + COMPILE=cl.exe + COMPILEPP=cl.exe + OBJ_POSTFIX=.obj + FLAG_OBJ="-c -Fo" + FLAG_EXE="-Fe" + elif command -v gcc >/dev/null 2>&1; then + echo "C compiler found - GCC" + elif command -v clang >/dev/null 2>&1; then + echo "C compiler found - Clang" + COMPILE=clang + COMPILEPP=clang++ + else + echo "C compiler not found" + exit 1 + fi fi - fi - if [ "$COMPILE" = "cl.exe" ]; then - LINK_FLAGS="Shlwapi.lib Advapi32.lib" - else - LINK_FLAGS="-lShlwapi -lAdvapi32" - fi - ;; - *) - if [ "$2" = "" ]; then - if command -v gcc >/dev/null 2>&1; then - echo "C compiler found - GCC" - elif command -v clang >/dev/null 2>&1; then - echo "C compiler found - Clang" - COMPILE=clang - COMPILEPP=clang++ + if [ "$COMPILE" = "cl.exe" ]; then + LINK_FLAGS="Shlwapi.lib Advapi32.lib" else - echo "C compiler not found" - exit 1 + LINK_FLAGS="-lShlwapi -lAdvapi32" fi - fi - ;; -esac + ;; + *) + if [ "$2" = "" ]; then + if command -v gcc >/dev/null 2>&1; then + echo "C compiler found - GCC" + elif command -v clang >/dev/null 2>&1; then + echo "C compiler found - Clang" + COMPILE=clang + COMPILEPP=clang++ + else + echo "C compiler not found" + exit 1 + fi + fi + ;; + esac +fi -if [ "$COMPILE" = "gcc" ] || [ "$COMPILE" = "clang" ]; then +if [ "$COMPILE" = "gcc" ] || [ "$COMPILE" = "clang" ] || [ "$COMPILE" = "emcc" ]; then if [ "$1" = "release" ]; then - FLAGS="-O3" + FLAGS="-O3 -DNDEBUG" elif [ "$COMPILE" = "gcc" ] && [ "$OS" != "Windows" ]; then FLAGS="-O0 -fsanitize=undefined,address,leak" - elif [ "$OS" != "Windows" ]; then + elif [ "$OS" != "Windows" ] && [ "$COMPILE" != "emcc" ]; then FLAGS="-O0 -fsanitize=undefined,address" else FLAGS="-O0" fi else if [ "$1" = "release" ]; then - FLAGS="-O2" + FLAGS="-O2 -DNDEBUG" else FLAGS="-Od" fi fi +if [ ! -d "$FOLDER" ]; then + mkdir "$FOLDER" +fi + echo "" +# +# Project-specific instructions +# + echo "Build kit" $COMPILE ${FLAGS} \ ${FLAG_OBJ}"build/kit${OBJ_POSTFIX}" \ diff --git a/source/kit/file.c b/source/kit/file.c index 8fcf4fb..e5b834f 100644 --- a/source/kit/file.c +++ b/source/kit/file.c @@ -260,6 +260,9 @@ kit_str_t kit_path_take(kit_str_t path, i64 count) { return s; } +// TODO +// Long path support for Windows +// static void kit_prepare_path_(char *buf, kit_str_t path) { assert(path.size == 0 || path.values != NULL); assert(path.size + 1 < PATH_BUF_SIZE); @@ -268,6 +271,7 @@ static void kit_prepare_path_(char *buf, kit_str_t path) { if (path.size > 0 && path.size + 1 < PATH_BUF_SIZE) memcpy(buf, path.values, path.size); } + #define PREPARE_PATH_BUF_ \ char buf[PATH_BUF_SIZE]; \ kit_prepare_path_(buf, path) -- cgit v1.2.3