-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
36 lines (28 loc) · 791 Bytes
/
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
# Defines C++ Compiler
CXX := g++
# Final file name
BINARY := out
# Code directory structure
BINDIR := bin
BUILDDIR := build
INCDIR := include
SRCDIR := src
# Compiler flags
CXXFLAGS := -Wall -I $(INCDIR)
# Linker flags
LDFLAGS := -lm
# %.o file names
NAMES := $(notdir $(basename $(wildcard $(SRCDIR)/*.cpp)))
OBJECTS := $(patsubst %,$(BUILDDIR)/%.o,$(NAMES))
# Rule for link and generate the binary file
all: $(OBJECTS)
@ if [ ! -d ./$(BINDIR) ]; then mkdir -p $(BINDIR); fi
$(CXX) -o $(BINDIR)/$(BINARY) $+ $(LDFLAGS)
# Rule for object binaries compilation
$(BUILDDIR)/%.o: $(SRCDIR)/%.cpp
@ if [ ! -d ./$(BUILDDIR) ]; then mkdir -p $(BUILDDIR);fi
$(CXX) -c $^ -o $@ $(CXXFLAGS)
# Clean BIN and BUILD dirs
.PHONY: clean
clean:
rm -rf $(BUILDDIR) $(BINDIR) $(BINDIR)/$(BINARY)