Makefile 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. THIS_DIR = $(shell pwd)
  2. filter-false = $(strip $(filter-out 0 off OFF false FALSE,$1))
  3. filter-true = $(strip $(filter-out 1 on ON true TRUE,$1))
  4. # See contrib/local.mk.example
  5. -include local.mk
  6. CMAKE_PRG ?= $(shell (command -v cmake3 || echo cmake))
  7. CMAKE_BUILD_TYPE ?= Debug
  8. CMAKE_FLAGS := -DCMAKE_BUILD_TYPE=$(CMAKE_BUILD_TYPE)
  9. BUILD_TYPE ?= $(shell (type ninja > /dev/null 2>&1 && echo "Ninja") || \
  10. echo "Unix Makefiles")
  11. DEPS_BUILD_DIR ?= .deps
  12. ifneq (1,$(words [$(DEPS_BUILD_DIR)]))
  13. $(error DEPS_BUILD_DIR must not contain whitespace)
  14. endif
  15. ifeq (,$(BUILD_TOOL))
  16. ifeq (Ninja,$(BUILD_TYPE))
  17. ifneq ($(shell $(CMAKE_PRG) --help 2>/dev/null | grep Ninja),)
  18. BUILD_TOOL := ninja
  19. else
  20. # User's version of CMake doesn't support Ninja
  21. BUILD_TOOL = $(MAKE)
  22. BUILD_TYPE := Unix Makefiles
  23. endif
  24. else
  25. BUILD_TOOL = $(MAKE)
  26. endif
  27. endif
  28. ifneq ($(VERBOSE),)
  29. # Only need to handle Ninja here. Make will inherit the VERBOSE variable.
  30. ifeq ($(BUILD_TYPE),Ninja)
  31. VERBOSE_FLAG := -v
  32. endif
  33. endif
  34. BUILD_CMD = $(BUILD_TOOL) $(VERBOSE_FLAG)
  35. # Extra CMake flags which extend the default set
  36. CMAKE_EXTRA_FLAGS ?=
  37. DEPS_CMAKE_FLAGS ?=
  38. # Back-compat: USE_BUNDLED_DEPS was the old name.
  39. USE_BUNDLED ?= $(USE_BUNDLED_DEPS)
  40. ifneq (,$(USE_BUNDLED))
  41. BUNDLED_CMAKE_FLAG := -DUSE_BUNDLED=$(USE_BUNDLED)
  42. endif
  43. ifneq (,$(findstring functionaltest-lua,$(MAKECMDGOALS)))
  44. BUNDLED_LUA_CMAKE_FLAG := -DUSE_BUNDLED_LUA=ON
  45. $(shell [ -x $(DEPS_BUILD_DIR)/usr/bin/lua ] || rm build/.ran-*)
  46. endif
  47. # For use where we want to make sure only a single job is run. This does issue
  48. # a warning, but we need to keep SCRIPTS argument.
  49. SINGLE_MAKE = export MAKEFLAGS= ; $(MAKE)
  50. all: nvim
  51. nvim: build/.ran-cmake deps
  52. +$(BUILD_CMD) -C build
  53. libnvim: build/.ran-cmake deps
  54. +$(BUILD_CMD) -C build libnvim
  55. cmake:
  56. touch CMakeLists.txt
  57. $(MAKE) build/.ran-cmake
  58. build/.ran-cmake: | deps
  59. cd build && $(CMAKE_PRG) -G '$(BUILD_TYPE)' $(CMAKE_FLAGS) $(CMAKE_EXTRA_FLAGS) $(THIS_DIR)
  60. touch $@
  61. deps: | build/.ran-third-party-cmake
  62. ifeq ($(call filter-true,$(USE_BUNDLED)),)
  63. +$(BUILD_CMD) -C $(DEPS_BUILD_DIR)
  64. endif
  65. build/.ran-third-party-cmake:
  66. ifeq ($(call filter-true,$(USE_BUNDLED)),)
  67. mkdir -p $(DEPS_BUILD_DIR)
  68. cd $(DEPS_BUILD_DIR) && \
  69. $(CMAKE_PRG) -G '$(BUILD_TYPE)' $(BUNDLED_CMAKE_FLAG) $(BUNDLED_LUA_CMAKE_FLAG) \
  70. $(DEPS_CMAKE_FLAGS) $(THIS_DIR)/third-party
  71. endif
  72. mkdir -p build
  73. touch $@
  74. # TODO: cmake 3.2+ add_custom_target() has a USES_TERMINAL flag.
  75. oldtest: | nvim helptags
  76. +$(SINGLE_MAKE) -C src/nvim/testdir clean
  77. ifeq ($(strip $(TEST_FILE)),)
  78. +$(SINGLE_MAKE) -C src/nvim/testdir NVIM_PRG="$(realpath build/bin/nvim)" $(MAKEOVERRIDES)
  79. else
  80. +$(SINGLE_MAKE) -C src/nvim/testdir NVIM_PRG="$(realpath build/bin/nvim)" NEW_TESTS=$(TEST_FILE) SCRIPTS= $(MAKEOVERRIDES)
  81. endif
  82. helptags: | nvim
  83. +$(BUILD_CMD) -C build helptags
  84. # Builds help HTML _and_ checks for invalid help tags.
  85. helphtml: | nvim helptags
  86. +$(BUILD_CMD) -C build doc_html
  87. functionaltest: | nvim
  88. +$(BUILD_CMD) -C build functionaltest
  89. functionaltest-lua: | nvim
  90. +$(BUILD_CMD) -C build functionaltest-lua
  91. testlint: | build/.ran-cmake deps
  92. $(BUILD_CMD) -C build testlint
  93. lualint: | build/.ran-cmake deps
  94. $(BUILD_CMD) -C build lualint
  95. unittest: | nvim
  96. +$(BUILD_CMD) -C build unittest
  97. benchmark: | nvim
  98. +$(BUILD_CMD) -C build benchmark
  99. test: functionaltest unittest
  100. clean:
  101. +test -d build && $(BUILD_CMD) -C build clean || true
  102. $(MAKE) -C src/nvim/testdir clean
  103. $(MAKE) -C runtime/doc clean
  104. distclean: clean
  105. rm -rf $(DEPS_BUILD_DIR) build
  106. install: | nvim
  107. +$(BUILD_CMD) -C build install
  108. clint: build/.ran-cmake
  109. +$(BUILD_CMD) -C build clint
  110. clint-full: build/.ran-cmake
  111. +$(BUILD_CMD) -C build clint-full
  112. check-single-includes: build/.ran-cmake
  113. +$(BUILD_CMD) -C build check-single-includes
  114. generated-sources: build/.ran-cmake
  115. +$(BUILD_CMD) -C build generated-sources
  116. appimage:
  117. bash scripts/genappimage.sh
  118. # Build an appimage with embedded update information appimage-nightly for
  119. # nightly builds or appimage-latest for a release
  120. appimage-%:
  121. bash scripts/genappimage.sh $*
  122. lint: check-single-includes clint testlint lualint
  123. .PHONY: test testlint lualint functionaltest unittest lint clint clean distclean nvim libnvim cmake deps install appimage