An empty C++17 project with a lil bit of a dependency management to it.
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

163 Zeilen
4.4 KiB

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