-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
50 lines (40 loc) · 1019 Bytes
/
Copy pathMakefile
File metadata and controls
50 lines (40 loc) · 1019 Bytes
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
# Variables
CXX = g++
CXXFLAGS = -std=c++17 -I./include -Wall
LDFLAGS =
# Directories
SRCDIR = source
HEADERSDIR = include
BUILDDIR = build
TARGET = $(BUILDDIR)/main
# Source and object files
SOURCES := $(wildcard $(SRCDIR)/*.cpp)
OBJECTS := $(SOURCES:$(SRCDIR)/%.cpp=$(BUILDDIR)/%.o)
# Default rule
all: clean pre_compile $(TARGET) newline
# Clean, compile and run the final target
run: all
@echo "Running the application..."
@echo ""
@echo ""
@$(TARGET)
pre_compile:
@echo "Compiling..."
newline:
@echo ""
# Compile the final target and run it
$(TARGET): $(OBJECTS)
@echo "Starting to link the executable..."
@$(CXX) $(LDFLAGS) -o $@ $^
@echo "Executable built. Cleaning up object files..."
@rm -f $(OBJECTS)
# Rule to compile .o files from .cpp files
$(BUILDDIR)/%.o: $(SRCDIR)/%.cpp | $(BUILDDIR)
@$(CXX) $(CXXFLAGS) -c -o $@ $<
# Clean compiled files
clean:
@echo "Cleaning the build directory..."
@rm -rf $(BUILDDIR)
@mkdir -p $(BUILDDIR)
# Phony targets
.PHONY: all clean run pre_compile