-
Notifications
You must be signed in to change notification settings - Fork 0
/
makefile
71 lines (53 loc) · 2.02 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
# Project Information and Contact Details
BU_NAME := abixby1
GITHUB_ID := alanbixby
COURSE := CSXXX
CP := 1
EXECUTABLE_NAME := program$(CP)
TAR_NAME := $(BU_NAME)_program$(CP)
TAR_IGNORES := .vscode spec
# Source File Directory - if none, use .
SOURCES_DIR := src
FILE_EXT := cpp
# Make Run Arguments
RUN_ARGS :=
# Compiler Flags - should be fine for most people
CXXFLAGS := -Wall -Wextra -std=c++17 -O3
LDFLAGS :=
LDLIBS :=
#################################################################################################
# ***You should not have to edit the makefile past this line.*** #
#################################################################################################
# Debug Flag - hides debugging by default (recommended; use make debug to debug)
DEBUG := -DNDEBUG
# Tar Flags
TAR_IGNORES := --exclude-vcs --exclude-vcs-ignores $(addprefix --exclude=, $(TAR_IGNORES))
# Source Files
SRC_FILES = $(shell find $(SOURCES_DIR)/ -type f -name '*.$(FILE_EXT)')
OBJ_FILES := $(patsubst %.$(FILE_EXT),%.o,$(SRC_FILES))
DEP_FILES := $(patsubst %.$(FILE_EXT),%.d,$(SRC_FILES))
# Makefile Rules
$(EXECUTABLE_NAME): $(OBJ_FILES)
$(CXX) $(CXXFLAGS) $(LDFLAGS) $^ -o $@ $(LDLIBS)
# Update .gitignore to exclude the executable; ignore if .gitignore is absent
-sed -i "1c $(EXECUTABLE_NAME)" .gitignore 2> /dev/null
-include $(DEP_FILES)
%.o: %.$(FILE_EXT)
$(CXX) $(CXXFLAGS) $(LDFLAGS) $(DEBUG) -MMD -MP -c $< -o $@ $(LDLIBS)
all: $(EXECUTABLE_NAME)
debug:
@$(MAKE) --no-print-directory DEBUG="" rebuild
new: clean run
run: $(EXECUTABLE_NAME)
./$(EXECUTABLE_NAME) $(RUN_ARGS)
rebuild: clean $(EXECUTABLE_NAME)
tar: clean
cd .. \
&& ln -sf $(notdir $(CURDIR)) $(TAR_NAME) \
&& tar $(TAR_IGNORES) --dereference -cvzf $(TAR_NAME).tar.gz $(TAR_NAME) \
&& mv $(TAR_NAME).tar.gz $(notdir $(CURDIR))/$(TAR_NAME).tar.gz \
; rm $(TAR_NAME)
clean:
find . -type f -name '*.o' -delete -o -name '*.d' -delete
rm -f $(EXECUTABLE_NAME) *.tar.gz
.PHONY: $(EXECUTABLE_NAME) all debug run rebuild tar clean