Makefile 4.19 KB
Newer Older
1
THIS_DIR = $(shell pwd)
2 3 4
filter-false = $(strip $(filter-out 0 off OFF false FALSE,$1))
filter-true = $(strip $(filter-out 1 on ON true TRUE,$1))

5
# See contrib/local.mk.example
6 7
-include local.mk

8
CMAKE_PRG ?= $(shell (command -v cmake3 || echo cmake))
9 10 11
CMAKE_BUILD_TYPE ?= Debug

CMAKE_FLAGS := -DCMAKE_BUILD_TYPE=$(CMAKE_BUILD_TYPE)
12 13 14

BUILD_TYPE ?= $(shell (type ninja > /dev/null 2>&1 && echo "Ninja") || \
    echo "Unix Makefiles")
15 16 17 18 19
DEPS_BUILD_DIR ?= .deps

ifneq (1,$(words [$(DEPS_BUILD_DIR)]))
  $(error DEPS_BUILD_DIR must not contain whitespace)
endif
20 21 22

ifeq (,$(BUILD_TOOL))
  ifeq (Ninja,$(BUILD_TYPE))
23
    ifneq ($(shell $(CMAKE_PRG) --help 2>/dev/null | grep Ninja),)
24 25 26
      BUILD_TOOL := ninja
    else
      # User's version of CMake doesn't support Ninja
27
      BUILD_TOOL = $(MAKE)
28 29 30 31
      BUILD_TYPE := Unix Makefiles
    endif
  else
    BUILD_TOOL = $(MAKE)
32 33
  endif
endif
34

35
ifneq ($(VERBOSE),)
36 37 38 39
  # Only need to handle Ninja here.  Make will inherit the VERBOSE variable.
  ifeq ($(BUILD_TYPE),Ninja)
    VERBOSE_FLAG := -v
  endif
40 41 42 43
endif

BUILD_CMD = $(BUILD_TOOL) $(VERBOSE_FLAG)

44
# Extra CMake flags which extend the default set
45 46
CMAKE_EXTRA_FLAGS ?=
DEPS_CMAKE_FLAGS ?=
47 48
# Back-compat: USE_BUNDLED_DEPS was the old name.
USE_BUNDLED ?= $(USE_BUNDLED_DEPS)
49

50 51
ifneq (,$(USE_BUNDLED))
  BUNDLED_CMAKE_FLAG := -DUSE_BUNDLED=$(USE_BUNDLED)
52
endif
53

54 55
ifneq (,$(findstring functionaltest-lua,$(MAKECMDGOALS)))
  BUNDLED_LUA_CMAKE_FLAG := -DUSE_BUNDLED_LUA=ON
56
  $(shell [ -x $(DEPS_BUILD_DIR)/usr/bin/lua ] || rm build/.ran-*)
57 58
endif

59 60
# For use where we want to make sure only a single job is run.  This does issue 
# a warning, but we need to keep SCRIPTS argument.
61 62
SINGLE_MAKE = export MAKEFLAGS= ; $(MAKE)

63
all: nvim
64

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

68 69 70
libnvim: build/.ran-cmake deps
	+$(BUILD_CMD) -C build libnvim

71 72 73
cmake:
	touch CMakeLists.txt
	$(MAKE) build/.ran-cmake
74

75
build/.ran-cmake: | deps
76
	cd build && $(CMAKE_PRG) -G '$(BUILD_TYPE)' $(CMAKE_FLAGS) $(CMAKE_EXTRA_FLAGS) $(THIS_DIR)
77
	touch $@
78

79
deps: | build/.ran-third-party-cmake
80
ifeq ($(call filter-true,$(USE_BUNDLED)),)
81
	+$(BUILD_CMD) -C $(DEPS_BUILD_DIR)
82
endif
83

84
build/.ran-third-party-cmake:
85
ifeq ($(call filter-true,$(USE_BUNDLED)),)
86 87
	mkdir -p $(DEPS_BUILD_DIR)
	cd $(DEPS_BUILD_DIR) && \
88
		$(CMAKE_PRG) -G '$(BUILD_TYPE)' $(BUNDLED_CMAKE_FLAG) $(BUNDLED_LUA_CMAKE_FLAG) \
89
		$(DEPS_CMAKE_FLAGS) $(THIS_DIR)/third-party
90 91
endif
	mkdir -p build
92
	touch $@
93

94
# TODO: cmake 3.2+ add_custom_target() has a USES_TERMINAL flag.
95
oldtest: | nvim helptags
96 97 98 99 100 101
	+$(SINGLE_MAKE) -C src/nvim/testdir clean
ifeq ($(strip $(TEST_FILE)),)
	+$(SINGLE_MAKE) -C src/nvim/testdir NVIM_PRG="$(realpath build/bin/nvim)" $(MAKEOVERRIDES)
else
	+$(SINGLE_MAKE) -C src/nvim/testdir NVIM_PRG="$(realpath build/bin/nvim)" NEW_TESTS=$(TEST_FILE) SCRIPTS= $(MAKEOVERRIDES)
endif
102

103
helptags: | nvim
104
	+$(BUILD_CMD) -C build helptags
105

Justin M. Keyes's avatar
Justin M. Keyes committed
106 107 108 109
# Builds help HTML _and_ checks for invalid help tags.
helphtml: | nvim helptags
	+$(BUILD_CMD) -C build doc_html

110 111 112
functionaltest: | nvim
	+$(BUILD_CMD) -C build functionaltest

113 114 115
functionaltest-lua: | nvim
	+$(BUILD_CMD) -C build functionaltest-lua

116
testlint: | build/.ran-cmake deps
117 118
	$(BUILD_CMD) -C build testlint

119 120 121
lualint: | build/.ran-cmake deps
	$(BUILD_CMD) -C build lualint

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

David Bürgin's avatar
David Bürgin committed
125 126 127
benchmark: | nvim
	+$(BUILD_CMD) -C build benchmark

128 129
test: functionaltest unittest

130
clean:
131
	+test -d build && $(BUILD_CMD) -C build clean || true
132
	$(MAKE) -C src/nvim/testdir clean
133
	$(MAKE) -C runtime/doc clean
134

135
distclean: clean
136
	rm -rf $(DEPS_BUILD_DIR) build
137

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

141 142 143 144 145
clint: build/.ran-cmake
	+$(BUILD_CMD) -C build clint

clint-full: build/.ran-cmake
	+$(BUILD_CMD) -C build clint-full
146

147 148 149
check-single-includes: build/.ran-cmake
	+$(BUILD_CMD) -C build check-single-includes

150 151 152
generated-sources: build/.ran-cmake
	+$(BUILD_CMD) -C build generated-sources

AdnoC's avatar
AdnoC committed
153 154 155
appimage:
	bash scripts/genappimage.sh

156 157 158 159 160
# Build an appimage with embedded update information appimage-nightly for
# nightly builds or appimage-latest for a release
appimage-%:
	bash scripts/genappimage.sh $*

161
lint: check-single-includes clint testlint lualint
162

163
.PHONY: test testlint lualint functionaltest unittest lint clint clean distclean nvim libnvim cmake deps install appimage