makefile 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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_AUTH_CPP_OBJ_DIR := $(OBJ_DIR)test/integrationtest_auth/
  12. INTEGRATIONTEST_C_OBJ_DIR := $(INTEGRATIONTEST_CPP_OBJ_DIR)
  13. INTEGRATIONTEST_AUTH_C_OBJ_DIR := $(INTEGRATIONTEST_AUTH_CPP_OBJ_DIR)
  14. UNITTEST_OBJ_DIR := $(OBJ_DIR)test/unittest/
  15. CC := gcc
  16. CPP := g++
  17. LN := ln
  18. SOURCES := src/shellmatta.c \
  19. src/shellmatta_autocomplete.c \
  20. src/shellmatta_history.c \
  21. src/shellmatta_utils.c \
  22. src/shellmatta_escape.c \
  23. src/shellmatta_opt.c
  24. INCLUDES := api .
  25. UNITTEST_SOURCES := test/unittest/test_main.cpp \
  26. test/unittest/shellmatta_opt/test_opt_findNextHunk.cpp \
  27. test/unittest/shellmatta_opt/test_opt_peekNextHunk.cpp \
  28. test/unittest/shellmatta_utils/test_utils_writeEcho.cpp \
  29. test/unittest/shellmatta_utils/test_utils_shellItoa.cpp \
  30. test/unittest/shellmatta_utils/test_utils_saveCursorPos.cpp \
  31. test/unittest/shellmatta_utils/test_utils_restoreCursorPos.cpp \
  32. test/unittest/shellmatta_utils/test_utils_eraseLine.cpp \
  33. test/unittest/shellmatta_utils/test_utils_rewindCursor.cpp \
  34. test/unittest/shellmatta_utils/test_utils_forwardCursor.cpp \
  35. test/unittest/shellmatta_utils/test_utils_clearInput.cpp \
  36. test/unittest/shellmatta_utils/test_utils_insertChars.cpp \
  37. test/unittest/shellmatta_utils/test_utils_terminateInput.cpp \
  38. test/unittest/shellmatta_utils/test_utils_removeChars.cpp \
  39. test/unittest/shellmatta_autocomplete/test_autocomplete_run.cpp \
  40. test/unittest/shellmatta_escape/test_escape_processArrowKeys.cpp \
  41. test/unittest/shellmatta_history/test_appendHistoryByte.cpp \
  42. test/unittest/shellmatta/test_shellmatta_doInit.cpp
  43. INTEGRATIONTEST_SOURCES := test/integrationtest/test_main.cpp \
  44. test/integrationtest/test_integration.cpp \
  45. test/integrationtest/test_integration_opt.cpp \
  46. test/integrationtest/test_integration_optLong.cpp \
  47. test/integrationtest/test_integration_continue.cpp \
  48. test/integrationtest/test_integration_busy.cpp \
  49. test/integrationtest/test_integration_history.cpp \
  50. test/integrationtest/test_integration_help.cpp
  51. INTEGRATIONTEST_AUTH_SOURCES := test/integrationtest_auth/test_main.cpp \
  52. test/integrationtest_auth/test_integration_auth.cpp
  53. UNITTEST_CPPOBJ := $(patsubst %.cpp,$(UNITTEST_OBJ_DIR)%.o,$(UNITTEST_SOURCES))
  54. INTEGRATIONTEST_CPPOBJ := $(patsubst %.cpp,$(INTEGRATIONTEST_CPP_OBJ_DIR)%.o,$(INTEGRATIONTEST_SOURCES))
  55. INTEGRATIONTEST_COBJ := $(patsubst %.c,$(INTEGRATIONTEST_CPP_OBJ_DIR)%.o,$(SOURCES))
  56. INTEGRATIONTEST_AUTH_CPPOBJ := $(patsubst %.cpp,$(INTEGRATIONTEST_AUTH_CPP_OBJ_DIR)%.o,$(INTEGRATIONTEST_AUTH_SOURCES))
  57. INTEGRATIONTEST_AUTH_COBJ := $(patsubst %.c,$(INTEGRATIONTEST_AUTH_CPP_OBJ_DIR)%.o,$(SOURCES) src/shellmatta_auth.c)
  58. CFLAGS := $(INCLUDES:%=-I%) -g -Wall -Werror -Wextra -pedantic -DSHELLMATTA_HELP_ALIAS=\(char*\)\"?\"
  59. CFLAGS_EXAMPLE = $(CFLAGS) -DSHELLMATTA_AUTHENTICATION
  60. TESTFLAGS := $(CFLAGS) -fprofile-arcs -ftest-coverage
  61. TESTFLAGS_AUTH := $(CFLAGS) -DSHELLMATTA_AUTHENTICATION -fprofile-arcs -ftest-coverage
  62. TESTLFLAGS := -fprofile-arcs -Wl,--allow-multiple-definition
  63. DEPEND = -MT $@ -MF "$(@:%.o=%.d)" -MG -MM
  64. COBJ := $(patsubst %.c,$(OBJ_DIR)%.o,$(SOURCES))
  65. EXAMPLE_SOURCES := $(SOURCES) src/shellmatta_auth.c example/main.c
  66. EXAMPLE_COBJ := $(patsubst %.c,$(OBJ_DIR_EXAMPLE)%.o,$(EXAMPLE_SOURCES))
  67. EXAMPLE_TARGET := $(OBJ_DIR)example/example
  68. UNITTEST_TARGET := $(OBJ_DIR)test/unittest/unittest
  69. INTEGRATIONTEST_TARGET := $(OBJ_DIR)test/integrationtest/integrationtest
  70. INTEGRATIONTEST_TARGET_AUTH := $(OBJ_DIR)test/integrationtest_auth/integrationtest_auth
  71. TEST_RUN_TARGETS := unittest integrationtest integrationtest_auth
  72. TEST_TARGETS := $(UNITTEST_TARGET) $(INTEGRATIONTEST_TARGET) $(INTEGRATIONTEST_TARGET_AUTH)
  73. OBJ := $(COBJ) $(EXAMPLE_COBJ) $(UNITTEST_CPPOBJ) $(INTEGRATIONTEST_CPPOBJ) $(INTEGRATIONTEST_COBJ) $(INTEGRATIONTEST_AUTH_CPPOBJ) $(INTEGRATIONTEST_AUTH_COBJ)
  74. DEPS := $(OBJ:%.o=%.d)
  75. export
  76. .PHONY: help cppcheck doc clean
  77. help:
  78. @echo Shellmatta help
  79. @echo -----------------------------------------------
  80. @echo test - run all tests
  81. @echo cppcheck - run static code analysis \(cppcheck\)
  82. @echo example - build example
  83. @echo -----------------------------------------------
  84. test: $(TEST_RUN_TARGETS)
  85. cppcheck:
  86. - @mkdir -p output/cppcheck/html
  87. cppcheck --enable=all --template=gcc --cppcheck-build-dir=output/cppcheck $(SOURCES)
  88. cppcheck --enable=all --template=gcc --cppcheck-build-dir=output/cppcheck $(SOURCES) --xml 2>output/cppcheck/cppcheck.xml
  89. cppcheck-htmlreport --file=output/cppcheck/cppcheck.xml --title="Shellmatta" --report-dir=output/cppcheck/html
  90. $(TEST_RUN_TARGETS): $(TEST_TARGETS)
  91. - @mkdir -p output/test/$@/report
  92. @echo running test $@:
  93. # remove coverage from former run
  94. @-find . -name "*.gcda" -type f -delete
  95. -$(OBJ_DIR)test/$@/$@
  96. # remove report from former run
  97. -rm -rf $(OBJ_DIR)test/$@/report/*
  98. gcovr --html-details --output $(OBJ_DIR)test/$@/report/report.html output/test/$@ -f src -f api -d
  99. example: $(EXAMPLE_TARGET)
  100. @echo building example
  101. doc:
  102. - @mkdir -p output/doc/html
  103. - @mkdir -p output/doc/latex
  104. doxygen cfg/doxygen/doxyfile
  105. clean:
  106. - rm -rf $(OBJ_DIR)
  107. $(EXAMPLE_TARGET): $(EXAMPLE_COBJ)
  108. - @mkdir -p $(@D)
  109. $(CC) $(LFLAGS) $(LIB_PATH) -o $@ $^ $(LIBS)
  110. $(UNITTEST_TARGET): $(UNITTEST_CPPOBJ)
  111. - @mkdir -p $(@D)
  112. $(CPP) $(TESTLFLAGS) $(LIB_PATH) -o $@ $^ $(LIBS)
  113. $(INTEGRATIONTEST_TARGET): $(INTEGRATIONTEST_CPPOBJ) $(INTEGRATIONTEST_COBJ)
  114. - @mkdir -p $(@D)
  115. $(CPP) $(TESTLFLAGS) $(LIB_PATH) -o $@ $^ $(LIBS)
  116. $(INTEGRATIONTEST_TARGET_AUTH): $(INTEGRATIONTEST_AUTH_CPPOBJ) $(INTEGRATIONTEST_AUTH_COBJ)
  117. - @mkdir -p $(@D)
  118. echo askdjhaskjdhskj
  119. $(CPP) $(TESTLFLAGS) $(LIB_PATH) -o $@ $^ $(LIBS)
  120. $(TARGET): $(OBJ)
  121. - @mkdir -p $(@D)
  122. $(CC) $(LFLAGS) $(LIB_PATH) -o $@ $^ $(LIBS)
  123. $(COBJ):
  124. - @mkdir -p $(@D)
  125. @$(CC) -c $(CFLAGS) $(DEPEND) -o $@ $(subst $(OBJ_DIR), ,$(@:%.o=%.c))
  126. $(CC) -c $(CFLAGS) -o $@ $(subst $(OBJ_DIR), ,$(@:%.o=%.c))
  127. $(EXAMPLE_COBJ):
  128. - @mkdir -p $(@D)
  129. @echo sdlfkjsdlk
  130. @$(CC) -c $(CFLAGS_EXAMPLE) $(DEPEND) -o $@ $(subst $(OBJ_DIR_EXAMPLE), ,$(@:%.o=%.c))
  131. $(CC) -c $(CFLAGS_EXAMPLE) -o $@ $(subst $(OBJ_DIR_EXAMPLE), ,$(@:%.o=%.c))
  132. $(UNITTEST_CPPOBJ):
  133. - @mkdir -p $(@D)
  134. @$(CPP) -c $(TESTFLAGS) $(DEPEND) -o $@ $(subst $(UNITTEST_OBJ_DIR), ,$(@:%.o=%.cpp))
  135. $(CPP) -c $(TESTFLAGS) -o $@ $(subst $(UNITTEST_OBJ_DIR), ,$(@:%.o=%.cpp))
  136. $(INTEGRATIONTEST_CPPOBJ):
  137. - @mkdir -p $(@D)
  138. @$(CPP) -c $(TESTFLAGS) $(DEPEND) -o $@ $(subst $(INTEGRATIONTEST_CPP_OBJ_DIR), ,$(@:%.o=%.cpp))
  139. $(CPP) -c $(TESTFLAGS) -o $@ $(subst $(INTEGRATIONTEST_CPP_OBJ_DIR), ,$(@:%.o=%.cpp))
  140. $(INTEGRATIONTEST_COBJ):
  141. - @mkdir -p $(@D)
  142. @$(CC) -c $(TESTFLAGS) $(DEPEND) -o $@ $(subst $(INTEGRATIONTEST_C_OBJ_DIR), ,$(@:%.o=%.c))
  143. $(CC) -c $(TESTFLAGS) -o $@ $(subst $(INTEGRATIONTEST_C_OBJ_DIR), ,$(@:%.o=%.c))
  144. $(INTEGRATIONTEST_AUTH_CPPOBJ):
  145. - @mkdir -p $(@D)
  146. @$(CPP) -c $(TESTFLAGS_AUTH) $(DEPEND) -o $(@:%.o=%.d) $(subst $(INTEGRATIONTEST_AUTH_CPP_OBJ_DIR), ,$(@:%.o=%.cpp))
  147. $(CPP) -c $(TESTFLAGS_AUTH) -o $@ $(subst $(INTEGRATIONTEST_AUTH_CPP_OBJ_DIR), ,$(@:%.o=%.cpp))
  148. $(INTEGRATIONTEST_AUTH_COBJ):
  149. - @mkdir -p $(@D)
  150. $(CC) -c $(TESTFLAGS_AUTH) $(DEPEND) -o $(@:%.o=%.d) $(subst $(INTEGRATIONTEST_AUTH_C_OBJ_DIR), ,$(@:%.o=%.c))
  151. $(CC) -c $(TESTFLAGS_AUTH) -o $@ $(subst $(INTEGRATIONTEST_AUTH_C_OBJ_DIR), ,$(@:%.o=%.c))
  152. %.o: %.cpp
  153. - @mkdir -p $(@D)
  154. @$(CPP) -c $(CFLAGS) $(DEPEND) -o $@ $(subst $(OBJ_DIR), ,$(@:%.o=%.c))
  155. $(CPP) -c $(CFLAGS) -o $@ $<
  156. -include $(DEPS)