forked from ArielMAJ/test.me
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
110 lines (90 loc) · 2.96 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# Makefile for the test.me tool
# Sets the `make` command to silent mode by default if VERBOSE is not set (e.g. make VERBOSE=1)
ifndef VERBOSE
.SILENT:
endif
# tool macros
CC := gcc
CFLAGS := -Wno-sign-compare -Wfloat-equal -Wundef -Wcast-align -Wwrite-strings -Wlogical-op -Wredundant-decls -Wno-unused-parameter -Wno-unused-variable -Wshadow -Wall -Wextra
CCOBJFLAGS := $(CFLAGS) -c
# path macros
BIN_PATH := bin
OBJ_PATH := obj
SRC_PATH := src
ifeq ($(OS),Windows_NT)
MKDIR_COMMAND := \
if not exist $(BIN_PATH) (mkdir $(BIN_PATH)) & \
if not exist $(OBJ_PATH) (mkdir $(OBJ_PATH))
else
MKDIR_COMMAND := mkdir -p $(BIN_PATH) $(OBJ_PATH)
endif
# compile macros
TARGET_BASE_NAME := test.me
ifeq ($(OS),Windows_NT)
TARGET_NAME := $(addsuffix .exe,$(TARGET_BASE_NAME))
else
TARGET_NAME := $(TARGET_BASE_NAME)
endif
TARGET := $(BIN_PATH)/$(TARGET_NAME)
# src files
SRC := $(foreach x, $(SRC_PATH), $(wildcard $(addprefix $(x)/*,.c*)))
OBJ := $(addprefix $(OBJ_PATH)/, $(addsuffix .o, $(notdir $(basename $(SRC)))))
# clean files list
CLEAN_LIST := $(BIN_PATH) \
$(OBJ_PATH)
ifeq ($(OS),Windows_NT)
RM_COMMAND := for %%a in ($(CLEAN_LIST)) do if exist "%%~a" (rmdir /s /q "%%~a")
else
RM_COMMAND := rm -rf $(CLEAN_LIST)
endif
# default rule
default: clean makedir all
# non-phony targets
$(TARGET): $(OBJ)
$(CC) $(CFLAGS) -o $@ $(OBJ)
$(OBJ_PATH)/%.o: $(SRC_PATH)/%.c
$(CC) $(CCOBJFLAGS) -o $@ $<
# phony rules
.PHONY: makedir
makedir:
$(MKDIR_COMMAND)
.PHONY: all
all: $(TARGET)
.PHONY: clean
clean:
$(RM_COMMAND)
.PHONY: run
run: default
@echo Example run:
@echo ./$(TARGET) ./example_input/Q03/solution.c ./example_input/Q03/tests/
./$(TARGET) ./example_input/Q03/solution.c ./example_input/Q03/tests/
.PHONY: run_all
run_all: default
@echo Example run:
@echo ./$(TARGET) ./solution.c ./tests/ ./example_input/
./$(TARGET) ./solution.c ./tests/ ./example_input/
.PHONY: valgrind
valgrind: default
valgrind --leak-check=full --show-leak-kinds=all --track-origins=yes ./$(TARGET) ./example_input/Q03/solution.c ./example_input/Q03/tests/
.PHONY: valgrind_all
valgrind_all: default
valgrind --leak-check=full --show-leak-kinds=all --track-origins=yes ./$(TARGET) ./solution.c ./tests/ ./example_input/
.PHONY: format
format:
@echo clang-format -i $(SRC) --style=Google
clang-format -i $(SRC) --style=Google
.PHONY: help
help:
@echo "Makefile for the test.me tool"
@echo ""
@echo "Usage 01: make"
@echo "Usage 02: make [option]"
@echo ""
@echo "Target rules (options):"
@echo " run - Compiles and runs binary file with a single folder"
@echo " run_all - Compiles and runs binary file with multiple folders"
@echo " format - Formats the source code using clang-format tool"
@echo " valgrind - Compiles and runs binary file using valgrind tool"
@echo " valgrind_all - Compiles and runs binary file with multiple folders using valgrind tool"
@echo " clean - Removes files and folders created by running make"
@echo " help - Prints a help message with target rules"