aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2018-08-19 21:16:34 +0200
committerDavid Robillard <d@drobilla.net>2018-09-29 14:50:30 +0200
commit97605a44e0b531f67a8e9a751ce7f81a14c67763 (patch)
tree668ca1dd44dab34559a62a1a89b86a6d3a190bfd
parent801b92b6d788d9f693612c0120e96b6b1ceb0e0a (diff)
downloadchilbert-97605a44e0b531f67a8e9a751ce7f81a14c67763.tar.gz
chilbert-97605a44e0b531f67a8e9a751ce7f81a14c67763.tar.bz2
chilbert-97605a44e0b531f67a8e9a751ce7f81a14c67763.zip
Clean up Makefile
-rw-r--r--Makefile86
1 files changed, 77 insertions, 9 deletions
diff --git a/Makefile b/Makefile
index 1b7a09a..e397515 100644
--- a/Makefile
+++ b/Makefile
@@ -1,22 +1,90 @@
-CXXFLAGS += -I. -std=c++14 -Wall -Wextra -Wno-unused-parameter
+#################
+# Configuration #
+#################
+
+# User variables
+DEBUG ?= 0
+TEST ?= 0
+
+prefix ?= /usr/local
+includedir ?= $(prefix)/include
+bindir ?= $(prefix)/bin
+
+# Wipe user flags if DEBUG is on
+ifeq ($(DEBUG), 1)
+CXXFLAGS = -O0 -g
+endif
+
+# Append mandatory flags
+CXXFLAGS += -I. -std=c++14
+
+# Set strict debugging flags for known compilers
+ifeq ($(DEBUG), 1)
+
+ifeq ($(findstring clang,$(CXX)),clang)
+ CXXFLAGS += -Weverything -Wno-c++98-compat -Wno-c++98-compat-pedantic
+else ifeq ($(findstring g++,$(CXX)),g++)
+ CXXFLAGS += -ftree-vrp -ftrapv -Waddress -Wall -Warray-bounds=2 -Wbool-compare -Wc++14-compat -Wcast-align -Wcast-qual -Wchar-subscripts -Wchkp -Wclobbered -Wcomment -Wconditionally-supported -Wconversion -Wcoverage-mismatch -Wdate-time -Wdelete-incomplete -Wdisabled-optimization -Wdouble-promotion -Wduplicated-cond -Wempty-body -Wenum-compare -Werror=pedantic -Wextra -Wfloat-conversion -Wfloat-equal -Wformat -Wformat-nonliteral -Wformat-security -Wformat-signedness -Wformat-y2k -Wformat=2 -Wframe-address -Whsa -Wignored-attributes -Wignored-qualifiers -Winit-self -Winline -Winvalid-memory-model -Winvalid-pch -Wlogical-not-parentheses -Wlogical-op -Wmain -Wmaybe-uninitialized -Wmemset-transposed-args -Wmisleading-indentation -Wmissing-declarations -Wmissing-field-initializers -Wmissing-format-attribute -Wmissing-include-dirs -Wno-aggressive-loop-optimizations -Wno-attributes -Wno-builtin-macro-redefined -Wno-cpp -Wno-deprecated -Wno-deprecated-declarations -Wno-div-by-zero -Wno-endif-labels -Wno-format-contains-nul -Wno-format-extra-args -Wno-free-nonheap-object -Wno-int-to-pointer-cast -Wno-invalid-offsetof -Wno-multichar -Wno-overflow -Wno-pedantic-ms-format -Wno-pragmas -Wno-return-local-addr -Wno-scalar-storage-order -Wno-undef -Wno-unused-result -Wnonnull -Wnonnull-compare -Wnormalized -Wnull-dereference -Wodr -Wopenmp-simd -Woverlength-strings -Wpacked -Wpacked-bitfield-compat -Wparentheses -Wpedantic -Wplacement-new=2 -Wpointer-arith -Wredundant-decls -Wreturn-type -Wsequence-point -Wshadow -Wshift-count-negative -Wshift-count-overflow -Wshift-negative-value -Wshift-overflow -Wshift-overflow=2 -Wsign-compare -Wsign-conversion -Wsizeof-array-argument -Wsizeof-pointer-memaccess -Wstack-protector -Wstrict-aliasing -Wstrict-overflow -Wsubobject-linkage -Wsuggest-attribute=const -Wsuggest-attribute=format -Wsuggest-attribute=noreturn -Wsuggest-attribute=pure -Wsuggest-final-methods -Wsuggest-final-types -Wsuggest-override -Wswitch -Wswitch-bool -Wswitch-default -Wswitch-enum -Wsync-nand -Wtautological-compare -Wtrampolines -Wtrigraphs -Wtype-limits -Wundef -Wuninitialized -Wunknown-pragmas -Wunsafe-loop-optimizations -Wunused -Wunused-but-set-parameter -Wunused-but-set-variable -Wunused-const-variable -Wunused-const-variable=2 -Wunused-function -Wunused-label -Wunused-local-typedefs -Wunused-parameter -Wunused-value -Wunused-variable -Wuseless-cast -Wvariadic-macros -Wvector-operation-performance -Wvla -Wvolatile-register-var -Wwrite-strings -Wzero-as-null-pointer-constant -fstrict-aliasing -fstrict-overflow -pedantic-errors
+else
+$(info warning: Unknown compiler, not setting strict debugging flags)
+$(info )
+endif
+
+endif # DEBUG
+
+
+###############
+# Build Rules #
+###############
HEADERS = $(wildcard chilbert/*.hpp) $(wildcard chilbert/*.ipp)
+DETAIL_HEADERS = $(wildcard chilbert/detail/*.hpp)
TESTS = test/test_bitvec test/test_gray_code_rank test/test_hilbert
+PROGS = bin/chilbert_obj bin/chilbert_svg
-all: $(TESTS)
+ALL_HEADERS = $(HEADERS) $(DETAIL_HEADERS)
+PROG_NAMES = $(subst bin/,,$(PROGS))
-clean:
- rm -f $(TESTS)
+all: $(PROGS)
+
+tests: $(TESTS)
-test/%: test/%.cpp $(HEADERS)
+test/%: test/%.cpp $(ALL_HEADERS)
$(CXX) $(CXXFLAGS) -o $@ $@.cpp
-test/test_hilbert: test/test_hilbert.cpp $(HEADERS)
+test/test_hilbert: test/test_hilbert.cpp $(ALL_HEADERS)
$(CXX) $(CXXFLAGS) -lgmp -lgmpxx -o $@ $@.cpp
+bin/%: bin/%.cpp $(ALL_HEADERS)
+ $(CXX) $(CXXFLAGS) -o $@ $@.cpp
+
+
+##################
+# Forced Targets #
+##################
+
FORCE:
-test/%.run: $(TESTS) FORCE
- test/$*
+clean:
+ rm -f $(TESTS) $(PROGS)
+
+%.run: tests
+ $*
+
+test: $(addsuffix .run, $(TESTS)) FORCE
+
+install: FORCE
+ install -d $(DESTDIR)$(includedir)/chilbert/
+ install -d $(DESTDIR)$(includedir)/chilbert/detail/
+ install -d $(DESTDIR)$(bindir)/
+
+ install -m 755 -t $(DESTDIR)$(includedir)/chilbert/ $(HEADERS)
+ install -m 755 -t $(DESTDIR)$(includedir)/chilbert/detail/ $(DETAIL_HEADERS)
+ install -m 755 -t $(DESTDIR)$(bindir)/ $(PROGS)
+
+uninstall: FORCE
+ rm -f $(subst bin/,$(DESTDIR)$(bindir)/,$(PROGS))
+ rm -f $(subst chilbert/,$(DESTDIR)$(includedir)/chilbert/,$(ALL_HEADERS))
-test: $(addsuffix .run, $(TESTS))
+ -rmdir $(DESTDIR)$(bindir)/
+ -rmdir -p $(DESTDIR)$(includedir)/chilbert/detail/