From 2e1fcb9536bbfbb379ad401b6060037e6388fa9a Mon Sep 17 00:00:00 2001 From: Timerix Date: Tue, 30 Jul 2024 01:02:42 +0300 Subject: [PATCH] initial commit --- .gitignore | 23 ++++ .gitmodules | 10 ++ .vscode/.gitignore | 1 + .vscode/c_cpp_properties.json | 17 +++ .vscode/launch.json | 28 ++++ .vscode/tasks.json | 32 +++++ README.md | 38 ++++++ dependencies/.gitignore | 2 + dependencies/imgui | 1 + dependencies/imgui.config | 12 ++ dependencies/imgui.project.config | 101 +++++++++++++++ dependencies/imnodes | 1 + dependencies/imnodes.config | 12 ++ dependencies/imnodes.project.config | 95 ++++++++++++++ dependencies/precompiled.config | 21 +++ dependencies/resource_embedder | 1 + dependencies/resources.config | 8 ++ project.config | 191 ++++++++++++++++++++++++++++ src/UsefulException.cpp | 15 +++ src/UsefulException.hpp | 21 +++ src/format.cpp | 66 ++++++++++ src/format.hpp | 7 + src/main.cpp | 9 ++ src/std.hpp | 60 +++++++++ tasks/clean_additions.sh | 3 + 25 files changed, 775 insertions(+) create mode 100644 .gitignore create mode 100644 .gitmodules create mode 100644 .vscode/.gitignore create mode 100644 .vscode/c_cpp_properties.json create mode 100644 .vscode/launch.json create mode 100644 .vscode/tasks.json create mode 100644 README.md create mode 100644 dependencies/.gitignore create mode 160000 dependencies/imgui create mode 100644 dependencies/imgui.config create mode 100644 dependencies/imgui.project.config create mode 160000 dependencies/imnodes create mode 100644 dependencies/imnodes.config create mode 100644 dependencies/imnodes.project.config create mode 100644 dependencies/precompiled.config create mode 160000 dependencies/resource_embedder create mode 100644 dependencies/resources.config create mode 100644 project.config create mode 100644 src/UsefulException.cpp create mode 100644 src/UsefulException.hpp create mode 100644 src/format.cpp create mode 100644 src/format.hpp create mode 100644 src/main.cpp create mode 100644 src/std.hpp create mode 100644 tasks/clean_additions.sh diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b603471 --- /dev/null +++ b/.gitignore @@ -0,0 +1,23 @@ +# build results +bin/ +obj/ +src/generated/ +imgui.ini + +# IDE files +.vs/ +.vshistory/ +.editorconfig +*.user +*.vcxproj.filters + +# other files +.old*/ +old/ +tmp/ +temp/ +*.tmp +*.temp +logs/ +log/ +*.log diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..7d6a9ca --- /dev/null +++ b/.gitmodules @@ -0,0 +1,10 @@ +[submodule "dependencies/imgui"] + path = dependencies/imgui + url = https://github.com/ocornut/imgui.git + branch = docking +[submodule "dependencies/imnodes"] + path = dependencies/imnodes + url = https://github.com/Nelarius/imnodes.git +[submodule "dependencies/resource_embedder"] + path = dependencies/resource_embedder + url = https://timerix.ddns.net:3322/Timerix/resource_embedder.git diff --git a/.vscode/.gitignore b/.vscode/.gitignore new file mode 100644 index 0000000..e38da20 --- /dev/null +++ b/.vscode/.gitignore @@ -0,0 +1 @@ +settings.json diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..b198f99 --- /dev/null +++ b/.vscode/c_cpp_properties.json @@ -0,0 +1,17 @@ +{ + "configurations": [ + { + "name": "all", + "defines": [ + "SDL_DISABLE_ANALYZE_MACROS", + "DEBUG=1" + ], + "includePath": [ + "dependencies/include/SDL2", + "dependencies/imgui", + "${default}" + ] + } + ], + "version": 4 +} \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..42c5cc2 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,28 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "gdb_debug", + "type": "cppdbg", + "request": "launch", + "program": "${workspaceFolder}/bin/ougge", + "windows": { "program": "${workspaceFolder}/bin/ougge.exe" }, + "preLaunchTask": "build_exec_dbg", + "stopAtEntry": false, + "cwd": "${workspaceFolder}/bin", + "externalConsole": false, + "MIMode": "gdb", + "miDebuggerPath": "gdb", + "setupCommands": [ + { + "text": "-enable-pretty-printing", + "ignoreFailures": true + }, + { + "text": "-gdb-set disassembly-flavor intel", + "ignoreFailures": true + } + ] + } + ] +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..9840ce9 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,32 @@ + +{ + + "version": "2.0.0", + "tasks": [ + { + "label": "build_exec_dbg", + "detail": "build project with debug symbols", + "type": "cppbuild", + "command": "bash", + "args": [ + "-c", + "cbuild build_exec_dbg" + ], + "options": { + "cwd": "${workspaceFolder}" + }, + "problemMatcher": ["$gcc"], + "group": { + "kind": "build" + }, + "presentation": { + "echo": true, + "reveal": "always", + "focus": true, + "panel": "shared", + "showReuseMessage": false, + "clear": true + } + } + ] + } \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..100324b --- /dev/null +++ b/README.md @@ -0,0 +1,38 @@ +# ougge +A game engine or something, idk. + +## Installation +1. Clone the repository +```sh +git clone --recurse-submodules https://timerix.ddns.net:3322/Timerix/ougge.git +``` +2. Install [cbuild](https://timerix.ddns.net:3322/Timerix/cbuild.git) +3. Install **SDL2** from package manager or compile it from source. + **If you are using msys, switch to mingw64 sh.** + ```sh + git clone https://github.com/libsdl-org/SDL.git + cd SDL + ./configure + make -j [number of cpu threads] + ``` + Then you can install it systemwide (on **Linux**): + ```sh + sudo make install + ``` + or copy to ./dependencies/precompiled/ (on **Windows**): + ```sh + mkdir -p ../ougge/dependencies/precompiled/ + cp ./build/.libs/SDL2.dll ../ougge/dependencies/precompiled/ + ``` + If it doesn't work, read [SDL/INSTALL.txt](https://github.com/libsdl-org/SDL/blob/SDL2/INSTALL.txt) and [SDL/docs/README.md](https://github.com/libsdl-org/SDL/blob/SDL2/docs/README.md). +4. Symlink SDL headers directory to `dependencies/include` + ```sh + cd ../ougge + ln -s SDL2_HEADERS_DIRECTORY_ABSOLUTE_PATH -T dependencies/include/SDL2 + ``` + Location of the headers can be found by `pkg-config --cflags --libs sdl2`. + Mingw installs SDL2 headers to `/mingw64/include/SDL2`. +5. Compile the program + ```sh + cbuild build_exec_dbg + ``` diff --git a/dependencies/.gitignore b/dependencies/.gitignore new file mode 100644 index 0000000..4119546 --- /dev/null +++ b/dependencies/.gitignore @@ -0,0 +1,2 @@ +/include/ +/precompiled/ diff --git a/dependencies/imgui b/dependencies/imgui new file mode 160000 index 0000000..271910e --- /dev/null +++ b/dependencies/imgui @@ -0,0 +1 @@ +Subproject commit 271910e3495e686a252b4b85369dec0605ba0d20 diff --git a/dependencies/imgui.config b/dependencies/imgui.config new file mode 100644 index 0000000..7c708b4 --- /dev/null +++ b/dependencies/imgui.config @@ -0,0 +1,12 @@ +#!/usr/bin/env bash +DEP_WORKING_DIR='dependencies/imgui' +DEP_PRE_BUILD_COMMAND='' +if [[ "$TASK" = *_dbg ]]; then + DEP_BUILD_COMMAND='cbuild -c ../imgui.project.config build_static_lib_dbg' +else + DEP_BUILD_COMMAND='cbuild -c ../imgui.project.config build_static_lib' +fi +DEP_POST_BUILD_COMMAND='' +DEP_CLEAN_COMMAND='cbuild clean -c ../imgui.project.config' +DEP_STATIC_OUT_FILES='../bin/libimgui.a' +DEP_DYNAMIC_OUT_FILES='' diff --git a/dependencies/imgui.project.config b/dependencies/imgui.project.config new file mode 100644 index 0000000..861ddfe --- /dev/null +++ b/dependencies/imgui.project.config @@ -0,0 +1,101 @@ +#!/usr/bin/env bash +CBUILD_VERSION=2.1.2 +CONFIG_VERSION=1 + +PROJECT="imgui" +CMP_C="gcc" +CMP_CPP="g++" +STD_C="c11" +STD_CPP="c++11" +WARN_C="-Wall -Wno-discarded-qualifiers -Wno-unused-parameter" +WARN_CPP="-Wall -Wno-unused-parameter" +SRC_C="" +SRC_CPP="imgui.cpp + imgui_demo.cpp + imgui_draw.cpp + imgui_tables.cpp + imgui_widgets.cpp + backends/imgui_impl_sdl2.cpp + backends/imgui_impl_opengl3.cpp" + +# Directory with dependency configs. +# See cbuild/example_dependency_configs +DEPENDENCY_CONFIGS_DIR='dependencies' +# List of dependency config files in DEPENDENCY_CONFIGS_DIR separated by space. +ENABLED_DEPENDENCIES='' + +# OBJDIR structure: +# ├── objects/ - Compiled object files. Cleans on each call of build task +# ├── static_libs/ - Symbolic links to static libraries used by linker. Cleans on each call of build task. +# ├── static_libs/ - Symbolic links to dynamic libraries used by linker. Cleans on each call of build task. +# └── profile/ - gcc *.gcda profiling info files +OBJDIR="../obj" +OUTDIR="../bin" +STATIC_LIB_FILE="lib$PROJECT.a" + +# header include directories +INCLUDE="-I. -I../include/SDL2" + +# OS-specific options +case "$OS" in + WINDOWS) + EXEC_FILE="$PROJECT.exe" + SHARED_LIB_FILE="lib$PROJECT.dll" + ;; + LINUX) + EXEC_FILE="$PROJECT" + SHARED_LIB_FILE="lib$PROJECT.so" + ;; + *) + error "operating system $OS has no configuration variants" + ;; +esac + +# TASKS +case "$TASK" in + # creates shared library + build_shared_lib) + C_ARGS="-O2 -fpic -flto -shared" + CPP_ARGS="$C_ARGS" + LINKER_ARGS="$CPP_ARGS -Wl,-soname,$SHARED_LIB_FILE" + PRE_TASK_SCRIPT= + TASK_SCRIPT=cbuild/default_tasks/build_shared_lib.sh + POST_TASK_SCRIPT= + ;; + # creates shared library with debug symbols and no optimizations + build_shared_lib_dbg) + C_ARGS="-O0 -g3 -fpic -shared" + CPP_ARGS="$C_ARGS" + LINKER_ARGS="$CPP_ARGS -Wl,-soname,$SHARED_LIB_FILE" + PRE_TASK_SCRIPT= + TASK_SCRIPT=cbuild/default_tasks/build_shared_lib.sh + POST_TASK_SCRIPT= + ;; + # creates static library + build_static_lib) + C_ARGS="-O2" + CPP_ARGS="$C_ARGS" + PRE_TASK_SCRIPT= + TASK_SCRIPT=cbuild/default_tasks/build_static_lib.sh + POST_TASK_SCRIPT= + ;; + # creates static library with debug symbols and no optimizations + build_static_lib_dbg) + C_ARGS="-O0 -g3" + CPP_ARGS="$C_ARGS" + PRE_TASK_SCRIPT= + TASK_SCRIPT=cbuild/default_tasks/build_static_lib.sh + POST_TASK_SCRIPT= + ;; + # deletes generated files + clean) + TASK_SCRIPT=cbuild/default_tasks/clean.sh + ;; + # nothing to do + "" | no_task) + ;; + # unknown task + *) + error "task <$TASK> not found" + ;; +esac diff --git a/dependencies/imnodes b/dependencies/imnodes new file mode 160000 index 0000000..8563e16 --- /dev/null +++ b/dependencies/imnodes @@ -0,0 +1 @@ +Subproject commit 8563e1655bd9bb1f249e6552cc6274d506ee788b diff --git a/dependencies/imnodes.config b/dependencies/imnodes.config new file mode 100644 index 0000000..c7ec1a0 --- /dev/null +++ b/dependencies/imnodes.config @@ -0,0 +1,12 @@ +#!/usr/bin/env bash +DEP_WORKING_DIR='dependencies/imnodes' +DEP_PRE_BUILD_COMMAND='' +if [[ "$TASK" = *_dbg ]]; then + DEP_BUILD_COMMAND='cbuild -c ../imnodes.project.config build_static_lib_dbg' +else + DEP_BUILD_COMMAND='cbuild -c ../imnodes.project.config build_static_lib' +fi +DEP_POST_BUILD_COMMAND='' +DEP_CLEAN_COMMAND='cbuild clean -c ../imnodes.project.config' +DEP_STATIC_OUT_FILES='../bin/libimnodes.a' +DEP_DYNAMIC_OUT_FILES='' diff --git a/dependencies/imnodes.project.config b/dependencies/imnodes.project.config new file mode 100644 index 0000000..52c6953 --- /dev/null +++ b/dependencies/imnodes.project.config @@ -0,0 +1,95 @@ +#!/usr/bin/env bash +CBUILD_VERSION=2.1.2 +CONFIG_VERSION=1 + +PROJECT="imnodes" +CMP_C="gcc" +CMP_CPP="g++" +STD_C="c11" +STD_CPP="c++11" +WARN_C="-Wall -Wno-discarded-qualifiers -Wno-unused-parameter" +WARN_CPP="-Wall -Wno-unused-parameter" +SRC_C="" +SRC_CPP="imnodes.cpp" + +# Directory with dependency configs. +# See cbuild/example_dependency_configs +DEPENDENCY_CONFIGS_DIR='dependencies' +# List of dependency config files in DEPENDENCY_CONFIGS_DIR separated by space. +ENABLED_DEPENDENCIES='' + +# OBJDIR structure: +# ├── objects/ - Compiled object files. Cleans on each call of build task +# ├── static_libs/ - Symbolic links to static libraries used by linker. Cleans on each call of build task. +# ├── static_libs/ - Symbolic links to dynamic libraries used by linker. Cleans on each call of build task. +# └── profile/ - gcc *.gcda profiling info files +OBJDIR="../obj" +OUTDIR="../bin" +STATIC_LIB_FILE="lib$PROJECT.a" + +# header include directories +INCLUDE="-I. -I../imgui -I../imgui/backends" + +# OS-specific options +case "$OS" in + WINDOWS) + EXEC_FILE="$PROJECT.exe" + SHARED_LIB_FILE="lib$PROJECT.dll" + ;; + LINUX) + EXEC_FILE="$PROJECT" + SHARED_LIB_FILE="lib$PROJECT.so" + ;; + *) + error "operating system $OS has no configuration variants" + ;; +esac + +# TASKS +case "$TASK" in + # creates shared library + build_shared_lib) + C_ARGS="-O2 -fpic -flto -shared" + CPP_ARGS="$C_ARGS" + LINKER_ARGS="$CPP_ARGS -Wl,-soname,$SHARED_LIB_FILE" + PRE_TASK_SCRIPT= + TASK_SCRIPT=cbuild/default_tasks/build_shared_lib.sh + POST_TASK_SCRIPT= + ;; + # creates shared library with debug symbols and no optimizations + build_shared_lib_dbg) + C_ARGS="-O0 -g3 -fpic -shared" + CPP_ARGS="$C_ARGS" + LINKER_ARGS="$CPP_ARGS -Wl,-soname,$SHARED_LIB_FILE" + PRE_TASK_SCRIPT= + TASK_SCRIPT=cbuild/default_tasks/build_shared_lib.sh + POST_TASK_SCRIPT= + ;; + # creates static library + build_static_lib) + C_ARGS="-O2" + CPP_ARGS="$C_ARGS" + PRE_TASK_SCRIPT= + TASK_SCRIPT=cbuild/default_tasks/build_static_lib.sh + POST_TASK_SCRIPT= + ;; + # creates static library with debug symbols and no optimizations + build_static_lib_dbg) + C_ARGS="-O0 -g3" + CPP_ARGS="$C_ARGS" + PRE_TASK_SCRIPT= + TASK_SCRIPT=cbuild/default_tasks/build_static_lib.sh + POST_TASK_SCRIPT= + ;; + # deletes generated files + clean) + TASK_SCRIPT=cbuild/default_tasks/clean.sh + ;; + # nothing to do + "" | no_task) + ;; + # unknown task + *) + error "task <$TASK> not found" + ;; +esac diff --git a/dependencies/precompiled.config b/dependencies/precompiled.config new file mode 100644 index 0000000..352b745 --- /dev/null +++ b/dependencies/precompiled.config @@ -0,0 +1,21 @@ +#!/usr/bin/env bash +mkdir -p 'dependencies/precompiled' +DEP_WORKING_DIR='dependencies/precompiled' +DEP_PRE_BUILD_COMMAND='' +DEP_BUILD_COMMAND='' +DEP_POST_BUILD_COMMAND='' +DEP_CLEAN_COMMAND='' +# won't be copied to project $OUTDIR +DEP_STATIC_OUT_FILES=$(find dependencies/precompiled -name '*.a' | sed 's,dependencies/precompiled/,,') +# will be copied tp project $OUTDIR +case $OS in + WINDOWS) + DEP_DYNAMIC_OUT_FILES=$(find dependencies/precompiled -name '*.dll' | sed 's,dependencies/precompiled/,,') + ;; + LINUX) + DEP_DYNAMIC_OUT_FILES=$(find dependencies/precompiled -name '*.so' | sed 's,dependencies/precompiled/,,') + ;; + *) + error "operating system $OS has no configuration variants" + ;; +esac diff --git a/dependencies/resource_embedder b/dependencies/resource_embedder new file mode 160000 index 0000000..9cc2fd7 --- /dev/null +++ b/dependencies/resource_embedder @@ -0,0 +1 @@ +Subproject commit 9cc2fd7814eb6172b753fa1c7e2bea9656033755 diff --git a/dependencies/resources.config b/dependencies/resources.config new file mode 100644 index 0000000..f521f4d --- /dev/null +++ b/dependencies/resources.config @@ -0,0 +1,8 @@ +#!/usr/bin/env bash +DEP_WORKING_DIR='dependencies/resource_embedder' +DEP_PRE_BUILD_COMMAND='./build.sh' +DEP_BUILD_COMMAND='../compile_resources.sh' +DEP_POST_BUILD_COMMAND='' +DEP_CLEAN_COMMAND='rm -f ./resource_embedder ./resource_embedder.exe ../obj/resources.c ../bin/resources.o' +DEP_STATIC_OUT_FILES='../bin/resources.o' +DEP_DYNAMIC_OUT_FILES= diff --git a/project.config b/project.config new file mode 100644 index 0000000..2289d73 --- /dev/null +++ b/project.config @@ -0,0 +1,191 @@ +#!/usr/bin/env bash +CBUILD_VERSION=2.1.2 +CONFIG_VERSION=1 + +PROJECT="ougge" +CMP_C="gcc" +CMP_CPP="g++" +STD_C="c11" +STD_CPP="c++17" +WARN_C="-Wall -Wno-discarded-qualifiers -Wextra -Wno-unused-parameter" +WARN_CPP="-Wall -Wextra -Wno-unused-parameter" +SRC_C="$(find src -name '*.c')" +SRC_CPP="$(find src -name '*.cpp')" + +# Directory with dependency configs. +# See cbuild/example_dependency_configs +DEPENDENCY_CONFIGS_DIR='dependencies' +# List of dependency config files in DEPENDENCY_CONFIGS_DIR separated by space. +ENABLED_DEPENDENCIES='imnodes imgui precompiled' + +# OBJDIR structure: +# ├── objects/ - Compiled object files. Cleans on each call of build task +# ├── static_libs/ - Symbolic links to static libraries used by linker. Cleans on each call of build task. +# ├── static_libs/ - Symbolic links to dynamic libraries used by linker. Cleans on each call of build task. +# └── profile/ - gcc *.gcda profiling info files +OBJDIR="obj" +OUTDIR="bin" +STATIC_LIB_FILE="lib$PROJECT.a" + +# header include directories +INCLUDE="-I./dependencies/imgui -I./dependencies/include/SDL2" + +# OS-specific options +case "$OS" in + WINDOWS) + EXEC_FILE="$PROJECT.exe" + SHARED_LIB_FILE="$PROJECT.dll" + LINKER_LIBS="-lopengl32 -lpthread" + ;; + LINUX) + EXEC_FILE="$PROJECT" + SHARED_LIB_FILE="$PROJECT.so" + LINKER_LIBS="-lSDL2 -lGL" + ;; + *) + error "operating system $OS has no configuration variants" + ;; +esac + + +# TASKS +case "$TASK" in + # creates executable using profiling info if it exists + build_exec) + # -flto applies more optimizations across object files + # -flto=auto is needed to multithreaded copilation + # -fuse-linker-plugin is required to use static libs with lto + # -fprofile-use enables compiler to use profiling info files to optimize executable + # -fprofile-prefix-path sets path where profiling info about objects are be saved + # -fdata-sections -ffunction-sections -Wl,--gc-sections removes unused code + C_ARGS="-O2 -flto=auto -fuse-linker-plugin -fprofile-use -fprofile-prefix-path=$(realpath $OBJDIR)/objects -fdata-sections -ffunction-sections -Wl,--gc-sections" + CPP_ARGS="$C_ARGS" + LINKER_ARGS="$CPP_ARGS $LINKER_LIBS" + PRE_TASK_SCRIPT= + TASK_SCRIPT=cbuild/default_tasks/build_exec.sh + POST_TASK_SCRIPT= + ;; + # creates executable with debug info and no optimizations + build_exec_dbg) + C_ARGS="-O0 -g3" + CPP_ARGS="$C_ARGS" + LINKER_ARGS="$CPP_ARGS $LINKER_LIBS" + PRE_TASK_SCRIPT= + TASK_SCRIPT=cbuild/default_tasks/build_exec.sh + POST_TASK_SCRIPT= + ;; + # creates shared library + build_shared_lib) + C_ARGS="-O2 -fpic -flto -shared" + CPP_ARGS="$C_ARGS" + LINKER_ARGS="$CPP_ARGS $LINKER_LIBS -Wl,-soname,$SHARED_LIB_FILE" + PRE_TASK_SCRIPT= + TASK_SCRIPT=cbuild/default_tasks/build_shared_lib.sh + POST_TASK_SCRIPT= + ;; + # creates shared library with debug symbols and no optimizations + build_shared_lib_dbg) + C_ARGS="-O0 -g3 -fpic -shared" + CPP_ARGS="$C_ARGS" + LINKER_ARGS="$CPP_ARGS $LINKER_LIBS -Wl,-soname,$SHARED_LIB_FILE" + PRE_TASK_SCRIPT= + TASK_SCRIPT=cbuild/default_tasks/build_shared_lib.sh + POST_TASK_SCRIPT= + ;; + # creates static library + build_static_lib) + C_ARGS="-O2 -fpic -fdata-sections -ffunction-sections" + CPP_ARGS="$C_ARGS" + PRE_TASK_SCRIPT= + TASK_SCRIPT=cbuild/default_tasks/build_static_lib.sh + POST_TASK_SCRIPT= + ;; + # creates static library with debug symbols and no optimizations + build_static_lib_dbg) + C_ARGS="-O0 -g3" + CPP_ARGS="$C_ARGS" + PRE_TASK_SCRIPT= + TASK_SCRIPT=cbuild/default_tasks/build_static_lib.sh + POST_TASK_SCRIPT= + ;; + # executes $EXEC_FILE + exec) + TASK_SCRIPT=cbuild/default_tasks/exec.sh + ;; + # executes $EXEC_FILE with valgrind memory checker + valgrind) + VALGRIND_ARGS="-s --read-var-info=yes --track-origins=yes --fullpath-after=$(pwd) --leak-check=full --show-leak-kinds=all" + TASK_SCRIPT=cbuild/default_tasks/valgrind.sh + ;; + # generates profiling info + profile) + OUTDIR="$OUTDIR/profile" + # -flto applies more optimizations across object files + # -flto=auto is needed to multithreaded copilation + # -fuse-linker-plugin is required to use static libs with lto + # -pg adds code to executable, that generates file containing function call info (gmon.out) + # -fprofile-generate generates executable with profiling code + # -fprofile-prefix-path sets path where profiling info about objects will be saved + C_ARGS="-O2 -flto=auto -fuse-linker-plugin -fprofile-generate -fprofile-prefix-path=$(realpath $OBJDIR)/objects" + CPP_ARGS="$C_ARGS" + LINKER_ARGS="$CPP_ARGS $LINKER_LIBS" + PRE_TASK_SCRIPT=cbuild/default_tasks/build_exec.sh + TASK_SCRIPT=cbuild/default_tasks/profile.sh + POST_TASK_SCRIPT= + ;; + # compiles program with -pg and runs it with gprof + # uses gprof2dot python script to generate function call tree (pip install gprof2dot) + # requires graphviz (https://www.graphviz.org/download/source/) + gprof) + OUTDIR="$OUTDIR/gprof" + # -pg adds code to executable, that generates file containing function call info (gmon.out) + C_ARGS="-O2 -flto=auto -fuse-linker-plugin -pg" + CPP_ARGS="$C_ARGS" + LINKER_ARGS="$CPP_ARGS $LINKER_LIBS" + PRE_TASK_SCRIPT=cbuild/default_tasks/build_exec.sh + TASK_SCRIPT=cbuild/default_tasks/gprof.sh + POST_TASK_SCRIPT= + ;; + # compiles program and runs it with callgrind (part of valgrind) + # uses gprof2dot python script to generate function call tree (pip install gprof2dot) + # requires graphviz (https://www.graphviz.org/download/source/) + # P.S. detailed results can be viewed in KCacheGrind + callgrind) + OUTDIR="$OUTDIR/callgrind" + # -pg adds code to executable, that generates file containing function call info (gmon.out) + C_ARGS="-O2 -flto=auto -fuse-linker-plugin" + CPP_ARGS="$C_ARGS" + LINKER_ARGS="$CPP_ARGS $LINKER_LIBS" + PRE_TASK_SCRIPT=cbuild/default_tasks/build_exec.sh + TASK_SCRIPT=cbuild/default_tasks/callgrind.sh + POST_TASK_SCRIPT= + ;; + # compiles executable with sanitizers and executes it to find errors and warnings + sanitize) + OUTDIR="$OUTDIR/sanitize" + C_ARGS="-O0 -g3 -fsanitize=undefined,address" + CPP_ARGS="$C_ARGS" + LINKER_ARGS="$CPP_ARGS $LINKER_LIBS" + PRE_TASK_SCRIPT=cbuild/default_tasks/build_exec.sh + TASK_SCRIPT=cbuild/default_tasks/exec.sh + POST_TASK_SCRIPT= + ;; + # rebuilds specified dependencies + # EXAMPLE: `cbuild rebuild_dependencies=libexample1,fonts` + # 'all' can be specified to rebuild all dependencies + rebuild_dependencies) + TASK_SCRIPT=cbuild/default_tasks/rebuild_dependencies.sh + ;; + # deletes generated files + clean) + TASK_SCRIPT=cbuild/default_tasks/clean.sh + POST_TASK_SCRIPT=tasks/clean_additions.sh + ;; + # nothing to do + "" | no_task) + ;; + # unknown task + *) + error "task <$PROJECT/$TASK> not found" + ;; +esac diff --git a/src/UsefulException.cpp b/src/UsefulException.cpp new file mode 100644 index 0000000..5e9e8ac --- /dev/null +++ b/src/UsefulException.cpp @@ -0,0 +1,15 @@ +#include "UsefulException.hpp" +#include + +UsefulException_::UsefulException_(const std::string& _message, const std::string& _file, const std::string& _func, int _line_n) + : message(_message), file(_file), function(_func), line_n(_line_n) +{ + std::stringstream ss; + ss< +#include + +#define UsefulException(MSG) UsefulException_(MSG, __FILE__, __func__, __LINE__) + +class UsefulException_ : public std::exception { + std::string message; + std::string file; + std::string function; + int line_n; + std::string complete_text; + +public: + UsefulException_(const std::string& msg, const std::string& _file, const std::string& _func, int line_n); + + virtual char const* what() const noexcept; +}; + +#define useful_assert(EXPR, ERRMSG) if(!EXPR) throw UsefulException(ERRMSG); diff --git a/src/format.cpp b/src/format.cpp new file mode 100644 index 0000000..8d98bce --- /dev/null +++ b/src/format.cpp @@ -0,0 +1,66 @@ +#include +#include +#include +#include "UsefulException.hpp" +#include "std.hpp" + +std::string _format(const std::string& format_str, const size_t args_count, ...){ + va_list vl; + va_start(vl, args_count); + std::stringstream ss; + + for(size_t i = 0; i < format_str.length(); i++){ + char c = format_str[i]; + + // format specifier + if(c == '%'){ + c = format_str[++i]; + bool l = false; + while(c == 'l'){ + l = true; + c = format_str[++i]; + } + + switch(c){ + case 'u': + if(l) ss<<(u64)va_arg(vl, u64); + else ss<<(u32)va_arg(vl, u32); + break; + case 'i': + case 'd': + if(l) ss<<(i64)va_arg(vl, i64); + else ss<<(i32)va_arg(vl, i32); + break; + case 'f': + // f32 is promoted to f64 when passed through '...' + ss<<(f64)va_arg(vl, f64); + break; + case 'p': + ss<<(void*)va_arg(vl, void*); + break; + case 'x': + if(l) ss<"; + break; + } + case 'c': + ss<<(char)va_arg(vl,int); + break; + default: + throw UsefulException("invalid format cpecifier"); + } + } + + // regular character + else ss< +#include "../dependencies/kerep/src/base/std.h" + +std::string _format(const std::string& format_str, const size_t args_count, ...); +#define format(FORMAT_STR, ARGS...) _format(FORMAT_STR, count_args(ARGS) ,##ARGS) diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..20eeefc --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,9 @@ +#define SDL_MAIN_HANDLED +#include +#include "std.hpp" +#include + +int main(int argc, const char** argv){ + std::cout<<"UwU"< + +typedef int8_t i8; +typedef uint8_t u8; +typedef int16_t i16; +typedef uint16_t u16; +typedef int32_t i32; +typedef uint32_t u32; +typedef int64_t i64; +typedef uint64_t u64; +typedef float f32; +typedef double f64; +/// anonymous pointer without specified freeMembers() func +typedef void* Pointer; + +#define nameof(V) #V + +#ifdef _MSC_VER + #pragma comment(lib, "mincore_downlevel.lib") // Support OS older than SDK + #define _CRT_SECURE_NO_WARNINGS 1 + #define EXPORT __declspec(dllexport) + #define CALL __cdecl +#elif defined(__GNUC__) + #define EXPORT __attribute__((visibility("default"))) + #if __SIZEOF_POINTER__ == 4 + #define CALL __attribute__((__cdecl__)) + #else + #define CALL + #endif + #ifndef typeof + #define typeof(X) __typeof__(X) + #endif +#else + #pragma GCC error "unknown compiler" +#endif + +#define __count_args( \ + a0, a1, a2, a3, a4, a5, a6, a7 , \ + a8, a9, a10,a11,a12,a13,a14,a15, \ + a16,a17,a18,a19,a20,a21,a22,a23, \ + a24,a25,a26,a27,a28,a29,a30,a31, \ + a32,a33,a34,a35,a36,a37,a38,a39, \ + a40,a41,a42,a43,a44,a45,a46,a47, \ + a48,a49,a50,a51,a52,a53,a54,a55, \ + a56,a57,a58,a59,a60,a61,a62,a63, \ + a64,...) a64 +// Macro for counting variadic arguments (max 64) +// (see usage in kprint.h) +#define count_args(ARGS...) __count_args( \ + ARGS, \ + 64,63,62,61,60,59,58,57, \ + 56,55,54,53,52,51,50,49, \ + 48,47,46,45,44,43,42,41, \ + 40,39,38,37,36,35,34,33, \ + 32,31,30,29,28,27,26,25, \ + 24,23,22,21,20,19,18,17, \ + 16,15,14,13,12,11,10,9, \ + 8, 7, 6, 5, 4, 3, 2, 1, 0) diff --git a/tasks/clean_additions.sh b/tasks/clean_additions.sh new file mode 100644 index 0000000..83fa64f --- /dev/null +++ b/tasks/clean_additions.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +try_delete_dir_or_file src/generated