-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakefile
84 lines (67 loc) · 2.01 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
# C++ Makefile Template
# Copyright (c) 2018 Ignacio Tampe
# Based on Manuel Weitzman Makefile: https://github.com/mudetz/rcvrp/blob/master/Makefile thanks! <3
# You may use/distribute this template under the terms of the MIT LICENSE
# HowTo:
# Create a src/ dir for all .cpp files
# Create a head/ dir for all .h files
# In .cpp files import .h files as if they were in the same dir
# You have available:
# make Compile binaries
# make install Install final exec to root folder
# make uninstall Remove final exec from root folder
# make clean Remove intermediate .o files
# make distclean Remove final executable
# make cleanall clean+distclean
# Final executable name
EXEC = top.exe
# Macros
BENCHMARK ?= 0
# Directories for sourcefiles, headers and object files
SRCDIR = src
HEADDIR = head
OBJDIR = obj
# Files will be detected automatically (they shall not be in subdirectories
# though)
SOURCES = $(wildcard $(SRCDIR)/*.cpp)
OBJECTS = $(patsubst $(SRCDIR)/%.cpp, $(OBJDIR)/%.o, $(SOURCES))
# Compiler options
CXX = g++
CPPFLAGS = $(addprefix -I, $(HEADDIR)) -MMD -MP -lm
CFLAGS = -O2 -Wall -std=c++11 -D"BENCHMARK=${BENCHMARK}"
LDFLAGS =
LDLIBS =
# Utilities used for output and others
ECHO = echo
RM = rm -rf
MKDIR = mkdir
INSTALL = install
FIND = find
CP = cp
# Makefile rules
.PHONY: all
all: $(OBJDIR) $(EXEC)
$(EXEC): $(OBJECTS)
$(CXX) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -o $@ $^ $(LDLIBS)
$(OBJDIR)/%.o: $(SRCDIR)/%.cpp
$(CXX) $(CFLAGS) $(CPPFLAGS) -c $< -o $@
$(OBJDIR):
@$(MKDIR) -p $@
.PHONY: install
install:
$(INSTALL) $(EXEC) $(EXEC)
.PHONY: uninstall
uninstall:
$(RM) $(EXEC)
.PHONY: cleanall
cleanall: clean distclean
.PHONY: clean
clean:
$(FIND) . -iname '*.d' -type f -delete
$(FIND) . -iname '*.o' -type f -delete
$(FIND) . -iname '*.exe' -type f -delete
$(FIND) . -iname '*.out' -type f -delete
.PHONY: distclean
distclean:
$(RM) $(EXEC)
-include $(wildcard $(OBJDIR)/*.d)