diff --git a/.travis.yml b/.travis.yml index 5d2d9ae..f27934e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -21,5 +21,6 @@ before_script: - mkdir -p "$BUILDDIR" - cd "$BUILDDIR" script: - - make -f "$OLDPWD/Makefile" all - - sudo make -f "$OLDPWD/Makefile" install + - make -d -f "$OLDPWD/Makefile" all + #- sudo make -f "$OLDPWD/Makefile" install-daemon + #- sudo make -f "$OLDPWD/Makefile" install-vim diff --git a/Makefile b/Makefile index ca680b1..ff1b1bf 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ -CXX_SOURCES := src/daemon/clang-cache.cpp \ - src/daemon/client/client.cpp \ +# Sources +DAEMON_SOURCES := src/daemon/client/client.cpp \ src/daemon/server/cache.cpp \ src/daemon/server/clc_service.cpp \ src/daemon/server/server.cpp \ @@ -8,49 +8,52 @@ CXX_SOURCES := src/daemon/clang-cache.cpp \ src/daemon/utils/daemon.cpp \ src/daemon/utils/logger.cpp \ src/daemon/utils/mkdirp.cpp \ - src/daemon/utils/waitdir.cpp - -THRIFT_SOURCES := src/clc_if.thrift + src/daemon/utils/waitdir.cpp \ + src/daemon/clang-cache.cpp +VIM_SOURCES := src/vim/clc.py src/vim/clc.vim +THRIFT_SOURCES := src/thrift/clc_if.thrift DOC_SOURCES := doc/clang-cache.1.md +# Out of tree build stuff +REPO_ROOT := $(dir $(lastword $(MAKEFILE_LIST))) +VPATH := $(REPO_ROOT) + +# Compilers and flags CXX ?= g++ -CXXFLAGS := `pkg-config --cflags thrift` -std=c++11 -pedantic -Wall -Wextra -Werror -I$(dir $(lastword $(MAKEFILE_LIST)))src/daemon -Isrc/daemon -I$(dir $(lastword $(MAKEFILE_LIST)))src -Isrc +CXXFLAGS := -std=c++11 -pedantic -Wall -Wextra -Werror \ + -I$(REPO_ROOT)src/daemon -Isrc/thrift \ + `pkg-config --cflags thrift` LDFLAGS := `pkg-config --libs thrift` -lclang PREFIX := /usr/local -GEN_SOURCES := $(THRIFT_SOURCES:.thrift=_types.cpp) $(THRIFT_SOURCES:.thrift=_constants.cpp) $(THRIFT_SOURCES:.thrift=.cpp) -GEN_HEADERS := $(THRIFT_SOURCES:.thrift=_types.h) $(THRIFT_SOURCES:.thrift=_constants.h) $(THRIFT_SOURCES:.thrift=.h) -OBJECTS := $(CXX_SOURCES:.cpp=.o) $(GEN_SOURCES:.cpp=.o) -DEPENDS := $(OBJECTS:.o=.d) -TARGET := src/clang-cache -DOCTARGETS := $(DOC_SOURCES:.1.md=.1) +# Intermediates and targets +DAEMON_THRIFT := $(THRIFT_SOURCES:.thrift=_types.cpp) \ + $(THRIFT_SOURCES:.thrift=_constants.cpp) \ + $(THRIFT_SOURCES:.thrift=.cpp) +DAEMON_THRIFT_H := $(DAEMON_THRIFT:.cpp=.h) +DAEMON_OBJECTS := $(DAEMON_SOURCES:.cpp=.o) $(DAEMON_THRIFT:.cpp=.o) +DAEMON_DEPENDS := $(DAEMON_OBJECTS:.o=.d) +DAEMON_TARGET := src/daemon/clang-cache -VPATH := $(dir $(lastword $(MAKEFILE_LIST))) +VIM_THRIFT := $(THRIFT_SOURCES:.thrift=/) +VIM_TARGET := src/vim/plugin -default: $(TARGET) +DOC_TARGET := $(DOC_SOURCES:.1.md=.1) -all: $(TARGET) $(DOCTARGETS) +# What to build? -$(CXX_SOURCES:.cpp=.o): | $(GEN_SOURCES) $(GEN_HEADERS) +default: $(DAEMON_TARGET) -install: all - install -d $(PREFIX)/bin/ - install -d $(PREFIX)/share/man/man1/ - install -s -t $(PREFIX)/bin/ $(TARGET) - install -t $(PREFIX)/share/man/man1/ $(DOCTARGETS) +all: $(DAEMON_TARGET) $(VIM_TARGET) $(DOC_TARGET) -clean: - rm -f $(GEN_SOURCES) $(GEN_HEADERS) - rm -f $(OBJECTS) - rm -f $(DEPENDS) - -distclean: clean - rm -f $(TARGET) - rm -f $(DOCTARGETS) +# Daemon rules -$(TARGET): $(OBJECTS) +$(DAEMON_TARGET): $(DAEMON_OBJECTS) + @mkdir -p $(dir $@) $(CXX) -o $@ $^ $(LDFLAGS) +$(DAEMON_SOURCES:.cpp=.o): | $(DAEMON_THRIFT) $(DAEMON_THRIFT_H) + %.o: %.cpp @mkdir -p $(dir $@) $(CXX) $(CXXFLAGS) -MMD -o $@ -c $< @@ -58,14 +61,48 @@ $(TARGET): $(OBJECTS) %.cpp %.h %_types.cpp %_types.h %_constants.cpp %_constants.h: %.thrift @mkdir -p $(dir $@) thrift --gen cpp:pure_enums -out $(dir $@) $< - # Yes this is lame, but we don't have much choice... - thrift --gen py:new_style -out $(dir $(lastword $(MAKEFILE_LIST)))src/vim/plugin $< + rm -f $(dir $@)$(basename $(notdir $<))_server.skeleton.cpp + +# Vim plugin rules + +$(VIM_TARGET): $(VIM_SOURCES) $(VIM_THRIFT) + @mkdir -p $@ + cp -r $^ $@ + +%/: %.thrift + @mkdir -p $@ + thrift --gen py:new_style -out $@.. $< + rm -f $@../__init__.py $@$(basename $(notdir $<))-remote + +# Documentation rules %.1: %.1.md @mkdir -p $(dir $@) ronn --roff --pipe $< >$@ -.PHONY: all install clean distclean +# Boilerplate rules + +install-daemon: $(DAEMON_TARGET) $(DOC_TARGET) + mkdir -p $(PREFIX)/bin $(PREFIX)/share/man/man1 + cp $(DAEMON_TARGET) $(PREFIX)/bin/ + cp $(DOC_TARGET) $(PREFIX)/share/man/man1/ + +install-vim: $(VIM_TARGET) + mkdir -p $(PREFIX)/share/vim/vimfiles + cp -r $(VIM_TARGET) $(PREFIX)/share/vim/vimfiles/ + +clean: + rm -fr $(DAEMON_OBJECTS) + rm -fr $(DAEMON_DEPENDS) + rm -fr $(DAEMON_THRIFT) $(DAEMON_THRIFT_H) + rm -fr $(VIM_THRIFT) + +distclean: clean + rm -fr $(DAEMON_TARGET) + rm -fr $(VIM_TARGET) + rm -fr $(DOC_TARGET) + +.PHONY: default all install-daemon install-vim clean distclean .SECONDARY: -include $(DEPENDS) diff --git a/src/clc_if.thrift b/src/thrift/clc_if.thrift similarity index 100% rename from src/clc_if.thrift rename to src/thrift/clc_if.thrift diff --git a/src/vim/plugin/clc.py b/src/vim/clc.py similarity index 100% rename from src/vim/plugin/clc.py rename to src/vim/clc.py diff --git a/src/vim/plugin/clc.vim b/src/vim/clc.vim similarity index 100% rename from src/vim/plugin/clc.vim rename to src/vim/clc.vim