makefile 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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_utils/test_utils_terminateInput.cpp \
  29. test/unittest/shellmatta_autocomplete/test_autocomplete_run.cpp \
  30. test/unittest/shellmatta_escape/test_escape_processArrowKeys.cpp \
  31. test/unittest/shellmatta_history/test_appendHistoryByte.cpp \
  32. test/unittest/shellmatta/test_shellmatta_doInit.cpp
  33. INTEGRATIONTEST_SOURCES := test/integrationtest/test_main.cpp \
  34. test/integrationtest/test_integration.cpp
  35. UNITTEST_CPPOBJ := $(patsubst %.cpp,$(OBJ_DIR)%.o,$(UNITTEST_SOURCES))
  36. INTEGRATIONTEST_CPPOBJ := $(patsubst %.cpp,$(OBJ_DIR)%.o,$(INTEGRATIONTEST_SOURCES))
  37. CFLAGS := $(INCLUDES:%=-I%) -g -Wall -Werror -pedantic
  38. TESTFLAGS := $(INCLUDES:%=-I%) -g -Wall -Werror -fprofile-arcs -ftest-coverage -pedantic
  39. TESTLFLAGS := -fprofile-arcs -Wl,--allow-multiple-definition
  40. DEPEND = -MT $@ -MF "$(@:%.o=%.d)" -MG -MM
  41. COBJ := $(patsubst %.c,$(OBJ_DIR)%.o,$(SOURCES))
  42. EXAMPLE_SOURCES := example/main.c
  43. EXAMPLE_COBJ := $(patsubst %.c,$(OBJ_DIR)%.o,$(EXAMPLE_SOURCES))
  44. EXAMPLE_TARGET := $(OBJ_DIR)example/example
  45. UNITTEST_TARGET := $(OBJ_DIR)test/unittest/unittest
  46. INTEGRATIONTEST_TARGET := $(OBJ_DIR)test/integrationtest/integrationtest
  47. OBJ := $(COBJ) $(EXAMPLE_COBJ) $(UNITTEST_CPPOBJ) $(INTEGRATIONTEST_CPPOBJ)
  48. DEPS := $(OBJ:%.o=%.d)
  49. export
  50. help:
  51. @echo Shellmatta help
  52. @echo -------------------------
  53. @echo test - run all tests
  54. @echo example - build example
  55. @echo -------------------------
  56. test: unittest integrationtest
  57. cppcheck:
  58. - @mkdir -p output/cppcheck/html
  59. cppcheck --addon=/usr/bin/misra.py --enable=all --template=gcc --cppcheck-build-dir=output/cppcheck $(SOURCES)
  60. cppcheck --addon=/usr/bin/misra.py --enable=all --template=gcc --cppcheck-build-dir=output/cppcheck $(SOURCES) --xml 2>output/cppcheck/cppcheck.xml
  61. cppcheck-htmlreport --file=output/cppcheck/cppcheck.xml --title="Shellmatta" --report-dir=output/cppcheck/html
  62. unittest: $(UNITTEST_TARGET)
  63. - @mkdir -p output/test/unittest/report
  64. @echo running test:
  65. @# remove coverage from former run
  66. @-find . -name "*.gcda" -type f -delete
  67. -$(UNITTEST_TARGET)
  68. @#gcov -o output/test/unittest $(UNITTEST_CPPOBJ) -r src
  69. @# remove report from former run
  70. -rm -rf $(OBJ_DIR)test/unittest/report/*
  71. gcovr --html-details --output $(OBJ_DIR)test/unittest/report/report.html output/test/unittest -f src -f api
  72. @#-rm *.gcov
  73. integrationtest: $(INTEGRATIONTEST_TARGET)
  74. - @mkdir -p output/test/integrationtest/report
  75. @echo running test:
  76. -$(INTEGRATIONTEST_TARGET)
  77. #gcov -o output/test $(TEST_CPPOBJ) -r
  78. gcovr --html-details --output $(OBJ_DIR)test/integrationtest/report/report.html output/src -f src -f api
  79. #-rm *.gcov
  80. example: $(EXAMPLE_TARGET)
  81. @echo building example
  82. doc:
  83. - @mkdir -p output/doc/html
  84. - @mkdir -p output/doc/latex
  85. doxygen cfg/doxygen/doxyfile
  86. clean:
  87. - rm -rf $(OBJ_DIR)
  88. $(EXAMPLE_TARGET): $(COBJ) $(EXAMPLE_COBJ)
  89. - @mkdir -p $(@D)
  90. $(CC) $(LFLAGS) $(LIB_PATH) -o $@ $^ $(LIBS)
  91. $(UNITTEST_TARGET): $(UNITTEST_CPPOBJ)
  92. - @mkdir -p $(@D)
  93. $(CPP) $(TESTLFLAGS) $(LIB_PATH) -o $@ $^ $(LIBS)
  94. $(INTEGRATIONTEST_TARGET): $(INTEGRATIONTEST_CPPOBJ) $(COBJ)
  95. - @mkdir -p $(@D)
  96. $(CPP) $(TESTLFLAGS) $(LIB_PATH) -o $@ $^ $(LIBS)
  97. $(TARGET): $(OBJ)
  98. - @mkdir -p $(@D)
  99. $(CC) $(LFLAGS) $(LIB_PATH) -o $@ $^ $(LIBS)
  100. $(COBJ):
  101. - @mkdir -p $(@D)
  102. @$(CC) -c $(CFLAGS) $(DEPEND) -o $@ $(subst $(OBJ_DIR), ,$(@:%.o=%.c))
  103. $(CC) -c $(CFLAGS) -o $@ $(subst $(OBJ_DIR), ,$(@:%.o=%.c))
  104. $(EXAMPLE_COBJ):
  105. - @mkdir -p $(@D)
  106. @$(CC) -c $(CFLAGS) $(DEPEND) -o $@ $(subst $(OBJ_DIR), ,$(@:%.o=%.c))
  107. $(CC) -c $(CFLAGS) -o $@ $(subst $(OBJ_DIR), ,$(@:%.o=%.c))
  108. $(UNITTEST_CPPOBJ) $(INTEGRATIONTEST_CPPOBJ):
  109. - @mkdir -p $(@D)
  110. @$(CPP) -c $(TESTFLAGS) $(DEPEND) -o $@ $(subst $(OBJ_DIR), ,$(@:%.o=%.cpp))
  111. $(CPP) -c $(TESTFLAGS) -o $@ $(subst $(OBJ_DIR), ,$(@:%.o=%.cpp))
  112. %.o: %.cpp
  113. - @mkdir -p $(@D)
  114. @$(CPP) -c $(CFLAGS) $(DEPEND) -o $@ $(subst $(OBJ_DIR), ,$(@:%.o=%.c))
  115. $(CPP) -c $(CFLAGS) -o $@ $<
  116. -include $(DEPS)