aboutsummaryrefslogtreecommitdiff
path: root/Makefile
blob: 6cb7b5736934567ea4d80f9af8b955bb83ea9d6a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
-include local.mk

CMAKE_FLAGS := -DCMAKE_BUILD_TYPE=Debug

BUILD_TYPE ?= $(shell (type ninja > /dev/null 2>&1 && echo "Ninja") || \
    echo "Unix Makefiles")

ifeq (,$(BUILD_TOOL))
  ifeq (Ninja,$(BUILD_TYPE))
      ifneq ($(shell cmake --help 2>/dev/null | grep Ninja),)
          BUILD_TOOL := ninja
      else
          # User's version of CMake doesn't support Ninja
          BUILD_TOOL = $(MAKE)
          BUILD_TYPE := Unix Makefiles
      endif
  else
      BUILD_TOOL = $(MAKE)
  endif
endif

ifneq ($(VERBOSE),)
    # Only need to handle Ninja here.  Make will inherit the VERBOSE variable.
    ifeq ($(BUILD_TYPE),Ninja)
        VERBOSE_FLAG := -v
    endif
endif

BUILD_CMD = $(BUILD_TOOL) $(VERBOSE_FLAG)

# Extra CMake flags which extend the default set
CMAKE_EXTRA_FLAGS ?=
DEPS_CMAKE_FLAGS ?=

# For use where we want to make sure only a single job is run.  This also avoids
# any warnings from the sub-make.
SINGLE_MAKE = export MAKEFLAGS= ; $(MAKE)

all: nvim

nvim: build/.ran-cmake deps
	+$(BUILD_CMD) -C build

cmake:
	touch CMakeLists.txt
	$(MAKE) build/.ran-cmake

build/.ran-cmake: | deps
	mkdir -p build
	cd build && cmake -G '$(BUILD_TYPE)' $(CMAKE_FLAGS) $(CMAKE_EXTRA_FLAGS) ..
	touch $@

deps: | .deps/build/third-party/.ran-cmake
	+$(BUILD_CMD) -C .deps/build/third-party

.deps/build/third-party/.ran-cmake:
	mkdir -p .deps/build/third-party
	cd .deps/build/third-party && \
		cmake -G '$(BUILD_TYPE)' $(DEPS_CMAKE_FLAGS) ../../../third-party
	touch $@

test: | nvim
	+$(SINGLE_MAKE) -C src/testdir

unittest: | nvim
	+$(BUILD_CMD) -C build unittest

clean:
	+test -d build && $(BUILD_CMD) -C build clean || true
	$(MAKE) -C src/testdir clean

distclean: clean
	rm -rf .deps build

install: | nvim
	+$(BUILD_CMD) -C build install

.PHONY: test unittest clean distclean nvim cmake deps install