You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

217 lines
6.2KB

  1. THIS_DIR = $(shell pwd)
  2. filter-false = $(strip $(filter-out 0 off OFF false FALSE,$1))
  3. filter-true = $(strip $(filter-out 1 on ON true TRUE,$1))
  4. # See contrib/local.mk.example
  5. -include local.mk
  6. all: nvim
  7. CMAKE_PRG ?= $(shell (command -v cmake3 || echo cmake))
  8. CMAKE_BUILD_TYPE ?= Debug
  9. CMAKE_FLAGS := -DCMAKE_BUILD_TYPE=$(CMAKE_BUILD_TYPE)
  10. # Extra CMake flags which extend the default set
  11. CMAKE_EXTRA_FLAGS ?=
  12. # CMAKE_INSTALL_PREFIX
  13. # - May be passed directly or as part of CMAKE_EXTRA_FLAGS.
  14. # - `checkprefix` target checks that it matches the CMake-cached value. #9615
  15. ifneq (,$(CMAKE_INSTALL_PREFIX)$(CMAKE_EXTRA_FLAGS))
  16. CMAKE_INSTALL_PREFIX := $(shell echo $(CMAKE_EXTRA_FLAGS) | 2>/dev/null \
  17. grep -o 'CMAKE_INSTALL_PREFIX=[^ ]\+' | cut -d '=' -f2)
  18. endif
  19. ifneq (,$(CMAKE_INSTALL_PREFIX))
  20. override CMAKE_EXTRA_FLAGS += -DCMAKE_INSTALL_PREFIX=$(CMAKE_INSTALL_PREFIX)
  21. checkprefix:
  22. @if [ -f build/.ran-cmake ]; then \
  23. cached_prefix=$(shell $(CMAKE_PRG) -L -N build | 2>/dev/null grep 'CMAKE_INSTALL_PREFIX' | cut -d '=' -f2); \
  24. if ! [ "$(CMAKE_INSTALL_PREFIX)" = "$$cached_prefix" ]; then \
  25. printf "Re-running CMake: CMAKE_INSTALL_PREFIX '$(CMAKE_INSTALL_PREFIX)' does not match cached value '%s'.\n" "$$cached_prefix"; \
  26. $(RM) build/.ran-cmake; \
  27. fi \
  28. fi
  29. else
  30. checkprefix: ;
  31. endif
  32. BUILD_TYPE ?= $(shell (type ninja > /dev/null 2>&1 && echo "Ninja") || \
  33. echo "Unix Makefiles")
  34. DEPS_BUILD_DIR ?= .deps
  35. ifneq (1,$(words [$(DEPS_BUILD_DIR)]))
  36. $(error DEPS_BUILD_DIR must not contain whitespace)
  37. endif
  38. ifeq (,$(BUILD_TOOL))
  39. ifeq (Ninja,$(BUILD_TYPE))
  40. ifneq ($(shell $(CMAKE_PRG) --help 2>/dev/null | grep Ninja),)
  41. BUILD_TOOL := ninja
  42. else
  43. # User's version of CMake doesn't support Ninja
  44. BUILD_TOOL = $(MAKE)
  45. BUILD_TYPE := Unix Makefiles
  46. endif
  47. else
  48. BUILD_TOOL = $(MAKE)
  49. endif
  50. endif
  51. BUILD_CMD = $(BUILD_TOOL)
  52. ifneq ($(VERBOSE),)
  53. # Only need to handle Ninja here. Make will inherit the VERBOSE variable.
  54. ifeq ($(BUILD_TYPE),Ninja)
  55. BUILD_CMD += -v
  56. endif
  57. endif
  58. DEPS_CMAKE_FLAGS ?=
  59. # Back-compat: USE_BUNDLED_DEPS was the old name.
  60. USE_BUNDLED ?= $(USE_BUNDLED_DEPS)
  61. ifneq (,$(USE_BUNDLED))
  62. BUNDLED_CMAKE_FLAG := -DUSE_BUNDLED=$(USE_BUNDLED)
  63. endif
  64. ifneq (,$(findstring functionaltest-lua,$(MAKECMDGOALS)))
  65. BUNDLED_LUA_CMAKE_FLAG := -DUSE_BUNDLED_LUA=ON
  66. $(shell [ -x $(DEPS_BUILD_DIR)/usr/bin/lua ] || rm build/.ran-*)
  67. endif
  68. # For use where we want to make sure only a single job is run. This does issue
  69. # a warning, but we need to keep SCRIPTS argument.
  70. SINGLE_MAKE = export MAKEFLAGS= ; $(MAKE)
  71. nvim: build/.ran-cmake deps
  72. +$(BUILD_CMD) -C build
  73. libnvim: build/.ran-cmake deps
  74. +$(BUILD_CMD) -C build libnvim
  75. cmake:
  76. touch CMakeLists.txt
  77. $(MAKE) build/.ran-cmake
  78. build/.ran-cmake: | deps
  79. cd build && $(CMAKE_PRG) -G '$(BUILD_TYPE)' $(CMAKE_FLAGS) $(CMAKE_EXTRA_FLAGS) $(THIS_DIR)
  80. touch $@
  81. deps: | build/.ran-third-party-cmake
  82. ifeq ($(call filter-true,$(USE_BUNDLED)),)
  83. +$(BUILD_CMD) -C $(DEPS_BUILD_DIR)
  84. endif
  85. ifeq ($(call filter-true,$(USE_BUNDLED)),)
  86. $(DEPS_BUILD_DIR):
  87. mkdir -p "$@"
  88. build/.ran-third-party-cmake:: $(DEPS_BUILD_DIR)
  89. cd $(DEPS_BUILD_DIR) && \
  90. $(CMAKE_PRG) -G '$(BUILD_TYPE)' $(BUNDLED_CMAKE_FLAG) $(BUNDLED_LUA_CMAKE_FLAG) \
  91. $(DEPS_CMAKE_FLAGS) $(THIS_DIR)/third-party
  92. endif
  93. build/.ran-third-party-cmake::
  94. mkdir -p build
  95. touch $@
  96. # TODO: cmake 3.2+ add_custom_target() has a USES_TERMINAL flag.
  97. oldtest: | nvim build/runtime/doc/tags
  98. +$(SINGLE_MAKE) -C src/nvim/testdir clean
  99. ifeq ($(strip $(TEST_FILE)),)
  100. +$(SINGLE_MAKE) -C src/nvim/testdir NVIM_PRG="$(realpath build/bin/nvim)" $(MAKEOVERRIDES)
  101. else
  102. @# Handle TEST_FILE=test_foo{,.res,.vim}.
  103. +$(SINGLE_MAKE) -C src/nvim/testdir NVIM_PRG="$(realpath build/bin/nvim)" SCRIPTS= $(MAKEOVERRIDES) $(patsubst %.vim,%,$(patsubst %.res,%,$(TEST_FILE)))
  104. endif
  105. # Build oldtest by specifying the relative .vim filename.
  106. .PHONY: phony_force
  107. src/nvim/testdir/%.vim: phony_force
  108. +$(SINGLE_MAKE) -C src/nvim/testdir NVIM_PRG="$(realpath build/bin/nvim)" SCRIPTS= $(MAKEOVERRIDES) $(patsubst src/nvim/testdir/%.vim,%,$@)
  109. build/runtime/doc/tags helptags: | nvim
  110. +$(BUILD_CMD) -C build runtime/doc/tags
  111. # Builds help HTML _and_ checks for invalid help tags.
  112. helphtml: | nvim build/runtime/doc/tags
  113. +$(BUILD_CMD) -C build doc_html
  114. functionaltest: | nvim
  115. +$(BUILD_CMD) -C build functionaltest
  116. functionaltest-lua: | nvim
  117. +$(BUILD_CMD) -C build functionaltest-lua
  118. lualint: | build/.ran-cmake deps
  119. $(BUILD_CMD) -C build lualint
  120. shlint:
  121. @shellcheck --version | head -n 2
  122. shellcheck scripts/vim-patch.sh
  123. _opt_shlint:
  124. @command -v shellcheck && { $(MAKE) shlint; exit $$?; } \
  125. || echo "SKIP: shlint (shellcheck not found)"
  126. pylint:
  127. flake8 contrib/ scripts/ src/ test/
  128. # Run pylint only if flake8 is installed.
  129. _opt_pylint:
  130. @command -v flake8 && { $(MAKE) pylint; exit $$?; } \
  131. || echo "SKIP: pylint (flake8 not found)"
  132. unittest: | nvim
  133. +$(BUILD_CMD) -C build unittest
  134. benchmark: | nvim
  135. +$(BUILD_CMD) -C build benchmark
  136. test: functionaltest unittest
  137. clean:
  138. +test -d build && $(BUILD_CMD) -C build clean || true
  139. $(MAKE) -C src/nvim/testdir clean
  140. $(MAKE) -C runtime/doc clean
  141. $(MAKE) -C runtime/indent clean
  142. distclean:
  143. rm -rf $(DEPS_BUILD_DIR) build
  144. $(MAKE) clean
  145. install: checkprefix nvim
  146. +$(BUILD_CMD) -C build install
  147. clint: build/.ran-cmake
  148. +$(BUILD_CMD) -C build clint
  149. clint-full: build/.ran-cmake
  150. +$(BUILD_CMD) -C build clint-full
  151. check-single-includes: build/.ran-cmake
  152. +$(BUILD_CMD) -C build check-single-includes
  153. generated-sources: build/.ran-cmake
  154. +$(BUILD_CMD) -C build generated-sources
  155. appimage:
  156. bash scripts/genappimage.sh
  157. # Build an appimage with embedded update information.
  158. # appimage-nightly: for nightly builds
  159. # appimage-latest: for a release
  160. appimage-%:
  161. bash scripts/genappimage.sh $*
  162. lint: check-single-includes clint lualint _opt_pylint _opt_shlint
  163. # Generic pattern rules, allowing for `make build/bin/nvim` etc.
  164. # Does not work with "Unix Makefiles".
  165. ifeq ($(BUILD_TYPE),Ninja)
  166. build/%: phony_force
  167. $(BUILD_CMD) -C build $(patsubst build/%,%,$@)
  168. $(DEPS_BUILD_DIR)/%: phony_force
  169. $(BUILD_CMD) -C $(DEPS_BUILD_DIR) $(patsubst $(DEPS_BUILD_DIR)/%,%,$@)
  170. endif
  171. .PHONY: test lualint pylint shlint functionaltest unittest lint clint clean distclean nvim libnvim cmake deps install appimage checkprefix