From d134118ee714a75dfcea88011000c5dd4dbcc313 Mon Sep 17 00:00:00 2001 From: Jaeho Shin Date: Tue, 3 Jan 2017 19:18:35 -0800 Subject: [PATCH] Reorganizes Makefile in a modular fashion as it's starting to get out of control --- Makefile | 124 ++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 82 insertions(+), 42 deletions(-) diff --git a/Makefile b/Makefile index 2ae558633..1df2e5b41 100644 --- a/Makefile +++ b/Makefile @@ -1,12 +1,12 @@ -# Makefile for sampler +# Makefile for DimmWitted Gibbs Sampler .DEFAULT_GOAL := all +################################################################################ # common compiler flags CXXFLAGS += -std=c++0x -Wall -Werror -fno-strict-aliasing -LDFLAGS = -LDLIBS = -CXXFLAGS += -I./lib/tclap/include/ -I./src +LDFLAGS += +LDLIBS += ifdef DEBUG CXXFLAGS += -g -DDEBUG @@ -22,11 +22,6 @@ endif ifndef DEBUG CXXFLAGS += -Ofast endif -# using NUMA for Linux -CXXFLAGS += -I./lib/numactl/include -LDFLAGS += -L./lib/numactl/lib -LDFLAGS += -Wl,-Bstatic -Wl,-Bdynamic -LDLIBS += -lnuma -lrt -lpthread endif ifeq ($(UNAME), Darwin) @@ -41,6 +36,7 @@ CXXFLAGS += -stdlib=libc++ CXXFLAGS += -flto endif +################################################################################ # source files SOURCES += src/dimmwitted.cc SOURCES += src/cmd_parser.cc @@ -71,15 +67,12 @@ TEST_SOURCES += test/factor_graph_test.cc TEST_SOURCES += test/sampler_test.cc TEST_OBJECTS = $(TEST_SOURCES:.cc=.o) TEST_PROGRAM = $(PROGRAM)_test -# test files need gtest -$(OBJECTS): CXXFLAGS += -I./lib/gtest-1.7.0/include/ -$(TEST_OBJECTS): CXXFLAGS += -I./lib/gtest-1.7.0/include/ -$(TEST_PROGRAM): LDFLAGS += -L./lib/gtest/ -$(TEST_PROGRAM): LDLIBS += -lgtest -lpthread +$(TEST_OBJECTS): CXXFLAGS += -I./src/ all: $(PROGRAM) .PHONY: all +################################################################################ # how to link our sampler $(PROGRAM): $(OBJECTS) $(CXX) -o $@ $(LDFLAGS) $^ $(LDLIBS) @@ -88,6 +81,7 @@ $(PROGRAM): $(OBJECTS) $(TEST_PROGRAM): $(TEST_OBJECTS) $(filter-out src/main.o,$(OBJECTS)) $(CXX) -o $@ $(LDFLAGS) $^ $(LDLIBS) +################################################################################ # compiler generated dependency # See: http://stackoverflow.com/a/16969086 DEPENDENCIES = $(SOURCES:.cc=.d) $(TEST_SOURCES:.cc=.d) $(TEXT2BIN_SOURCES:.cc=.d) @@ -98,44 +92,99 @@ CXXFLAGS += -MMD %.o: %.cc $(CXX) -o $@ $(CPPFLAGS) $(CXXFLAGS) -c $< +################################################################################ # how to get dependencies prepared dep: +.PHONY: dep + +### Google Test for unit tests +# https://github.com/google/googletest +# test files need gtest +$(OBJECTS): CXXFLAGS += -I./lib/gtest-1.7.0/include/ +$(TEST_OBJECTS): CXXFLAGS += -I./lib/gtest-1.7.0/include/ +$(TEST_PROGRAM): LDFLAGS += -L./lib/gtest/ +$(TEST_PROGRAM): LDLIBS += -lgtest +dep: lib/gtest +lib/gtest: lib/gtest-1.7.0.zip # gtest for tests - cd lib;\ - unzip -o gtest-1.7.0.zip;\ - mkdir gtest;\ - cd gtest;\ - cmake ../gtest-1.7.0;\ - make - # tclap for command-line args parsing - cd lib;\ - tar xf tclap-1.2.1.tar.gz;\ - cd tclap-1.2.1;\ - ./configure --prefix=`pwd`/../tclap;\ - make;\ + set -eu;\ + cd $(@D);\ + unzip -o $("$$expected"; \ + done +.PHONY: actual-expected + +################################################################################ # how to format code # XXX requiring a particular version since clang-format is not backward-compatible CLANG_FORMAT_REQUIRED_VERSION := 3.7 @@ -158,12 +207,3 @@ format: $(CLANG_FORMAT) -i $(SOURCES) $(TEST_SOURCES) $(TEXT2BIN_SOURCES) $(HEADERS) endif .PHONY: format - -# how to quickly turn actual test output into expected ones -actual-expected: - for actual in test/*/*.bin; do \ - expected="$$actual".txt; \ - [[ -e "$$expected" ]] || continue; \ - xxd "$$actual" >"$$expected"; \ - done -.PHONY: actual-expected