wrote build system in bash
This commit is contained in:
parent
85293d8c32
commit
e9b740183d
7
.gitignore
vendored
7
.gitignore
vendored
@ -2,12 +2,11 @@
|
|||||||
bin/
|
bin/
|
||||||
obj/
|
obj/
|
||||||
|
|
||||||
# IDE files
|
# user files
|
||||||
|
.old*/
|
||||||
.vs/
|
.vs/
|
||||||
.vscode/
|
.vscode/
|
||||||
.vshistory/
|
.vshistory/
|
||||||
.editorconfig
|
.editorconfig
|
||||||
*.user
|
*.user
|
||||||
|
.config
|
||||||
#backups
|
|
||||||
.old*/
|
|
||||||
|
|||||||
118
Makefile
118
Makefile
@ -1,113 +1,15 @@
|
|||||||
######################################
|
|
||||||
###### Config #######
|
|
||||||
######################################
|
|
||||||
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 #-Wextra
|
|
||||||
SRC_C:= $(wildcard src/*.c ) $(wildcard src/**/*.c )
|
|
||||||
SRC_CPP:= $(wildcard src/*.cpp ) $(wildcard src/**/*.cpp )
|
|
||||||
TESTS_C:= $(wildcard tests/*c ) $(wildcard tests/**/*.c )
|
|
||||||
TESTS_CPP:=$(wildcard tests/*cpp) $(wildcard tests/**/*.cpp)
|
|
||||||
|
|
||||||
|
|
||||||
######################################
|
|
||||||
###### Small tasks #######
|
|
||||||
######################################
|
|
||||||
|
|
||||||
all: clear_c clear_bin build_test
|
|
||||||
|
|
||||||
clear_c:
|
|
||||||
clear
|
|
||||||
|
|
||||||
clear_bin:
|
|
||||||
@echo -e '\e[96m-------------[clear_bin]--------------\e[0m'
|
|
||||||
rm -rf $(OUTDIR)
|
|
||||||
mkdir $(OUTDIR)
|
|
||||||
|
|
||||||
clear_obj:
|
|
||||||
@echo -e '\e[96m-------------[clear_obj]--------------\e[0m'
|
|
||||||
rm -rf $(OBJDIR)
|
|
||||||
mkdir $(OBJDIR)
|
|
||||||
|
|
||||||
|
|
||||||
######################################
|
|
||||||
###### Build tasks #######
|
###### Build tasks #######
|
||||||
######################################
|
build_test:
|
||||||
|
@build_scripts/build_test.sh
|
||||||
|
|
||||||
# set it in build targets
|
build_lib:
|
||||||
SOURCES_C:=
|
@build_scripts/build_lib.sh
|
||||||
SOURCES_CPP:=
|
|
||||||
CMPARGS:=
|
|
||||||
LNKARGS:=
|
|
||||||
OUTFILE:=
|
|
||||||
|
|
||||||
compile_c_file=$(CMP_C) -std=$(STD_C) $(WARN_C) $(CMPARGS) -c ../$(SRCFILE)
|
|
||||||
__compile_c:
|
|
||||||
@echo -e '\e[96m-------------[compile_c]--------------\e[0m'
|
|
||||||
$(eval commands:=cd $(OBJDIR) $(foreach SRCFILE, $(SOURCES_C), ; $(compile_c_file)))
|
|
||||||
$(commands)
|
|
||||||
|
|
||||||
compile_cpp_file=$(CMP_CPP) -std=$(STD_CPP) $(WARN_CPP) $(CMPARGS) -c ../$(SRCFILE)
|
|
||||||
__compile_cpp:
|
|
||||||
@echo -e '\e[96m------------[compile_cpp]-------------\e[0m'
|
|
||||||
$(eval commands:=cd $(OBJDIR) $(foreach SRCFILE, $(SOURCES_CPP), ; $(compile_cpp_file)))
|
|
||||||
$(commands)
|
|
||||||
|
|
||||||
__compile: __compile_c #__compile_cpp
|
|
||||||
|
|
||||||
__link:
|
|
||||||
@echo -e '\e[96m----------------[link]----------------\e[0m'
|
|
||||||
$(CMP_C) $(LNKARGS) -o $(OUTDIR)/$(OUTFILE) $(wildcard $(OBJDIR)/*.o)
|
|
||||||
|
|
||||||
###### Build test #######
|
|
||||||
__build_test_pre:
|
|
||||||
@echo -e '\e[96m===========[build_test_dbg]===========\e[0m'
|
|
||||||
build_test: OUTFILE=$(TEST_FILE)
|
|
||||||
build_test: SOURCES_C=$(SRC_C) $(TESTS_C)
|
|
||||||
build_test: SOURCES_CPP=$(SRC_CPP) $(TESTS_CPP)
|
|
||||||
build_test: CMPARGS=-O0 -g
|
|
||||||
build_test: LNKARGS=
|
|
||||||
build_test: clear_c __build_test_pre clear_obj __compile __link
|
|
||||||
|
|
||||||
###### Build lib #######
|
|
||||||
__build_lib_pre:
|
|
||||||
@echo -e '\e[96m=============[build_lib]==============\e[0m'
|
|
||||||
build_lib: OUTFILE=$(LIB_FILE)
|
|
||||||
build_lib: SOURCES_C=$(SRC_C) tests/test_marshalling.c
|
|
||||||
build_lib: SOURCES_CPP=$(SRC_CPP)
|
|
||||||
build_lib: CMPARGS=-O2 -fpic -shared
|
|
||||||
build_lib: LNKARGS=-flto -Wl,-soname,$(LIB_FILE)
|
|
||||||
build_lib: clear_c __build_lib_pre clear_obj __compile __link
|
|
||||||
|
|
||||||
###### Build dll #######
|
|
||||||
__build_dll_pre:
|
|
||||||
@echo -e '\e[96m=============[build_dll]==============\e[0m'
|
|
||||||
build_dll: OUTFILE=$(DLL_FILE)
|
|
||||||
build_dll: SOURCES_C=$(SRC_C) tests/test_marshalling.c
|
|
||||||
build_dll: SOURCES_CPP=$(SRC_CPP)
|
|
||||||
build_dll: CMPARGS=-O2 -fpic -shared
|
|
||||||
build_dll: LNKARGS=-static-libgcc -static-libstdc++
|
|
||||||
build_dll: clear_c __build_dll_pre clear_obj __compile __link
|
|
||||||
|
|
||||||
|
|
||||||
######################################
|
|
||||||
###### Testing tasks #######
|
###### Testing tasks #######
|
||||||
######################################
|
test:
|
||||||
test: build_test
|
@build_scripts/test.sh
|
||||||
@echo -e '\e[96m================[test]================\e[0m'
|
|
||||||
@tabs 4
|
|
||||||
cd $(OUTDIR); ./$(TEST_FILE)
|
|
||||||
|
|
||||||
valgrind: build_test
|
test_valgrind:
|
||||||
@echo -e '\e[96m==============[valgrind]==============\e[0m'
|
@build_scripts/test_valgrind.sh
|
||||||
@tabs 4
|
|
||||||
cd $(OUTDIR); valgrind -s --read-var-info=yes --track-origins=yes --fullpath-after=kerep/ \
|
all: build_test test
|
||||||
--leak-check=full --show-leak-kinds=all $(TEST_FILE).dbg
|
|
||||||
|
|||||||
11
build_scripts/build_lib.sh
Normal file
11
build_scripts/build_lib.sh
Normal 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
|
||||||
11
build_scripts/build_test.sh
Normal file
11
build_scripts/build_test.sh
Normal 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
11
build_scripts/colors.sh
Normal 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'
|
||||||
19
build_scripts/default.config.sh
Normal file
19
build_scripts/default.config.sh
Normal 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
|
||||||
53
build_scripts/functions.sh
Normal file
53
build_scripts/functions.sh
Normal 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
23
build_scripts/init.sh
Normal 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
8
build_scripts/test.sh
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
source build_scripts/init.sh
|
||||||
|
|
||||||
|
print "${CYAN}================[test]================\n"
|
||||||
|
cd $OUTDIR;
|
||||||
|
./$TEST_FILE
|
||||||
|
cd ..
|
||||||
8
build_scripts/test_valgrind.sh
Normal file
8
build_scripts/test_valgrind.sh
Normal 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 ..
|
||||||
Loading…
Reference in New Issue
Block a user