makefile 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. INTEGRATIONTEST_SOURCES := test/integrationtest/test_main.cpp \
  29. test/integrationtest/test_integration.cpp
  30. UNITTEST_CPPOBJ := $(patsubst %.cpp,$(OBJ_DIR)%.o,$(UNITTEST_SOURCES))
  31. INTEGRATIONTEST_CPPOBJ := $(patsubst %.cpp,$(OBJ_DIR)%.o,$(INTEGRATIONTEST_SOURCES))
  32. CFLAGS := $(INCLUDES:%=-I%) -g -Wall -Werror
  33. TESTFLAGS := $(INCLUDES:%=-I%) -g -Wall -Werror -fprofile-arcs -ftest-coverage
  34. TESTLFLAGS := -fprofile-arcs -Wl,--allow-multiple-definition
  35. DEPEND = -MT $@ -MF "$(@:%.o=%.d)" -MG -MM
  36. COBJ := $(patsubst %.c,$(OBJ_DIR)%.o,$(SOURCES))
  37. EXAMPLE_SOURCES := example/main.c
  38. EXAMPLE_COBJ := $(patsubst %.c,$(OBJ_DIR)%.o,$(EXAMPLE_SOURCES))
  39. EXAMPLE_TARGET := $(OBJ_DIR)example/example
  40. UNITTEST_TARGET := $(OBJ_DIR)test/unittest/unittest
  41. INTEGRATIONTEST_TARGET := $(OBJ_DIR)test/integrationtest/integrationtest
  42. OBJ := $(COBJ) $(EXAMPLE_COBJ) $(UNITTEST_CPPOBJ) $(INTEGRATIONTEST_CPPOBJ)
  43. DEPS := $(OBJ:%.o=%.d)
  44. export
  45. help:
  46. @echo Shellmatta help
  47. @echo -------------------------
  48. @echo test - run all tests
  49. @echo example - build example
  50. @echo -------------------------
  51. test: unittest integrationtest
  52. unittest: $(UNITTEST_TARGET)
  53. - @mkdir -p output/test/unittest/report
  54. @echo running test:
  55. -$(UNITTEST_TARGET)
  56. #gcov -o output/test $(TEST_CPPOBJ) -r
  57. gcovr --html-details --output $(OBJ_DIR)test/unittest/report/report.html output/test/unittest -f src -f api
  58. #-rm *.gcov
  59. integrationtest: $(INTEGRATIONTEST_TARGET)
  60. - @mkdir -p output/test/integrationtest/report
  61. @echo running test:
  62. -$(INTEGRATIONTEST_TARGET)
  63. #gcov -o output/test $(TEST_CPPOBJ) -r
  64. gcovr --html-details --output $(OBJ_DIR)test/integrationtest/report/report.html output/src -f src -f api
  65. #-rm *.gcov
  66. example: $(EXAMPLE_TARGET)
  67. @echo building example
  68. doc:
  69. - @mkdir -p output/doc/html
  70. - @mkdir -p output/doc/latex
  71. doxygen settings/doxygen/doxyfile
  72. clean:
  73. - rm -rf $(OBJ_DIR)
  74. $(EXAMPLE_TARGET): $(COBJ) $(EXAMPLE_COBJ)
  75. - @mkdir -p $(@D)
  76. $(CC) $(LFLAGS) $(LIB_PATH) -o $@ $^ $(LIBS)
  77. $(UNITTEST_TARGET): $(UNITTEST_CPPOBJ)
  78. - @mkdir -p $(@D)
  79. $(CPP) $(TESTLFLAGS) $(LIB_PATH) -o $@ $^ $(LIBS)
  80. $(INTEGRATIONTEST_TARGET): $(INTEGRATIONTEST_CPPOBJ) $(COBJ)
  81. - @mkdir -p $(@D)
  82. $(CPP) $(TESTLFLAGS) $(LIB_PATH) -o $@ $^ $(LIBS)
  83. $(TARGET): $(OBJ)
  84. - @mkdir -p $(@D)
  85. $(CC) $(LFLAGS) $(LIB_PATH) -o $@ $^ $(LIBS)
  86. $(COBJ):
  87. - @mkdir -p $(@D)
  88. @$(CC) -c $(CFLAGS) $(DEPEND) -o $@ $(subst $(OBJ_DIR), ,$(@:%.o=%.c))
  89. $(CC) -c $(CFLAGS) -o $@ $(subst $(OBJ_DIR), ,$(@:%.o=%.c))
  90. $(EXAMPLE_COBJ):
  91. - @mkdir -p $(@D)
  92. @$(CC) -c $(CFLAGS) $(DEPEND) -o $@ $(subst $(OBJ_DIR), ,$(@:%.o=%.c))
  93. $(CC) -c $(CFLAGS) -o $@ $(subst $(OBJ_DIR), ,$(@:%.o=%.c))
  94. $(UNITTEST_CPPOBJ) $(INTEGRATIONTEST_CPPOBJ):
  95. - @mkdir -p $(@D)
  96. @$(CPP) -c $(TESTFLAGS) $(DEPEND) -o $@ $(subst $(OBJ_DIR), ,$(@:%.o=%.cpp))
  97. $(CPP) -c $(TESTFLAGS) -o $@ $(subst $(OBJ_DIR), ,$(@:%.o=%.cpp))
  98. %.o: %.cpp
  99. - @mkdir -p $(@D)
  100. @$(CPP) -c $(CFLAGS) $(DEPEND) -o $@ $(subst $(OBJ_DIR), ,$(@:%.o=%.c))
  101. $(CPP) -c $(CFLAGS) -o $@ $<
  102. -include $(DEPS)