makefile 9.4 KB

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