From 246de238c4416bd79318d7a6e2c1ddfa632ffb7c Mon Sep 17 00:00:00 2001 From: Daniel Yrovas Date: Wed, 2 Mar 2022 17:05:08 +1100 Subject: [PATCH] makefile template --- .gitignore | 2 ++ Makefile | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ README.md | 2 ++ src/main.cpp | 7 +++++++ 4 files changed, 63 insertions(+) create mode 100644 .gitignore create mode 100644 Makefile create mode 100644 README.md create mode 100644 src/main.cpp diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..dc84959 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +build/ + diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..c794561 --- /dev/null +++ b/Makefile @@ -0,0 +1,52 @@ +CXX := -c++ +CXXFLAGS := -pedantic-errors -Wall -Wextra -Werror +LDFLAGS := -L/usr/lib -lstdc++ -lm +BUILD := ./build +OBJ_DIR := $(BUILD)/objects +APP_DIR := $(BUILD)/apps +TARGET := program +INCLUDE := -Iinclude/ +SRC := \ + $(wildcard src/module1/*.cpp) \ + $(wildcard src/module2/*.cpp) \ + $(wildcard src/*.cpp) \ + +OBJECTS := $(SRC:%.cpp=$(OBJ_DIR)/%.o) +DEPENDENCIES \ + := $(OBJECTS:.o=.d) + +all: build $(APP_DIR)/$(TARGET) + +$(OBJ_DIR)/%.o: %.cpp + @mkdir -p $(@D) + $(CXX) $(CXXFLAGS) $(INCLUDE) -c $< -MMD -o $@ + +$(APP_DIR)/$(TARGET): $(OBJECTS) + @mkdir -p $(@D) + $(CXX) $(CXXFLAGS) -o $(APP_DIR)/$(TARGET) $^ $(LDFLAGS) + +-include $(DEPENDENCIES) + +.PHONY: all build clean debug release info + +build: + @mkdir -p $(APP_DIR) + @mkdir -p $(OBJ_DIR) + +debug: CXXFLAGS += -DDEBUG -g +debug: all + +release: CXXFLAGS += -O2 +release: all + +clean: + -@rm -rvf $(OBJ_DIR)/* + -@rm -rvf $(APP_DIR)/* + +info: + @echo "[*] Application dir: ${APP_DIR} " + @echo "[*] Object dir: ${OBJ_DIR} " + @echo "[*] Sources: ${SRC} " + @echo "[*] Objects: ${OBJECTS} " + @echo "[*] Dependencies: ${DEPENDENCIES}" + diff --git a/README.md b/README.md new file mode 100644 index 0000000..ad890bf --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +## C++ Repo Template + diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..19b20a0 --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,7 @@ +#include + +int main() +{ + std::cout << "Hello World!\n"; + return 0; +}