From c5f8f6ee0904ee0f75a0b67a9f964e55e9f7fb38 Mon Sep 17 00:00:00 2001 From: Timerix Date: Sun, 21 Jul 2024 01:55:55 +0300 Subject: [PATCH] changed compile_c and compile_cpp functions --- default_tasks/build_exec.sh | 4 ++-- default_tasks/build_shared_lib.sh | 4 ++-- default_tasks/build_static_lib.sh | 4 ++-- functions.sh | 38 +++++++++++++++++++++++++------ 4 files changed, 37 insertions(+), 13 deletions(-) diff --git a/default_tasks/build_exec.sh b/default_tasks/build_exec.sh index 1242057..c1f380d 100755 --- a/default_tasks/build_exec.sh +++ b/default_tasks/build_exec.sh @@ -15,6 +15,6 @@ else done fi -compile_c "$C_ARGS" "$SRC_C" -compile_cpp "$CPP_ARGS" "$SRC_CPP" +[ ! -z "$SRC_C" ] && compile_c "$CMP_C" "$STD_C" "$WARN_C" "$C_ARGS" "$INCLUDE" "$SRC_C" +[ ! -z "$SRC_CPP" ] && compile_cpp "$CMP_CPP" "$STD_CPP" "$WARN_CPP" "$CPP_ARGS" "$INCLUDE" "$SRC_CPP" link "$LINKER_ARGS" "$EXEC_FILE" diff --git a/default_tasks/build_shared_lib.sh b/default_tasks/build_shared_lib.sh index 45d0574..bebf893 100755 --- a/default_tasks/build_shared_lib.sh +++ b/default_tasks/build_shared_lib.sh @@ -2,6 +2,6 @@ # delete old objects clean_dir "$OBJDIR/objects" -compile_c "$C_ARGS" "$SRC_C" -compile_cpp "$CPP_ARGS" "$SRC_CPP" +[ ! -z "$SRC_C" ] && compile_c "$CMP_C" "$STD_C" "$WARN_C" "$C_ARGS" "$INCLUDE" "$SRC_C" +[ ! -z "$SRC_CPP" ] && compile_cpp "$CMP_CPP" "$STD_CPP" "$WARN_CPP" "$CPP_ARGS" "$INCLUDE" "$SRC_CPP" link "$LINKER_ARGS" "$SHARED_LIB_FILE" diff --git a/default_tasks/build_static_lib.sh b/default_tasks/build_static_lib.sh index e2db349..6be5ccb 100755 --- a/default_tasks/build_static_lib.sh +++ b/default_tasks/build_static_lib.sh @@ -2,6 +2,6 @@ # delete old objects clean_dir "$OBJDIR/objects" -compile_c "$C_ARGS" "$SRC_C" -compile_cpp "$CPP_ARGS" "$SRC_CPP" +[ ! -z "$SRC_C" ] && compile_c "$CMP_C" "$STD_C" "$WARN_C" "$C_ARGS" "$INCLUDE" "$SRC_C" +[ ! -z "$SRC_CPP" ] && compile_cpp "$CMP_CPP" "$STD_CPP" "$WARN_CPP" "$CPP_ARGS" "$INCLUDE" "$SRC_CPP" pack_static_lib "$STATIC_LIB_FILE" diff --git a/functions.sh b/functions.sh index daba609..0f244c5 100755 --- a/functions.sh +++ b/functions.sh @@ -116,16 +116,16 @@ function compile { print_hline "${BLUE}" "─" local cmp="$1" - myprint "${BLUE}compiler: ${GRAY}$cmp" local std="$2" - myprint "${BLUE}standard: ${GRAY}$std" local warn="$3" - myprint "${BLUE}warnings: ${GRAY}$warn" local args="$4" - myprint "${BLUE}args: ${GRAY}$args" local include="$5" - myprint "${BLUE}include dirs: ${GRAY}$include" local sources="$6" + myprint "${BLUE}compiler: ${GRAY}$cmp" + myprint "${BLUE}standard: ${GRAY}$std" + myprint "${BLUE}warnings: ${GRAY}$warn" + myprint "${BLUE}args: ${GRAY}$args" + myprint "${BLUE}include dirs: ${GRAY}$include" myprint "${BLUE}sources: ${GRAY}$sources" for srcfile in $sources do ( @@ -141,14 +141,26 @@ function compile { # (args, sources) function compile_c { + local cmp="$1" + local std="$2" + local warn="$3" + local args="$4" + local include="$5" + local sources="$6" print_header "${CYAN}" "─" "$PROJECT/$TASK/compile_c" - compile "$CMP_C" "$STD_C" "$WARN_C" "$1" "$INCLUDE" "$2" + compile "$cmp" "$std" "$warn" "$args" "$include" "$sources" } # (args, sources) function compile_cpp { + local cmp="$1" + local std="$2" + local warn="$3" + local args="$4" + local include="$5" + local sources="$6" print_header "${CYAN}" "─" "$PROJECT/$TASK/compile_cpp" - compile "$CMP_CPP" "$STD_CPP" "$WARN_CPP" "$1" "$INCLUDE" "$2" + compile "$cmp" "$std" "$warn" "$args" "$include" "$sources" } # (outfile) @@ -156,8 +168,13 @@ function pack_static_lib { print_header "${CYAN}" "─" "$PROJECT/$TASK/pack_static_lib" local outfile="$1" myprint "${BLUE}outfile: ${GRAY}$outfile" + local objects="$(find $OBJDIR/objects -type f,l | tr '\n' ' ')" myprint "${BLUE}objects: ${GRAY}$objects" + if [ -z "$objects" ]; then + error "no compiled objects found" + fi + local command="ar rcs $OUTDIR/$outfile $objects" myprint "$command" if $command @@ -174,16 +191,23 @@ function link { local outfile="$2" myprint "${BLUE}args: ${GRAY}$args" myprint "${BLUE}outfile: ${GRAY}$outfile" + local objects="$(find $OBJDIR/objects -type f,l | tr '\n' ' ')" myprint "${BLUE}objects: ${GRAY}$objects" + if [ -z "$objects" ]; then + error "no compiled objects found" + fi + local static_libs="$(find $OBJDIR/static_libs -type f,l | tr '\n' ' ')" myprint "${BLUE}static libraries: ${GRAY}$static_libs" + local dynamic_libs="$(find $OBJDIR/dynamic_libs -type f,l | tr '\n' ' ')" myprint "${BLUE}dynamic libraries: ${GRAY}$dynamic_libs" local dynamic_libs_args="-L $OBJDIR/dynamic_libs" for lib in $dynamic_libs; do dynamic_libs_args="$dynamic_libs_args -l:$lib" done + local command="$CMP_CPP $objects $static_libs $args $dynamic_libs_args -o $OUTDIR/$outfile" myprint "$command" if $command