An empty C++17 project with a lil bit of a dependency management to it.
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

153 行
4.1 KiB

  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. # COMPILATION MODES #
  31. #####################
  32. all:
  33. +make deps
  34. +make executable
  35. debug:
  36. +make deps
  37. +make debug_executable
  38. release:
  39. +make deps
  40. +make release_executable
  41. executable: deps
  42. executable: build $(APP_DIR)/$(TARGET)
  43. debug_executable: CFLAGS += -DDEBUG -g
  44. debug_executable: CXXFLAGS += -DDEBUG -g
  45. debug_executable: build $(APP_DIR)/$(TARGET)
  46. gdb $(APP_DIR)/$(TARGET)
  47. release_executable: CFLAGS += -O2 -march=native -D_FORTIFY_SOURCE=2 -fstack-protector-strong --param ssp-buffer-size=4 -fPIE -pie -Wl,-z,relro,-z,now
  48. release_executable: CXXFLAGS += -O2 -march=native -D_FORTIFY_SOURCE=2 -fstack-protector-strong --param ssp-buffer-size=4 -fPIE -pie -Wl,-z,relro,-z,now
  49. release_executable: build $(APP_DIR)/$(TARGET)
  50. #############################
  51. # DEPENDENCIES DECLARATIONS #
  52. #############################
  53. JINX_URL := https://raw.githubusercontent.com/JamesBoer/Jinx/master/Include/Jinx.hpp
  54. SQLITE_SPDLOG_URL := https://raw.githubusercontent.com/PedroRod/sqlite_sink/master/sqlite_sink.h
  55. SQLITE_VERSION_STR := sqlite-amalgamation-3320300
  56. SQLITE_URL := https://www.sqlite.org/2020/$(SQLITE_VERSION_STR).zip
  57. SPDLOG_URL := https://github.com/gabime/spdlog
  58. deps: $(DEPS)
  59. .deps/jinx: $(INCLUDE_DEPS)/Jinx.hpp
  60. @mkdir -p $(@D)
  61. echo $(JINX_URL) > $@
  62. .deps/sqlite3:
  63. @mkdir -p $(@D)
  64. @rm -rf /tmp/sqlite
  65. @mkdir -p /tmp/sqlite
  66. @mkdir -p $(SOURCE_DEPS) $(INCLUDE_DEPS)
  67. cd /tmp/sqlite; wget --quiet --output-document=sqlite.zip $(SQLITE_URL)
  68. cd /tmp/sqlite; unzip sqlite.zip
  69. cp /tmp/sqlite/$(SQLITE_VERSION_STR)/sqlite3.h $(INCLUDE_DEPS)/sqlite3.h
  70. cp /tmp/sqlite/$(SQLITE_VERSION_STR)/sqlite3.c $(SOURCE_DEPS)/sqlite3.c
  71. echo $(SQLITE_VERSION_STR) > $@
  72. .deps/spdlog: $(DEPS_DIR)/libspdlog.a
  73. @mkdir -p $(@D)
  74. echo $(SPDLOG_URL) > $@
  75. .deps/spdlog_sqlite: $(INCLUDE_DEPS)/sqlite_sink.h
  76. @mkdir -p $(@D)
  77. echo $(SQLITE_SPDLOG_URL) > $@
  78. ################################
  79. # DEPENDENCIES IMPLEMENTATIONS #
  80. ################################
  81. $(INCLUDE_DEPS)/Jinx.hpp:
  82. @mkdir -p $(@D)
  83. wget --quiet --output-document=$@ $(JINX_URL)
  84. $(INCLUDE_DEPS)/sqlite_sink.h:
  85. @mkdir -p $(@D)
  86. wget --quiet --output-document=$@ $(SQLITE_SPDLOG_URL)
  87. $(DEPS_DIR)/libspdlog.a:
  88. @rm -rf /tmp/spdlog
  89. @mkdir /tmp/spdlog
  90. @mkdir -p $(@D)
  91. cd /tmp/spdlog; git clone --quiet --depth=1 $(SPDLOG_URL)
  92. cd /tmp/spdlog; mkdir build
  93. cd /tmp/spdlog/build; cmake --log-level=ERROR ../spdlog/
  94. +cd /tmp/spdlog/build; make
  95. cp -fr /tmp/spdlog/spdlog/include/spdlog $(INCLUDE_DEPS)
  96. cp /tmp/spdlog/build/libspdlog.a $@
  97. #######################
  98. # PROJECT COMPILATION #
  99. #######################
  100. $(OBJ_DIR)/%.cpp.o: %.cpp
  101. @mkdir -p $(@D)
  102. $(CXX) $(CXXFLAGS) $(INCLUDE) -c $< -o $@ $(LDFLAGS)
  103. $(OBJ_DIR)/%.c.o: %.c
  104. @mkdir -p $(@D)
  105. $(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@ $(LDFLAGS)
  106. $(APP_DIR)/$(TARGET): $(OBJECTS)
  107. @mkdir -p $(@D)
  108. $(CXX) $(CXXFLAGS) -o $(APP_DIR)/$(TARGET) $^ $(LDFLAGS)
  109. .PHONY: all build clean debug release
  110. print_objects:
  111. @echo $(OBJECTS)
  112. build:
  113. @mkdir -p $(APP_DIR)
  114. @mkdir -p $(OBJ_DIR)
  115. clean_all: clean deps_clean
  116. clean:
  117. -@rm -rvf $(OBJ_DIR)/*
  118. -@rm -rvf $(APP_DIR)/*
  119. deps_clean:
  120. -@rm -rvf include_deps/*
  121. -@rm -rvf src_deps/*
  122. -@rm -rvf $(DEPS_DIR)/*
  123. -@rm -rvf .deps/*