makefile 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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. INTEGRATIONTEST_CPP_OBJ_DIR := $(OBJ_DIR)test/integrationtest/
  10. INTEGRATIONTEST_C_OBJ_DIR := $(INTEGRATIONTEST_CPP_OBJ_DIR)
  11. INTEGRATIONTEST_CPP_OBJ_DIR_TRANSPORT := $(OBJ_DIR)test/integrationtest_transport/
  12. INTEGRATIONTEST_C_OBJ_DIR_TRANSPORT := $(INTEGRATIONTEST_CPP_OBJ_DIR_TRANSPORT)
  13. UNITTEST_OBJ_DIR := $(OBJ_DIR)test/unittest/
  14. CC := gcc
  15. CPP := g++
  16. LN := ln
  17. SOURCES := src/shellmatta.c \
  18. src/shellmatta_autocomplete.c \
  19. src/shellmatta_history.c \
  20. src/shellmatta_utils.c \
  21. src/shellmatta_escape.c \
  22. src/shellmatta_opt.c \
  23. src/shellmatta_ymodem.c
  24. SOURCES_TRANPORT_LAYER := $(SOURCES) \
  25. src/shellmatta_transport.c \
  26. src/shellmatta_crc.c
  27. INCLUDES := api .
  28. UNITTEST_SOURCES := test/unittest/test_main.cpp \
  29. test/unittest/shellmatta_opt/test_opt_findNextHunk.cpp \
  30. test/unittest/shellmatta_opt/test_opt_peekNextHunk.cpp \
  31. test/unittest/shellmatta_utils/test_utils_writeEcho.cpp \
  32. test/unittest/shellmatta_utils/test_utils_shellItoa.cpp \
  33. test/unittest/shellmatta_utils/test_utils_saveCursorPos.cpp \
  34. test/unittest/shellmatta_utils/test_utils_restoreCursorPos.cpp \
  35. test/unittest/shellmatta_utils/test_utils_eraseLine.cpp \
  36. test/unittest/shellmatta_utils/test_utils_rewindCursor.cpp \
  37. test/unittest/shellmatta_utils/test_utils_forwardCursor.cpp \
  38. test/unittest/shellmatta_utils/test_utils_clearInput.cpp \
  39. test/unittest/shellmatta_utils/test_utils_insertChars.cpp \
  40. test/unittest/shellmatta_utils/test_utils_terminateInput.cpp \
  41. test/unittest/shellmatta_utils/test_utils_removeChars.cpp \
  42. test/unittest/shellmatta_autocomplete/test_autocomplete_run.cpp \
  43. test/unittest/shellmatta_escape/test_escape_processArrowKeys.cpp \
  44. test/unittest/shellmatta_history/test_appendHistoryByte.cpp \
  45. test/unittest/shellmatta/test_shellmatta_doInit.cpp \
  46. test/unittest/shellmatta_crc/test_crc32Slow.cpp \
  47. test/unittest/shellmatta_crc/test_crc32Fast.cpp
  48. INTEGRATIONTEST_SOURCES := test/integrationtest/test_main.cpp \
  49. test/integrationtest/test_integration.cpp \
  50. test/integrationtest/test_integration_opt.cpp \
  51. test/integrationtest/test_integration_optLong.cpp \
  52. test/integrationtest/test_integration_continue.cpp \
  53. test/integrationtest/test_integration_busy.cpp \
  54. test/integrationtest/test_integration_history.cpp \
  55. test/integrationtest/test_integration_help.cpp
  56. INTEGRATIONTEST_TRANSPORT_SOURCES := $(INTEGRATIONTEST_SOURCES) \
  57. test/integrationtest/test_integration_transport.cpp
  58. UNITTEST_CPPOBJ := $(patsubst %.cpp,$(UNITTEST_OBJ_DIR)%.o,$(UNITTEST_SOURCES))
  59. INTEGRATIONTEST_CPPOBJ := $(patsubst %.cpp,$(INTEGRATIONTEST_CPP_OBJ_DIR)%.o,$(INTEGRATIONTEST_SOURCES))
  60. INTEGRATIONTEST_COBJ := $(patsubst %.c,$(INTEGRATIONTEST_CPP_OBJ_DIR)%.o,$(SOURCES))
  61. INTEGRATIONTEST_TRANSPORT_CPPOBJ := $(patsubst %.cpp,$(INTEGRATIONTEST_CPP_OBJ_DIR_TRANSPORT)%.o,$(INTEGRATIONTEST_TRANSPORT_SOURCES))
  62. INTEGRATIONTEST_TRANSPORT_COBJ := $(patsubst %.c,$(INTEGRATIONTEST_CPP_OBJ_DIR_TRANSPORT)%.o,$(SOURCES_TRANPORT_LAYER))
  63. CFLAGS := $(INCLUDES:%=-I%) -g -Wall -Werror -Wextra -pedantic
  64. CFLAGS += -DSHELLMATTA_HELP_ALIAS=\(char*\)\"?\"
  65. TESTFLAGS := $(CFLAGS) -fprofile-arcs -ftest-coverage
  66. TESTLFLAGS := -fprofile-arcs -Wl,--allow-multiple-definition
  67. TESTFLAGS_TRANSPORT := $(TESTFLAGS) -DSHELLMATTA_TRANSPORT_ENABLE
  68. TESTLFLAGS_TRANSPORT := $(TESTLFLAGS)
  69. EXAMPLE_CFLAGS := $(CFLAGS) -DSHELLMATTA_TRANSPORT_ENABLE
  70. DEPEND = -MT $@ -MF "$(@:%.o=%.d)" -MG -MM
  71. EXAMPLE_SOURCES := example/main.c $(SOURCES_TRANPORT_LAYER)
  72. EXAMPLE_COBJ := $(patsubst %.c,$(OBJ_DIR)%.o,$(EXAMPLE_SOURCES))
  73. EXAMPLE_TARGET := $(OBJ_DIR)example/example
  74. UNITTEST_TARGET := $(OBJ_DIR)test/unittest/unittest
  75. INTEGRATIONTEST_TARGET := $(OBJ_DIR)test/integrationtest/integrationtest
  76. INTEGRATIONTEST_TRANSPORT_TARGET := $(OBJ_DIR)test/integrationtest_transport/integrationtest_transport
  77. OBJ := $(EXAMPLE_COBJ) \
  78. $(UNITTEST_CPPOBJ) \
  79. $(INTEGRATIONTEST_CPPOBJ) \
  80. $(INTEGRATIONTEST_COBJ) \
  81. $(INTEGRATIONTEST_TRANSPORT_CPPOBJ) \
  82. $(INTEGRATIONTEST_TRANSPORT_COBJ)
  83. DEPS := $(OBJ:%.o=%.d)
  84. export
  85. .PHONY: help cppcheck doc clean
  86. help:
  87. @echo Shellmatta help
  88. @echo -----------------------------------------------
  89. @echo test - run all tests
  90. @echo cppcheck - run static code analysis \(cppcheck\)
  91. @echo example - build example
  92. @echo -----------------------------------------------
  93. test: unittest integrationtest integrationtest_transport
  94. cppcheck:
  95. - @mkdir -p output/cppcheck/html
  96. cppcheck --enable=all --template=gcc --cppcheck-build-dir=output/cppcheck $(SOURCES)
  97. cppcheck --enable=all --template=gcc --cppcheck-build-dir=output/cppcheck $(SOURCES) --xml 2>output/cppcheck/cppcheck.xml
  98. cppcheck-htmlreport --file=output/cppcheck/cppcheck.xml --title="Shellmatta" --report-dir=output/cppcheck/html
  99. unittest: $(UNITTEST_TARGET)
  100. - @mkdir -p output/test/unittest/report
  101. @echo running test:
  102. # remove coverage from former run
  103. @-find . -name "*.gcda" -type f -delete
  104. -$(UNITTEST_TARGET)
  105. # remove report from former run
  106. -rm -rf $(OBJ_DIR)test/unittest/report/*
  107. gcovr --html-details --output $(OBJ_DIR)test/unittest/report/report.html output/test/unittest -f src -f api -d
  108. integrationtest: $(INTEGRATIONTEST_TARGET)
  109. - @mkdir -p output/test/integrationtest/report
  110. @echo running test:
  111. # remove coverage from former run
  112. # @-find . -name "*.gcda" -type f -delete
  113. -$(INTEGRATIONTEST_TARGET)
  114. # remove report from former run
  115. # -rm -rf $(OBJ_DIR)test/unittest/report/*
  116. gcovr --html-details --output $(OBJ_DIR)test/integrationtest/report/report.html output/test/integrationtest -f src -f api -d
  117. integrationtest_transport: $(INTEGRATIONTEST_TRANSPORT_TARGET)
  118. - @mkdir -p output/test/integrationtest_transport/report
  119. @echo running test:
  120. # remove coverage from former run
  121. # @-find . -name "*.gcda" -type f -delete
  122. -$(INTEGRATIONTEST_TRANSPORT_TARGET)
  123. # remove report from former run
  124. # -rm -rf $(OBJ_DIR)test/unittest/report/*
  125. gcovr --html-details --output $(OBJ_DIR)test/integrationtest_transport/report/report.html output/test/integrationtest_transport -f src -f api -d
  126. example: $(EXAMPLE_TARGET)
  127. @echo building example
  128. doc:
  129. - @mkdir -p output/doc/html
  130. - @mkdir -p output/doc/latex
  131. doxygen cfg/doxygen/doxyfile
  132. clean:
  133. - rm -rf $(OBJ_DIR)
  134. $(EXAMPLE_TARGET): $(EXAMPLE_COBJ)
  135. - @mkdir -p $(@D)
  136. $(CC) $(LFLAGS) $(LIB_PATH) -o $@ $^ $(LIBS)
  137. $(UNITTEST_TARGET): $(UNITTEST_CPPOBJ)
  138. - @mkdir -p $(@D)
  139. $(CPP) $(TESTLFLAGS) $(LIB_PATH) -o $@ $^ $(LIBS)
  140. $(INTEGRATIONTEST_TARGET): $(INTEGRATIONTEST_CPPOBJ) $(INTEGRATIONTEST_COBJ)
  141. - @mkdir -p $(@D)
  142. $(CPP) $(TESTLFLAGS) $(LIB_PATH) -o $@ $^ $(LIBS)
  143. $(INTEGRATIONTEST_TRANSPORT_TARGET): $(INTEGRATIONTEST_TRANSPORT_CPPOBJ) $(INTEGRATIONTEST_TRANSPORT_COBJ)
  144. - @mkdir -p $(@D)
  145. $(CPP) $(TESTLFLAGS_TRANSPORT) $(LIB_PATH) -o $@ $^ $(LIBS)
  146. $(EXAMPLE_COBJ):
  147. - @mkdir -p $(@D)
  148. @$(CC) -c $(EXAMPLE_CFLAGS) $(DEPEND) -o $@ $(subst $(OBJ_DIR), ,$(@:%.o=%.c))
  149. $(CC) -c $(EXAMPLE_CFLAGS) -o $@ $(subst $(OBJ_DIR), ,$(@:%.o=%.c))
  150. $(UNITTEST_CPPOBJ):
  151. - @mkdir -p $(@D)
  152. @$(CPP) -c $(TESTFLAGS) $(DEPEND) -o $@ $(subst $(UNITTEST_OBJ_DIR), ,$(@:%.o=%.cpp))
  153. $(CPP) -c $(TESTFLAGS) -o $@ $(subst $(UNITTEST_OBJ_DIR), ,$(@:%.o=%.cpp))
  154. $(INTEGRATIONTEST_CPPOBJ):
  155. - @mkdir -p $(@D)
  156. @$(CPP) -c $(TESTFLAGS) $(DEPEND) -o $@ $(subst $(INTEGRATIONTEST_CPP_OBJ_DIR), ,$(@:%.o=%.cpp))
  157. $(CPP) -c $(TESTFLAGS) -o $@ $(subst $(INTEGRATIONTEST_CPP_OBJ_DIR), ,$(@:%.o=%.cpp))
  158. $(INTEGRATIONTEST_COBJ):
  159. - @mkdir -p $(@D)
  160. @$(CC) -c $(TESTFLAGS) $(DEPEND) -o $@ $(subst $(INTEGRATIONTEST_C_OBJ_DIR), ,$(@:%.o=%.c))
  161. $(CC) -c $(TESTFLAGS) -o $@ $(subst $(INTEGRATIONTEST_C_OBJ_DIR), ,$(@:%.o=%.c))
  162. $(INTEGRATIONTEST_TRANSPORT_CPPOBJ):
  163. - @mkdir -p $(@D)
  164. @$(CPP) -c $(TESTFLAGS_TRANSPORT) $(DEPEND) -o $@ $(subst $(INTEGRATIONTEST_CPP_OBJ_DIR_TRANSPORT), ,$(@:%.o=%.cpp))
  165. $(CPP) -c $(TESTFLAGS_TRANSPORT) -o $@ $(subst $(INTEGRATIONTEST_CPP_OBJ_DIR_TRANSPORT), ,$(@:%.o=%.cpp))
  166. $(INTEGRATIONTEST_TRANSPORT_COBJ):
  167. - @mkdir -p $(@D)
  168. @$(CC) -c $(TESTFLAGS_TRANSPORT) $(DEPEND) -o $@ $(subst $(INTEGRATIONTEST_C_OBJ_DIR_TRANSPORT), ,$(@:%.o=%.c))
  169. $(CC) -c $(TESTFLAGS_TRANSPORT) -o $@ $(subst $(INTEGRATIONTEST_C_OBJ_DIR_TRANSPORT), ,$(@:%.o=%.c))
  170. %.o: %.cpp
  171. - @mkdir -p $(@D)
  172. @$(CPP) -c $(CFLAGS) $(DEPEND) -o $@ $(subst $(OBJ_DIR), ,$(@:%.o=%.c))
  173. $(CPP) -c $(CFLAGS) -o $@ $<
  174. -include $(DEPS)