-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
123 lines (95 loc) · 3.35 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#Compiler/Linker
CXX := g++
#Target binary
TARGET := runner
# Update this
HEADERONLYDIR := /usr/local/headeronly
HDF5DIR := /usr/local/hdf5/serial
#Directories
SRCDIR := ./src
INCDIR := ./include
BUILDDIR := ./build
TARGETDIR := ./bin
RESDIR := ./resources
IDEASDIR := ./ideas
TESTDIR := ./test
DOCDIR := ./doc
DOCUMENTSDIR := ./documents
SRCEXT := cpp
DEPEXT := d
OBJEXT := o
#Flags, Libraries and Includes
CXXFLAGS := -std=c++11 -O3 #-Xpreprocessor -fopenmp #-lomp -Wall #-fopenmp -Wall -O3 -g
LIB := -L$(HDF5DIR)/lib -lhdf5 -lboost_serialization -lboost_filesystem -lboost_system#-fopenmp -lm -larmadillo
INC := -I$(INCDIR) -I$(HEADERONLYDIR) -I$(HDF5DIR)/include -I/usr/local/include
INCDEP := -I$(INC)
#Source and Object files
SOURCES := $(shell find $(SRCDIR) -type f -name "*.$(SRCEXT)")
OBJECTS := $(patsubst $(SRCDIR)/%,$(BUILDDIR)/%,$(SOURCES:.$(SRCEXT)=.$(OBJEXT)))
#Documentation (Doxygen)
DOXY := /usr/local/Cellar/doxygen/1.8.20/bin/doxygen
DOXYFILE := $(DOCDIR)/Doxyfile
#default make (all)
all: resources tester ideas $(TARGET)
#make regarding source files
sources: resources $(TARGET)
#remake
remake: cleaner all
# build all with debug flags
debug: CXXFLAGS += -g -Wall
# show linker invocation when building debug target
debug: LDFLAGS += -v
debug: all
#copy Resources from Resources Directory to Target Directory
resources: directories
@cp -r $(RESDIR)/ $(TARGETDIR)/
#make directories
directories:
@mkdir -p $(TARGETDIR)
@mkdir -p $(BUILDDIR)
@mkdir -p $(RESDIR)
#clean objects
clean:
@$(RM) -rf $(BUILDDIR)
#clean objects and binaries
cleaner: clean
@$(RM) -rf $(TARGETDIR)
#Pull in dependency info for *existing* .o files
-include $(OBJECTS:.$(OBJEXT)=.$(DEPEXT))
#link
$(TARGET): $(OBJECTS)
$(CXX) -o $(TARGETDIR)/$(TARGET) $^ $(LIB) $(LDFLAGS)
#compile
$(BUILDDIR)/%.$(OBJEXT): $(SRCDIR)/%.$(SRCEXT)
@mkdir -p $(dir $@)
$(CXX) $(CXXFLAGS) $(INC) -c -o $@ $<
@$(CXX) $(CXXFLAGS) $(INCDEP) -MM $(SRCDIR)/$*.$(SRCEXT) > $(BUILDDIR)/$*.$(DEPEXT)
@cp -f $(BUILDDIR)/$*.$(DEPEXT) $(BUILDDIR)/$*.$(DEPEXT).tmp
@sed -e 's|.*:|$(BUILDDIR)/$*.$(OBJEXT):|' < $(BUILDDIR)/$*.$(DEPEXT).tmp > $(BUILDDIR)/$*.$(DEPEXT)
@sed -e 's/.*://' -e 's/\\$$//' < $(BUILDDIR)/$*.$(DEPEXT).tmp | fmt -1 | sed -e 's/^ *//' -e 's/$$/:/' >> $(BUILDDIR)/$*.$(DEPEXT)
@rm -f $(BUILDDIR)/$*.$(DEPEXT).tmp
#compile test files
tester: directories
ifneq ("$(wildcard $(TESTDIR)/*.$(SRCEXT) )","")
$(CXX) $(CXXFLAGS) test/*.cpp $(INC) $(LIB) -o bin/tester
else
@echo "No $(SRCEXT)-files within $(TESTDIR)!"
endif
#compile idea files
ideas: directories
ifneq ("$(wildcard $(IDEASDIR)/*.$(SRCEXT) )","")
$(CXX) $(CXXFLAGS) ideas/*.cpp $(INC) $(LIB) -o bin/ideas
else
@echo "No $(SRCEXT)-files within $(IDEASDIR)!"
endif
doxyfile.inc: #Makefile
@echo INPUT = README.md . $(SRCDIR)/ $(INCDIR)/ $(DOCUMENTSDIR)/ > $(DOCDIR)/doxyfile.inc
@echo FILE_PATTERNS = "*.md" "*.h" "*.$(SRCEXT)" >> $(DOCDIR)/doxyfile.inc
@echo OUTPUT_DIRECTORY = $(DOCDIR)/ >> $(DOCDIR)/doxyfile.inc
doc: doxyfile.inc
$(DOXY) $(DOXYFILE) &> $(DOCDIR)/doxygen.log
@$(MAKE) -C $(DOCDIR)/latex/ &> $(DOCDIR)/latex/latex.log
@mkdir -p "./docs"
cp -r "./doc/html/" "./docs/"
#Non-File Targets
.PHONY: all remake clean cleaner resources sources directories ideas tester doc debug