makefile 5.8 KB

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