Skip to content

Commit 01bda8c

Browse files
author
Paula
authored
Merge pull request #73 from stuart-knock/makefile
Extend Makefile
2 parents 300c96a + 483200a commit 01bda8c

File tree

5 files changed

+235
-76
lines changed

5 files changed

+235
-76
lines changed

.gitignore

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
# Ignore files associated with compiling
22
bin/
33
obj/
4+
dep/
45

56
# Ignore files associated with doxygen docs
6-
Documentation/html/
7-
Documentation/latex/
7+
doc/html/
8+
doc/latex/
89

910
# Ignore NeuroField output files
1011
*.output

Makefile

Lines changed: 196 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,203 @@
1-
# Standard Linux (gcc must be > 4.9) performance
2-
CXX = g++
3-
CXXFLAGS = -g -lm -Wall -O3 -Wextra -pedantic -std=c++11 -msse -msse2 -msse3 -mfpmath=sse -march=native -mtune=native -funroll-loops -flto #-m64
4-
5-
# Mac OS
6-
# CXX = g++-4.9
7-
# CXXFLAGS = -lm -Wall -O3 -std=c++11
8-
9-
10-
# Windows
11-
# CXX = x86_64-w64-mingw32-g++
12-
# CXXFLAGS = -lm -Wall -O3 -msse -msse2 -msse3 -mfpmath=sse -funroll-loops -flto -m64 -std=gnu++11 -static -static-libgcc -static-libstdc++
13-
14-
# Debugging
15-
# CXX = g++
16-
# CXXFLAGS = g++ -g -lm -Wall -Wextra -pedantic -std=c++11 -msse -msse2 -msse3
17-
18-
19-
HEADER = $(wildcard src/*.h)
20-
CPP = $(wildcard src/*.cpp)
21-
OBJ = $(addprefix obj/,$(notdir $(CPP:.cpp=.o)))
22-
23-
# target: default - compile bin/neurofield
24-
default: bin/neurofield
25-
26-
debugmode: CXXFLAGS = -g -ggdb3 -lm -Wall -Wextra -pedantic -std=c++11 -msse -msse2 -msse3
27-
28-
debugmode: bin/neurofield
29-
30-
bin/neurofield: $(OBJ)
31-
@mkdir -p bin
32-
@echo "$(CXX) $(CXXFLAGS) $(OBJ) -o $@"
33-
@$(CXX) $(CXXFLAGS) $(OBJ) -o $@ || (echo "mycommand failed $$?"; exit 1)
1+
#Makefile for neurofield
2+
#
3+
# Type 'make help' for a list of possible targets with brief descriptions.
4+
# If you're having problems, the Makefile itself can be debugged using the
5+
# option -d, eg 'make -d help'. Also 'make info' will display the contents
6+
# of key variables in the Makefile, to help with debugging.
7+
#
8+
9+
#Specify our directories.
10+
SRCDIR := src/
11+
OBJDIR := obj/
12+
BINDIR := bin/
13+
DOCDIR := doc/
14+
DEPDIR := dep/
15+
16+
#Default to *nix, suffix-less, binary.
17+
BIN := neurofield
18+
19+
#User-manual files
20+
USER_MANUAL := NeurofieldManual.pdf
21+
USER_MANUAL_SRC := NeurofieldManual.tex
22+
23+
#Default to *nix commands.
24+
MV := mv -f
25+
RM := rm -f
26+
RMDIR := rm -rf
27+
GREP := egrep
28+
CAT := cat
29+
30+
# Standard Linux (gcc must be >= 4.8.5) performance
31+
ifeq ($(shell uname -s), Linux)
32+
CXX := g++
33+
CXXFLAGS := -std=c++11 -lm -Wall -Wextra -pedantic -msse -msse2 -msse3 -mfpmath=sse -march=native -mtune=native -funroll-loops -flto -O3
34+
DEBUG := -std=c++11 -ggdb3 -Og -lm -Wall -Wextra -pedantic -msse -msse2 -msse3 -mfpmath=sse -march=native -mtune=native -funroll-loops
35+
DEPFLAGS = -std=c++11 -MM -MP -MT $(OBJDIR)$*.o
36+
endif
37+
38+
# Mac OS, default to clang++
39+
ifeq ($(shell uname -s), Darwin)
40+
CXX := clang++
41+
CXXFLAGS := -std=c++11 -Weverything -Wno-c++98-compat -Wno-c++98-compat-pedantic -fdiagnostics-fixit-info -Wdocumentation -march=native -funroll-loops -flto -O3
42+
DEBUG := -std=c++11 -glldb -Weverything -Wno-c++98-compat -Wno-c++98-compat-pedantic -fdiagnostics-fixit-info -Wdocumentation
43+
DEPFLAGS = -std=c++11 -MM -MP -MT $(OBJDIR)$*.o
44+
endif
45+
46+
# Source and header files
47+
HEADER := $(wildcard $(SRCDIR)*.h)
48+
CPP := $(wildcard $(SRCDIR)*.cpp)
49+
OBJ := $(addprefix $(OBJDIR),$(notdir $(CPP:.cpp=.o)))
50+
DEP := $(addprefix $(DEPDIR),$(notdir $(CPP:.cpp=.d)))
51+
52+
#Targets that don't need the dependencies evaluated/included.
53+
NO_DEPS := make_bin_dir make_obj_dir make_dep_dir help help-dev docs info $(DOCDIR)$(USER_MANUAL) reference-manual user-manual
54+
NO_DEPS += clean-user-manual clean-reference-manual clean-docs clean-deps clean-objs clean-bin clean clean-all
55+
56+
# Delete the default suffixes
57+
.SUFFIXES:
58+
# Define our suffix list
59+
.SUFFIXES: .o .d .cpp .h .tex
60+
61+
.PHONY: neurofield debug all clang make_bin_dir make_obj_dir make_dep_dir help help-dev info docs user-manual reference-manual \
62+
clean-user-manual clean-reference-manual clean-docs clean-deps clean-objs clean-bin clean clean-all
63+
64+
# target: neurofield - compile neurofield placing the executable in the bin directory.
65+
neurofield: $(BINDIR)$(BIN)
66+
67+
# target: debug - compile neurofield with debugging enabled.
68+
debug: CXXFLAGS := $(DEBUG)
69+
debug: neurofield
70+
71+
# target: all - compile neurofield and build all documentation.
72+
all: neurofield docs
73+
74+
# target: clang - Build using clang++, redundant on MacOS as clang++ is default.
75+
ifeq ($(MAKECMDGOALS), clang)
76+
CXX := $(shell command -v clang++ 2> /dev/null)
77+
ifndef CXX
78+
$(error "You don't appear to have clang++ installed. If it is installed make sure it's in your PATH.")
79+
endif
80+
CXXFLAGS := -std=c++11 -Weverything -Wno-c++98-compat -Wno-c++98-compat-pedantic -fdiagnostics-fixit-info -Wdocumentation -march=native -funroll-loops -flto -O3
81+
DEPFLAGS = -std=c++11 -MM -MP -MT $(OBJDIR)$*.o
82+
endif
83+
clang: neurofield
84+
85+
# target: icc - Build using intel C++ compiler.
86+
ifeq ($(MAKECMDGOALS), icc)
87+
CXX := $(shell command -v icc 2> /dev/null)
88+
ifndef CXX
89+
$(error "You don't appear to have icc installed. If it is installed make sure it's in your PATH.")
90+
endif
91+
#TODO: consider/test -ipp -mkl -unroll-aggressive -static
92+
CXXFLAGS := -std=c++11 -Wall -Wremarks -Wchecks -Weffec++ -xHost -funroll-loops -ipo -O3
93+
DEPFLAGS = -std=c++11 -MM -MP -MT $(OBJDIR)$*.o
94+
endif
95+
icc: neurofield
96+
97+
# target: $(BINDIR)$(BIN) - Main target for the final build, linking objects into an executable.
98+
$(BINDIR)$(BIN): $(OBJ) | make_bin_dir
99+
$(CXX) $(CXXFLAGS) $(OBJ) -o $@
34100
@echo "====="
35-
@cat license.txt
101+
@$(CAT) license.txt
36102
@echo "====="
37103
@echo "USE OF NEUROFIELD CONSTITUTES ACCEPTANCE OF THE LICENSE CONDITIONS ABOVE"
38104

105+
# target: make_bin_dir - Create the directory $BINDIR if it doesn't already exist.
106+
make_bin_dir:
107+
@test -d $(BINDIR) || { mkdir $(BINDIR) ; echo "mkdir $(BINDIR)"; }
108+
109+
# target: make_obj_dir - Create the directory $OBJDIR if it doesn't already exist.
110+
make_obj_dir:
111+
@test -d $(OBJDIR) || { mkdir $(OBJDIR) ; echo "mkdir $(OBJDIR)"; }
112+
113+
# target: make_dep_dir - Create the directory $DEPDIR if it doesn't already exist.
114+
make_dep_dir:
115+
@test -d $(DEPDIR) || { mkdir $(DEPDIR) ; echo "mkdir $(DEPDIR)"; }
116+
117+
#Only create and include dependencies if the current target requires them.
118+
ifeq (, $(filter $(MAKECMDGOALS), $(NO_DEPS)))
119+
#Create obj/*.d header dependencies
120+
$(DEPDIR)%.d: $(SRCDIR)%.cpp | make_dep_dir
121+
$(CXX) $(DEPFLAGS) $< > $(DEPDIR)$*.d
39122
# Include any existing dependencies in the build
40-
-include $(OBJ:.o=.d)
41-
42-
# Build object code and also create obj/*.d header dependencies
43-
obj/%.o: src/%.cpp
44-
@mkdir -p obj
45-
@$(CXX) $(CXXFLAGS) -c $< -o $@
46-
@$(CXX) -MM $(CXXFLAGS) $< > obj/$*.d
47-
@echo "CXX $<"
48-
@mv -f obj/$*.d obj/$*.d.tmp
49-
@sed -e 's|.*:|$@:|' < obj/$*.d.tmp > obj/$*.d
50-
@sed -e 's/.*://' -e 's/\\$$//' < obj/$*.d.tmp | fmt -1 | \
51-
sed -e 's/^ *//' -e 's/$$/:/' >> obj/$*.d
52-
@rm -f obj/$*.d.tmp
53-
54-
# Build documentation: compile tex file and produce html docs from code
55-
build_docs:
56-
cd Documentation && pdflatex neurofield && pdflatex neurofield && cd ../ && doxygen Doxyfile
57-
58-
.PHONY: clean doc help
59-
60-
# target: help - Print this message
61-
help:
62-
@egrep "^# target:" Makefile
123+
-include $(DEP)
124+
endif
63125

64-
# target: doc - compile Documentation/neurofield.pdf
65-
doc: Documentation/neurofield.pdf
126+
# Build object code
127+
$(OBJDIR)%.o: $(SRCDIR)%.cpp | make_obj_dir
128+
$(CXX) $(CXXFLAGS) -c $< -o $@
66129

67-
# target: clean - Delete ./bin/, ./obj/, and LaTeX temporary files in ./Documentation/
68-
clean:
69-
@-rm -rf bin obj Documentation/{user,developer}.{aux,log,out,toc} Documentation/x.log
130+
# target: help - Print this message.
131+
help:
132+
@echo "Available Makefile targets, call as 'make target', eg. make all"
133+
@$(GREP) "^# target:" Makefile
134+
135+
# target: help-dev - Print an extended list of targets.
136+
help-dev: help
137+
@echo "Additional targets, mainly useful for developers."
138+
@$(GREP) "^# target:" Makefile
139+
140+
# target: info - A convenience target for debugging the Makefile.
141+
info:
142+
@echo " SHELL: $(SHELL)"
143+
@echo " MAKE_VERSION: $(MAKE_VERSION)"
144+
@echo " .VARIABLES: $(.VARIABLES)"
145+
@echo " .DEFAULT_GOAL: $(.DEFAULT_GOAL)"
146+
@echo " SRCDIR: $(SRCDIR)"
147+
@echo " OBJDIR: $(OBJDIR)"
148+
@echo " BINDIR: $(BINDIR)"
149+
@echo " DOCDIR: $(DOCDIR)"
150+
@echo " HEADER: $(HEADER)"
151+
@echo " CPP: $(CPP)"
152+
@echo " OBJ: $(OBJ)"
153+
@echo " DEP: $(DEP)"
154+
@echo " CXX: $(CXX)"
155+
@echo " CXXFLAGS: $(CXXFLAGS)"
156+
@echo " DEBUG: $(DEBUG)"
157+
@echo " NO_DEPS: $(NO_DEPS)"
158+
159+
# target: docs - Build user and reference manuals.
160+
docs: user-manual reference-manual
161+
162+
# target: user-manual - Build only the user-manual.
163+
user-manual: $(DOCDIR)$(USER_MANUAL)
164+
165+
# target: $(DOCDIR)$(USER_MANUAL) - target that actually builds the user manual.
166+
$(DOCDIR)$(USER_MANUAL): $(DOCDIR)$(USER_MANUAL_SRC)
167+
cd $(DOCDIR) && \
168+
pdflatex $(USER_MANUAL_SRC) && \
169+
pdflatex $(USER_MANUAL_SRC)
170+
171+
# target: reference-manual - Build only the reference-manual.
172+
reference-manual:
173+
doxygen Doxyfile
174+
175+
# target: clean-docs - Delete temporary LaTeX files and Doxygen generated reference-manual.
176+
clean-docs: clean-user-manual clean-reference-manual
177+
178+
# target: clean-user-manual - Delete temporary LaTeX files generated when building the user-manual.
179+
clean-user-manual:
180+
-$(RM) $(DOCDIR)$(USER_MANUAL_SRC:.tex=).{aux,log,out,toc}
181+
182+
# target: clean-reference-manual - Delete Doxygen generated reference-manual.
183+
clean-reference-manual:
184+
-$(RMDIR) $(DOCDIR)html
185+
-$(RMDIR) $(DOCDIR)latex
186+
187+
# target: clean-deps - Delete the dependencies created during build.
188+
clean-deps:
189+
-$(RM) $(DEP)
190+
191+
# target: clean-objs - Delete the objects created during build.
192+
clean-objs:
193+
-$(RM) $(OBJ)
194+
195+
# target: clean-bin - Delete the executable generated by the build.
196+
clean-bin:
197+
-$(RM) $(BINDIR)$(BIN)
198+
199+
# target: clean - Delete dependency files, temporary build objects and temporary LaTeX files.
200+
clean: clean-deps clean-objs clean-user-manual
201+
202+
# target: clean-all - Same as clean but also delete Doxygen generated docs, and the executable.
203+
clean-all: clean-deps clean-objs clean-bin clean-docs

README.md

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,28 @@
11
### Quick start
22

3-
make ./bin/neurofield -i configs/example.conf -o example.output
4-
doxygen Doxyfile
5-
6-
The html files will be place under `doc/html`
3+
To build the executable on Linux or Mac, open a terminal in the neurofield directory and type:
4+
5+
make
6+
7+
this produces the executable (bin/neurofield). The user-manual is available as doc/NeurofieldManual.pdf.
8+
9+
To build the reference manual, generated from the code, type:
10+
11+
make reference-manual
12+
13+
The html files for the reference-manual will be place under `doc/html`, point your browser at the index.html file in that directory.
14+
15+
For a brief description of available Makefile targets, type:
16+
17+
make help
18+
719
### Setup guide
820

921
**Please check the [NeuroField wiki](https://github.com/BrainDynamicsUSYD/neurofield/wiki) for the setup walkthrough. The instructions below are a standalone summary if you do not have internet access. More detailed instructions are also included in the PDF documentation**
1022

1123
1. Ensure you have a compiler that supports the `C++11` standard. We recommend GCC 4.8 or higher.
1224

13-
2. Type `make` to build the binary `Release/NeuroField`. More information about [cross platform for non-Linux](https://github.com/BrainDynamicsUSYD/neurofield/wiki/Cross-platform-support) systems is also available.
25+
2. Type `make` to build the binary `bin/neurofield`. More information about [cross platform for non-Linux](https://github.com/BrainDynamicsUSYD/neurofield/wiki/Cross-platform-support) systems is also available.
1426

1527
3. Example configurations including examples for published results are available in the `configs` folder.
1628

doc/NeurofieldManual.pdf

1.03 KB
Binary file not shown.

doc/NeurofieldManual.tex

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,10 @@ \subsection{Directory layout}
113113
\begin{tabular}{l p{13cm}}
114114
\type{src/}& \type{C++} source code.\\
115115
\type{(obj/)}& This folder is created during compilation and stores intermediate object code.\\
116+
\type{(dep/)}& This folder is created during compilation and stores dependency information.\\
116117
\type{(bin/)}& The compiled binary \type{neurofield} is created here.\\
117118
\type{configs/}& Stores example configuration files for \NF.\\
118-
\type{doc/}& Contains this manual.\\
119+
\type{doc/}& Contains this manual and the reference manual once it's built.\\
119120
\type{+nf/}& Matlab package folder containing \NF helper scripts.\\
120121
\type{test/}& Directory for development testing and is irrelevant for users.\\
121122
\end{tabular}
@@ -128,17 +129,26 @@ \subsection{Compiling NeuroField}
128129
make
129130
\end{lstlisting}
130131

131-
from the root directory. The compiler command is specified in \type{Makefile} and should be edited if you wish to use a different compiler, or if your compiler does not support some of the compiler flags. To run \NF on Windows, we suggest cross-compiling using MinGW on a Unix-like system. Example compiler flags for this are included in \type{Makefile}. Compiling with the Microsoft Visual \type{C++} compiler has not been tested.
132+
from the root directory. The compiler command is specified in \type{Makefile}. On Linux this defaults to \type{g++} and on Mac it defaults to \type{clang++}. To run \NF on Windows, we suggest cross-compiling using MinGW on a Unix-like system. Example compiler flags for this are included in \type{Makefile}. Compiling with the Microsoft Visual \type{C++} compiler has not been tested.
132133

133-
The \type{Makefile} also provides two additional commands. This documentation can be generated by running
134+
The \type{Makefile} also provides a number of additional commands. This documentation along with the reference-manual can be generated by running
134135
\begin{lstlisting}
135-
make doc
136+
make docs
136137
\end{lstlisting}
137-
which will compile the \LaTeX\ files in the \type{doc/} directory. To delete the \NF binary files, object code, and temporary \LaTeX\ files (e.g., to perform a clean compile of the program), you can use
138+
which will recompile the \LaTeX\ files in the \type{doc/} directory if they've been updated since the last time this .pdf was generated, and run doxygen to generate the reference-manual from the source code. The reference manual can then be viewed by pointing your web-browser at
139+
140+
\begin{lstlisting}
141+
doc/html/index.html
142+
\end{lstlisting}
143+
144+
To delete the dependency files, object code, and temporary \LaTeX\ files (e.g., to perform a clean compile of the program), you can use
138145
\begin{lstlisting}
139146
make clean
140147
\end{lstlisting}
141-
which will delete the \type{bin} and \type{obj} folders, as well as the temporary files in \type{doc/}.
148+
which will delete the \type{dep/*.d} and \type{obj/*.o} files, as well as the temporary \LaTeX\ files in \type{doc/}. For a list of additional make targets, including brief descriptions of their function, run
149+
\begin{lstlisting}
150+
make help
151+
\end{lstlisting}
142152

143153
\section{Running NeuroField}
144154
\label{sec:running}
@@ -544,12 +554,14 @@ \subsubsection{Couple Classes}
544554
\begin{lstlisting}
545555
CaDP - nu: 13e-6 nu_max: 80e-6 Dth: .25e-6 Pth: .45e-6 xyth: 1e-4 x: 2.3e-2 y: 2e-2 B: 30e3 glu_0: 200e-6 gNMDA: 2e-3 t_BCM: 7
546556
\end{lstlisting}
547-
\item[DiffArctan]\ \\
557+
558+
\item[DiffArctan]\ \\
548559
This type of coupling allows the connection strength $\nu_{ab}$ to vary as a function of time, such that $\nu$ can be smoothly ramped up and down.
549560
\begin{lstlisting}
550561
DiffArctan - nu_min: 0.002 nu_max: 0.006 delta: 10 t_half_up:50 t_half_down:100
551562
\end{lstlisting}
552563
where \type{nu\_min} and \type{nu\_max} are the min and max $\nu$'s respectively. \type{delta} determines the slope of the ramp (1/\type{delta}) and is the time interval in which the connection strenght increases (decreases) from 0.25 to 0.75 of \type{nu\_max}. \type{t\_half\_up} and \type{t\_half\_down} are the half way times to maximum and minimum amplitude, respectively.
564+
553565
\end{description}
554566
\end{itemize}
555567

0 commit comments

Comments
 (0)