makefile 6.4 KB

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