Makefile 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. MAKEFILE_PATH := $(abspath $(lastword $(MAKEFILE_LIST)))
  2. MAKEFILE_DIR := $(dir $(MAKEFILE_PATH))
  3. filter-false = $(strip $(filter-out 0 off OFF false FALSE,$1))
  4. filter-true = $(strip $(filter-out 1 on ON true TRUE,$1))
  5. # See contrib/local.mk.example
  6. -include local.mk
  7. all: nvim
  8. CMAKE ?= $(shell (command -v cmake3 || echo cmake))
  9. CMAKE_FLAGS := -DCMAKE_BUILD_TYPE=$(CMAKE_BUILD_TYPE)
  10. # Extra CMake flags which extend the default set
  11. CMAKE_EXTRA_FLAGS ?=
  12. NVIM_PRG := $(MAKEFILE_DIR)/build/bin/nvim
  13. # CMAKE_INSTALL_PREFIX
  14. # - May be passed directly or as part of CMAKE_EXTRA_FLAGS.
  15. # - `checkprefix` target checks that it matches the CMake-cached value. #9615
  16. ifneq (,$(CMAKE_INSTALL_PREFIX)$(CMAKE_EXTRA_FLAGS))
  17. CMAKE_INSTALL_PREFIX := $(shell echo $(CMAKE_EXTRA_FLAGS) | 2>/dev/null \
  18. grep -o 'CMAKE_INSTALL_PREFIX=[^ ]\+' | cut -d '=' -f2)
  19. endif
  20. ifneq (,$(CMAKE_INSTALL_PREFIX))
  21. override CMAKE_EXTRA_FLAGS += -DCMAKE_INSTALL_PREFIX=$(CMAKE_INSTALL_PREFIX)
  22. checkprefix:
  23. @if [ -f build/.ran-cmake ]; then \
  24. cached_prefix=$(shell $(CMAKE) -L -N build | 2>/dev/null grep 'CMAKE_INSTALL_PREFIX' | cut -d '=' -f2); \
  25. if ! [ "$(CMAKE_INSTALL_PREFIX)" = "$$cached_prefix" ]; then \
  26. printf "Re-running CMake: CMAKE_INSTALL_PREFIX '$(CMAKE_INSTALL_PREFIX)' does not match cached value '%s'.\n" "$$cached_prefix"; \
  27. $(RM) build/.ran-cmake; \
  28. fi \
  29. fi
  30. else
  31. checkprefix: ;
  32. endif
  33. CMAKE_GENERATOR ?= $(shell (command -v ninja > /dev/null 2>&1 && echo "Ninja") || \
  34. echo "Unix Makefiles")
  35. DEPS_BUILD_DIR ?= .deps
  36. ifneq (1,$(words [$(DEPS_BUILD_DIR)]))
  37. $(error DEPS_BUILD_DIR must not contain whitespace)
  38. endif
  39. ifeq (,$(BUILD_TOOL))
  40. ifeq (Ninja,$(CMAKE_GENERATOR))
  41. BUILD_TOOL = ninja
  42. else
  43. BUILD_TOOL = $(MAKE)
  44. endif
  45. endif
  46. DEPS_CMAKE_FLAGS ?=
  47. USE_BUNDLED ?=
  48. ifneq (,$(USE_BUNDLED))
  49. BUNDLED_CMAKE_FLAG := -DUSE_BUNDLED=$(USE_BUNDLED)
  50. endif
  51. ifneq (,$(findstring functionaltest-lua,$(MAKECMDGOALS)))
  52. BUNDLED_LUA_CMAKE_FLAG := -DUSE_BUNDLED_LUA=ON
  53. $(shell [ -x $(DEPS_BUILD_DIR)/usr/bin/lua ] || rm build/.ran-*)
  54. endif
  55. # For use where we want to make sure only a single job is run. This does issue
  56. # a warning, but we need to keep SCRIPTS argument.
  57. SINGLE_MAKE = export MAKEFLAGS= ; $(MAKE)
  58. nvim: build/.ran-cmake deps
  59. $(BUILD_TOOL) -C build
  60. libnvim: build/.ran-cmake deps
  61. $(BUILD_TOOL) -C build libnvim
  62. cmake:
  63. touch CMakeLists.txt
  64. $(MAKE) build/.ran-cmake
  65. build/.ran-cmake: | deps
  66. $(CMAKE) -B build -G '$(CMAKE_GENERATOR)' $(CMAKE_FLAGS) $(CMAKE_EXTRA_FLAGS) $(MAKEFILE_DIR)
  67. touch $@
  68. deps: | build/.ran-deps-cmake
  69. ifeq ($(call filter-true,$(USE_BUNDLED)),)
  70. $(BUILD_TOOL) -C $(DEPS_BUILD_DIR)
  71. endif
  72. ifeq ($(call filter-true,$(USE_BUNDLED)),)
  73. $(DEPS_BUILD_DIR):
  74. mkdir -p "$@"
  75. build/.ran-deps-cmake:: $(DEPS_BUILD_DIR)
  76. $(CMAKE) -S $(MAKEFILE_DIR)/cmake.deps -B $(DEPS_BUILD_DIR) -G '$(CMAKE_GENERATOR)' \
  77. $(BUNDLED_CMAKE_FLAG) $(BUNDLED_LUA_CMAKE_FLAG) $(DEPS_CMAKE_FLAGS)
  78. endif
  79. build/.ran-deps-cmake::
  80. mkdir -p build
  81. touch $@
  82. # TODO: cmake 3.2+ add_custom_target() has a USES_TERMINAL flag.
  83. oldtest: | nvim
  84. $(SINGLE_MAKE) -C test/old/testdir clean
  85. ifeq ($(strip $(TEST_FILE)),)
  86. $(SINGLE_MAKE) -C test/old/testdir NVIM_PRG=$(NVIM_PRG) $(MAKEOVERRIDES)
  87. else
  88. @# Handle TEST_FILE=test_foo{,.res,.vim}.
  89. $(SINGLE_MAKE) -C test/old/testdir NVIM_PRG=$(NVIM_PRG) SCRIPTS= $(MAKEOVERRIDES) $(patsubst %.vim,%,$(patsubst %.res,%,$(TEST_FILE)))
  90. endif
  91. # Build oldtest by specifying the relative .vim filename.
  92. .PHONY: phony_force
  93. test/old/testdir/%.vim: phony_force nvim
  94. $(SINGLE_MAKE) -C test/old/testdir NVIM_PRG=$(NVIM_PRG) SCRIPTS= $(MAKEOVERRIDES) $(patsubst test/old/testdir/%.vim,%,$@)
  95. functionaltest-lua: | nvim
  96. $(BUILD_TOOL) -C build functionaltest
  97. FORMAT=formatc formatlua format
  98. LINT=lintlua lintsh lintc clang-analyzer lintcommit lintdoc lint
  99. TEST=functionaltest unittest
  100. generated-sources benchmark $(FORMAT) $(LINT) $(TEST) doc: | build/.ran-cmake
  101. $(CMAKE) --build build --target $@
  102. test: $(TEST)
  103. iwyu: build/.ran-cmake
  104. $(CMAKE) --preset iwyu
  105. $(CMAKE) --build build > build/iwyu.log
  106. iwyu-fix-includes --only_re="src/nvim" --ignore_re="(src/nvim/eval/encode.c\
  107. |src/nvim/auto/\
  108. |src/nvim/os/lang.c\
  109. |src/nvim/map.c\
  110. )" --nosafe_headers < build/iwyu.log
  111. $(CMAKE) -B build -U ENABLE_IWYU
  112. $(CMAKE) --build build
  113. clean:
  114. test -d build && $(BUILD_TOOL) -C build clean || true
  115. $(MAKE) -C test/old/testdir clean
  116. $(MAKE) -C runtime/indent clean
  117. distclean:
  118. rm -rf $(DEPS_BUILD_DIR) build
  119. $(MAKE) clean
  120. install: checkprefix nvim
  121. $(BUILD_TOOL) -C build install
  122. appimage:
  123. bash scripts/genappimage.sh
  124. # Build an appimage with embedded update information.
  125. # appimage-nightly: for nightly builds
  126. # appimage-latest: for a release
  127. appimage-%:
  128. bash scripts/genappimage.sh $*
  129. # Generic pattern rules, allowing for `make build/bin/nvim` etc.
  130. # Does not work with "Unix Makefiles".
  131. ifeq ($(CMAKE_GENERATOR),Ninja)
  132. build/%: phony_force
  133. $(BUILD_TOOL) -C build $(patsubst build/%,%,$@)
  134. $(DEPS_BUILD_DIR)/%: phony_force
  135. $(BUILD_TOOL) -C $(DEPS_BUILD_DIR) $(patsubst $(DEPS_BUILD_DIR)/%,%,$@)
  136. endif
  137. .PHONY: test clean distclean nvim libnvim cmake deps install appimage checkprefix benchmark $(FORMAT) $(LINT) $(TEST)