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