Makefile 5.5 KB

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