diff options
author | Santo Cariotti <santo@dcariotti.me> | 2021-01-12 13:36:56 +0100 |
---|---|---|
committer | Santo Cariotti <santo@dcariotti.me> | 2021-01-12 13:36:56 +0100 |
commit | efe3267e26566c4e0286263e9ee563ada26b8c2d (patch) | |
tree | a517ad4778bc41b1cf1c91fc9e3c3502f178930f |
init
-rw-r--r-- | Makefile | 68 | ||||
-rw-r--r-- | README.md | 0 |
2 files changed, 68 insertions, 0 deletions
diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..26b79fb --- /dev/null +++ b/Makefile @@ -0,0 +1,68 @@ + +CXX ?= g++ +CPPFLAGS ?= -pipe -O2 -Wall -Wextra -fPIC -std=c++14 + +OK_STRING = "[OK]" +ERROR_STRING = "[ERROR]" +WARN_STRING = "[WARNING]" +COM_STRING = "Compiling" + +SRC_DIR := src +HEADER_DIR := include +BIN_DIR := bin +OBJ_DIR := $(BIN_DIR)/obj +MAIN := $(SRC_DIR)/main.cc +SOURCES := $(filter-out $(SRC_DIR)/main.cc, $(wildcard $(SRC_DIR)/*.cc)) +OBJECTS := $(SOURCES:$(SRC_DIR)/%.cc=$(OBJ_DIR)/%.o) +EXECUTABLE := $(BIN_DIR)/hmacsha256 + +clean: COUNT=$(words $(wildcard $(OBJ_DIR)/*.o)) + +all: $(EXECUTABLE) +all: $(EXECUTABLE) + +$(EXECUTABLE): $(OBJECTS) $(MAIN) + @script -q -e -c '$(CXX) -I$(HEADER_DIR) -o $@ $(OBJECTS) $(MAIN)' $@.log > /dev/null; \ + RESULT=$$?; \ + sed -i '1d;$$d' $@.log; \ + sed -i '/^[[:space:]]*$$/d' $@.log; \ + if [ $$RESULT -ne 0 ]; then \ + printf "%-60b%b" "Building $@" "$(ERROR_STRING)\n"; \ + elif [ -s $@.log ]; then \ + printf "%-60b%b" "Building $@" "$(WARN_STRING)\n"; \ + else \ + printf "%-60b%b" "Building $@" "$(OK_STRING)\n"; \ + printf "%b" "Build success\n"; \ + fi; \ + cat $@.log; \ + rm -f $@.log; \ + +$(OBJECTS): $(OBJ_DIR)/%.o : $(SRC_DIR)/%.cc + @script -q -e -c '$(CXX) $(CPPFLAGS) -c -I$(HEADER_DIR) $< -o $@' $@.log > /dev/null; \ + RESULT=$$?; \ + sed -i '1d;$$d' $@.log; \ + sed -i '/^[[:space:]]*$$/d' $@.log; \ + if [ $$RESULT -ne 0 ]; then \ + printf "%-60b%b" "$(COM_STRING) $@" "$(ERROR_STRING)\n"; \ + elif [ -s $@.log ]; then \ + printf "%-60b%b" "$(COM_STRING) $@" "$(WARN_STRING)\n"; \ + else \ + printf "%-60b%b" "$(COM_STRING) $@" "$(OK_STRING)\n"; \ + fi; \ + cat $@.log; \ + rm -f $@.log; \ + +clean: + @if [ $(COUNT) -ne 0 ] || [ -f $(EXECUTABLE) ]; then \ + if [ $(COUNT) -ne 0 ]; then \ + printf "%b" "Cleaning objects\n"; \ + rm -f $(OBJ_DIR)/*.o; \ + fi; \ + if [ -f $(EXECUTABLE) ]; then \ + printf "%b" "Removing executable\n"; \ + rm -f $(EXECUTABLE); \ + fi; \ + printf "%b" "Clean complete\n"; \ + else \ + printf "%b" "Nothing to clean\n"; \ + fi; diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/README.md |