makefile 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. #
  2. # Copyright (c) 2019 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. CC := gcc
  10. CPP := g++
  11. LN := ln
  12. SOURCES := src/shellmatta.c \
  13. src/shellmatta_autocomplete.c \
  14. src/shellmatta_history.c \
  15. src/shellmatta_utils.c \
  16. src/shellmatta_escape.c
  17. INCLUDES := api .
  18. UNITTEST_SOURCES := test/unittest/test_main.cpp \
  19. test/unittest/shellmatta_utils/test_utils_writeEcho.cpp \
  20. test/unittest/shellmatta_utils/test_utils_shellItoa.cpp \
  21. test/unittest/shellmatta_utils/test_utils_saveCursorPos.cpp \
  22. test/unittest/shellmatta_utils/test_utils_restoreCursorPos.cpp \
  23. test/unittest/shellmatta_utils/test_utils_eraseLine.cpp \
  24. test/unittest/shellmatta_utils/test_utils_rewindCursor.cpp \
  25. test/unittest/shellmatta_utils/test_utils_forwardCursor.cpp \
  26. test/unittest/shellmatta_utils/test_utils_clearInput.cpp \
  27. test/unittest/shellmatta_utils/test_utils_insertChars.cpp \
  28. test/unittest/shellmatta_autocomplete/test_autocomplete_run.cpp \
  29. test/unittest/shellmatta_escape/test_escape_processArrowKeys.cpp \
  30. test/unittest/shellmatta_history/test_appendHistoryByte.cpp \
  31. test/unittest/shellmatta/test_shellmatta_doInit.cpp
  32. INTEGRATIONTEST_SOURCES := test/integrationtest/test_main.cpp \
  33. test/integrationtest/test_integration.cpp
  34. UNITTEST_CPPOBJ := $(patsubst %.cpp,$(OBJ_DIR)%.o,$(UNITTEST_SOURCES))
  35. INTEGRATIONTEST_CPPOBJ := $(patsubst %.cpp,$(OBJ_DIR)%.o,$(INTEGRATIONTEST_SOURCES))
  36. CFLAGS := $(INCLUDES:%=-I%) -g -Wall -Werror
  37. TESTFLAGS := $(INCLUDES:%=-I%) -g -Wall -Werror -fprofile-arcs -ftest-coverage
  38. TESTLFLAGS := -fprofile-arcs -Wl,--allow-multiple-definition
  39. DEPEND = -MT $@ -MF "$(@:%.o=%.d)" -MG -MM
  40. COBJ := $(patsubst %.c,$(OBJ_DIR)%.o,$(SOURCES))
  41. EXAMPLE_SOURCES := example/main.c
  42. EXAMPLE_COBJ := $(patsubst %.c,$(OBJ_DIR)%.o,$(EXAMPLE_SOURCES))
  43. EXAMPLE_TARGET := $(OBJ_DIR)example/example
  44. UNITTEST_TARGET := $(OBJ_DIR)test/unittest/unittest
  45. INTEGRATIONTEST_TARGET := $(OBJ_DIR)test/integrationtest/integrationtest
  46. OBJ := $(COBJ) $(EXAMPLE_COBJ) $(UNITTEST_CPPOBJ) $(INTEGRATIONTEST_CPPOBJ)
  47. DEPS := $(OBJ:%.o=%.d)
  48. export
  49. help:
  50. @echo Shellmatta help
  51. @echo -------------------------
  52. @echo test - run all tests
  53. @echo example - build example
  54. @echo -------------------------
  55. test: unittest integrationtest
  56. cppcheck:
  57. - @mkdir -p output/cppcheck/html
  58. cppcheck --addon=/usr/bin/misra.py --enable=all --template=gcc --cppcheck-build-dir=output/cppcheck $(SOURCES)
  59. cppcheck --addon=/usr/bin/misra.py --enable=all --template=gcc --cppcheck-build-dir=output/cppcheck $(SOURCES) --xml 2>output/cppcheck/cppcheck.xml
  60. cppcheck-htmlreport --file=output/cppcheck/cppcheck.xml --title="Shellmatta" --report-dir=output/cppcheck/html
  61. unittest: $(UNITTEST_TARGET)
  62. - @mkdir -p output/test/unittest/report
  63. @echo running test:
  64. -$(UNITTEST_TARGET)
  65. #gcov -o output/test $(TEST_CPPOBJ) -r
  66. gcovr --html-details --output $(OBJ_DIR)test/unittest/report/report.html output/test/unittest -f src -f api
  67. #-rm *.gcov
  68. integrationtest: $(INTEGRATIONTEST_TARGET)
  69. - @mkdir -p output/test/integrationtest/report
  70. @echo running test:
  71. -$(INTEGRATIONTEST_TARGET)
  72. #gcov -o output/test $(TEST_CPPOBJ) -r
  73. gcovr --html-details --output $(OBJ_DIR)test/integrationtest/report/report.html output/src -f src -f api
  74. #-rm *.gcov
  75. example: $(EXAMPLE_TARGET)
  76. @echo building example
  77. doc:
  78. - @mkdir -p output/doc/html
  79. - @mkdir -p output/doc/latex
  80. doxygen settings/doxygen/doxyfile
  81. clean:
  82. - rm -rf $(OBJ_DIR)
  83. $(EXAMPLE_TARGET): $(COBJ) $(EXAMPLE_COBJ)
  84. - @mkdir -p $(@D)
  85. $(CC) $(LFLAGS) $(LIB_PATH) -o $@ $^ $(LIBS)
  86. $(UNITTEST_TARGET): $(UNITTEST_CPPOBJ)
  87. - @mkdir -p $(@D)
  88. $(CPP) $(TESTLFLAGS) $(LIB_PATH) -o $@ $^ $(LIBS)
  89. $(INTEGRATIONTEST_TARGET): $(INTEGRATIONTEST_CPPOBJ) $(COBJ)
  90. - @mkdir -p $(@D)
  91. $(CPP) $(TESTLFLAGS) $(LIB_PATH) -o $@ $^ $(LIBS)
  92. $(TARGET): $(OBJ)
  93. - @mkdir -p $(@D)
  94. $(CC) $(LFLAGS) $(LIB_PATH) -o $@ $^ $(LIBS)
  95. $(COBJ):
  96. - @mkdir -p $(@D)
  97. @$(CC) -c $(CFLAGS) $(DEPEND) -o $@ $(subst $(OBJ_DIR), ,$(@:%.o=%.c))
  98. $(CC) -c $(CFLAGS) -o $@ $(subst $(OBJ_DIR), ,$(@:%.o=%.c))
  99. $(EXAMPLE_COBJ):
  100. - @mkdir -p $(@D)
  101. @$(CC) -c $(CFLAGS) $(DEPEND) -o $@ $(subst $(OBJ_DIR), ,$(@:%.o=%.c))
  102. $(CC) -c $(CFLAGS) -o $@ $(subst $(OBJ_DIR), ,$(@:%.o=%.c))
  103. $(UNITTEST_CPPOBJ) $(INTEGRATIONTEST_CPPOBJ):
  104. - @mkdir -p $(@D)
  105. @$(CPP) -c $(TESTFLAGS) $(DEPEND) -o $@ $(subst $(OBJ_DIR), ,$(@:%.o=%.cpp))
  106. $(CPP) -c $(TESTFLAGS) -o $@ $(subst $(OBJ_DIR), ,$(@:%.o=%.cpp))
  107. %.o: %.cpp
  108. - @mkdir -p $(@D)
  109. @$(CPP) -c $(CFLAGS) $(DEPEND) -o $@ $(subst $(OBJ_DIR), ,$(@:%.o=%.c))
  110. $(CPP) -c $(CFLAGS) -o $@ $<
  111. -include $(DEPS)