cbuild v7

This commit is contained in:
Timerix22 2024-02-22 01:15:34 +06:00
parent 14e103833a
commit 713c80a93d
18 changed files with 98 additions and 92 deletions

2
.gitmodules vendored
View File

@ -13,7 +13,7 @@
url = https://github.com/Timerix22/imgui.git
branch = docking_cbuild
[submodule "imgui-node-editor"]
path = dependencies/imgui-node-editor
path = dependencies/imgui_node_editor
url = https://github.com/Timerix22/imgui-node-editor.git
branch = develop_cbuild
[submodule "imnodes"]

View File

@ -12,6 +12,31 @@ build_exec: rebuild_all # profile
build_exec_dbg:
@cbuild/call_task.sh build_exec_dbg 2>&1 | tee make_raw.log
######################################
###### Rebuild dependencies #######
######################################
# recompile kerep.a in the next build task
rebuild_kerep:
@cbuild/rebuild_dep.sh libkerep.a 2>&1 | tee make_raw.log
# recompile imgui.a in the next build task
rebuild_imgui:
@cbuild/rebuild_dep.sh libimgui.a 2>&1 | tee make_raw.log
rebuild_imgui_node_editor:
@cbuild/rebuild_dep.sh libimgui-node-editor.a 2>&1 | tee make_raw.log
rebuild_imnodes:
@cbuild/rebuild_dep.sh libimnodes.a 2>&1 | tee make_raw.log
# writes ttf fonts fron ./fonts/ to C compressed arrays in C source files
# builds static library from font arrays definitions
embed_fonts:
@cbuild/call_task.sh embed_fonts
rebuild_all: rebuild_kerep rebuild_imgui rebuild_imgui_node_editor rebuild_imnodes embed_fonts
######################################
###### Launch tasks #######
######################################
@ -33,10 +58,18 @@ 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
# uses gprof2dot python script to generate function call tree (pip install gprof2dot)
# requires graphviz (https://www.graphviz.org/download/source/)
gprof:
@cbuild/call_task.sh gprof 2>&1 | tee make_raw.log
# 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:
@cbuild/call_task.sh callgrind 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
@ -59,23 +92,3 @@ fix_log:
| sed 's/ H //g' \
| sed 's/\[3gH //g' \
> make_fixed.log
# recompile kerep.a in the next build task
rebuild_kerep:
@tasks/rebuild_lib.sh kerep
# recompile imgui.a in the next build task
rebuild_imgui:
@tasks/rebuild_lib.sh imgui
rebuild_imgui-node-editor:
@tasks/rebuild_lib.sh imgui-node-editor
rebuild_imnodes:
@tasks/rebuild_lib.sh imnodes
# writes ttf fonts fron ./fonts/ to C compressed arrays in C source files
# builds static library from font arrays definitions
embed_fonts:
@cbuild/call_task.sh embed_fonts
rebuild_all: rebuild_kerep rebuild_imgui rebuild_imgui-node-editor rebuild_imnodes embed_fonts

2
cbuild

@ -1 +1 @@
Subproject commit 60fa8c11c2673a10f8afbe37bcea13c9be3317b8
Subproject commit 574ce6eab3b65e05888adad95a0211f532dd1125

View File

