neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

Makefile (6077B)


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