Skip to content

Commit

Permalink
Makefile: revisit/improve checkprefix handling (neovim#10348)
Browse files Browse the repository at this point in the history
Main improvement: do not error out, but re-run CMake in case
CMAKE_INSTALL_PREFIX changed, and only check it for "install".

- only look at CMAKE_EXTRA_FLAGS via shell if not empty
- add CMAKE_INSTALL_PREFIX to CMAKE_EXTRA_FLAGS (not CMAKE_FLAGS), to
  override it being set in CMAKE_EXTRA_FLAGS from local.mk
- use an empty "checkprefix" target if CMAKE_INSTALL_PREFIX is not
  provided
- skip checking of cached value without build/.ran-cmake; it will be run
  then anyway
- only use it with "install" target; it is only relevant there
- do not error, but re-run CMake (by removing the stamp file)
  • Loading branch information
blueyed authored Jun 29, 2019
1 parent 2d4a37e commit 5031e32
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,23 @@ CMAKE_EXTRA_FLAGS ?=
# 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_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))
CMAKE_FLAGS += -DCMAKE_INSTALL_PREFIX=$(CMAKE_INSTALL_PREFIX)
CMAKE_EXTRA_FLAGS += -DCMAKE_INSTALL_PREFIX=$(CMAKE_INSTALL_PREFIX)

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: ;
endif

BUILD_TYPE ?= $(shell (type ninja > /dev/null 2>&1 && echo "Ninja") || \
Expand Down Expand Up @@ -69,7 +82,7 @@ SINGLE_MAKE = export MAKEFLAGS= ; $(MAKE)

all: nvim

nvim: checkprefix build/.ran-cmake deps
nvim: build/.ran-cmake deps
+$(BUILD_CMD) -C build

libnvim: build/.ran-cmake deps
Expand Down Expand Up @@ -146,7 +159,7 @@ distclean:
rm -rf $(DEPS_BUILD_DIR) build
$(MAKE) clean

install: | nvim
install: checkprefix nvim
+$(BUILD_CMD) -C build install

clint: build/.ran-cmake
Expand All @@ -172,13 +185,4 @@ appimage-%:

lint: check-single-includes clint testlint lualint

checkprefix:
@cached_prefix=$$("$(CMAKE_PRG)" -L -N build | 2>/dev/null grep 'CMAKE_INSTALL_PREFIX' | cut -d '=' -f2); \
if [ -n "$(CMAKE_INSTALL_PREFIX)" ] && [ -n "$$cached_prefix" ] && ! [ "$(CMAKE_INSTALL_PREFIX)" = "$$cached_prefix" ]; then \
printf "\nerror: CMAKE_INSTALL_PREFIX '$(CMAKE_INSTALL_PREFIX)' does not match cached value '%s'\n" "$$cached_prefix"; \
printf " Run this command, then try again:\n"; \
printf " cmake build -DCMAKE_INSTALL_PREFIX=$(CMAKE_INSTALL_PREFIX)\n"; \
exit 1; \
fi;

.PHONY: test testlint lualint functionaltest unittest lint clint clean distclean nvim libnvim cmake deps install appimage checkprefix

0 comments on commit 5031e32

Please sign in to comment.