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.

212 lines
5.9KB

  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. +$(SINGLE_MAKE) -C src/nvim/testdir NVIM_PRG="$(realpath build/bin/nvim)" NEW_TESTS=$(TEST_FILE) SCRIPTS= $(MAKEOVERRIDES)
  103. endif
  104. build/runtime/doc/tags helptags: | nvim
  105. +$(BUILD_CMD) -C build runtime/doc/tags
  106. # Builds help HTML _and_ checks for invalid help tags.
  107. helphtml: | nvim build/runtime/doc/tags
  108. +$(BUILD_CMD) -C build doc_html
  109. functionaltest: | nvim
  110. +$(BUILD_CMD) -C build functionaltest
  111. functionaltest-lua: | nvim
  112. +$(BUILD_CMD) -C build functionaltest-lua
  113. lualint: | build/.ran-cmake deps
  114. $(BUILD_CMD) -C build lualint
  115. shlint:
  116. @shellcheck --version | head -n 2
  117. shellcheck scripts/vim-patch.sh
  118. _opt_shlint:
  119. @command -v shellcheck && { $(MAKE) shlint; exit $$?; } \
  120. || echo "SKIP: shlint (shellcheck not found)"
  121. pylint:
  122. flake8 contrib/ scripts/ src/ test/
  123. # Run pylint only if flake8 is installed.
  124. _opt_pylint:
  125. @command -v flake8 && { $(MAKE) pylint; exit $$?; } \
  126. || echo "SKIP: pylint (flake8 not found)"
  127. unittest: | nvim
  128. +$(BUILD_CMD) -C build unittest
  129. benchmark: | nvim
  130. +$(BUILD_CMD) -C build benchmark
  131. test: functionaltest unittest
  132. clean:
  133. +test -d build && $(BUILD_CMD) -C build clean || true
  134. $(MAKE) -C src/nvim/testdir clean
  135. $(MAKE) -C runtime/doc clean
  136. $(MAKE) -C runtime/indent clean
  137. distclean:
  138. rm -rf $(DEPS_BUILD_DIR) build
  139. $(MAKE) clean
  140. install: checkprefix nvim
  141. +$(BUILD_CMD) -C build install
  142. clint: build/.ran-cmake
  143. +$(BUILD_CMD) -C build clint
  144. clint-full: build/.ran-cmake
  145. +$(BUILD_CMD) -C build clint-full
  146. check-single-includes: build/.ran-cmake
  147. +$(BUILD_CMD) -C build check-single-includes
  148. generated-sources: build/.ran-cmake
  149. +$(BUILD_CMD) -C build generated-sources
  150. appimage:
  151. bash scripts/genappimage.sh
  152. # Build an appimage with embedded update information.
  153. # appimage-nightly: for nightly builds
  154. # appimage-latest: for a release
  155. appimage-%:
  156. bash scripts/genappimage.sh $*
  157. lint: check-single-includes clint lualint _opt_pylint _opt_shlint
  158. # Generic pattern rules, allowing for `make build/bin/nvim` etc.
  159. # Does not work with "Unix Makefiles".
  160. ifeq ($(BUILD_TYPE),Ninja)
  161. build/%:
  162. $(BUILD_CMD) -C build $(patsubst build/%,%,$@)
  163. $(DEPS_BUILD_DIR)/%:
  164. $(BUILD_CMD) -C $(DEPS_BUILD_DIR) $(patsubst $(DEPS_BUILD_DIR)/%,%,$@)
  165. endif
  166. .PHONY: test lualint pylint shlint functionaltest unittest lint clint clean distclean nvim libnvim cmake deps install appimage checkprefix