Makefile 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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. # Only need to handle Ninja here. Make will inherit the VERBOSE variable, and the -j and -n flags.
  53. ifeq ($(BUILD_TYPE),Ninja)
  54. ifneq ($(VERBOSE),)
  55. BUILD_CMD += -v
  56. endif
  57. BUILD_CMD += $(shell printf '%s' '$(MAKEFLAGS)' | grep -o -- '-j[0-9]\+')
  58. ifeq (n,$(findstring n,$(firstword -$(MAKEFLAGS))))
  59. BUILD_CMD += -n
  60. endif
  61. endif
  62. DEPS_CMAKE_FLAGS ?=
  63. # Back-compat: USE_BUNDLED_DEPS was the old name.
  64. USE_BUNDLED ?= $(USE_BUNDLED_DEPS)
  65. ifneq (,$(USE_BUNDLED))
  66. BUNDLED_CMAKE_FLAG := -DUSE_BUNDLED=$(USE_BUNDLED)
  67. endif
  68. ifneq (,$(findstring functionaltest-lua,$(MAKECMDGOALS)))
  69. BUNDLED_LUA_CMAKE_FLAG := -DUSE_BUNDLED_LUA=ON
  70. $(shell [ -x $(DEPS_BUILD_DIR)/usr/bin/lua ] || rm build/.ran-*)
  71. endif
  72. # For use where we want to make sure only a single job is run. This does issue
  73. # a warning, but we need to keep SCRIPTS argument.
  74. SINGLE_MAKE = export MAKEFLAGS= ; $(MAKE)
  75. nvim: build/.ran-cmake deps
  76. +$(BUILD_CMD) -C build
  77. libnvim: build/.ran-cmake deps
  78. +$(BUILD_CMD) -C build libnvim
  79. cmake:
  80. touch CMakeLists.txt
  81. $(MAKE) build/.ran-cmake
  82. build/.ran-cmake: | deps
  83. cd build && $(CMAKE_PRG) -G '$(BUILD_TYPE)' $(CMAKE_FLAGS) $(CMAKE_EXTRA_FLAGS) $(THIS_DIR)
  84. touch $@
  85. deps: | build/.ran-third-party-cmake
  86. ifeq ($(call filter-true,$(USE_BUNDLED)),)
  87. +$(BUILD_CMD) -C $(DEPS_BUILD_DIR)
  88. endif
  89. ifeq ($(call filter-true,$(USE_BUNDLED)),)
  90. $(DEPS_BUILD_DIR):
  91. mkdir -p "$@"
  92. build/.ran-third-party-cmake:: $(DEPS_BUILD_DIR)
  93. cd $(DEPS_BUILD_DIR) && \
  94. $(CMAKE_PRG) -G '$(BUILD_TYPE)' $(BUNDLED_CMAKE_FLAG) $(BUNDLED_LUA_CMAKE_FLAG) \
  95. $(DEPS_CMAKE_FLAGS) $(THIS_DIR)/third-party
  96. endif
  97. build/.ran-third-party-cmake::
  98. mkdir -p build
  99. touch $@
  100. # TODO: cmake 3.2+ add_custom_target() has a USES_TERMINAL flag.
  101. oldtest: | nvim build/runtime/doc/tags
  102. +$(SINGLE_MAKE) -C src/nvim/testdir clean
  103. ifeq ($(strip $(TEST_FILE)),)
  104. +$(SINGLE_MAKE) -C src/nvim/testdir NVIM_PRG="$(realpath build/bin/nvim)" $(MAKEOVERRIDES)
  105. else
  106. @# Handle TEST_FILE=test_foo{,.res,.vim}.
  107. +$(SINGLE_MAKE) -C src/nvim/testdir NVIM_PRG="$(realpath build/bin/nvim)" SCRIPTS= $(MAKEOVERRIDES) $(patsubst %.vim,%,$(patsubst %.res,%,$(TEST_FILE)))
  108. endif
  109. # Build oldtest by specifying the relative .vim filename.
  110. .PHONY: phony_force
  111. src/nvim/testdir/%.vim: phony_force
  112. +$(SINGLE_MAKE) -C src/nvim/testdir NVIM_PRG="$(realpath build/bin/nvim)" SCRIPTS= $(MAKEOVERRIDES) $(patsubst src/nvim/testdir/%.vim,%,$@)
  113. build/runtime/doc/tags helptags: | nvim
  114. +$(BUILD_CMD) -C build runtime/doc/tags
  115. # Builds help HTML _and_ checks for invalid help tags.
  116. helphtml: | nvim build/runtime/doc/tags
  117. +$(BUILD_CMD) -C build doc_html
  118. functionaltest: | nvim
  119. +$(BUILD_CMD) -C build functionaltest
  120. functionaltest-lua: | nvim
  121. +$(BUILD_CMD) -C build functionaltest-lua
  122. lualint: | build/.ran-cmake deps
  123. $(BUILD_CMD) -C build lualint
  124. shlint:
  125. @shellcheck --version | head -n 2
  126. shellcheck scripts/vim-patch.sh
  127. _opt_shlint:
  128. @command -v shellcheck && { $(MAKE) shlint; exit $$?; } \
  129. || echo "SKIP: shlint (shellcheck not found)"
  130. pylint:
  131. flake8 contrib/ scripts/ src/ test/
  132. # Run pylint only if flake8 is installed.
  133. _opt_pylint:
  134. @command -v flake8 && { $(MAKE) pylint; exit $$?; } \
  135. || echo "SKIP: pylint (flake8 not found)"
  136. unittest: | nvim
  137. +$(BUILD_CMD) -C build unittest
  138. benchmark: | nvim
  139. +$(BUILD_CMD) -C build benchmark
  140. test: functionaltest unittest
  141. clean:
  142. +test -d build && $(BUILD_CMD) -C build clean || true
  143. $(MAKE) -C src/nvim/testdir clean
  144. $(MAKE) -C runtime/doc clean
  145. $(MAKE) -C runtime/indent clean
  146. distclean:
  147. rm -rf $(DEPS_BUILD_DIR) build
  148. $(MAKE) clean
  149. install: checkprefix nvim
  150. +$(BUILD_CMD) -C build install
  151. clint: build/.ran-cmake
  152. +$(BUILD_CMD) -C build clint
  153. clint-full: build/.ran-cmake
  154. +$(BUILD_CMD) -C build clint-full
  155. check-single-includes: build/.ran-cmake
  156. +$(BUILD_CMD) -C build check-single-includes
  157. generated-sources: build/.ran-cmake
  158. +$(BUILD_CMD) -C build generated-sources
  159. appimage:
  160. bash scripts/genappimage.sh
  161. # Build an appimage with embedded update information.
  162. # appimage-nightly: for nightly builds
  163. # appimage-latest: for a release
  164. appimage-%:
  165. bash scripts/genappimage.sh $*
  166. lint: check-single-includes clint lualint _opt_pylint _opt_shlint
  167. # Generic pattern rules, allowing for `make build/bin/nvim` etc.
  168. # Does not work with "Unix Makefiles".
  169. ifeq ($(BUILD_TYPE),Ninja)
  170. build/%: phony_force
  171. $(BUILD_CMD) -C build $(patsubst build/%,%,$@)
  172. $(DEPS_BUILD_DIR)/%: phony_force
  173. $(BUILD_CMD) -C $(DEPS_BUILD_DIR) $(patsubst $(DEPS_BUILD_DIR)/%,%,$@)
  174. endif
  175. .PHONY: test lualint pylint shlint functionaltest unittest lint clint clean distclean nvim libnvim cmake deps install appimage checkprefix