@ -1,6 +1,6 @@
#!/bin/bash
CBUILD_VERSION=6
CONFIG_VERSION=4
CBUILD_VERSION=7
CONFIG_VERSION=6
PROJECT="GraphC"
CMP_C="gcc"
@ -14,6 +14,19 @@ SRC_CPP="$(find src -name '*.cpp')"
#TESTS_C="$( find tests -name '*.c')"
#TESTS_CPP="$(find tests -name '*.cpp')"
# dir with dependeicy dirs
DEPS_BASEDIR="dependencies"
# EXAMPLE: "dependency_dir='build_task out_dir lib_file'
# other_depndency_dir=..."
# Dependencies must be declared on separate lines
# Values can be override by resetting one of dependencies:
# DEPS="$DEPS
# dependency_dir='...'"
DEPS="kerep='build_static_lib bin libkerep.a'
imgui='build_static_lib bin libimgui.a'
imnodes='build_static_lib bin libimnodes.a'
imgui_node_editor='build_static_lib bin libimgui-node-editor.a'"
# 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
@ -26,13 +39,13 @@ OUTDIR="bin"
case "$OS" in
WINDOWS)
EXEC_FILE="$PROJECT.exe"
INCLUDE="-I./imgui -I/usr/include/SDL2"
LINKER_LIBS="-L./$OBJDIR/libs/ -lSDL2 -lopengl32"
INCLUDE="-I./dependencies/imgui -I./dependencies/SDL2/include"
LINKER_LIBS="-L./$OBJDIR/libs/ -lSDL2 -lopengl32 -lpthread -lws2_32"
;;
LINUX)
EXEC_FILE="$PROJECT"
INCLUDE="-I./imgui -I/usr/include/SDL2"
LINKER_LIBS="-lSDL2 -lGL"
INCLUDE="-I./dependencies/imgui -I./dependencies/SDL2/include"
LINKER_LIBS="-L./$OBJDIR/libs/ -lSDL2 -lGL"
;;
*)
error "operating system $OS has no configuration variants"
@ -126,11 +139,28 @@ case "$TASK" in
POST_TASK_SCRIPT=cbuild/default_tasks/exec.sh
DEPS_BUILD_TASK=build_static_lib
;;
# 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"
PRE_TASK_SCRIPT=tasks/pre_build.sh
TASK_SCRIPT=cbuild/default_tasks/build_exec.sh
POST_TASK_SCRIPT=cbuild/default_tasks/callgrind.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 <$TASK> not found"

2
dependencies/imgui vendored

@ -1 +1 @@
Subproject commit 109735a0d10c55d95c569bae2aa4c2adbfcf9056
Subproject commit 00263d9c22ab255d1886493c7f058d9e22128dd3

@ -1 +0,0 @@
Subproject commit 50ba2846746af233922da40694380fd090b304ab

1
dependencies/imgui_node_editor vendored Submodule

@ -0,0 +1 @@
Subproject commit 50f39362c22fb7d21312adb07cea66d56da3166a

@ -1 +1 @@
Subproject commit 1bff83fbd0fe749b28df5af6844ec0e036320305
Subproject commit 83af9066dbf8dceef44009ef21ac1d6d042db2a3

2
dependencies/kerep vendored

@ -1 +1 @@
Subproject commit 53cf9875e6785a30b2313cf294acb89061a92713
Subproject commit dd5788f72a909b602592da7861ba717d529be9f3

View File

