makefile 3.0 KB

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