makefile 9.0 KB

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