123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272 |
- #
- # Copyright (c) 2019 - 2024 Stefan Strobel <stefan.strobel@shimatta.net>
- #
- # This Source Code Form is subject to the terms of the Mozilla Public
- # License, v. 2.0. If a copy of the MPL was not distributed with this
- # file, You can obtain one at https://mozilla.org/MPL/2.0/.
- #
- OBJ_DIR := output/
- OBJ_DIR_EXAMPLE := $(OBJ_DIR)example_obj/
- INTEGRATIONTEST_CPP_OBJ_DIR := $(OBJ_DIR)test/integrationtest/
- INTEGRATIONTEST_AUTH_CPP_OBJ_DIR := $(OBJ_DIR)test/integrationtest_auth/
- INTEGRATIONTEST_C_OBJ_DIR := $(INTEGRATIONTEST_CPP_OBJ_DIR)
- INTEGRATIONTEST_CPP_OBJ_DIR_TRANSPORT := $(OBJ_DIR)test/integrationtest_transport/
- INTEGRATIONTEST_C_OBJ_DIR_TRANSPORT := $(INTEGRATIONTEST_CPP_OBJ_DIR_TRANSPORT)
- INTEGRATIONTEST_AUTH_C_OBJ_DIR := $(INTEGRATIONTEST_AUTH_CPP_OBJ_DIR)
- UNITTEST_OBJ_DIR := $(OBJ_DIR)test/unittest/
- # helper define to run tests from a list
- define \n
- endef
- CC := gcc
- CPP := g++
- LN := ln
- SOURCES := src/shellmatta.c \
- src/shellmatta_autocomplete.c \
- src/shellmatta_history.c \
- src/shellmatta_utils.c \
- src/shellmatta_escape.c \
- src/shellmatta_opt.c \
- src/shellmatta_ymodem.c \
- src/shellmatta_crc.c
- SOURCES_TRANPORT_LAYER := $(SOURCES) \
- src/shellmatta_transport.c \
- src/shellmatta_crc.c
- AUTH_SOURCES := $(SOURCES) src/shellmatta_auth.c
- EXAMPLE_SOURCES := example/main.c
- EXAMPLE_SOURCES += $(filter-out $(EXAMPLE_SOURCES),$(AUTH_SOURCES))
- EXAMPLE_SOURCES += $(filter-out $(EXAMPLE_SOURCES),$(SOURCES_TRANPORT_LAYER))
- EXAMPLE_COBJ := $(patsubst %.c,$(OBJ_DIR_EXAMPLE)%.o,$(EXAMPLE_SOURCES))
- CPPCHECK_SOURCES := $(AUTH_SOURCES) \
- src/shellmatta_transport.c \
- src/shellmatta_crc.c
- CPPCHECK_OPTIONS := --enable=all \
- --check-level=exhaustive \
- --template=gcc \
- --cppcheck-build-dir=output/cppcheck \
- --suppress-xml=cfg/cppcheck/cppcheck_suppressions.xml \
- -DSHELLMATTA_AUTHENTICATION \
- -Iapi \
- $(CPPCHECK_SOURCES)
- INCLUDES := api .
- UNITTEST_SOURCES := test/unittest/test_main.cpp \
- test/unittest/shellmatta_opt/test_opt_findNextHunk.cpp \
- test/unittest/shellmatta_opt/test_opt_peekNextHunk.cpp \
- test/unittest/shellmatta_utils/test_utils_writeEcho.cpp \
- test/unittest/shellmatta_utils/test_utils_shellItoa.cpp \
- test/unittest/shellmatta_utils/test_utils_saveCursorPos.cpp \
- test/unittest/shellmatta_utils/test_utils_restoreCursorPos.cpp \
- test/unittest/shellmatta_utils/test_utils_eraseLine.cpp \
- test/unittest/shellmatta_utils/test_utils_rewindCursor.cpp \
- test/unittest/shellmatta_utils/test_utils_forwardCursor.cpp \
- test/unittest/shellmatta_utils/test_utils_clearInput.cpp \
- test/unittest/shellmatta_utils/test_utils_insertChars.cpp \
- test/unittest/shellmatta_utils/test_utils_terminateInput.cpp \
- test/unittest/shellmatta_utils/test_utils_removeChars.cpp \
- test/unittest/shellmatta_autocomplete/test_autocomplete_run.cpp \
- test/unittest/shellmatta_escape/test_escape_processArrowKeys.cpp \
- test/unittest/shellmatta_history/test_appendHistoryByte.cpp \
- test/unittest/shellmatta/test_shellmatta_doInit.cpp \
- test/unittest/shellmatta_crc/test_crc32Slow.cpp \
- test/unittest/shellmatta_crc/test_crc32Fast.cpp \
- test/unittest/shellmatta_ymodem/test_ymodem.cpp
- INTEGRATIONTEST_SOURCES := test/integrationtest/test_main.cpp \
- test/integrationtest/test_integration.cpp \
- test/integrationtest/test_integration_opt.cpp \
- test/integrationtest/test_integration_optLong.cpp \
- test/integrationtest/test_integration_continue.cpp \
- test/integrationtest/test_integration_busy.cpp \
- test/integrationtest/test_integration_history.cpp \
- test/integrationtest/test_integration_help.cpp
- INTEGRATIONTEST_TRANSPORT_SOURCES := $(INTEGRATIONTEST_SOURCES) \
- test/integrationtest_transport/test_integration_transport.cpp
- INTEGRATIONTEST_AUTH_SOURCES := test/integrationtest_auth/test_main.cpp \
- test/integrationtest_auth/test_integration_auth.cpp
- UNITTEST_CPPOBJ := $(patsubst %.cpp,$(UNITTEST_OBJ_DIR)%.o,$(UNITTEST_SOURCES))
- INTEGRATIONTEST_CPPOBJ := $(patsubst %.cpp,$(INTEGRATIONTEST_CPP_OBJ_DIR)%.o,$(INTEGRATIONTEST_SOURCES))
- INTEGRATIONTEST_COBJ := $(patsubst %.c,$(INTEGRATIONTEST_CPP_OBJ_DIR)%.o,$(SOURCES))
- INTEGRATIONTEST_TRANSPORT_CPPOBJ := $(patsubst %.cpp,$(INTEGRATIONTEST_CPP_OBJ_DIR_TRANSPORT)%.o,$(INTEGRATIONTEST_TRANSPORT_SOURCES))
- INTEGRATIONTEST_TRANSPORT_COBJ := $(patsubst %.c,$(INTEGRATIONTEST_CPP_OBJ_DIR_TRANSPORT)%.o,$(SOURCES_TRANPORT_LAYER))
- INTEGRATIONTEST_AUTH_CPPOBJ := $(patsubst %.cpp,$(INTEGRATIONTEST_AUTH_CPP_OBJ_DIR)%.o,$(INTEGRATIONTEST_AUTH_SOURCES))
- INTEGRATIONTEST_AUTH_COBJ := $(patsubst %.c,$(INTEGRATIONTEST_AUTH_CPP_OBJ_DIR)%.o,$(AUTH_SOURCES))
- CFLAGS := $(INCLUDES:%=-I%) -g -Wall -Werror -Wextra -pedantic
- CFLAGS += -DSHELLMATTA_HELP_ALIAS=\(char*\)\"?\"
- CFLAGS_EXAMPLE := $(CFLAGS) -DSHELLMATTA_AUTHENTICATION -DSHELLMATTA_TRANSPORT
- TESTFLAGS := $(CFLAGS) -fprofile-arcs -ftest-coverage
- TESTFLAGS_AUTH := $(CFLAGS) -DSHELLMATTA_AUTHENTICATION -fprofile-arcs -ftest-coverage
- TESTLFLAGS := -fprofile-arcs -Wl,--allow-multiple-definition
- TESTFLAGS_TRANSPORT := $(TESTFLAGS) -DSHELLMATTA_TRANSPORT
- TESTLFLAGS_TRANSPORT := $(TESTLFLAGS)
- DEPEND = -MT $@ -MF "$(@:%.o=%.d)" -MG -MM
- COBJ := $(patsubst %.c,$(OBJ_DIR)%.o,$(SOURCES))
- EXAMPLE_TARGET := $(OBJ_DIR)example/example
- UNITTEST_TARGET := $(OBJ_DIR)test/unittest/unittest
- INTEGRATIONTEST_TARGET := $(OBJ_DIR)test/integrationtest/integrationtest
- INTEGRATIONTEST_TARGET_AUTH := $(OBJ_DIR)test/integrationtest_auth/integrationtest_auth
- INTEGRATIONTEST_TARGET_TRANSPORT := $(OBJ_DIR)test/integrationtest_transport/integrationtest_transport
- TEST_RUN_TARGETS := unittest integrationtest integrationtest_auth integrationtest_transport
- # ensure the tests are running one after another when general test target is called
- ifneq ($(filter test,$(MAKECMDGOALS)),)
- TEST_RUN_TARGETS_HELPER := $(TEST_RUN_TARGETS)
- endif
- TEST_TARGETS := $(UNITTEST_TARGET) $(INTEGRATIONTEST_TARGET) $(INTEGRATIONTEST_TARGET_AUTH) $(INTEGRATIONTEST_TARGET_TRANSPORT)
- OBJ := $(COBJ) \
- $(EXAMPLE_COBJ) \
- $(UNITTEST_CPPOBJ) \
- $(INTEGRATIONTEST_CPPOBJ) \
- $(INTEGRATIONTEST_COBJ) \
- $(INTEGRATIONTEST_AUTH_CPPOBJ) \
- $(INTEGRATIONTEST_AUTH_COBJ) \
- $(INTEGRATIONTEST_TRANSPORT_CPPOBJ) \
- $(INTEGRATIONTEST_TRANSPORT_COBJ)
- DEPS := $(OBJ:%.o=%.d)
- export
- .PHONY: help cppcheck doc clean
- help:
- @echo Shellmatta help
- @echo -----------------------------------------------
- @echo test - run all tests
- @echo cppcheck - run static code analysis \(cppcheck\)
- @echo example - build example
- @echo -----------------------------------------------
- test: $(TEST_RUN_TARGETS)
- - @mkdir -p output/test/report
- # run the test alltogether to get coverage from all combined tests
- # remove coverage from former run
- @-find . -name "*.gcda" -type f -delete
- $(foreach TEST_RUN_TARGET,$(TEST_RUN_TARGETS),./$(OBJ_DIR)test/$(TEST_RUN_TARGET)/$(TEST_RUN_TARGET)${\n})
- # remove report from former run
- -rm -rf $(OBJ_DIR)test/report/*
- gcovr --html-details --output $(OBJ_DIR)test/report/report.html -f src -f api -d
- cppcheck:
- - @mkdir -p output/cppcheck/html
- cppcheck $(CPPCHECK_OPTIONS)
- cppcheck $(CPPCHECK_OPTIONS) --xml 2>output/cppcheck/cppcheck.xml
- cppcheck-htmlreport --file=output/cppcheck/cppcheck.xml --title="Shellmatta" --report-dir=output/cppcheck/html
- $(TEST_RUN_TARGETS): $(TEST_TARGETS) $(filter-out $@,$(TEST_RUN_TARGETS_HELPER))
- - @mkdir -p output/test/$@/report
- @echo running test $@:
- # remove coverage from former run
- @-find . -name "*.gcda" -type f -delete
- -$(OBJ_DIR)test/$@/$@
- # remove report from former run
- -rm -rf $(OBJ_DIR)test/$@/report/*
- gcovr --html-details --output $(OBJ_DIR)test/$@/report/report.html output/test/$@ -f src -f api -d
- example: $(EXAMPLE_TARGET)
- @echo building example
- doc:
- - @mkdir -p output/doc/html
- - @mkdir -p output/doc/latex
- doxygen cfg/doxygen/doxyfile
- clean:
- - rm -rf $(OBJ_DIR)
- $(EXAMPLE_TARGET): $(EXAMPLE_COBJ)
- - @mkdir -p $(@D)
- $(CC) $(LFLAGS) $(LIB_PATH) -o $@ $^ $(LIBS)
- $(UNITTEST_TARGET): $(UNITTEST_CPPOBJ)
- - @mkdir -p $(@D)
- $(CPP) $(TESTLFLAGS) $(LIB_PATH) -o $@ $^ $(LIBS)
- $(INTEGRATIONTEST_TARGET): $(INTEGRATIONTEST_CPPOBJ) $(INTEGRATIONTEST_COBJ)
- - @mkdir -p $(@D)
- $(CPP) $(TESTLFLAGS) $(LIB_PATH) -o $@ $^ $(LIBS)
-
- $(INTEGRATIONTEST_TARGET_TRANSPORT): $(INTEGRATIONTEST_TRANSPORT_CPPOBJ) $(INTEGRATIONTEST_TRANSPORT_COBJ)
- - @mkdir -p $(@D)
- $(CPP) $(TESTLFLAGS_TRANSPORT) $(LIB_PATH) -o $@ $^ $(LIBS)
- $(INTEGRATIONTEST_TARGET_AUTH): $(INTEGRATIONTEST_AUTH_CPPOBJ) $(INTEGRATIONTEST_AUTH_COBJ)
- - @mkdir -p $(@D)
- $(CPP) $(TESTLFLAGS) $(LIB_PATH) -o $@ $^ $(LIBS)
- $(TARGET): $(OBJ)
- - @mkdir -p $(@D)
- $(CC) $(LFLAGS) $(LIB_PATH) -o $@ $^ $(LIBS)
- $(COBJ):
- - @mkdir -p $(@D)
- @$(CC) -c $(CFLAGS) $(DEPEND) -o $(@:%.o=%.d) $(subst $(OBJ_DIR), ,$(@:%.o=%.c))
- $(CC) -c $(CFLAGS) -o $@ $(subst $(OBJ_DIR), ,$(@:%.o=%.c))
- $(EXAMPLE_COBJ):
- - @mkdir -p $(@D)
- @$(CC) -c $(CFLAGS_EXAMPLE) $(DEPEND) -o $(@:%.o=%.d) $(subst $(OBJ_DIR_EXAMPLE), ,$(@:%.o=%.c))
- $(CC) -c $(CFLAGS_EXAMPLE) -o $@ $(subst $(OBJ_DIR_EXAMPLE), ,$(@:%.o=%.c))
- $(UNITTEST_CPPOBJ):
- - @mkdir -p $(@D)
- @$(CPP) -c $(TESTFLAGS) $(DEPEND) -o $(@:%.o=%.d) $(subst $(UNITTEST_OBJ_DIR), ,$(@:%.o=%.cpp))
- $(CPP) -c $(TESTFLAGS) -o $@ $(subst $(UNITTEST_OBJ_DIR), ,$(@:%.o=%.cpp))
- $(INTEGRATIONTEST_CPPOBJ):
- - @mkdir -p $(@D)
- @$(CPP) -c $(TESTFLAGS) $(DEPEND) -o $(@:%.o=%.d) $(subst $(INTEGRATIONTEST_CPP_OBJ_DIR), ,$(@:%.o=%.cpp))
- $(CPP) -c $(TESTFLAGS) -o $@ $(subst $(INTEGRATIONTEST_CPP_OBJ_DIR), ,$(@:%.o=%.cpp))
- $(INTEGRATIONTEST_COBJ):
- - @mkdir -p $(@D)
- @$(CC) -c $(TESTFLAGS) $(DEPEND) -o $(@:%.o=%.d) $(subst $(INTEGRATIONTEST_C_OBJ_DIR), ,$(@:%.o=%.c))
- $(CC) -c $(TESTFLAGS) -o $@ $(subst $(INTEGRATIONTEST_C_OBJ_DIR), ,$(@:%.o=%.c))
- $(INTEGRATIONTEST_TRANSPORT_CPPOBJ):
- - @mkdir -p $(@D)
- @$(CPP) -c $(TESTFLAGS_TRANSPORT) $(DEPEND) -o $(@:%.o=%.d) $(subst $(INTEGRATIONTEST_CPP_OBJ_DIR_TRANSPORT), ,$(@:%.o=%.cpp))
- $(CPP) -c $(TESTFLAGS_TRANSPORT) -o $@ $(subst $(INTEGRATIONTEST_CPP_OBJ_DIR_TRANSPORT), ,$(@:%.o=%.cpp))
- $(INTEGRATIONTEST_TRANSPORT_COBJ):
- - @mkdir -p $(@D)
- @$(CC) -c $(TESTFLAGS_TRANSPORT) $(DEPEND) -o $(@:%.o=%.d) $(subst $(INTEGRATIONTEST_C_OBJ_DIR_TRANSPORT), ,$(@:%.o=%.c))
- $(CC) -c $(TESTFLAGS_TRANSPORT) -o $@ $(subst $(INTEGRATIONTEST_C_OBJ_DIR_TRANSPORT), ,$(@:%.o=%.c))
- $(INTEGRATIONTEST_AUTH_CPPOBJ):
- - @mkdir -p $(@D)
- @$(CPP) -c $(TESTFLAGS_AUTH) $(DEPEND) -o $(@:%.o=%.d) $(subst $(INTEGRATIONTEST_AUTH_CPP_OBJ_DIR), ,$(@:%.o=%.cpp))
- $(CPP) -c $(TESTFLAGS_AUTH) -o $@ $(subst $(INTEGRATIONTEST_AUTH_CPP_OBJ_DIR), ,$(@:%.o=%.cpp))
- $(INTEGRATIONTEST_AUTH_COBJ):
- - @mkdir -p $(@D)
- $(CC) -c $(TESTFLAGS_AUTH) $(DEPEND) -o $(@:%.o=%.d) $(subst $(INTEGRATIONTEST_AUTH_C_OBJ_DIR), ,$(@:%.o=%.c))
- $(CC) -c $(TESTFLAGS_AUTH) -o $@ $(subst $(INTEGRATIONTEST_AUTH_C_OBJ_DIR), ,$(@:%.o=%.c))
- %.o: %.cpp
- - @mkdir -p $(@D)
- @$(CPP) -c $(CFLAGS) $(DEPEND) -o $(@:%.o=%.d) $(subst $(OBJ_DIR), ,$(@:%.o=%.c))
- $(CPP) -c $(CFLAGS) -o $@ $<
- -include $(DEPS)
|