-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #73 from stuart-knock/makefile
Extend Makefile
- Loading branch information
Showing
5 changed files
with
235 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,69 +1,203 @@ | ||
# Standard Linux (gcc must be > 4.9) performance | ||
CXX = g++ | ||
CXXFLAGS = -g -lm -Wall -O3 -Wextra -pedantic -std=c++11 -msse -msse2 -msse3 -mfpmath=sse -march=native -mtune=native -funroll-loops -flto #-m64 | ||
|
||
# Mac OS | ||
# CXX = g++-4.9 | ||
# CXXFLAGS = -lm -Wall -O3 -std=c++11 | ||
|
||
|
||
# Windows | ||
# CXX = x86_64-w64-mingw32-g++ | ||
# CXXFLAGS = -lm -Wall -O3 -msse -msse2 -msse3 -mfpmath=sse -funroll-loops -flto -m64 -std=gnu++11 -static -static-libgcc -static-libstdc++ | ||
|
||
# Debugging | ||
# CXX = g++ | ||
# CXXFLAGS = g++ -g -lm -Wall -Wextra -pedantic -std=c++11 -msse -msse2 -msse3 | ||
|
||
|
||
HEADER = $(wildcard src/*.h) | ||
CPP = $(wildcard src/*.cpp) | ||
OBJ = $(addprefix obj/,$(notdir $(CPP:.cpp=.o))) | ||
|
||
# target: default - compile bin/neurofield | ||
default: bin/neurofield | ||
|
||
debugmode: CXXFLAGS = -g -ggdb3 -lm -Wall -Wextra -pedantic -std=c++11 -msse -msse2 -msse3 | ||
|
||
debugmode: bin/neurofield | ||
|
||
bin/neurofield: $(OBJ) | ||
@mkdir -p bin | ||
@echo "$(CXX) $(CXXFLAGS) $(OBJ) -o $@" | ||
@$(CXX) $(CXXFLAGS) $(OBJ) -o $@ || (echo "mycommand failed $$?"; exit 1) | ||
#Makefile for neurofield | ||
# | ||
# Type 'make help' for a list of possible targets with brief descriptions. | ||
# If you're having problems, the Makefile itself can be debugged using the | ||
# option -d, eg 'make -d help'. Also 'make info' will display the contents | ||
# of key variables in the Makefile, to help with debugging. | ||
# | ||
|
||
#Specify our directories. | ||
SRCDIR := src/ | ||
OBJDIR := obj/ | ||
BINDIR := bin/ | ||
DOCDIR := doc/ | ||
DEPDIR := dep/ | ||
|
||
#Default to *nix, suffix-less, binary. | ||
BIN := neurofield | ||
|
||
#User-manual files | ||
USER_MANUAL := NeurofieldManual.pdf | ||
USER_MANUAL_SRC := NeurofieldManual.tex | ||
|
||
#Default to *nix commands. | ||
MV := mv -f | ||
RM := rm -f | ||
RMDIR := rm -rf | ||
GREP := egrep | ||
CAT := cat | ||
|
||
# Standard Linux (gcc must be >= 4.8.5) performance | ||
ifeq ($(shell uname -s), Linux) | ||
CXX := g++ | ||
CXXFLAGS := -std=c++11 -lm -Wall -Wextra -pedantic -msse -msse2 -msse3 -mfpmath=sse -march=native -mtune=native -funroll-loops -flto -O3 | ||
DEBUG := -std=c++11 -ggdb3 -Og -lm -Wall -Wextra -pedantic -msse -msse2 -msse3 -mfpmath=sse -march=native -mtune=native -funroll-loops | ||
DEPFLAGS = -std=c++11 -MM -MP -MT $(OBJDIR)$*.o | ||
endif | ||
|
||
# Mac OS, default to clang++ | ||
ifeq ($(shell uname -s), Darwin) | ||
CXX := clang++ | ||
CXXFLAGS := -std=c++11 -Weverything -Wno-c++98-compat -Wno-c++98-compat-pedantic -fdiagnostics-fixit-info -Wdocumentation -march=native -funroll-loops -flto -O3 | ||
DEBUG := -std=c++11 -glldb -Weverything -Wno-c++98-compat -Wno-c++98-compat-pedantic -fdiagnostics-fixit-info -Wdocumentation | ||
DEPFLAGS = -std=c++11 -MM -MP -MT $(OBJDIR)$*.o | ||
endif | ||
|
||
# Source and header files | ||
HEADER := $(wildcard $(SRCDIR)*.h) | ||
CPP := $(wildcard $(SRCDIR)*.cpp) | ||
OBJ := $(addprefix $(OBJDIR),$(notdir $(CPP:.cpp=.o))) | ||
DEP := $(addprefix $(DEPDIR),$(notdir $(CPP:.cpp=.d))) | ||
|
||
#Targets that don't need the dependencies evaluated/included. | ||
NO_DEPS := make_bin_dir make_obj_dir make_dep_dir help help-dev docs info $(DOCDIR)$(USER_MANUAL) reference-manual user-manual | ||
NO_DEPS += clean-user-manual clean-reference-manual clean-docs clean-deps clean-objs clean-bin clean clean-all | ||
|
||
# Delete the default suffixes | ||
.SUFFIXES: | ||
# Define our suffix list | ||
.SUFFIXES: .o .d .cpp .h .tex | ||
|
||
.PHONY: neurofield debug all clang make_bin_dir make_obj_dir make_dep_dir help help-dev info docs user-manual reference-manual \ | ||
clean-user-manual clean-reference-manual clean-docs clean-deps clean-objs clean-bin clean clean-all | ||
|
||
# target: neurofield - compile neurofield placing the executable in the bin directory. | ||
neurofield: $(BINDIR)$(BIN) | ||
|
||
# target: debug - compile neurofield with debugging enabled. | ||
debug: CXXFLAGS := $(DEBUG) | ||
debug: neurofield | ||
|
||
# target: all - compile neurofield and build all documentation. | ||
all: neurofield docs | ||
|
||
# target: clang - Build using clang++, redundant on MacOS as clang++ is default. | ||
ifeq ($(MAKECMDGOALS), clang) | ||
CXX := $(shell command -v clang++ 2> /dev/null) | ||
ifndef CXX | ||
$(error "You don't appear to have clang++ installed. If it is installed make sure it's in your PATH.") | ||
endif | ||
CXXFLAGS := -std=c++11 -Weverything -Wno-c++98-compat -Wno-c++98-compat-pedantic -fdiagnostics-fixit-info -Wdocumentation -march=native -funroll-loops -flto -O3 | ||
DEPFLAGS = -std=c++11 -MM -MP -MT $(OBJDIR)$*.o | ||
endif | ||
clang: neurofield | ||
|
||
# target: icc - Build using intel C++ compiler. | ||
ifeq ($(MAKECMDGOALS), icc) | ||
CXX := $(shell command -v icc 2> /dev/null) | ||
ifndef CXX | ||
$(error "You don't appear to have icc installed. If it is installed make sure it's in your PATH.") | ||
endif | ||
#TODO: consider/test -ipp -mkl -unroll-aggressive -static | ||
CXXFLAGS := -std=c++11 -Wall -Wremarks -Wchecks -Weffec++ -xHost -funroll-loops -ipo -O3 | ||
DEPFLAGS = -std=c++11 -MM -MP -MT $(OBJDIR)$*.o | ||
endif | ||
icc: neurofield | ||
|
||
# target: $(BINDIR)$(BIN) - Main target for the final build, linking objects into an executable. | ||
$(BINDIR)$(BIN): $(OBJ) | make_bin_dir | ||
$(CXX) $(CXXFLAGS) $(OBJ) -o $@ | ||
@echo "=====" | ||
@cat license.txt | ||
@$(CAT) license.txt | ||
@echo "=====" | ||
@echo "USE OF NEUROFIELD CONSTITUTES ACCEPTANCE OF THE LICENSE CONDITIONS ABOVE" | ||
|
||
# target: make_bin_dir - Create the directory $BINDIR if it doesn't already exist. | ||
make_bin_dir: | ||
@test -d $(BINDIR) || { mkdir $(BINDIR) ; echo "mkdir $(BINDIR)"; } | ||
|
||
# target: make_obj_dir - Create the directory $OBJDIR if it doesn't already exist. | ||
make_obj_dir: | ||
@test -d $(OBJDIR) || { mkdir $(OBJDIR) ; echo "mkdir $(OBJDIR)"; } | ||
|
||
# target: make_dep_dir - Create the directory $DEPDIR if it doesn't already exist. | ||
make_dep_dir: | ||
@test -d $(DEPDIR) || { mkdir $(DEPDIR) ; echo "mkdir $(DEPDIR)"; } | ||
|
||
#Only create and include dependencies if the current target requires them. | ||
ifeq (, $(filter $(MAKECMDGOALS), $(NO_DEPS))) | ||
#Create obj/*.d header dependencies | ||
$(DEPDIR)%.d: $(SRCDIR)%.cpp | make_dep_dir | ||
$(CXX) $(DEPFLAGS) $< > $(DEPDIR)$*.d | ||
# Include any existing dependencies in the build | ||
-include $(OBJ:.o=.d) | ||
|
||
# Build object code and also create obj/*.d header dependencies | ||
obj/%.o: src/%.cpp | ||
@mkdir -p obj | ||
@$(CXX) $(CXXFLAGS) -c $< -o $@ | ||
@$(CXX) -MM $(CXXFLAGS) $< > obj/$*.d | ||
@echo "CXX $<" | ||
@mv -f obj/$*.d obj/$*.d.tmp | ||
@sed -e 's|.*:|$@:|' < obj/$*.d.tmp > obj/$*.d | ||
@sed -e 's/.*://' -e 's/\\$$//' < obj/$*.d.tmp | fmt -1 | \ | ||
sed -e 's/^ *//' -e 's/$$/:/' >> obj/$*.d | ||
@rm -f obj/$*.d.tmp | ||
|
||
# Build documentation: compile tex file and produce html docs from code | ||
build_docs: | ||
cd Documentation && pdflatex neurofield && pdflatex neurofield && cd ../ && doxygen Doxyfile | ||
|
||
.PHONY: clean doc help | ||
|
||
# target: help - Print this message | ||
help: | ||
@egrep "^# target:" Makefile | ||
-include $(DEP) | ||
endif | ||
|
||
# target: doc - compile Documentation/neurofield.pdf | ||
doc: Documentation/neurofield.pdf | ||
# Build object code | ||
$(OBJDIR)%.o: $(SRCDIR)%.cpp | make_obj_dir | ||
$(CXX) $(CXXFLAGS) -c $< -o $@ | ||
|
||
# target: clean - Delete ./bin/, ./obj/, and LaTeX temporary files in ./Documentation/ | ||
clean: | ||
@-rm -rf bin obj Documentation/{user,developer}.{aux,log,out,toc} Documentation/x.log | ||
# target: help - Print this message. | ||
help: | ||
@echo "Available Makefile targets, call as 'make target', eg. make all" | ||
@$(GREP) "^# target:" Makefile | ||
|
||
# target: help-dev - Print an extended list of targets. | ||
help-dev: help | ||
@echo "Additional targets, mainly useful for developers." | ||
@$(GREP) "^# target:" Makefile | ||
|
||
# target: info - A convenience target for debugging the Makefile. | ||
info: | ||
@echo " SHELL: $(SHELL)" | ||
@echo " MAKE_VERSION: $(MAKE_VERSION)" | ||
@echo " .VARIABLES: $(.VARIABLES)" | ||
@echo " .DEFAULT_GOAL: $(.DEFAULT_GOAL)" | ||
@echo " SRCDIR: $(SRCDIR)" | ||
@echo " OBJDIR: $(OBJDIR)" | ||
@echo " BINDIR: $(BINDIR)" | ||
@echo " DOCDIR: $(DOCDIR)" | ||
@echo " HEADER: $(HEADER)" | ||
@echo " CPP: $(CPP)" | ||
@echo " OBJ: $(OBJ)" | ||
@echo " DEP: $(DEP)" | ||
@echo " CXX: $(CXX)" | ||
@echo " CXXFLAGS: $(CXXFLAGS)" | ||
@echo " DEBUG: $(DEBUG)" | ||
@echo " NO_DEPS: $(NO_DEPS)" | ||
|
||
# target: docs - Build user and reference manuals. | ||
docs: user-manual reference-manual | ||
|
||
# target: user-manual - Build only the user-manual. | ||
user-manual: $(DOCDIR)$(USER_MANUAL) | ||
|
||
# target: $(DOCDIR)$(USER_MANUAL) - target that actually builds the user manual. | ||
$(DOCDIR)$(USER_MANUAL): $(DOCDIR)$(USER_MANUAL_SRC) | ||
cd $(DOCDIR) && \ | ||
pdflatex $(USER_MANUAL_SRC) && \ | ||
pdflatex $(USER_MANUAL_SRC) | ||
|
||
# target: reference-manual - Build only the reference-manual. | ||
reference-manual: | ||
doxygen Doxyfile | ||
|
||
# target: clean-docs - Delete temporary LaTeX files and Doxygen generated reference-manual. | ||
clean-docs: clean-user-manual clean-reference-manual | ||
|
||
# target: clean-user-manual - Delete temporary LaTeX files generated when building the user-manual. | ||
clean-user-manual: | ||
-$(RM) $(DOCDIR)$(USER_MANUAL_SRC:.tex=).{aux,log,out,toc} | ||
|
||
# target: clean-reference-manual - Delete Doxygen generated reference-manual. | ||
clean-reference-manual: | ||
-$(RMDIR) $(DOCDIR)html | ||
-$(RMDIR) $(DOCDIR)latex | ||
|
||
# target: clean-deps - Delete the dependencies created during build. | ||
clean-deps: | ||
-$(RM) $(DEP) | ||
|
||
# target: clean-objs - Delete the objects created during build. | ||
clean-objs: | ||
-$(RM) $(OBJ) | ||
|
||
# target: clean-bin - Delete the executable generated by the build. | ||
clean-bin: | ||
-$(RM) $(BINDIR)$(BIN) | ||
|
||
# target: clean - Delete dependency files, temporary build objects and temporary LaTeX files. | ||
clean: clean-deps clean-objs clean-user-manual | ||
|
||
# target: clean-all - Same as clean but also delete Doxygen generated docs, and the executable. | ||
clean-all: clean-deps clean-objs clean-bin clean-docs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters