makefile 7.4 KB

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