makefile 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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. OBJ_DIR_EXAMPLE := $(OBJ_DIR)example_obj/
  10. INTEGRATIONTEST_CPP_OBJ_DIR := $(OBJ_DIR)test/integrationtest/
  11. INTEGRATIONTEST_C_OBJ_DIR := $(INTEGRATIONTEST_CPP_OBJ_DIR)
  12. UNITTEST_OBJ_DIR := $(OBJ_DIR)test/unittest/
  13. CC := gcc
  14. CPP := g++
  15. LN := ln
  16. SOURCES := src/shellmatta.c \
  17. src/shellmatta_autocomplete.c \
  18. src/shellmatta_history.c \
  19. src/shellmatta_utils.c \
  20. src/shellmatta_escape.c \
  21. src/shellmatta_opt.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*\)\"?\"
  53. CFLAGS_EXAMPLE = $(CFLAGS) -DSHELLMATTA_AUTHENTICATION
  54. TESTFLAGS := $(CFLAGS) -fprofile-arcs -ftest-coverage
  55. TESTLFLAGS := -fprofile-arcs -Wl,--allow-multiple-definition
  56. DEPEND = -MT $@ -MF "$(@:%.o=%.d)" -MG -MM
  57. COBJ := $(patsubst %.c,$(OBJ_DIR)%.o,$(SOURCES))
  58. EXAMPLE_SOURCES := $(SOURCES) src/shellmatta_auth.c example/main.c
  59. EXAMPLE_COBJ := $(patsubst %.c,$(OBJ_DIR_EXAMPLE)%.o,$(EXAMPLE_SOURCES))
  60. EXAMPLE_TARGET := $(OBJ_DIR)example/example
  61. UNITTEST_TARGET := $(OBJ_DIR)test/unittest/unittest
  62. INTEGRATIONTEST_TARGET := $(OBJ_DIR)test/integrationtest/integrationtest
  63. OBJ := $(COBJ) $(EXAMPLE_COBJ) $(UNITTEST_CPPOBJ) $(INTEGRATIONTEST_CPPOBJ) $(INTEGRATIONTEST_COBJ)
  64. DEPS := $(OBJ:%.o=%.d)
  65. export
  66. .PHONY: help cppcheck doc clean
  67. help:
  68. @echo Shellmatta help
  69. @echo -----------------------------------------------
  70. @echo test - run all tests
  71. @echo cppcheck - run static code analysis \(cppcheck\)
  72. @echo example - build example
  73. @echo -----------------------------------------------
  74. test: unittest integrationtest
  75. cppcheck:
  76. - @mkdir -p output/cppcheck/html
  77. cppcheck --enable=all --template=gcc --cppcheck-build-dir=output/cppcheck $(SOURCES)
  78. cppcheck --enable=all --template=gcc --cppcheck-build-dir=output/cppcheck $(SOURCES) --xml 2>output/cppcheck/cppcheck.xml
  79. cppcheck-htmlreport --file=output/cppcheck/cppcheck.xml --title="Shellmatta" --report-dir=output/cppcheck/html
  80. unittest: $(UNITTEST_TARGET)
  81. - @mkdir -p output/test/unittest/report
  82. @echo running test:
  83. # remove coverage from former run
  84. @-find . -name "*.gcda" -type f -delete
  85. -$(UNITTEST_TARGET)
  86. # remove report from former run
  87. -rm -rf $(OBJ_DIR)test/unittest/report/*
  88. gcovr --html-details --output $(OBJ_DIR)test/unittest/report/report.html output/test/unittest -f src -f api -d
  89. integrationtest: $(INTEGRATIONTEST_TARGET)
  90. - @mkdir -p output/test/integrationtest/report
  91. @echo running test:
  92. # remove coverage from former run
  93. # @-find . -name "*.gcda" -type f -delete
  94. -$(INTEGRATIONTEST_TARGET)
  95. # remove report from former run
  96. # -rm -rf $(OBJ_DIR)test/unittest/report/*
  97. gcovr --html-details --output $(OBJ_DIR)test/integrationtest/report/report.html output/test/integrationtest -f src -f api -d
  98. example: $(EXAMPLE_TARGET)
  99. @echo building example
  100. doc:
  101. - @mkdir -p output/doc/html
  102. - @mkdir -p output/doc/latex
  103. doxygen cfg/doxygen/doxyfile
  104. clean:
  105. - rm -rf $(OBJ_DIR)
  106. $(EXAMPLE_TARGET): $(EXAMPLE_COBJ)
  107. - @mkdir -p $(@D)
  108. $(CC) $(LFLAGS) $(LIB_PATH) -o $@ $^ $(LIBS)
  109. $(UNITTEST_TARGET): $(UNITTEST_CPPOBJ)
  110. - @mkdir -p $(@D)
  111. $(CPP) $(TESTLFLAGS) $(LIB_PATH) -o $@ $^ $(LIBS)
  112. $(INTEGRATIONTEST_TARGET): $(INTEGRATIONTEST_CPPOBJ) $(INTEGRATIONTEST_COBJ)
  113. - @mkdir -p $(@D)
  114. $(CPP) $(TESTLFLAGS) $(LIB_PATH) -o $@ $^ $(LIBS)
  115. $(TARGET): $(OBJ)
  116. - @mkdir -p $(@D)
  117. $(CC) $(LFLAGS) $(LIB_PATH) -o $@ $^ $(LIBS)
  118. $(COBJ):
  119. - @mkdir -p $(@D)
  120. @$(CC) -c $(CFLAGS) $(DEPEND) -o $@ $(subst $(OBJ_DIR), ,$(@:%.o=%.c))
  121. $(CC) -c $(CFLAGS) -o $@ $(subst $(OBJ_DIR), ,$(@:%.o=%.c))
  122. $(EXAMPLE_COBJ):
  123. - @mkdir -p $(@D)
  124. @echo sdlfkjsdlk
  125. @$(CC) -c $(CFLAGS_EXAMPLE) $(DEPEND) -o $@ $(subst $(OBJ_DIR_EXAMPLE), ,$(@:%.o=%.c))
  126. $(CC) -c $(CFLAGS_EXAMPLE) -o $@ $(subst $(OBJ_DIR_EXAMPLE), ,$(@:%.o=%.c))
  127. $(UNITTEST_CPPOBJ):
  128. - @mkdir -p $(@D)
  129. @$(CPP) -c $(TESTFLAGS) $(DEPEND) -o $@ $(subst $(UNITTEST_OBJ_DIR), ,$(@:%.o=%.cpp))
  130. $(CPP) -c $(TESTFLAGS) -o $@ $(subst $(UNITTEST_OBJ_DIR), ,$(@:%.o=%.cpp))
  131. $(INTEGRATIONTEST_CPPOBJ):
  132. - @mkdir -p $(@D)
  133. @$(CPP) -c $(TESTFLAGS) $(DEPEND) -o $@ $(subst $(INTEGRATIONTEST_CPP_OBJ_DIR), ,$(@:%.o=%.cpp))
  134. $(CPP) -c $(TESTFLAGS) -o $@ $(subst $(INTEGRATIONTEST_CPP_OBJ_DIR), ,$(@:%.o=%.cpp))
  135. $(INTEGRATIONTEST_COBJ):
  136. - @mkdir -p $(@D)
  137. @$(CC) -c $(TESTFLAGS) $(DEPEND) -o $@ $(subst $(INTEGRATIONTEST_C_OBJ_DIR), ,$(@:%.o=%.c))
  138. $(CC) -c $(TESTFLAGS) -o $@ $(subst $(INTEGRATIONTEST_C_OBJ_DIR), ,$(@:%.o=%.c))
  139. %.o: %.cpp
  140. - @mkdir -p $(@D)
  141. @$(CPP) -c $(CFLAGS) $(DEPEND) -o $@ $(subst $(OBJ_DIR), ,$(@:%.o=%.c))
  142. $(CPP) -c $(CFLAGS) -o $@ $<
  143. -include $(DEPS)