makefile 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. TEST_SOURCES := test/test_main.cpp \
  19. test/shellmatta_utils/test_utils_writeEcho.cpp \
  20. test/shellmatta_utils/test_utils_shellItoa.cpp \
  21. test/shellmatta_utils/test_utils_saveCursorPos.cpp \
  22. test/shellmatta_utils/test_utils_restoreCursorPos.cpp \
  23. test/shellmatta_utils/test_utils_eraseLine.cpp \
  24. test/shellmatta_utils/test_utils_rewindCursor.cpp \
  25. test/shellmatta_utils/test_utils_forwardCursor.cpp \
  26. test/shellmatta_utils/test_utils_clearInput.cpp \
  27. test/shellmatta_utils/test_utils_insertChars.cpp
  28. TEST_CPPOBJ := $(patsubst %.cpp,$(OBJ_DIR)%.o,$(TEST_SOURCES))
  29. CFLAGS := $(INCLUDES:%=-I%) -g
  30. TESTFLAGS := $(INCLUDES:%=-I%) -g -fprofile-arcs -ftest-coverage
  31. TESTLFLAGS := -fprofile-arcs -Wl,--allow-multiple-definition
  32. DEPEND = -MT $@ -MF "$(@:%.o=%.d)" -MG -MM
  33. COBJ := $(patsubst %.c,$(OBJ_DIR)%.o,$(SOURCES))
  34. EXAMPLE_SOURCES := example/main.c
  35. EXAMPLE_COBJ := $(patsubst %.c,$(OBJ_DIR)%.o,$(EXAMPLE_SOURCES))
  36. EXAMPLE_TARGET := $(OBJ_DIR)example/example
  37. TEST_TARGET := $(OBJ_DIR)test/test
  38. OBJ := $(COBJ) $(EXAMPLE_COBJ) $(TEST_CPPOBJ)
  39. DEPS := $(OBJ:%.o=%.d)
  40. export
  41. help:
  42. @echo Shellmatta help
  43. @echo -------------------------
  44. @echo test - run all tests
  45. @echo example - build example
  46. @echo -------------------------
  47. test: $(TEST_TARGET)
  48. - @mkdir -p output/test/report
  49. @echo running test:
  50. -output/test/test
  51. #gcov -o output/test $(TEST_CPPOBJ) -r
  52. gcovr --html-details --output output/test/report/report.html output/test -f src -f api
  53. #-rm *.gcov
  54. example: $(EXAMPLE_TARGET)
  55. @echo building example
  56. doc:
  57. - @mkdir -p output/doc/html
  58. - @mkdir -p output/doc/latex
  59. doxygen settings/doxygen/doxyfile
  60. clean:
  61. - rm -rf $(OBJ_DIR)
  62. $(EXAMPLE_TARGET): $(COBJ) $(EXAMPLE_COBJ)
  63. - @mkdir -p $(@D)
  64. $(CC) $(LFLAGS) $(LIB_PATH) -o $@ $^ $(LIBS)
  65. $(TEST_TARGET): $(TEST_CPPOBJ)
  66. - @mkdir -p $(@D)
  67. $(CPP) $(TESTLFLAGS) $(LIB_PATH) -o $@ $^ $(LIBS)
  68. $(TARGET): $(OBJ)
  69. - @mkdir -p $(@D)
  70. $(CC) $(LFLAGS) $(LIB_PATH) -o $@ $^ $(LIBS)
  71. $(COBJ):
  72. - @mkdir -p $(@D)
  73. @$(CC) -c $(CFLAGS) $(DEPEND) -o $@ $(subst $(OBJ_DIR), ,$(@:%.o=%.c))
  74. $(CC) -c $(CFLAGS) -o $@ $(subst $(OBJ_DIR), ,$(@:%.o=%.c))
  75. $(EXAMPLE_COBJ):
  76. - @mkdir -p $(@D)
  77. @$(CC) -c $(CFLAGS) $(DEPEND) -o $@ $(subst $(OBJ_DIR), ,$(@:%.o=%.c))
  78. $(CC) -c $(CFLAGS) -o $@ $(subst $(OBJ_DIR), ,$(@:%.o=%.c))
  79. $(TEST_CPPOBJ):
  80. - @mkdir -p $(@D)
  81. @$(CPP) -c $(TESTFLAGS) $(DEPEND) -o $@ $(subst $(OBJ_DIR), ,$(@:%.o=%.cpp))
  82. $(CPP) -c $(TESTFLAGS) -o $@ $(subst $(OBJ_DIR), ,$(@:%.o=%.cpp))
  83. %.o: %.cpp
  84. - @mkdir -p $(@D)
  85. @$(CPP) -c $(CFLAGS) $(DEPEND) -o $@ $(subst $(OBJ_DIR), ,$(@:%.o=%.c))
  86. $(CPP) -c $(CFLAGS) -o $@ $<
  87. -include $(DEPS)