Makefile 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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. pylint:
  116. flake8 contrib/ scripts/ src/ test/
  117. # Run pylint only if flake8 is installed.
  118. _opt_pylint:
  119. @command -v flake8 && { $(MAKE) pylint; exit $$?; } \
  120. || echo "SKIP: pylint (flake8 not found)"
  121. unittest: | nvim
  122. +$(BUILD_CMD) -C build unittest
  123. benchmark: | nvim
  124. +$(BUILD_CMD) -C build benchmark
  125. test: functionaltest unittest
  126. clean:
  127. +test -d build && $(BUILD_CMD) -C build clean || true
  128. $(MAKE) -C src/nvim/testdir clean
  129. $(MAKE) -C runtime/doc clean
  130. distclean:
  131. rm -rf $(DEPS_BUILD_DIR) build
  132. $(MAKE) clean
  133. install: checkprefix nvim
  134. +$(BUILD_CMD) -C build install
  135. clint: build/.ran-cmake
  136. +$(BUILD_CMD) -C build clint
  137. clint-full: build/.ran-cmake
  138. +$(BUILD_CMD) -C build clint-full
  139. check-single-includes: build/.ran-cmake
  140. +$(BUILD_CMD) -C build check-single-includes
  141. generated-sources: build/.ran-cmake
  142. +$(BUILD_CMD) -C build generated-sources
  143. appimage:
  144. bash scripts/genappimage.sh
  145. # Build an appimage with embedded update information.
  146. # appimage-nightly: for nightly builds
  147. # appimage-latest: for a release
  148. appimage-%:
  149. bash scripts/genappimage.sh $*
  150. lint: check-single-includes clint lualint _opt_pylint
  151. # Generic pattern rules, allowing for `make build/bin/nvim` etc.
  152. # Does not work with "Unix Makefiles".
  153. ifeq ($(BUILD_TYPE),Ninja)
  154. build/%:
  155. $(BUILD_CMD) -C build $(patsubst build/%,%,$@)
  156. $(DEPS_BUILD_DIR)/%:
  157. $(BUILD_CMD) -C $(DEPS_BUILD_DIR) $(patsubst $(DEPS_BUILD_DIR)/%,%,$@)
  158. endif
  159. .PHONY: test lualint pylint functionaltest unittest lint clint clean distclean nvim libnvim cmake deps install appimage checkprefix