makefile 7.4 KB

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