Makefile 5.2 KB

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