From 9edf287034d1bedca49c08dec7a7c333e7a45d9e Mon Sep 17 00:00:00 2001 From: Timerix22 Date: Wed, 29 Mar 2023 14:39:03 +0600 Subject: [PATCH] project created --- .gitignore | 16 ++++++ .gitmodules | 6 ++ Makefile | 65 +++++++++++++++++++++ cbuild | 1 + default.config | 121 +++++++++++++++++++++++++++++++++++++++ kerep | 1 + src/main.c | 23 ++++++++ tasks/clean_additions.sh | 4 ++ tasks/pre_build.sh | 17 ++++++ tasks/rebuild_kerep.sh | 3 + 10 files changed, 257 insertions(+) create mode 100644 .gitignore create mode 100644 .gitmodules create mode 100644 Makefile create mode 160000 cbuild create mode 100644 default.config create mode 160000 kerep create mode 100644 src/main.c create mode 100644 tasks/clean_additions.sh create mode 100644 tasks/pre_build.sh create mode 100644 tasks/rebuild_kerep.sh diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4be6400 --- /dev/null +++ b/.gitignore @@ -0,0 +1,16 @@ +# build results +bin/ +obj/ +*.log +*.tmp + +# IDE files +.vs/ +.vshistory/ +.editorconfig +*.user +*.vcxproj.filters + +# other files +.old*/ +current.config diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..ab3e0b0 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,6 @@ +[submodule "cbuild"] + path = cbuild + url = https://github.com/Timerix22/cbuild.git +[submodule "kerep"] + path = kerep + url = https://github.com/Timerix22/kerep.git diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..13af7c1 --- /dev/null +++ b/Makefile @@ -0,0 +1,65 @@ +###################################### +###### Build tasks ####### +###################################### + +all: build_exec_dbg + +# creates executable using profile info generated by profile +build_exec: profile + @cbuild/call_task.sh build_exec 2>&1 | tee -a make_raw.log + +# creates executable with debug info and no optimizations +build_exec_dbg: + @cbuild/call_task.sh build_exec_dbg 2>&1 | tee make_raw.log + +###################################### +###### Launch tasks ####### +###################################### + +# executes $EXEC_FILE +exec: build_exec + @cbuild/call_task.sh exec 2>&1 | tee -a make_raw.log + +# executes $EXEC_FILE +exec_dbg: build_exec_dbg + @cbuild/call_task.sh exec 2>&1 | tee -a make_raw.log + +# executes $EXEC_FILE with valgrind memory checker +valgrind: build_exec_dbg + @cbuild/call_task.sh valgrind 2>&1 | tee -a make_raw.log + +# generates profiling info +profile: + @cbuild/call_task.sh profile 2>&1 | tee make_raw.log + +# compiles program with -pg and runs it with gprof +# uses gprof2dot python script to generate function call tree +gprof: + @cbuild/call_task.sh gprof 2>&1 | tee make_raw.log + +# compiles executable with sanitizers and executes it to find errors and warnings +sanitize: + @cbuild/call_task.sh sanitize 2>&1 | tee make_raw.log + +###################################### +###### Other tasks ####### +###################################### + +# deletes generated files +clean: + @cbuild/call_task.sh clean 2>&1 | tee make_raw.log + +# removes all unreadable characters copied from stdio +fix_log: + sed 's/[^[:blank:][:print:]]//g' make_raw.log \ + | sed 's/\[0;[0-9][0-9]m//g' \ + | sed 's/\[0;[0-9]m//g' \ + | sed 's/\[[0-9][0-9]m//g' \ + | sed 's/\[[0-9]m//g' \ + | sed 's/ H //g' \ + | sed 's/\[3gH //g' \ + > make_fixed.log + +# recompile kerep.a in the next build task +rebuild_kerep: + @cbuild/call_task.sh rebuild_kerep diff --git a/cbuild b/cbuild new file mode 160000 index 0000000..d64b1f3 --- /dev/null +++ b/cbuild @@ -0,0 +1 @@ +Subproject commit d64b1f3e9b41f6843c501ed28df6adbfdb384217 diff --git a/default.config b/default.config new file mode 100644 index 0000000..76df964 --- /dev/null +++ b/default.config @@ -0,0 +1,121 @@ +#!/bin/bash +CBUILD_VERSION=6 +CONFIG_VERSION=1 + +PROJECT="GraphC" +CMP_C="gcc" +CMP_CPP="g++" +STD_C="c11" +STD_CPP="c++11" +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')" +#TESTS_C="$( find tests -name '*.c')" +#TESTS_CPP="$(find tests -name '*.cpp')" + +# OBJDIR structure: +# ├── objects - dir where compiled *.o files are stored. cleans every call of build task +# ├── profile - dir where gcc *.gcda profiling info files stored +# ├── libs - there you can put static libs and linker will find them +# └── out - output files are created here and then copied to OUTDIR +OBJDIR="obj" +OUTDIR="bin" + +# OS-specific options +case "$OS" in + WINDOWS) + EXEC_FILE="$PROJECT.exe" + ;; + LINUX) + EXEC_FILE="$PROJECT" + ;; + *) + error "operating system $OS has no configuration variants" + ;; +esac + +# TASKS +case "$TASK" in + rebuild_kerep) + TASK_SCRIPT=tasks/rebuild_kerep.sh + ;; + # creates executable using profile info generated by build_profile + 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, it strips away all + C_ARGS="-O2 -flto=auto -fuse-linker-plugin -fprofile-use -fprofile-prefix-path=$(realpath $OBJDIR)/objects" + CPP_ARGS="$C_ARGS" + LINKER_ARGS="$CPP_ARGS" + PRE_TASK_SCRIPT=tasks/pre_build.sh + TASK_SCRIPT=cbuild/default_tasks/build_exec.sh + KEREP_BUILD_TASK=build_static_lib + ;; + # creates executable with debug info and no optimizations + build_exec_dbg) + C_ARGS="-O0 -g" + CPP_ARGS="$C_ARGS" + LINKER_ARGS="$CPP_ARGS" + PRE_TASK_SCRIPT=tasks/pre_build.sh + TASK_SCRIPT=cbuild/default_tasks/build_exec.sh + KEREP_BUILD_TASK=build_static_lib_dbg + ;; + # executes $EXEC_FILE + exec) + TASK_SCRIPT=cbuild/default_tasks/exec.sh + ;; + # executes $EXEC_FILE with valgrind memory checker + valgrind) + VALGRIND_ARGS="-s --log-file=valgrind.log --read-var-info=yes --track-origins=yes --fullpath-after=$PROJECT/ --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" + PRE_TASK_SCRIPT=tasks/pre_build.sh + TASK_SCRIPT=cbuild/default_tasks/build_exec.sh + POST_TASK_SCRIPT=cbuild/default_tasks/profile.sh + ;; + # 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" + PRE_TASK_SCRIPT=tasks/pre_build.sh + TASK_SCRIPT=cbuild/default_tasks/build_exec.sh + POST_TASK_SCRIPT=cbuild/default_tasks/gprof.sh + ;; + # 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" + PRE_TASK_SCRIPT=tasks/pre_build.sh + TASK_SCRIPT=cbuild/default_tasks/build_exec.sh + POST_TASK_SCRIPT=cbuild/default_tasks/exec.sh + ;; + # deletes generated files + clean) + TASK_SCRIPT=cbuild/default_tasks/clean.sh + POST_TASK_SCRIPT=tasks/clean_additions.sh + ;; + # unknown task + *) + error "task <$TASK> not found" + ;; +esac diff --git a/kerep b/kerep new file mode 160000 index 0000000..a2906e2 --- /dev/null +++ b/kerep @@ -0,0 +1 @@ +Subproject commit a2906e2c3aba5d3f94f9eea45bc3e6faed293a7b diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..6433139 --- /dev/null +++ b/src/main.c @@ -0,0 +1,23 @@ +#include "../kerep/src/base/base.h" + +void kt_initGraphCTypes(){ + +} + +int main(const int argc, const char* const* argv){ + if(setlocale(LC_CTYPE, "C.UTF-8")!=0) + kprintf("\e[93msetlocale failed!\n"); + + kt_beginInit(); + kt_initKerepTypes(); + kt_initGraphCTypes(); + kt_endInit(); + + kprintf("\e[37margs:"); + for(i32 i=0; i" + + cd kerep + if ! make "$KEREP_BUILD_TASK"; then + exit 1 + fi + cd .. + + cp kerep/bin/kerep.a $OBJDIR/libs/ + myprint "${GREEN}copied ${CYAN}kerep.a" + rm -f .rebuild_kerep.tmp +fi diff --git a/tasks/rebuild_kerep.sh b/tasks/rebuild_kerep.sh new file mode 100644 index 0000000..7698a61 --- /dev/null +++ b/tasks/rebuild_kerep.sh @@ -0,0 +1,3 @@ +#!/bin/bash +touch .rebuild_kerep.tmp +myprint "${YELLOW}kerep.a will be rebuilt in the next build task"