mirror of
https://github.com/neovim/neovim.git
synced 2026-09-09 07:25:51 +00:00
Problem: LuaLS struggles with the generics used in Nvim's runtime, requiring broad diagnostic suppressions. Indexing is also slow. Solution: Use EmmyLua for type checks in the build and CI. It offers more sophisticated type checking, substantially better support for generics, and much better flow analysis. Correct the affected annotations. Use `@internal`, supported directly by EmmyLua, instead of `@nodoc` for shared internal declarations, and support it in the help parser. AI-assisted
197 lines
5.8 KiB
Makefile
197 lines
5.8 KiB
Makefile
ifeq ($(OS),Windows_NT)
|
|
ifeq '$(findstring ;,$(PATH))' ';'
|
|
UNIX_LIKE := FALSE
|
|
else
|
|
UNIX_LIKE := TRUE
|
|
endif
|
|
else
|
|
UNIX_LIKE := TRUE
|
|
endif
|
|
|
|
ifeq ($(UNIX_LIKE),FALSE)
|
|
SHELL := powershell.exe
|
|
.SHELLFLAGS := -NoProfile -NoLogo
|
|
MKDIR := @$$null = new-item -itemtype directory -force
|
|
TOUCH := @$$null = new-item -force
|
|
RM := remove-item -force
|
|
CMAKE := cmake
|
|
CMAKE_GENERATOR := Ninja
|
|
define rmdir
|
|
if (Test-Path $1) { remove-item -recurse $1 }
|
|
endef
|
|
else
|
|
MKDIR := mkdir -p
|
|
TOUCH := touch
|
|
RM := rm -rf
|
|
CMAKE := $(shell (command -v cmake3 || command -v cmake || echo cmake))
|
|
CMAKE_GENERATOR ?= "$(shell (command -v ninja > /dev/null 2>&1 && echo "Ninja") || echo "Unix Makefiles")"
|
|
define rmdir
|
|
rm -rf $1
|
|
endef
|
|
endif
|
|
|
|
MAKEFILE_PATH := $(abspath $(lastword $(MAKEFILE_LIST)))
|
|
MAKEFILE_DIR := $(dir $(MAKEFILE_PATH))
|
|
|
|
filter-false = $(strip $(filter-out 0 off OFF false FALSE,$1))
|
|
filter-true = $(strip $(filter-out 1 on ON true TRUE,$1))
|
|
|
|
# See contrib/local.mk.example
|
|
-include local.mk
|
|
|
|
all: nvim
|
|
|
|
CMAKE_FLAGS := -DCMAKE_BUILD_TYPE=$(CMAKE_BUILD_TYPE)
|
|
# Extra CMake flags which extend the default set
|
|
CMAKE_EXTRA_FLAGS ?=
|
|
NVIM_PRG := $(MAKEFILE_DIR)/build/bin/nvim
|
|
|
|
# CMAKE_INSTALL_PREFIX
|
|
# - May be passed directly or as part of CMAKE_EXTRA_FLAGS.
|
|
# - `checkprefix` target checks that it matches the CMake-cached value. #9615
|
|
ifneq (,$(CMAKE_INSTALL_PREFIX)$(CMAKE_EXTRA_FLAGS))
|
|
CMAKE_INSTALL_PREFIX := $(shell echo $(CMAKE_EXTRA_FLAGS) | 2>/dev/null \
|
|
grep -o 'CMAKE_INSTALL_PREFIX=[^ ]\+' | cut -d '=' -f2)
|
|
endif
|
|
ifneq (,$(CMAKE_INSTALL_PREFIX))
|
|
override CMAKE_EXTRA_FLAGS += -DCMAKE_INSTALL_PREFIX=$(CMAKE_INSTALL_PREFIX)
|
|
|
|
checkprefix:
|
|
@if [ -f build/.ran-cmake ]; then \
|
|
cached_prefix=$(shell $(CMAKE) -L -N build | 2>/dev/null grep 'CMAKE_INSTALL_PREFIX' | cut -d '=' -f2); \
|
|
if ! [ "$(CMAKE_INSTALL_PREFIX)" = "$$cached_prefix" ]; then \
|
|
printf "Re-running CMake: CMAKE_INSTALL_PREFIX '$(CMAKE_INSTALL_PREFIX)' does not match cached value '%s'.\n" "$$cached_prefix"; \
|
|
$(RM) build/.ran-cmake; \
|
|
fi \
|
|
fi
|
|
else
|
|
checkprefix: ;
|
|
endif
|
|
|
|
DEPS_BUILD_DIR ?= ".deps"
|
|
ifneq (1,$(words [$(DEPS_BUILD_DIR)]))
|
|
$(error DEPS_BUILD_DIR must not contain whitespace)
|
|
endif
|
|
|
|
DEPS_CMAKE_FLAGS ?=
|
|
USE_BUNDLED ?=
|
|
|
|
ifdef BUNDLED_CMAKE_FLAG
|
|
$(error BUNDLED_CMAKE_FLAG was removed. Use DEPS_CMAKE_FLAGS instead)
|
|
endif
|
|
|
|
ifdef BUNDLED_LUA_CMAKE_FLAG
|
|
$(error BUNDLED_LUA_CMAKE_FLAG was removed. Use DEPS_CMAKE_FLAGS instead)
|
|
endif
|
|
|
|
# If USE_BUNDLED is non-empty, prepend the flag to DEPS_CMAKE_FLAGS
|
|
ifneq (,$(USE_BUNDLED))
|
|
DEPS_CMAKE_FLAGS := -DUSE_BUNDLED=$(USE_BUNDLED) $(DEPS_CMAKE_FLAGS)
|
|
endif
|
|
|
|
ifneq (,$(findstring functionaltest-lua,$(MAKECMDGOALS)))
|
|
DEPS_CMAKE_FLAGS := -DUSE_BUNDLED_LUA=ON $(DEPS_CMAKE_FLAGS)
|
|
$(shell [ -x $(DEPS_BUILD_DIR)/usr/bin/lua ] || $(RM) build/.ran-*)
|
|
endif
|
|
|
|
# For use where we want to make sure only a single job is run. This does issue
|
|
# a warning, but we need to keep SCRIPTS argument.
|
|
SINGLE_MAKE = export MAKEFLAGS= ; $(MAKE)
|
|
|
|
nvim: build/.ran-cmake deps
|
|
$(CMAKE) --build build
|
|
|
|
libnvim: build/.ran-cmake deps
|
|
$(CMAKE) --build build --target libnvim
|
|
|
|
cmake:
|
|
$(TOUCH) CMakeLists.txt
|
|
$(MAKE) build/.ran-cmake
|
|
|
|
build/.ran-cmake: | deps
|
|
$(CMAKE) -B build -G $(CMAKE_GENERATOR) $(CMAKE_FLAGS) $(CMAKE_EXTRA_FLAGS) $(MAKEFILE_DIR)
|
|
$(TOUCH) $@
|
|
|
|
ifneq ($(call filter-true,$(USE_BUNDLED)),)
|
|
deps: ;
|
|
else
|
|
deps: | build/.ran-deps-cmake
|
|
$(CMAKE) --build $(DEPS_BUILD_DIR)
|
|
|
|
$(DEPS_BUILD_DIR):
|
|
$(MKDIR) $@
|
|
build/.ran-deps-cmake:: $(DEPS_BUILD_DIR)
|
|
$(CMAKE) -S $(MAKEFILE_DIR)/cmake.deps -B $(DEPS_BUILD_DIR) -G $(CMAKE_GENERATOR) $(DEPS_CMAKE_FLAGS)
|
|
endif
|
|
|
|
build/.ran-deps-cmake::
|
|
$(MKDIR) build
|
|
$(TOUCH) "$@"
|
|
|
|
# TODO: cmake 3.2+ add_custom_target() has a USES_TERMINAL flag.
|
|
oldtest: | nvim
|
|
$(SINGLE_MAKE) -C test/old/testdir clean
|
|
ifeq ($(strip $(TEST_FILE)),)
|
|
$(SINGLE_MAKE) -C test/old/testdir NVIM_PRG=$(NVIM_PRG) $(MAKEOVERRIDES)
|
|
else
|
|
@# Handle TEST_FILE=test_foo{,.res,.vim}.
|
|
$(SINGLE_MAKE) -C test/old/testdir NVIM_PRG=$(NVIM_PRG) SCRIPTS= $(MAKEOVERRIDES) $(patsubst %.vim,%,$(patsubst %.res,%,$(TEST_FILE)))
|
|
endif
|
|
|
|
# Build oldtest by specifying the relative .vim filename.
|
|
.PHONY: phony_force
|
|
test/old/testdir/%.vim: phony_force nvim
|
|
$(SINGLE_MAKE) -C test/old/testdir NVIM_PRG=$(NVIM_PRG) SCRIPTS= $(MAKEOVERRIDES) $(patsubst test/old/testdir/%.vim,%,$@)
|
|
|
|
functionaltest-lua: | nvim
|
|
$(CMAKE) --build build --target functionaltest
|
|
|
|
FORMAT=formatc formatlua formatquery format
|
|
LINT=lintlua lintsh lintc clang-analyzer lintcommit lintdoc lintdocurls lint emmylua-check lintquery linterrcodes
|
|
TEST=functionaltest unittest
|
|
generated-sources benchmark $(FORMAT) $(LINT) $(TEST) doc: | build/.ran-cmake
|
|
$(CMAKE) --build build --target $@
|
|
|
|
test: $(TEST)
|
|
|
|
# iwyu-fix-includes can be downloaded from
|
|
# https://github.com/include-what-you-use/include-what-you-use/blob/master/fix_includes.py.
|
|
# Create a iwyu-fix-includes shell script in your $PATH that invokes the python script.
|
|
iwyu: build/.ran-cmake
|
|
$(CMAKE) --preset iwyu
|
|
$(CMAKE) --build build > build/iwyu.log
|
|
iwyu-fix-includes --only_re="src/nvim" --ignore_re="(src/nvim/eval/encode.c\
|
|
|src/nvim/auto/\
|
|
|src/nvim/os/lang.c\
|
|
|src/nvim/map.c\
|
|
)" --nosafe_headers < build/iwyu.log
|
|
$(CMAKE) -B build -U ENABLE_IWYU
|
|
$(CMAKE) --build build
|
|
|
|
clean:
|
|
ifneq ($(wildcard build),)
|
|
$(CMAKE) --build build --target clean
|
|
endif
|
|
$(MAKE) -C test/old/testdir clean
|
|
|
|
distclean:
|
|
$(call rmdir, $(DEPS_BUILD_DIR))
|
|
$(call rmdir, build)
|
|
$(call rmdir, .zig-cache)
|
|
$(call rmdir, zig-out)
|
|
$(MAKE) clean
|
|
|
|
install: checkprefix nvim
|
|
$(CMAKE) --install build
|
|
|
|
appimage:
|
|
bash scripts/genappimage.sh
|
|
|
|
# Build an appimage with embedded update information.
|
|
# appimage-nightly: for nightly builds
|
|
# appimage-latest: for a release
|
|
appimage-%:
|
|
bash scripts/genappimage.sh $*
|
|
|
|
.PHONY: test clean distclean nvim libnvim cmake deps install appimage checkprefix benchmark $(FORMAT) $(LINT) $(TEST)
|