-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
executable file
·73 lines (61 loc) · 2 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
#Author: Petr Skocik
#allowed commands: rm, gcc, g++, mkdir, doxygen, cp, mv, cd, ar, make
#OPTIONS
EXE=bignum
CXXFLAGS= -Wall -pedantic -Wno-long-long -O0 -ggdb -std=c++0x -DSTYPE=u64
#-DUSE_READLINE
#Add the above option along with adding -lreadline to CLIBS if you want readline support when running the program interactively
DOXY=Doxyfile
CLIBS=
#-lreadline
CXX=g++
RM=rm -rf
#DIRECTORIES:
#Sources
SRCDIR=src
DOCDIR=doc
BINDIR=bin
#NOTE: $() references established vars
#Objects
OBJDIR=$(BINDIR)/objs
#Dependencies
DEPDIR=$(SRCDIR)/.deps
#An object and a dependency file will be created out of each and every *.cpp in $(SRCDIR)
SRCS=$(wildcard $(SRCDIR)/*.cpp)
#Two ways to change suffixes below:
#% in substitutions = * (the wildcard)
#OBJS = $(patsubst $(SRCDIR)/%.cpp,$(OBJDIR)/%.o,$(SRCS))
#DEPS = $(patsubst $(OBJDIR)/%.o,$(DEPDIR)/%.d,$(OBJS))
OBJS = $(SRCS:.cpp=.o)
DEPS = $(SRCS:.cpp=.d)
#----------------------------------------------------------------------------------
#PHONY TARGETS (make won't get confused if the corresponding files exist)
.PHONY: all compile run clean deps
all: compile doc
compile: $(EXE)
run: $(EXE)
./$(EXE) test
clean:
$(RM) $(BINDIR) $(DOCDIR) $(EXE) $(DEPDIR)
deps: $(DEPS)
#@ suppresses echoing of the line that's prefixed with it
doc: $(DOXY) $(SRCDIR)/*
@mkdir -p doc
@doxygen $(DOXY) \&>/dev/null
#REAL TARGETS ----------------------------------------------------------------------------------
#Automatic Variables:
#$@ = The file of the target of the rule
#$* = stem of the target in an implicit rule (target - suffix)
#$< = file name of the first prerequisite
$(OBJDIR) $(DEPDIR):
mkdir -p $@
#generate dependencies into src/.deps (must exist)
$(DEPDIR)/%.d: $(SRCDIR)/%.cpp | $(DEPDIR)
$(CXX) $(CXXFLAGS) -MM -MF $@ -MT $(OBJDIR)/$*.o $<
# pull in dependency info for *existing* .o files
-include $(DEPS)
$(OBJDIR)/%.o: $(SRCDIR)/%.cpp | $(OBJDIR)
$(CXX) $(CXXFLAGS) -c $(SRCDIR)/$*.cpp -o $@
$(EXE): $(OBJS)
$(CXX) $(CXXFLAGS) $(OBJS) -o $(EXE) $(CLIBS)