Makefile 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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_PRG ?= $(shell (command -v cmake3 || echo cmake))
  9. CMAKE_BUILD_TYPE ?= Debug
  10. CMAKE_FLAGS := -DCMAKE_BUILD_TYPE=$(CMAKE_BUILD_TYPE)
  11. # Extra CMake flags which extend the default set
  12. CMAKE_EXTRA_FLAGS ?=
  13. NVIM_PRG := $(MAKEFILE_DIR)/build/bin/nvim
  14. # CMAKE_INSTALL_PREFIX
  15. # - May be passed directly or as part of CMAKE_EXTRA_FLAGS.
  16. # - `checkprefix` target checks that it matches the CMake-cached value. #9615
  17. ifneq (,$(CMAKE_INSTALL_PREFIX)$(CMAKE_EXTRA_FLAGS))
  18. CMAKE_INSTALL_PREFIX := $(shell echo $(CMAKE_EXTRA_FLAGS) | 2>/dev/null \
  19. grep -o 'CMAKE_INSTALL_PREFIX=[^ ]\+' | cut -d '=' -f2)
  20. endif
  21. ifneq (,$(CMAKE_INSTALL_PREFIX))
  22. override CMAKE_EXTRA_FLAGS += -DCMAKE_INSTALL_PREFIX=$(CMAKE_INSTALL_PREFIX)
  23. checkprefix:
  24. @if [ -f build/.ran-cmake ]; then \
  25. cached_prefix=$(shell $(CMAKE_PRG) -L -N build | 2>/dev/null grep 'CMAKE_INSTALL_PREFIX' | cut -d '=' -f2); \
  26. if ! [ "$(CMAKE_INSTALL_PREFIX)" = "$$cached_prefix" ]; then \
  27. printf "Re-running CMake: CMAKE_INSTALL_PREFIX '$(CMAKE_INSTALL_PREFIX)' does not match cached value '%s'.\n" "$$cached_prefix"; \
  28. $(RM) build/.ran-cmake; \
  29. fi \
  30. fi
  31. else
  32. checkprefix: ;
  33. endif
  34. CMAKE_GENERATOR ?= $(shell (command -v ninja > /dev/null 2>&1 && echo "Ninja") || \
  35. echo "Unix Makefiles")
  36. DEPS_BUILD_DIR ?= .deps
  37. ifneq (1,$(words [$(DEPS_BUILD_DIR)]))
  38. $(error DEPS_BUILD_DIR must not contain whitespace)
  39. endif
  40. ifeq (,$(BUILD_TOOL))
  41. ifeq (Ninja,$(CMAKE_GENERATOR))
  42. BUILD_TOOL = ninja
  43. else
  44. BUILD_TOOL = $(MAKE)
  45. endif
  46. endif
  47. # Only need to handle Ninja here. Make will inherit the VERBOSE variable, and the -j, -l, and -n flags.
  48. ifeq ($(CMAKE_GENERATOR),Ninja)
  49. ifneq ($(VERBOSE),)
  50. BUILD_TOOL += -v
  51. endif
  52. BUILD_TOOL += $(shell printf '%s' '$(MAKEFLAGS)' | grep -o -- ' *-[jl][0-9]\+ *')
  53. ifeq (n,$(findstring n,$(firstword -$(MAKEFLAGS))))
  54. BUILD_TOOL += -n
  55. endif
  56. endif
  57. DEPS_CMAKE_FLAGS ?=
  58. # Back-compat: USE_BUNDLED_DEPS was the old name.
  59. USE_BUNDLED ?= $(USE_BUNDLED_DEPS)
  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. +$(BUILD_TOOL) -C build
  72. libnvim: build/.ran-cmake deps
  73. +$(BUILD_TOOL) -C build libnvim
  74. cmake:
  75. touch CMakeLists.txt
  76. $(MAKE) build/.ran-cmake
  77. build/.ran-cmake: | deps
  78. cd build && $(CMAKE_PRG) -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. +$(BUILD_TOOL) -C $(DEPS_BUILD_DIR)
  83. endif
  84. ifeq ($(call filter-true,$(USE_BUNDLED)),)
  85. $(DEPS_BUILD_DIR):
  86. mkdir -p "$@"
  87. build/.ran-deps-cmake:: $(DEPS_BUILD_DIR)
  88. cd $(DEPS_BUILD_DIR) && \
  89. $(CMAKE_PRG) -G '$(CMAKE_GENERATOR)' $(BUNDLED_CMAKE_FLAG) $(BUNDLED_LUA_CMAKE_FLAG) \
  90. $(DEPS_CMAKE_FLAGS) $(MAKEFILE_DIR)/cmake.deps
  91. endif
  92. build/.ran-deps-cmake::
  93. mkdir -p build
  94. touch $@
  95. # TODO: cmake 3.2+ add_custom_target() has a USES_TERMINAL flag.
  96. oldtest: | nvim build/runtime/doc/tags
  97. +$(SINGLE_MAKE) -C src/nvim/testdir clean
  98. ifeq ($(strip $(TEST_FILE)),)
  99. +$(SINGLE_MAKE) -C src/nvim/testdir NVIM_PRG=$(NVIM_PRG) $(MAKEOVERRIDES)
  100. else
  101. @# Handle TEST_FILE=test_foo{,.res,.vim}.
  102. +$(SINGLE_MAKE) -C src/nvim/testdir NVIM_PRG=$(NVIM_PRG) SCRIPTS= $(MAKEOVERRIDES) $(patsubst %.vim,%,$(patsubst %.res,%,$(TEST_FILE)))
  103. endif
  104. # Build oldtest by specifying the relative .vim filename.
  105. .PHONY: phony_force
  106. src/nvim/testdir/%.vim: phony_force
  107. +$(SINGLE_MAKE) -C src/nvim/testdir NVIM_PRG=$(NVIM_PRG) SCRIPTS= $(MAKEOVERRIDES) $(patsubst src/nvim/testdir/%.vim,%,$@)
  108. functionaltest functionaltest-lua unittest benchmark: | nvim
  109. $(BUILD_TOOL) -C build $@
  110. lintlua lintsh lintpy lintuncrustify lintc lintcfull check-single-includes generated-sources lintcommit lint formatc formatlua format: | build/.ran-cmake
  111. $(CMAKE_PRG) --build build --target $@
  112. test: functionaltest unittest
  113. clean:
  114. +test -d build && $(BUILD_TOOL) -C build clean || true
  115. $(MAKE) -C src/nvim/testdir clean
  116. $(MAKE) -C runtime/doc clean
  117. $(MAKE) -C runtime/indent clean
  118. distclean:
  119. rm -rf $(DEPS_BUILD_DIR) build
  120. $(MAKE) clean
  121. install: checkprefix nvim
  122. +$(BUILD_TOOL) -C build install
  123. appimage:
  124. bash scripts/genappimage.sh
  125. # Build an appimage with embedded update information.
  126. # appimage-nightly: for nightly builds
  127. # appimage-latest: for a release
  128. appimage-%:
  129. bash scripts/genappimage.sh $*
  130. # Generic pattern rules, allowing for `make build/bin/nvim` etc.
  131. # Does not work with "Unix Makefiles".
  132. ifeq ($(CMAKE_GENERATOR),Ninja)
  133. build/%: phony_force
  134. $(BUILD_TOOL) -C build $(patsubst build/%,%,$@)
  135. $(DEPS_BUILD_DIR)/%: phony_force
  136. $(BUILD_TOOL) -C $(DEPS_BUILD_DIR) $(patsubst $(DEPS_BUILD_DIR)/%,%,$@)
  137. endif
  138. .PHONY: test lintlua lintpy lintsh functionaltest unittest lint lintc clean distclean nvim libnvim cmake deps install appimage checkprefix lintcommit formatc formatlua format