makefile 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. #
  2. # Copyright (c) 2019 - 2021 Stefan Strobel <stefan.strobel@shimatta.net>
  3. #
  4. # This Source Code Form is subject to the terms of the Mozilla Public
  5. # License, v. 2.0. If a copy of the MPL was not distributed with this
  6. # file, You can obtain one at https://mozilla.org/MPL/2.0/.
  7. #
  8. OBJ_DIR := output/
  9. OBJ_DIR_EXAMPLE := $(OBJ_DIR)example_obj/
  10. INTEGRATIONTEST_CPP_OBJ_DIR := $(OBJ_DIR)test/integrationtest/
  11. INTEGRATIONTEST_AUTH_CPP_OBJ_DIR := $(OBJ_DIR)test/integrationtest_auth/
  12. INTEGRATIONTEST_C_OBJ_DIR := $(INTEGRATIONTEST_CPP_OBJ_DIR)
  13. INTEGRATIONTEST_AUTH_C_OBJ_DIR := $(INTEGRATIONTEST_AUTH_CPP_OBJ_DIR)
  14. UNITTEST_OBJ_DIR := $(OBJ_DIR)test/unittest/
  15. # helper define to run tests from a list
  16. define \n
  17. endef
  18. CC := gcc
  19. CPP := g++
  20. LN := ln
  21. SOURCES := src/shellmatta.c \
  22. src/shellmatta_autocomplete.c \
  23. src/shellmatta_history.c \
  24. src/shellmatta_utils.c \
  25. src/shellmatta_escape.c \
  26. src/shellmatta_opt.c
  27. AUTH_SOURCES := $(SOURCES) src/shellmatta_auth.c
  28. EXAMPLE_SOURCES := $(AUTH_SOURCES) example/main.c
  29. EXAMPLE_COBJ := $(patsubst %.c,$(OBJ_DIR_EXAMPLE)%.o,$(EXAMPLE_SOURCES))
  30. CPPCHECK_SOURCES := $(AUTH_SOURCES)
  31. CPPCHECK_OPTIONS := --enable=all \
  32. --check-level=exhaustive \
  33. --template=gcc \
  34. --cppcheck-build-dir=output/cppcheck \
  35. --suppress-xml=cfg/cppcheck/cppcheck_suppressions.xml \
  36. -DSHELLMATTA_AUTHENTICATION \
  37. -Iapi \
  38. $(CPPCHECK_SOURCES)
  39. INCLUDES := api .
  40. UNITTEST_SOURCES := test/unittest/test_main.cpp \
  41. test/unittest/shellmatta_opt/test_opt_findNextHunk.cpp \
  42. test/unittest/shellmatta_opt/test_opt_peekNextHunk.cpp \
  43. test/unittest/shellmatta_utils/test_utils_writeEcho.cpp \
  44. test/unittest/shellmatta_utils/test_utils_shellItoa.cpp \
  45. test/unittest/shellmatta_utils/test_utils_saveCursorPos.cpp \
  46. test/unittest/shellmatta_utils/test_utils_restoreCursorPos.cpp \
  47. test/unittest/shellmatta_utils/test_utils_eraseLine.cpp \
  48. test/unittest/shellmatta_utils/test_utils_rewindCursor.cpp \
  49. test/unittest/shellmatta_utils/test_utils_forwardCursor.cpp \
  50. test/unittest/shellmatta_utils/test_utils_clearInput.cpp \
  51. test/unittest/shellmatta_utils/test_utils_insertChars.cpp \
  52. test/unittest/shellmatta_utils/test_utils_terminateInput.cpp \
  53. test/unittest/shellmatta_utils/test_utils_removeChars.cpp \
  54. test/unittest/shellmatta_autocomplete/test_autocomplete_run.cpp \
  55. test/unittest/shellmatta_escape/test_escape_processArrowKeys.cpp \
  56. test/unittest/shellmatta_history/test_appendHistoryByte.cpp \
  57. test/unittest/shellmatta/test_shellmatta_doInit.cpp
  58. INTEGRATIONTEST_SOURCES := test/integrationtest/test_main.cpp \
  59. test/integrationtest/test_integration.cpp \
  60. test/integrationtest/test_integration_opt.cpp \
  61. test/integrationtest/test_integration_optLong.cpp \
  62. test/integrationtest/test_integration_continue.cpp \
  63. test/integrationtest/test_integration_busy.cpp \
  64. test/integrationtest/test_integration_history.cpp \
  65. test/integrationtest/test_integration_help.cpp
  66. INTEGRATIONTEST_AUTH_SOURCES := test/integrationtest_auth/test_main.cpp \
  67. test/integrationtest_auth/test_integration_auth.cpp
  68. UNITTEST_CPPOBJ := $(patsubst %.cpp,$(UNITTEST_OBJ_DIR)%.o,$(UNITTEST_SOURCES))
  69. INTEGRATIONTEST_CPPOBJ := $(patsubst %.cpp,$(INTEGRATIONTEST_CPP_OBJ_DIR)%.o,$(INTEGRATIONTEST_SOURCES))
  70. INTEGRATIONTEST_COBJ := $(patsubst %.c,$(INTEGRATIONTEST_CPP_OBJ_DIR)%.o,$(SOURCES))
  71. INTEGRATIONTEST_AUTH_CPPOBJ := $(patsubst %.cpp,$(INTEGRATIONTEST_AUTH_CPP_OBJ_DIR)%.o,$(INTEGRATIONTEST_AUTH_SOURCES))
  72. INTEGRATIONTEST_AUTH_COBJ := $(patsubst %.c,$(INTEGRATIONTEST_AUTH_CPP_OBJ_DIR)%.o,$(AUTH_SOURCES))
  73. CFLAGS := $(INCLUDES:%=-I%) -g -Wall -Werror -Wextra -pedantic -DSHELLMATTA_HELP_ALIAS=\(char*\)\"?\"
  74. CFLAGS_EXAMPLE = $(CFLAGS) -DSHELLMATTA_AUTHENTICATION
  75. TESTFLAGS := $(CFLAGS) -fprofile-arcs -ftest-coverage
  76. TESTFLAGS_AUTH := $(CFLAGS) -DSHELLMATTA_AUTHENTICATION -fprofile-arcs -ftest-coverage
  77. TESTLFLAGS := -fprofile-arcs -Wl,--allow-multiple-definition
  78. DEPEND = -MT $@ -MF "$(@:%.o=%.d)" -MG -MM
  79. COBJ := $(patsubst %.c,$(OBJ_DIR)%.o,$(SOURCES))
  80. EXAMPLE_TARGET := $(OBJ_DIR)example/example
  81. UNITTEST_TARGET := $(OBJ_DIR)test/unittest/unittest
  82. INTEGRATIONTEST_TARGET := $(OBJ_DIR)test/integrationtest/integrationtest
  83. INTEGRATIONTEST_TARGET_AUTH := $(OBJ_DIR)test/integrationtest_auth/integrationtest_auth
  84. TEST_RUN_TARGETS := unittest integrationtest integrationtest_auth
  85. # ensure the tests are running one after another when general test target is called
  86. ifneq ($(filter test,$(MAKECMDGOALS)),)
  87. TEST_RUN_TARGETS_HELPER := $(TEST_RUN_TARGETS)
  88. endif
  89. TEST_TARGETS := $(UNITTEST_TARGET) $(INTEGRATIONTEST_TARGET) $(INTEGRATIONTEST_TARGET_AUTH)
  90. OBJ := $(COBJ) $(EXAMPLE_COBJ) $(UNITTEST_CPPOBJ) $(INTEGRATIONTEST_CPPOBJ) $(INTEGRATIONTEST_COBJ) $(INTEGRATIONTEST_AUTH_CPPOBJ) $(INTEGRATIONTEST_AUTH_COBJ)
  91. DEPS := $(OBJ:%.o=%.d)
  92. export
  93. .PHONY: help cppcheck doc clean
  94. help:
  95. @echo Shellmatta help
  96. @echo -----------------------------------------------
  97. @echo test - run all tests
  98. @echo cppcheck - run static code analysis \(cppcheck\)
  99. @echo example - build example
  100. @echo -----------------------------------------------
  101. test: $(TEST_RUN_TARGETS)
  102. - @mkdir -p output/test/report
  103. # run the test alltogether to get coverage from all combined tests
  104. # remove coverage from former run
  105. @-find . -name "*.gcda" -type f -delete
  106. $(foreach TEST_RUN_TARGET,$(TEST_RUN_TARGETS),./$(OBJ_DIR)test/$(TEST_RUN_TARGET)/$(TEST_RUN_TARGET)${\n})
  107. # remove report from former run
  108. -rm -rf $(OBJ_DIR)test/report/*
  109. gcovr --html-details --output $(OBJ_DIR)test/report/report.html -f src -f api -d
  110. cppcheck:
  111. - @mkdir -p output/cppcheck/html
  112. cppcheck $(CPPCHECK_OPTIONS)
  113. cppcheck $(CPPCHECK_OPTIONS) --xml 2>output/cppcheck/cppcheck.xml
  114. cppcheck-htmlreport --file=output/cppcheck/cppcheck.xml --title="Shellmatta" --report-dir=output/cppcheck/html
  115. $(TEST_RUN_TARGETS): $(TEST_TARGETS) $(filter-out $@,$(TEST_RUN_TARGETS_HELPER))
  116. - @mkdir -p output/test/$@/report
  117. @echo running test $@:
  118. # remove coverage from former run
  119. @-find . -name "*.gcda" -type f -delete
  120. -$(OBJ_DIR)test/$@/$@
  121. # remove report from former run
  122. -rm -rf $(OBJ_DIR)test/$@/report/*
  123. gcovr --html-details --output $(OBJ_DIR)test/$@/report/report.html output/test/$@ -f src -f api -d
  124. example: $(EXAMPLE_TARGET)
  125. @echo building example
  126. doc:
  127. - @mkdir -p output/doc/html
  128. - @mkdir -p output/doc/latex
  129. doxygen cfg/doxygen/doxyfile
  130. clean:
  131. - rm -rf $(OBJ_DIR)
  132. $(EXAMPLE_TARGET): $(EXAMPLE_COBJ)
  133. - @mkdir -p $(@D)
  134. $(CC) $(LFLAGS) $(LIB_PATH) -o $@ $^ $(LIBS)
  135. $(UNITTEST_TARGET): $(UNITTEST_CPPOBJ)
  136. - @mkdir -p $(@D)
  137. $(CPP) $(TESTLFLAGS) $(LIB_PATH) -o $@ $^ $(LIBS)
  138. $(INTEGRATIONTEST_TARGET): $(INTEGRATIONTEST_CPPOBJ) $(INTEGRATIONTEST_COBJ)
  139. - @mkdir -p $(@D)
  140. $(CPP) $(TESTLFLAGS) $(LIB_PATH) -o $@ $^ $(LIBS)
  141. $(INTEGRATIONTEST_TARGET_AUTH): $(INTEGRATIONTEST_AUTH_CPPOBJ) $(INTEGRATIONTEST_AUTH_COBJ)
  142. - @mkdir -p $(@D)
  143. echo askdjhaskjdhskj
  144. $(CPP) $(TESTLFLAGS) $(LIB_PATH) -o $@ $^ $(LIBS)
  145. $(TARGET): $(OBJ)
  146. - @mkdir -p $(@D)
  147. $(CC) $(LFLAGS) $(LIB_PATH) -o $@ $^ $(LIBS)
  148. $(COBJ):
  149. - @mkdir -p $(@D)
  150. @$(CC) -c $(CFLAGS) $(DEPEND) -o $(@:%.o=%.d) $(subst $(OBJ_DIR), ,$(@:%.o=%.c))
  151. $(CC) -c $(CFLAGS) -o $@ $(subst $(OBJ_DIR), ,$(@:%.o=%.c))
  152. $(EXAMPLE_COBJ):
  153. - @mkdir -p $(@D)
  154. @$(CC) -c $(CFLAGS_EXAMPLE) $(DEPEND) -o $(@:%.o=%.d) $(subst $(OBJ_DIR_EXAMPLE), ,$(@:%.o=%.c))
  155. $(CC) -c $(CFLAGS_EXAMPLE) -o $@ $(subst $(OBJ_DIR_EXAMPLE), ,$(@:%.o=%.c))
  156. $(UNITTEST_CPPOBJ):
  157. - @mkdir -p $(@D)
  158. @$(CPP) -c $(TESTFLAGS) $(DEPEND) -o $(@:%.o=%.d) $(subst $(UNITTEST_OBJ_DIR), ,$(@:%.o=%.cpp))
  159. $(CPP) -c $(TESTFLAGS) -o $@ $(subst $(UNITTEST_OBJ_DIR), ,$(@:%.o=%.cpp))
  160. $(INTEGRATIONTEST_CPPOBJ):
  161. - @mkdir -p $(@D)
  162. @$(CPP) -c $(TESTFLAGS) $(DEPEND) -o $(@:%.o=%.d) $(subst $(INTEGRATIONTEST_CPP_OBJ_DIR), ,$(@:%.o=%.cpp))
  163. $(CPP) -c $(TESTFLAGS) -o $@ $(subst $(INTEGRATIONTEST_CPP_OBJ_DIR), ,$(@:%.o=%.cpp))
  164. $(INTEGRATIONTEST_COBJ):
  165. - @mkdir -p $(@D)
  166. @$(CC) -c $(TESTFLAGS) $(DEPEND) -o $(@:%.o=%.d) $(subst $(INTEGRATIONTEST_C_OBJ_DIR), ,$(@:%.o=%.c))
  167. $(CC) -c $(TESTFLAGS) -o $@ $(subst $(INTEGRATIONTEST_C_OBJ_DIR), ,$(@:%.o=%.c))
  168. $(INTEGRATIONTEST_AUTH_CPPOBJ):
  169. - @mkdir -p $(@D)
  170. @$(CPP) -c $(TESTFLAGS_AUTH) $(DEPEND) -o $(@:%.o=%.d) $(subst $(INTEGRATIONTEST_AUTH_CPP_OBJ_DIR), ,$(@:%.o=%.cpp))
  171. $(CPP) -c $(TESTFLAGS_AUTH) -o $@ $(subst $(INTEGRATIONTEST_AUTH_CPP_OBJ_DIR), ,$(@:%.o=%.cpp))
  172. $(INTEGRATIONTEST_AUTH_COBJ):
  173. - @mkdir -p $(@D)
  174. $(CC) -c $(TESTFLAGS_AUTH) $(DEPEND) -o $(@:%.o=%.d) $(subst $(INTEGRATIONTEST_AUTH_C_OBJ_DIR), ,$(@:%.o=%.c))
  175. $(CC) -c $(TESTFLAGS_AUTH) -o $@ $(subst $(INTEGRATIONTEST_AUTH_C_OBJ_DIR), ,$(@:%.o=%.c))
  176. %.o: %.cpp
  177. - @mkdir -p $(@D)
  178. @$(CPP) -c $(CFLAGS) $(DEPEND) -o $(@:%.o=%.d) $(subst $(OBJ_DIR), ,$(@:%.o=%.c))
  179. $(CPP) -c $(CFLAGS) -o $@ $<
  180. -include $(DEPS)