diff --git a/Makefile b/Makefile index 1bb852409..2b316c907 100644 --- a/Makefile +++ b/Makefile @@ -33,7 +33,7 @@ nvim: | ${NVIM_PATH} git -C ${NVIM_MASTER_PATH} fetch origin master --depth 1 git -C ${NVIM_MASTER_PATH} checkout FETCH_HEAD -LUASNIP_DETECTED_OS?=$(shell uname) +LUASNIP_DETECTED_OS?=$(shell uname && false) ifeq ($(LUASNIP_DETECTED_OS),Darwin) # flags for dynamic linking on macos, from luarocks # (https://github.com/luarocks/luarocks/blob/9a3c5a879849f4f411a96cf1bdc0c4c7e26ade42/src/luarocks/core/cfg.lua#LL468C37-L468C80) @@ -41,28 +41,57 @@ ifeq ($(LUASNIP_DETECTED_OS),Darwin) LUA_LDLIBS=-undefined dynamic_lookup -all_load endif -JSREGEXP_PATH=deps/jsregexp -JSREGEXP005_PATH=deps/jsregexp005 +# On Windows, you may need to set: +# SHELL=C:/path/to/Git/usr/bin/sh.exe +# .SHELLFLAGS=-c +# CC=gcc +# NEOVIM_BIN_PATH=C:/path/to/Neovim/bin # contains lua51.dll, or use your own LUA_LDLIBS +LUASNIP_IS_ON_WINDOWS?=$(OS) +ifeq ($(LUASNIP_IS_ON_WINDOWS),Windows_NT) + # If neovim is installed by scoop, only scoop/shims is exposed. We need to find original nvim/bin that contains lua51.dll + # If neovim is installed by winget or other methods, nvim/bin is already included in PATH. + # NEOVIM_BIN_PATH?=$(shell type "scoop" >/dev/null 2>&1 && echo "$$(scoop prefix neovim)/bin | sed 's/") + NEOVIM_BIN_PATH?=$(shell \ + if (scoop prefix neovim | grep -v 'Could not find app path for') >/dev/null 2>&1; then \ + echo "$$(scoop prefix neovim)/bin" | sed 's/\\\\/\\//g' | sed 's/\\(.*\\) \\(.*\\)/"\\1 \\2"/'; \ + elif which nvim > /dev/null 2>&1; then \ + dirname "$$(which nvim)" | sed 's/^\\/\\(.\\)\\//\\U\\1:\\//' | sed 's/\\(.*\\) \\(.*\\)/"\\1 \\2"/'; \ + fi) + + LUA_LDLIBS?=$(if $(strip $(NEOVIM_BIN_PATH)),-L$(NEOVIM_BIN_PATH) -llua51,) +endif + +$(info SHELL is $(SHELL)) +$(info .SHELLFLAGS is $(.SHELLFLAGS)) +$(info CC is $(CC)) +$(info NEOVIM_BIN_PATH is $(NEOVIM_BIN_PATH)) +$(info LUA_LDLIBS is $(LUA_LDLIBS)) + +# some workaround to empty $(shell command) output on Windows +# @link: https://stackoverflow.com/questions/74481637/shell-command-in-makefile-returns-empty-on-windows-sometimes +PROJECT_ROOT:=$(shell pwd && false) +JSREGEXP_PATH=$(PROJECT_ROOT)/deps/jsregexp +JSREGEXP005_PATH=$(PROJECT_ROOT)/deps/jsregexp005 jsregexp: git submodule init git submodule update - $(MAKE) "CC=$(CC)" "INCLUDE_DIR=-I'$(shell pwd)/deps/lua51_include/'" LDLIBS="${LUA_LDLIBS}" -C "${JSREGEXP_PATH}" - $(MAKE) "CC=$(CC)" "INCLUDE_DIR=-I'$(shell pwd)/deps/lua51_include/'" LDLIBS="${LUA_LDLIBS}" -C "${JSREGEXP005_PATH}" + $(MAKE) "CC=$(CC)" "INCLUDE_DIR=-I$(PROJECT_ROOT)/deps/lua51_include/" LDLIBS='$(LUA_LDLIBS)' -C "$(JSREGEXP_PATH)" + $(MAKE) "CC=$(CC)" "INCLUDE_DIR=-I$(PROJECT_ROOT)/deps/lua51_include/" LDLIBS='$(LUA_LDLIBS)' -C "$(JSREGEXP005_PATH)" install_jsregexp: jsregexp # remove old binary. - rm "$(shell pwd)/lua/luasnip-jsregexp.so" || true + rm "$(PROJECT_ROOT)/lua/luasnip-jsregexp.so" || true # there is some additional trickery to make this work with jsregexp-0.0.6 in # util/jsregexp.lua. - cp "$(shell pwd)/${JSREGEXP_PATH}/jsregexp.lua" "$(shell pwd)/lua/luasnip-jsregexp.lua" + cp "$(JSREGEXP_PATH)/jsregexp.lua" "$(PROJECT_ROOT)/lua/luasnip-jsregexp.lua" # just move out of jsregexp-directory, so it is not accidentially deleted. - cp "$(shell pwd)/${JSREGEXP_PATH}/jsregexp.so" "$(shell pwd)/deps/luasnip-jsregexp.so" + cp "$(JSREGEXP_PATH)/jsregexp.so" "$(PROJECT_ROOT)/deps/luasnip-jsregexp.so" uninstall_jsregexp: # also remove binaries of older version. - rm -f "$(shell pwd)/lua/luasnip-jsregexp.so" - rm -f "$(shell pwd)/deps/luasnip-jsregexp.so" - rm -f "$(shell pwd)/lua/luasnip-jsregexp.lua" + rm -f "$(PROJECT_ROOT)/lua/luasnip-jsregexp.so" + rm -f "$(PROJECT_ROOT)/deps/luasnip-jsregexp.so" + rm -f "$(PROJECT_ROOT)/lua/luasnip-jsregexp.lua" TEST_07?=true TEST_09?=true @@ -73,11 +102,11 @@ test: nvim install_jsregexp # add our helper-functions to lpath. # exit as soon as an error occurs. unset LUA_PATH LUA_CPATH; \ - export LUASNIP_SOURCE=$(shell pwd); \ - export JSREGEXP_ABS_PATH=$(shell pwd)/${JSREGEXP_PATH}; \ - export JSREGEXP005_ABS_PATH=$(shell pwd)/${JSREGEXP005_PATH}; \ + export LUASNIP_SOURCE=$(PROJECT_ROOT); \ + export JSREGEXP_ABS_PATH=$(JSREGEXP_PATH); \ + export JSREGEXP005_ABS_PATH=$(JSREGEXP005_PATH); \ export TEST_FILE=$(realpath ${TEST_FILE}); \ - export BUSTED_ARGS=--lpath=$(shell pwd)/tests/?.lua; \ + export BUSTED_ARGS=--lpath=$(PROJECT_ROOT)/tests/?.lua; \ set -e; \ if ${TEST_07}; then $(MAKE) -C ${NVIM_0.7_PATH} functionaltest DEPS_CMAKE_FLAGS=-DUSE_BUNDLED_GPERF=OFF; fi; \ if ${TEST_09}; then $(MAKE) -C ${NVIM_0.9_PATH} functionaltest; fi; \