Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
103 changes: 70 additions & 33 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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 \
Expand All @@ -8,64 +8,101 @@ 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 $<

%.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)
File renamed without changes.
File renamed without changes.
File renamed without changes.