wrote build system in bash

This commit is contained in:
2022-05-31 18:36:01 +03:00
parent 85293d8c32
commit e9b740183d
10 changed files with 157 additions and 112 deletions

View File

@@ -0,0 +1,11 @@
#!/bin/bash
source build_scripts/init.sh
print "${CYAN}=============[build_lib]==============\n"
clear_dir bin
clear_dir obj
compile_c "-O2 -fpic -shared" "$SRC_C tests/test_marshalling.c"
compile_cpp "-flto -Wl,-soname,$LIB_FILE" "$SRC_CPP"
link " " $LIB_FILE
rm -rf $OBJDIR

View File

@@ -0,0 +1,11 @@
#!/bin/bash
source build_scripts/init.sh
print "${CYAN}=============[build_test]=============\n"
clear_dir bin
clear_dir obj
compile_c "-O0 -g" "$SRC_C $TESTS_C"
compile_cpp "-O0 -g" "$SRC_CPP $TESTS_CPP"
link " " $TEST_FILE
rm -rf $OBJDIR

11
build_scripts/colors.sh Normal file
View File

@@ -0,0 +1,11 @@
#!/bin/bash
BLACK='\033[0;30m'
GRAY='\033[0;37m'
WHITE='\033[0;97m'
RED='\033[0;91m'
GREEN='\033[0;92m'
YELLOW='\033[0;93m'
BLUE='\033[0;94m'
PURPLE='\033[0;95m'
CYAN='\033[0;96m'

View File

@@ -0,0 +1,19 @@
#!/bin/bash
OUTDIR=bin
OBJDIR=obj
TEST_FILE=kerep.com
LIB_FILE=kerep.so
DLL_FILE=kerep.dll
CMP_C=gcc
CMP_CPP=g++
STD_C=c11
STD_CPP=c++17
WARN_C="-Wall -Wno-discarded-qualifiers" #-Wextra
WARN_CPP="-Wall -Wconversion-null -Wno-unused-variable -Wno-return-type" #-Wextra
SRC_C="$( find src -name *.c)"
SRC_CPP="$( find src -name *.cpp)"
TESTS_C="$( find tests -name *.c)"
TESTS_CPP="$(find tests -name *.cpp)"
VALGRIND_ARGS=-s --read-var-info=yes --track-origins=yes --fullpath-after=kerep/ \
--leak-check=full --show-leak-kinds=all

View File

@@ -0,0 +1,53 @@
#!/bin/bash
function print {
printf "$1$GRAY"
}
function clear_dir {
print "${BLUE}clearing $1\n"
rm -rf $1
mkdir $1
}
function compile {
local cmp=$1
print "${BLUE}compiler: ${GRAY}$cmp\n"
local std=$2
print "${BLUE}standard: ${GRAY}$std\n"
local warn=$3
print "${BLUE}warnings: ${GRAY}$warn\n"
local args=$4
print "${BLUE}args: ${GRAY}$args\n"
local sources=$5
print "${BLUE}sources: ${GRAY}$sources\n"
for SRCFILE in $sources
do
$cmp -std=$std $warn $args -c -o "$OBJDIR/$(basename $SRCFILE).o" $SRCFILE
done
}
# (args, sources)
function compile_c {
print "${CYAN}-------------[compile_c]--------------\n"
compile $CMP_C $STD_C "$WARN_C " "$1" "$2"
}
# (args, sources)
function compile_cpp {
print "${CYAN}------------[compile_cpp]-------------\n"
compile $CMP_CPP $STD_CPP "$WARN_CPP" "$1" "$2"
}
# (args, outfile)
function link {
print "${CYAN}----------------[link]----------------\n"
local args=$1
print "${BLUE}args: ${GRAY}$args\n"
local outfile=$OUTDIR/$2
print "${BLUE}outfile: ${GRAY}$outfile\n"
local objects="$(find $OBJDIR -name *.o)"
print "${BLUE}objects: ${GRAY}$objects\n"
$CMP_C $args -o $outfile $(echo $objects | tr '\n' ' ')
print "${GREEN}file $CYAN$outfile ${GREEN}created\n"
}

23
build_scripts/init.sh Normal file
View File

@@ -0,0 +1,23 @@
#!/bin/bash
reset
tabs 4
source build_scripts/colors.sh
source build_scripts/functions.sh
if [ ! -f ".config" ]; then
print "${YELLOW}./.config doesn't exists\n"
cp build_scripts/default.config.sh .config
print "${YELLOW}default config created\n"
while true; do
print "${WHITE}continue? (y/n) "
read answ
case $answ in
[Yy] ) break;;
[Nn] ) exit;;
* ) print "${RED}incorrect answer\n";;
esac
done
fi
source .config

8
build_scripts/test.sh Normal file
View File

@@ -0,0 +1,8 @@
#!/bin/bash
source build_scripts/init.sh
print "${CYAN}================[test]================\n"
cd $OUTDIR;
./$TEST_FILE
cd ..

View File

@@ -0,0 +1,8 @@
#!/bin/bash
source build_scripts/init.sh
print "${CYAN}===========[test_valgrind]============\n"
cd $OUTDIR;
valgrind $VALGRIND_ARGS $TEST_FILE
cd ..