An empty C++17 project with a lil bit of a dependency management to it.
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 

163 righe
4.4 KiB

CC := -clang
CFLAGS := --std=c11 -pedantic-errors -Wall -Wextra -Werror -Wno-unused-command-line-argument
CXX := $(CC)
CXXFLAGS := --std=c++17 -pedantic-errors -Wall -Wextra -Werror -Wno-unused-command-line-argument
LDFLAGS := -pthread -ldl
BUILD := ./build
OBJ_DIR := $(BUILD)/objects
APP_DIR := $(BUILD)/apps
DEPS_DIR := $(BUILD)/deps
INCLUDE_DEPS := ./include_deps
SOURCE_DEPS := ./src_deps
INCLUDE := -Iinclude/ -I$(INCLUDE_DEPS)
####################
# PROJECT LISTINGS #
####################
TARGET := program
SRC := \
$(wildcard $(SOURCE_DEPS)/*.c) \
$(wildcard $(SOURCE_DEPS)/*.cpp) \
$(wildcard src/actions/*.cpp) \
$(wildcard src/datastructures/*.cpp) \
$(wildcard src/networking/*.cpp) \
$(wildcard src/*.cpp) \
OBJECTS := $(SRC:%=$(OBJ_DIR)/%.o)
DEPS := .deps/spdlog \
.deps/spdlog_sqlite \
.deps/sqlite3 \
.deps/jinx \
.deps/gplib
#####################
# COMPILATION MODES #
#####################
all:
+make deps
+make executable
debug:
+make deps
+make debug_executable
release:
+make deps
+make release_executable
executable: deps
executable: build $(APP_DIR)/$(TARGET)
debug_executable: CFLAGS += -DDEBUG -g
debug_executable: CXXFLAGS += -DDEBUG -g
debug_executable: build $(APP_DIR)/$(TARGET)
gdb $(APP_DIR)/$(TARGET)
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
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
release_executable: build $(APP_DIR)/$(TARGET)
#############################
# DEPENDENCIES DECLARATIONS #
#############################
JINX_URL := https://raw.githubusercontent.com/JamesBoer/Jinx/master/Include/Jinx.hpp
SQLITE_SPDLOG_URL := https://raw.githubusercontent.com/PedroRod/sqlite_sink/master/sqlite_sink.h
SQLITE_VERSION_STR := sqlite-amalgamation-3320300
SQLITE_URL := https://www.sqlite.org/2020/$(SQLITE_VERSION_STR).zip
SPDLOG_URL := https://github.com/gabime/spdlog
GPLIB_URL := https://git.nekoit.xyz/Archivist/gplib
deps: $(DEPS)
.deps/jinx: $(INCLUDE_DEPS)/Jinx.hpp
@mkdir -p $(@D)
echo $(JINX_URL) > $@
.deps/sqlite3:
@mkdir -p $(@D)
@rm -rf /tmp/sqlite
@mkdir -p /tmp/sqlite
@mkdir -p $(SOURCE_DEPS) $(INCLUDE_DEPS)
cd /tmp/sqlite; wget --quiet --output-document=sqlite.zip $(SQLITE_URL)
cd /tmp/sqlite; unzip sqlite.zip
cp /tmp/sqlite/$(SQLITE_VERSION_STR)/sqlite3.h $(INCLUDE_DEPS)/sqlite3.h
cp /tmp/sqlite/$(SQLITE_VERSION_STR)/sqlite3.c $(SOURCE_DEPS)/sqlite3.c
echo $(SQLITE_VERSION_STR) > $@
.deps/spdlog: $(DEPS_DIR)/libspdlog.a
@mkdir -p $(@D)
echo $(SPDLOG_URL) > $@
.deps/spdlog_sqlite: $(INCLUDE_DEPS)/sqlite_sink.h
@mkdir -p $(@D)
echo $(SQLITE_SPDLOG_URL) > $@
.deps/gplib:
@mkdir -p $(@D)
@rm -rf /tmp/gplib
cd /tmp; git clone --quiet --depth=1 $(GPLIB_URL)
cp -r /tmp/gplib/include/gp $(INCLUDE_DEPS)/gp
echo $(JINX_URL) > $@
################################
# DEPENDENCIES IMPLEMENTATIONS #
################################
$(INCLUDE_DEPS)/Jinx.hpp:
@mkdir -p $(@D)
wget --quiet --output-document=$@ $(JINX_URL)
$(INCLUDE_DEPS)/sqlite_sink.h:
@mkdir -p $(@D)
wget --quiet --output-document=$@ $(SQLITE_SPDLOG_URL)
$(DEPS_DIR)/libspdlog.a:
@rm -rf /tmp/spdlog
@mkdir /tmp/spdlog
@mkdir -p $(@D)
cd /tmp/spdlog; git clone --quiet --depth=1 $(SPDLOG_URL)
cd /tmp/spdlog; mkdir build
cd /tmp/spdlog/build; cmake --log-level=ERROR ../spdlog/
+cd /tmp/spdlog/build; make
cp -fr /tmp/spdlog/spdlog/include/spdlog $(INCLUDE_DEPS)
cp /tmp/spdlog/build/libspdlog.a $@
#######################
# PROJECT COMPILATION #
#######################
$(OBJ_DIR)/%.cpp.o: %.cpp
@mkdir -p $(@D)
$(CXX) $(CXXFLAGS) $(INCLUDE) -c $< -o $@ $(LDFLAGS)
$(OBJ_DIR)/%.c.o: %.c
@mkdir -p $(@D)
$(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@ $(LDFLAGS)
$(APP_DIR)/$(TARGET): $(OBJECTS)
@mkdir -p $(@D)
$(CXX) $(CXXFLAGS) -o $(APP_DIR)/$(TARGET) $^ $(LDFLAGS)
.PHONY: all build clean debug release
print_objects:
@echo $(OBJECTS)
build:
@mkdir -p $(APP_DIR)
@mkdir -p $(OBJ_DIR)
clean_all: clean deps_clean
clean:
-@rm -rvf $(OBJ_DIR)/*
-@rm -rvf $(APP_DIR)/*
deps_clean:
-@rm -rvf include_deps/*
-@rm -rvf src_deps/*
-@rm -rvf $(DEPS_DIR)/*
-@rm -rvf .deps/*