|
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 $@ |
34 | 100 | @echo "====="
|
35 |
| - @cat license.txt |
| 101 | + @$(CAT) license.txt |
36 | 102 | @echo "====="
|
37 | 103 | @echo "USE OF NEUROFIELD CONSTITUTES ACCEPTANCE OF THE LICENSE CONDITIONS ABOVE"
|
38 | 104 |
|
| 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 |
39 | 122 | # 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 |
63 | 125 |
|
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 $@ |
66 | 129 |
|
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 |
0 commit comments