makefile updated (compile_cpp doesnt work)

This commit is contained in:
Timerix22 2022-05-31 14:46:21 +03:00
parent 343d23dc26
commit 3cb3dca293

134
Makefile
View File

@ -1,73 +1,113 @@
SRC=$(wildcard src/**/*.c) $(wildcard src/*.c) ######################################
TESTS=$(wildcard tests/*c) $(wildcard tests/**/*.c) ###### 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)
OUTDIR=bin
CMP=gcc
OPT_ARGS=-O2 -flto -std=c17
WARN_ARGS=-Wall -Wno-discarded-qualifiers
all: clear_c clear_bin build_test_dbg ######################################
###### Small tasks #######
######################################
all: clear_c clear_bin build_test
clear_c: clear_c:
clear clear
clear_bin: clear_bin:
@echo -e '\n\e[96m-------------[clear_bin]--------------\e[0m' @echo -e '\e[96m-------------[clear_bin]--------------\e[0m'
rm -rf $(OUTDIR) rm -rf $(OUTDIR)
mkdir $(OUTDIR) mkdir $(OUTDIR)
clang: CMP=clang clear_obj:
clang: WARN_ARGS=-Wall -Wno-ignored-qualifiers -Wno-incompatible-pointer-types-discards-qualifiers -std=c17 @echo -e '\e[96m-------------[clear_obj]--------------\e[0m'
clang: all rm -rf $(OBJDIR)
mkdir $(OBJDIR)
###################################### ######################################
###### Build tasks ####### ###### Build tasks #######
###################################### ######################################
TEST_FILE=kerep_test.com
TEST_ARGS=$(WARN_ARGS) $(SRC) $(TESTS) -o $(OUTDIR)/$(TEST_FILE)
build_test: # set it in build targets
@echo -e '\n\e[96m-------------[build_test]-------------\e[0m' SOURCES_C:=
$(CMP) $(OPT_ARGS) $(TEST_ARGS) SOURCES_CPP:=
CMPARGS:=
LNKARGS:=
OUTFILE:=
build_test_dbg: compile_c_file=$(CMP_C) -std=$(STD_C) $(WARN_C) $(CMPARGS) -c ../$(SRCFILE)
@echo -e '\n\e[96m-----------[build_test_dbg]-----------\e[0m' __compile_c:
$(CMP) -g -O0 $(TEST_ARGS).dbg @echo -e '\e[96m-------------[compile_c]--------------\e[0m'
$(eval commands:=cd $(OBJDIR) $(foreach SRCFILE, $(SOURCES_C), ; $(compile_c_file)))
$(commands)
LIB_ARGS=$(OPT_ARGS) $(WARN_ARGS)\ compile_cpp_file=$(CMP_CPP) -std=$(STD_CPP) $(WARN_CPP) $(CMPARGS) -c ../$(SRCFILE)
-fpic -shared -Wl,-soname,$(LIB_FILE)\ __compile_cpp:
$(SRC) tests/test_marshalling.c @echo -e '\e[96m------------[compile_cpp]-------------\e[0m'
LIB_FILE=kerep.so $(eval commands:=cd $(OBJDIR) $(foreach SRCFILE, $(SOURCES_CPP), ; $(compile_cpp_file)))
$(commands)
build_lib: __compile: __compile_c #__compile_cpp
@echo -e '\n\e[96m-------------[build_lib]--------------\e[0m'
$(CMP) $(LIB_ARGS) -o $(OUTDIR)/$(LIB_FILE)
DLL_ARGS=$(OPT_ARGS) $(WARN_ARGS)\ __link:
-shared -fpic -static-libgcc -static-libstdc++\ @echo -e '\e[96m----------------[link]----------------\e[0m'
$(SRC) tests/test_marshalling.c $(CMP_C) $(LNKARGS) -o $(OUTDIR)/$(OUTFILE) $(wildcard $(OBJDIR)/*.o)
DLL_FILE=kerep.dll
###### 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
build_dll:
gcc --version
@echo -e '\n\e[96m-------------[build_dll]--------------\e[0m'
$(CMP) $(DLL_ARGS) -o $(OUTDIR)/$(DLL_FILE)
###################################### ######################################
###### Run tasks ####### ###### Testing tasks #######
###################################### ######################################
test: clear_c build_test test: build_test
@echo -e '\n\e[96m----------------[test]----------------\e[0m' @echo -e '\e[96m================[test]================\e[0m'
@tabs 4 @tabs 4
$(OUTDIR)/$(TEST_FILE) cd $(OUTDIR); ./$(TEST_FILE)
test_dbg: clear_c build_test valgrind: build_test
@echo -e '\n\e[96m--------------[test_dbg]--------------\e[0m' @echo -e '\e[96m==============[valgrind]==============\e[0m'
@tabs 4 @tabs 4
$(OUTDIR)/$(TEST_FILE) cd $(OUTDIR); valgrind -s --read-var-info=yes --track-origins=yes --fullpath-after=kerep/ \
--leak-check=full --show-leak-kinds=all $(TEST_FILE).dbg
valgrind: clear_c build_test_dbg
@echo -e '\n\e[96m--------------[valgrind]--------------\e[0m'
@tabs 4
valgrind -s --read-var-info=yes --track-origins=yes --fullpath-after=kerep/ \
--leak-check=full --show-leak-kinds=all $(OUTDIR)/$(TEST_FILE).dbg