Makefile 5.1 KB

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