2021-09-19 18:53:48 -04:00
|
|
|
MAKEFILE_PATH := $(abspath $(lastword $(MAKEFILE_LIST)))
|
|
|
|
MAKEFILE_DIR := $(dir $(MAKEFILE_PATH))
|
|
|
|
|
2014-06-14 11:39:20 -04:00
|
|
|
filter-false = $(strip $(filter-out 0 off OFF false FALSE,$1))
|
|
|
|
filter-true = $(strip $(filter-out 1 on ON true TRUE,$1))
|
|
|
|
|
2015-03-07 19:49:16 -05:00
|
|
|
# See contrib/local.mk.example
|
2014-02-25 09:55:36 -05:00
|
|
|
-include local.mk
|
|
|
|
|
2019-06-29 18:13:53 -04:00
|
|
|
all: nvim
|
|
|
|
|
2017-02-23 06:45:45 -05:00
|
|
|
CMAKE_PRG ?= $(shell (command -v cmake3 || echo cmake))
|
2014-05-31 08:13:49 -04:00
|
|
|
CMAKE_BUILD_TYPE ?= Debug
|
2019-03-18 21:49:33 -04:00
|
|
|
CMAKE_FLAGS := -DCMAKE_BUILD_TYPE=$(CMAKE_BUILD_TYPE)
|
2019-02-15 18:23:51 -05:00
|
|
|
# Extra CMake flags which extend the default set
|
|
|
|
CMAKE_EXTRA_FLAGS ?=
|
2021-09-19 18:53:48 -04:00
|
|
|
NVIM_PRG := $(MAKEFILE_DIR)/build/bin/nvim
|
2019-02-15 18:23:51 -05:00
|
|
|
|
|
|
|
# CMAKE_INSTALL_PREFIX
|
|
|
|
# - May be passed directly or as part of CMAKE_EXTRA_FLAGS.
|
2019-02-16 23:28:32 -05:00
|
|
|
# - `checkprefix` target checks that it matches the CMake-cached value. #9615
|
2019-06-29 19:29:10 -04:00
|
|
|
ifneq (,$(CMAKE_INSTALL_PREFIX)$(CMAKE_EXTRA_FLAGS))
|
|
|
|
CMAKE_INSTALL_PREFIX := $(shell echo $(CMAKE_EXTRA_FLAGS) | 2>/dev/null \
|
2019-02-15 18:23:51 -05:00
|
|
|
grep -o 'CMAKE_INSTALL_PREFIX=[^ ]\+' | cut -d '=' -f2)
|
2019-06-29 15:48:40 -04:00
|
|
|
endif
|
2019-03-18 21:49:33 -04:00
|
|
|
ifneq (,$(CMAKE_INSTALL_PREFIX))
|
2019-07-17 10:38:11 -04:00
|
|
|
override CMAKE_EXTRA_FLAGS += -DCMAKE_INSTALL_PREFIX=$(CMAKE_INSTALL_PREFIX)
|
2019-06-29 15:48:40 -04:00
|
|
|
|
|
|
|
checkprefix:
|
|
|
|
@if [ -f build/.ran-cmake ]; then \
|
|
|
|
cached_prefix=$(shell $(CMAKE_PRG) -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: ;
|
2019-03-18 21:49:33 -04:00
|
|
|
endif
|
2014-03-03 10:09:06 -05:00
|
|
|
|
2021-09-19 18:53:48 -04:00
|
|
|
CMAKE_GENERATOR ?= $(shell (command -v ninja > /dev/null 2>&1 && echo "Ninja") || \
|
2014-03-03 10:09:06 -05:00
|
|
|
echo "Unix Makefiles")
|
2018-03-11 08:15:42 -04:00
|
|
|
DEPS_BUILD_DIR ?= .deps
|
|
|
|
ifneq (1,$(words [$(DEPS_BUILD_DIR)]))
|
|
|
|
$(error DEPS_BUILD_DIR must not contain whitespace)
|
|
|
|
endif
|
2014-03-03 10:09:06 -05:00
|
|
|
|
|
|
|
ifeq (,$(BUILD_TOOL))
|
2021-09-19 18:53:48 -04:00
|
|
|
ifeq (Ninja,$(CMAKE_GENERATOR))
|
2022-06-09 11:09:24 -04:00
|
|
|
BUILD_TOOL = ninja
|
2014-06-15 02:34:28 -04:00
|
|
|
else
|
|
|
|
BUILD_TOOL = $(MAKE)
|
2014-03-03 10:09:06 -05:00
|
|
|
endif
|
|
|
|
endif
|
2014-01-31 08:39:15 -05:00
|
|
|
|
2021-09-21 02:19:46 -04:00
|
|
|
# Only need to handle Ninja here. Make will inherit the VERBOSE variable, and the -j, -l, and -n flags.
|
2021-09-19 18:53:48 -04:00
|
|
|
ifeq ($(CMAKE_GENERATOR),Ninja)
|
2020-05-01 10:36:56 -04:00
|
|
|
ifneq ($(VERBOSE),)
|
2021-09-19 18:53:48 -04:00
|
|
|
BUILD_TOOL += -v
|
2014-06-15 02:34:28 -04:00
|
|
|
endif
|
2021-09-21 02:19:46 -04:00
|
|
|
BUILD_TOOL += $(shell printf '%s' '$(MAKEFLAGS)' | grep -o -- ' *-[jl][0-9]\+ *')
|
2020-05-01 10:36:56 -04:00
|
|
|
ifeq (n,$(findstring n,$(firstword -$(MAKEFLAGS))))
|
2021-09-19 18:53:48 -04:00
|
|
|
BUILD_TOOL += -n
|
2020-05-01 10:36:56 -04:00
|
|
|
endif
|
2014-04-23 04:59:25 -04:00
|
|
|
endif
|
|
|
|
|
2014-03-03 10:09:06 -05:00
|
|
|
DEPS_CMAKE_FLAGS ?=
|
2023-01-19 16:12:27 -05:00
|
|
|
USE_BUNDLED ?=
|
2014-06-14 11:39:20 -04:00
|
|
|
|
2018-09-24 17:18:48 -04:00
|
|
|
ifneq (,$(USE_BUNDLED))
|
|
|
|
BUNDLED_CMAKE_FLAG := -DUSE_BUNDLED=$(USE_BUNDLED)
|
2014-06-14 11:39:20 -04:00
|
|
|
endif
|
2014-02-24 19:22:48 -05:00
|
|
|
|
2016-03-06 22:42:49 -05:00
|
|
|
ifneq (,$(findstring functionaltest-lua,$(MAKECMDGOALS)))
|
|
|
|
BUNDLED_LUA_CMAKE_FLAG := -DUSE_BUNDLED_LUA=ON
|
2018-03-11 08:15:42 -04:00
|
|
|
$(shell [ -x $(DEPS_BUILD_DIR)/usr/bin/lua ] || rm build/.ran-*)
|
2016-03-06 22:42:49 -05:00
|
|
|
endif
|
|
|
|
|
2014-06-14 11:42:50 -04:00
|
|
|
# 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.
|
2014-02-28 21:32:25 -05:00
|
|
|
SINGLE_MAKE = export MAKEFLAGS= ; $(MAKE)
|
|
|
|
|
2019-06-29 15:48:40 -04:00
|
|
|
nvim: build/.ran-cmake deps
|
2021-09-19 18:53:48 -04:00
|
|
|
+$(BUILD_TOOL) -C build
|
2014-02-01 09:27:24 -05:00
|
|
|
|
2014-11-30 21:22:46 -05:00
|
|
|
libnvim: build/.ran-cmake deps
|
2021-09-19 18:53:48 -04:00
|
|
|
+$(BUILD_TOOL) -C build libnvim
|
2014-11-30 21:22:46 -05:00
|
|
|
|
2014-03-31 04:41:26 -04:00
|
|
|
cmake:
|
|
|
|
touch CMakeLists.txt
|
|
|
|
$(MAKE) build/.ran-cmake
|
2014-02-27 14:57:06 -05:00
|
|
|
|
2014-03-03 10:09:06 -05:00
|
|
|
build/.ran-cmake: | deps
|
2021-09-19 18:53:48 -04:00
|
|
|
cd build && $(CMAKE_PRG) -G '$(CMAKE_GENERATOR)' $(CMAKE_FLAGS) $(CMAKE_EXTRA_FLAGS) $(MAKEFILE_DIR)
|
2014-03-03 10:09:06 -05:00
|
|
|
touch $@
|
2014-02-01 09:20:02 -05:00
|
|
|
|
2022-06-27 06:08:59 -04:00
|
|
|
deps: | build/.ran-deps-cmake
|
2018-09-24 17:18:48 -04:00
|
|
|
ifeq ($(call filter-true,$(USE_BUNDLED)),)
|
2021-09-19 18:53:48 -04:00
|
|
|
+$(BUILD_TOOL) -C $(DEPS_BUILD_DIR)
|
2014-06-14 11:39:20 -04:00
|
|
|
endif
|
2014-02-01 09:20:02 -05:00
|
|
|
|
2018-09-24 17:18:48 -04:00
|
|
|
ifeq ($(call filter-true,$(USE_BUNDLED)),)
|
2019-06-23 22:13:57 -04:00
|
|
|
$(DEPS_BUILD_DIR):
|
2019-06-26 16:44:48 -04:00
|
|
|
mkdir -p "$@"
|
2022-06-27 06:08:59 -04:00
|
|
|
build/.ran-deps-cmake:: $(DEPS_BUILD_DIR)
|
2018-03-11 08:15:42 -04:00
|
|
|
cd $(DEPS_BUILD_DIR) && \
|
2021-09-19 18:53:48 -04:00
|
|
|
$(CMAKE_PRG) -G '$(CMAKE_GENERATOR)' $(BUNDLED_CMAKE_FLAG) $(BUNDLED_LUA_CMAKE_FLAG) \
|
2022-06-27 06:08:59 -04:00
|
|
|
$(DEPS_CMAKE_FLAGS) $(MAKEFILE_DIR)/cmake.deps
|
2014-06-14 11:39:20 -04:00
|
|
|
endif
|
2022-06-27 06:08:59 -04:00
|
|
|
build/.ran-deps-cmake::
|
2019-07-02 18:25:49 -04:00
|
|
|
mkdir -p build
|
|
|
|
touch $@
|
2014-02-27 14:57:06 -05:00
|
|
|
|
2017-02-11 19:02:54 -05:00
|
|
|
# TODO: cmake 3.2+ add_custom_target() has a USES_TERMINAL flag.
|
2019-08-28 16:47:54 -04:00
|
|
|
oldtest: | nvim build/runtime/doc/tags
|
2023-03-06 22:13:04 -05:00
|
|
|
+$(SINGLE_MAKE) -C test/old/testdir clean
|
2017-02-11 19:02:54 -05:00
|
|
|
ifeq ($(strip $(TEST_FILE)),)
|
2023-03-06 22:13:04 -05:00
|
|
|
+$(SINGLE_MAKE) -C test/old/testdir NVIM_PRG=$(NVIM_PRG) $(MAKEOVERRIDES)
|
2017-02-11 19:02:54 -05:00
|
|
|
else
|
2019-12-02 11:18:37 -05:00
|
|
|
@# Handle TEST_FILE=test_foo{,.res,.vim}.
|
2023-03-06 22:13:04 -05:00
|
|
|
+$(SINGLE_MAKE) -C test/old/testdir NVIM_PRG=$(NVIM_PRG) SCRIPTS= $(MAKEOVERRIDES) $(patsubst %.vim,%,$(patsubst %.res,%,$(TEST_FILE)))
|
2017-02-11 19:02:54 -05:00
|
|
|
endif
|
2019-12-02 11:18:37 -05:00
|
|
|
# Build oldtest by specifying the relative .vim filename.
|
|
|
|
.PHONY: phony_force
|
2023-04-27 02:26:07 -04:00
|
|
|
test/old/testdir/%.vim: phony_force nvim
|
2023-03-06 22:13:04 -05:00
|
|
|
+$(SINGLE_MAKE) -C test/old/testdir NVIM_PRG=$(NVIM_PRG) SCRIPTS= $(MAKEOVERRIDES) $(patsubst test/old/testdir/%.vim,%,$@)
|
2014-09-29 08:43:52 -04:00
|
|
|
|
2023-01-19 16:12:27 -05:00
|
|
|
functionaltest-lua: | nvim
|
2023-05-24 15:14:47 -04:00
|
|
|
$(BUILD_TOOL) -C build functionaltest
|
2014-11-05 05:54:20 -05:00
|
|
|
|
2023-01-19 16:12:27 -05:00
|
|
|
FORMAT=formatc formatlua format
|
2023-02-08 12:16:48 -05:00
|
|
|
LINT=lintlua lintsh lintc clang-tidy lintcommit lint
|
2023-01-19 16:12:27 -05:00
|
|
|
TEST=functionaltest unittest
|
2023-04-08 09:12:38 -04:00
|
|
|
generated-sources benchmark $(FORMAT) $(LINT) $(TEST): | build/.ran-cmake
|
2022-06-09 11:09:24 -04:00
|
|
|
$(CMAKE_PRG) --build build --target $@
|
2016-03-06 22:42:49 -05:00
|
|
|
|
2023-01-19 16:12:27 -05:00
|
|
|
test: $(TEST)
|
2015-11-27 18:08:08 -05:00
|
|
|
|
2022-09-11 11:12:44 -04:00
|
|
|
iwyu: build/.ran-cmake
|
2023-03-11 13:21:54 -05:00
|
|
|
cmake --preset iwyu
|
|
|
|
cmake --build --preset iwyu > build/iwyu.log
|
2022-09-11 11:12:44 -04:00
|
|
|
iwyu-fix-includes --only_re="src/nvim" --ignore_re="src/nvim/(auto|map.h|eval/encode.c)" --safe_headers < build/iwyu.log
|
|
|
|
cmake -B build -U ENABLE_IWYU
|
|
|
|
|
2014-02-01 09:20:02 -05:00
|
|
|
clean:
|
2021-09-19 18:53:48 -04:00
|
|
|
+test -d build && $(BUILD_TOOL) -C build clean || true
|
2023-03-06 22:13:04 -05:00
|
|
|
$(MAKE) -C test/old/testdir clean
|
2019-09-18 16:40:06 -04:00
|
|
|
$(MAKE) -C runtime/indent clean
|
2014-02-01 09:20:02 -05:00
|
|
|
|
2019-06-25 13:51:28 -04:00
|
|
|
distclean:
|
2018-03-11 08:15:42 -04:00
|
|
|
rm -rf $(DEPS_BUILD_DIR) build
|
2019-06-25 13:51:28 -04:00
|
|
|
$(MAKE) clean
|
2014-02-24 19:04:51 -05:00
|
|
|
|
2019-06-29 15:48:40 -04:00
|
|
|
install: checkprefix nvim
|
2021-09-19 18:53:48 -04:00
|
|
|
+$(BUILD_TOOL) -C build install
|
2014-02-01 09:27:24 -05:00
|
|
|
|
2017-05-01 20:35:04 -04:00
|
|
|
appimage:
|
|
|
|
bash scripts/genappimage.sh
|
|
|
|
|
2019-02-15 18:23:51 -05:00
|
|
|
# Build an appimage with embedded update information.
|
|
|
|
# appimage-nightly: for nightly builds
|
|
|
|
# appimage-latest: for a release
|
2018-03-09 10:51:27 -05:00
|
|
|
appimage-%:
|
|
|
|
bash scripts/genappimage.sh $*
|
|
|
|
|
2019-08-04 11:13:04 -04:00
|
|
|
# Generic pattern rules, allowing for `make build/bin/nvim` etc.
|
|
|
|
# Does not work with "Unix Makefiles".
|
2021-09-19 18:53:48 -04:00
|
|
|
ifeq ($(CMAKE_GENERATOR),Ninja)
|
2019-12-02 11:18:37 -05:00
|
|
|
build/%: phony_force
|
2021-09-19 18:53:48 -04:00
|
|
|
$(BUILD_TOOL) -C build $(patsubst build/%,%,$@)
|
2019-07-30 07:53:33 -04:00
|
|
|
|
2019-12-02 11:18:37 -05:00
|
|
|
$(DEPS_BUILD_DIR)/%: phony_force
|
2021-09-19 18:53:48 -04:00
|
|
|
$(BUILD_TOOL) -C $(DEPS_BUILD_DIR) $(patsubst $(DEPS_BUILD_DIR)/%,%,$@)
|
2019-08-04 11:13:04 -04:00
|
|
|
endif
|
2019-07-30 07:53:33 -04:00
|
|
|
|
2023-01-30 12:45:07 -05:00
|
|
|
.PHONY: test clean distclean nvim libnvim cmake deps install appimage checkprefix benchmark uninstall $(FORMAT) $(LINT) $(TEST)
|