makefile 7.3 KB

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