@ -4,7 +4,7 @@
extern "C" {
#endif
#include "../../kerep/src/base/base.h"
#include "../../dependencies/kerep/src/base/base.h"
Maybe main_window_open(const char* window_title);
Maybe main_window_loop_start();

View File

@ -1,12 +1,12 @@
#pragma once
#include "gui.h"
#include "SDL2/SDL.h"
#include "SDL2/SDL_opengl.h"
#include "../../imgui/imgui.h"
#include "../../imgui/backends/imgui_impl_sdl2.h"
#include "../../imgui/backends/imgui_impl_opengl3.h"
#include "../../kerep/src/Filesystem/filesystem.h"
#include "../../dependencies/SDL2/include/SDL.h"
#include "../../dependencies/SDL2/include/SDL_opengl.h"
#include "../../dependencies/imgui/imgui.h"
#include "../../dependencies/imgui/backends/imgui_impl_sdl2.h"
#include "../../dependencies/imgui/backends/imgui_impl_opengl3.h"
#include "../../dependencies/kerep/src/Filesystem/filesystem.h"
//////////////////////////////////////
// Fonts //

View File

@ -1,5 +1,5 @@
#include "gui_internal.hpp"
#include "../../imgui-node-editor/imgui_node_editor.h"
#include "../../dependencies/imgui_node_editor/imgui_node_editor.h"
namespace NE = ax::NodeEditor;
NE::EditorContext* editor_context=nullptr;

View File

@ -1,5 +1,5 @@
#include "gui_internal.hpp"
#include "../../imnodes/imnodes.h"
#include "../../dependencies/imnodes/imnodes.h"
#include <vector>
#include <algorithm>

View File

@ -1,4 +1,4 @@
#include "../kerep/src/base/base.h"
#include "../dependencies/kerep/src/base/base.h"
#include "gui/gui.h"
void kt_initGraphCTypes(){
@ -9,7 +9,7 @@ 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_beginInit(true);
kt_initKerepTypes();
kt_initGraphCTypes();
kt_endInit();
@ -19,9 +19,9 @@ int main(const int argc, const char* const* argv){
kprintf(" %s", argv[i]);
kprintf("\n");
tryLast(main_window_open("GraphC"),_1);
tryLast(main_window_loop_start(),_2);
tryLast(main_window_close(),_3);
tryLast(main_window_open("GraphC"),_1, ;);
tryLast(main_window_loop_start(),_2, ;);
tryLast(main_window_close(),_3, ;);
kt_free();
return 0;

View File

@ -1,6 +1,4 @@
#!/usr/bin/bash
for tmpfile in $(ls -a | grep -e '\.rebuild.*\.tmp'); do
try_delete_dir_or_file "$tmpfile"
done
try_delete_dir_or_file fonts/generated
try_delete_dir_or_file libs/fonts_embedded.a

View File

@ -1,5 +1,4 @@
#!/bin/bash
cd fonts
SRC_C=""
HEADER="generated/fonts_embedded.h"
@ -30,17 +29,12 @@ mkdir -p src/generated/
cp -v fonts/$HEADER src/$HEADER
myprint "${GREEN}font arrays external definitions have been written to ${CYAN}src/$HEADER"
# delete old objects
clean_dir "$OBJDIR/objects"
myprint "${BLUE}hiding libs"
mv "$OBJDIR/libs" "$OBJDIR/libs_"
mkdir -p "$OBJDIR/libs"
# compiling
compile_c "$C_ARGS" "$SRC_C"
pack_static_lib "$STATIC_LIB_FILE"
rm -rf $OUTDIR/fonts_embedded.a
myprint "${BLUE}restoring libs"
rm -rf "$OBJDIR/libs"
mv "$OBJDIR/libs_" "$OBJDIR/libs"
cp "$OBJDIR/out/fonts_embedded.a" libs/
myprint "$OBJDIR/out/fonts_embedded.a -> libs/"
# moving lib file
mv "$OUTDIR/$STATIC_LIB_FILE" libs/
mkdir -p "libs"
myprint "$OUTDIR/$STATIC_LIB_FILE -> libs/"

View File

@ -1,35 +1,11 @@
#!/bin/bash
# if $lib_project.a doesn't exist or rebuild_* task was executed, builds static lib
function handle_static_dependency {
local lib_project="$1"
local lib_build_task="$2"
if [ ! -f "$OBJDIR/libs/$lib_project.a" ] || [ -f .rebuild_$lib_project.tmp ]; then
[[ -z "$lib_build_task" ]] && error "lib_build_task is empty"
myprint "${BLUE}making $lib_project task <$lib_build_task>"
cd $lib_project
if ! make "$lib_build_task"; then
exit 1
fi
cd ..
cp $lib_project/bin/$lib_project.a $OBJDIR/libs/
myprint "${GREEN}copied ${CYAN}$lib_project.a"
rm -f .rebuild_$lib_project.tmp
fi
}
# compile fonts
if [ ! -f libs/fonts_embedded.a ]; then
if ! make embed_fonts; then
exit 1
fi
fi
handle_static_dependency kerep $DEPS_BUILD_TASK
handle_static_dependency imgui $DEPS_BUILD_TASK
handle_static_dependency imgui-node-editor $DEPS_BUILD_TASK
handle_static_dependency imnodes $DEPS_BUILD_TASK
# copy all precompiled libs
cp libs/* $OBJDIR/libs/

View File

@ -1,5 +0,0 @@
#!/bin/bash
source cbuild/colors.sh
source cbuild/functions.sh
touch ".rebuild_$1.tmp"
myprint "${YELLOW}$1.a will be rebuilt in the next build task"