An empty C++17 project with a lil bit of a dependency management to it.
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

150 řádky
3.8 KiB

před 4 roky
  1. CC := -clang
  2. CFLAGS := --std=c11 -pedantic-errors -Wall -Wextra -Werror -Wno-unused-command-line-argument
  3. CXX := $(CC)
  4. CXXFLAGS := --std=c++17 -pedantic-errors -Wall -Wextra -Werror -Wno-unused-command-line-argument
  5. LDFLAGS := -pthread -ldl
  6. BUILD := ./build
  7. OBJ_DIR := $(BUILD)/objects
  8. APP_DIR := $(BUILD)/apps
  9. DEPS_DIR := $(BUILD)/deps
  10. INCLUDE_DEPS := ./include_deps
  11. SOURCE_DEPS := ./src_deps
  12. INCLUDE := -Iinclude/ -I$(INCLUDE_DEPS)
  13. ####################
  14. # PROJECT LISTINGS #
  15. ####################
  16. TARGET := program
  17. SRC := \
  18. $(wildcard $(SOURCE_DEPS)/*.c) \
  19. $(wildcard $(SOURCE_DEPS)/*.cpp) \
  20. $(wildcard src/actions/*.cpp) \
  21. $(wildcard src/datastructures/*.cpp) \
  22. $(wildcard src/networking/*.cpp) \
  23. $(wildcard src/*.cpp) \
  24. OBJECTS := $(SRC:%=$(OBJ_DIR)/%.o)
  25. DEPS := .deps/spdlog \
  26. .deps/spdlog_sqlite \
  27. .deps/sqlite3 \
  28. .deps/jinx
  29. #############################
  30. # DEPENDENCIES DECLARATIONS #
  31. #############################
  32. JINX_URL := https://raw.githubusercontent.com/JamesBoer/Jinx/master/Include/Jinx.hpp
  33. SQLITE_SPDLOG_URL := https://raw.githubusercontent.com/PedroRod/sqlite_sink/master/sqlite_sink.h
  34. SQLITE_VERSION_STR := sqlite-amalgamation-3320300
  35. SQLITE_URL := https://www.sqlite.org/2020/$(SQLITE_VERSION_STR).zip
  36. SPDLOG_URL := https://github.com/gabime/spdlog
  37. deps: $(DEPS)
  38. .deps/jinx: $(INCLUDE_DEPS)/Jinx.hpp
  39. @mkdir -p $(@D)
  40. echo $(JINX_URL) > $@
  41. .deps/sqlite3:
  42. @mkdir -p $(@D)
  43. @rm -rf /tmp/sqlite
  44. @mkdir -p /tmp/sqlite
  45. @mkdir -p $(SOURCE_DEPS) $(INCLUDE_DEPS)
  46. cd /tmp/sqlite; wget --quiet --output-document=sqlite.zip $(SQLITE_URL)
  47. cd /tmp/sqlite; unzip sqlite.zip
  48. cp /tmp/sqlite/$(SQLITE_VERSION_STR)/sqlite3.h $(INCLUDE_DEPS)/sqlite3.h
  49. cp /tmp/sqlite/$(SQLITE_VERSION_STR)/sqlite3.c $(SOURCE_DEPS)/sqlite3.c
  50. echo $(SQLITE_VERSION_STR) > $@
  51. .deps/spdlog: $(DEPS_DIR)/libspdlog.a
  52. @mkdir -p $(@D)
  53. echo $(SPDLOG_URL) > $@
  54. .deps/spdlog_sqlite: $(INCLUDE_DEPS)/sqlite_sink.h
  55. @mkdir -p $(@D)
  56. echo $(SQLITE_SPDLOG_URL) > $@
  57. ################################
  58. # DEPENDENCIES IMPLEMENTATIONS #
  59. ################################
  60. $(INCLUDE_DEPS)/Jinx.hpp:
  61. @mkdir -p $(@D)
  62. wget --quiet --output-document=$@ $(JINX_URL)
  63. $(INCLUDE_DEPS)/sqlite_sink.h:
  64. @mkdir -p $(@D)
  65. wget --quiet --output-document=$@ $(SQLITE_SPDLOG_URL)
  66. $(DEPS_DIR)/libspdlog.a:
  67. @rm -rf /tmp/spdlog
  68. @mkdir /tmp/spdlog
  69. @mkdir -p $(@D)
  70. cd /tmp/spdlog; git clone --quiet --depth=1 $(SPDLOG_URL)
  71. cd /tmp/spdlog; mkdir build
  72. cd /tmp/spdlog/build; cmake --log-level=ERROR ../spdlog/
  73. +cd /tmp/spdlog/build; make
  74. cp -fr /tmp/spdlog/spdlog/include/spdlog $(INCLUDE_DEPS)
  75. cp /tmp/spdlog/build/libspdlog.a $@
  76. #######################
  77. # PROJECT COMPILATION #
  78. #######################
  79. all:
  80. +make deps
  81. +make executable
  82. debug:
  83. +make deps
  84. +make debug_executable
  85. release:
  86. +make deps
  87. +make release_executable
  88. executable: deps
  89. executable: build $(APP_DIR)/$(TARGET)
  90. debug_executable: CFLAGS += -DDEBUG -g
  91. debug_executable: CXXFLAGS += -DDEBUG -g
  92. debug_executable: build $(APP_DIR)/$(TARGET)
  93. gdb $(APP_DIR)/$(TARGET)
  94. release_executable: CFLAGS += -O3 -march=native
  95. release_executable: CXXFLAGS += -O3 -march=native
  96. release_executable: build $(APP_DIR)/$(TARGET)
  97. $(OBJ_DIR)/%.cpp.o: %.cpp
  98. @mkdir -p $(@D)
  99. $(CXX) $(CXXFLAGS) $(INCLUDE) -c $< -o $@ $(LDFLAGS)
  100. $(OBJ_DIR)/%.c.o: %.c
  101. @mkdir -p $(@D)
  102. $(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@ $(LDFLAGS)
  103. $(APP_DIR)/$(TARGET): $(OBJECTS)
  104. @mkdir -p $(@D)
  105. $(CXX) $(CXXFLAGS) -o $(APP_DIR)/$(TARGET) $^ $(LDFLAGS)
  106. .PHONY: all build clean debug release
  107. print_objects:
  108. @echo $(OBJECTS)
  109. build:
  110. @mkdir -p $(APP_DIR)
  111. @mkdir -p $(OBJ_DIR)
  112. clean_all: clean deps_clean
  113. clean:
  114. -@rm -rvf $(OBJ_DIR)/*
  115. -@rm -rvf $(APP_DIR)/*
  116. deps_clean:
  117. -@rm -rvf include_deps/*
  118. -@rm -rvf src_deps/*
  119. -@rm -rvf $(DEPS_DIR)/*
  120. -@rm -rvf .deps/*