mirror of
https://github.com/tree-sitter/tree-sitter.git
synced 2026-09-10 07:26:23 -04:00
build(make): fix MinGW builds
Rename libtree-sitter.lib target to libtree-sitter.dll.a which is what MinGW actually uses, move the target after libtree-sitter.dll, and make sure it is installed to the correct location. Also avoid invoking `cc -dumpmachine` multiple times.
This commit is contained in:
parent
f04fab9b7a
commit
f8f93c1ec1
24
Makefile
24
Makefile
|
|
@ -6,6 +6,7 @@ HOMEPAGE_URL := https://tree-sitter.github.io/tree-sitter/
|
|||
PREFIX ?= /usr/local
|
||||
INCLUDEDIR ?= $(PREFIX)/include
|
||||
LIBDIR ?= $(PREFIX)/lib
|
||||
BINDIR ?= $(PREFIX)/bin
|
||||
PCLIBDIR ?= $(LIBDIR)/pkgconfig
|
||||
|
||||
# collect sources
|
||||
|
|
@ -31,24 +32,25 @@ SONAME_MAJOR := $(word 1,$(subst ., ,$(VERSION)))
|
|||
SONAME_MINOR := $(word 2,$(subst ., ,$(VERSION)))
|
||||
|
||||
# OS-specific bits
|
||||
ifneq ($(findstring darwin,$(shell $(CC) -dumpmachine)),)
|
||||
MACHINE := $(shell $(CC) -dumpmachine)
|
||||
|
||||
ifneq ($(findstring darwin,$(MACHINE)),)
|
||||
SOEXT = dylib
|
||||
SOEXTVER_MAJOR = $(SONAME_MAJOR).$(SOEXT)
|
||||
SOEXTVER = $(SONAME_MAJOR).$(SONAME_MINOR).$(SOEXT)
|
||||
LINKSHARED += -dynamiclib -Wl,-install_name,$(LIBDIR)/libtree-sitter.$(SOEXTVER)
|
||||
else ifneq ($(findstring mingw32,$(shell $(CC) -dumpmachine)),)
|
||||
else ifneq ($(findstring mingw32,$(MACHINE)),)
|
||||
SOEXT = dll
|
||||
LINKSHARED += -s -shared -Wl,--out-implib,$(@:dll=lib)
|
||||
libtree-sitter.lib: libtree-sitter.$(SOEXT)
|
||||
LINKSHARED += -s -shared -Wl,--out-implib,libtree-sitter.dll.a
|
||||
else
|
||||
SOEXT = so
|
||||
SOEXTVER_MAJOR = $(SOEXT).$(SONAME_MAJOR)
|
||||
SOEXTVER = $(SOEXT).$(SONAME_MAJOR).$(SONAME_MINOR)
|
||||
LINKSHARED += -shared -Wl,-soname,libtree-sitter.$(SOEXTVER)
|
||||
endif
|
||||
ifneq ($(filter $(shell uname),FreeBSD NetBSD DragonFly),)
|
||||
PCLIBDIR := $(PREFIX)/libdata/pkgconfig
|
||||
endif
|
||||
endif
|
||||
|
||||
all: libtree-sitter.a libtree-sitter.$(SOEXT) tree-sitter.pc
|
||||
|
||||
|
|
@ -61,6 +63,10 @@ ifneq ($(STRIP),)
|
|||
$(STRIP) $@
|
||||
endif
|
||||
|
||||
ifneq ($(findstring mingw32,$(MACHINE)),)
|
||||
libtree-sitter.dll.a: libtree-sitter.$(SOEXT)
|
||||
endif
|
||||
|
||||
tree-sitter.pc: lib/tree-sitter.pc.in
|
||||
sed -e 's|@PROJECT_VERSION@|$(VERSION)|' \
|
||||
-e 's|@CMAKE_INSTALL_LIBDIR@|$(LIBDIR:$(PREFIX)/%=%)|' \
|
||||
|
|
@ -70,16 +76,22 @@ tree-sitter.pc: lib/tree-sitter.pc.in
|
|||
-e 's|@CMAKE_INSTALL_PREFIX@|$(PREFIX)|' $< > $@
|
||||
|
||||
clean:
|
||||
$(RM) $(OBJ) tree-sitter.pc libtree-sitter.a libtree-sitter.$(SOEXT) libtree-stitter.lib
|
||||
$(RM) $(OBJ) tree-sitter.pc libtree-sitter.a libtree-sitter.$(SOEXT) libtree-stitter.dll.a
|
||||
|
||||
install: all
|
||||
install -d '$(DESTDIR)$(INCLUDEDIR)'/tree_sitter '$(DESTDIR)$(PCLIBDIR)' '$(DESTDIR)$(LIBDIR)'
|
||||
install -m644 lib/include/tree_sitter/api.h '$(DESTDIR)$(INCLUDEDIR)'/tree_sitter/api.h
|
||||
install -m644 tree-sitter.pc '$(DESTDIR)$(PCLIBDIR)'/tree-sitter.pc
|
||||
install -m644 libtree-sitter.a '$(DESTDIR)$(LIBDIR)'/libtree-sitter.a
|
||||
ifneq ($(findstring mingw32,$(MACHINE)),)
|
||||
install -d '$(DESTDIR)$(BINDIR)'
|
||||
install -m755 libtree-sitter.dll '$(DESTDIR)$(BINDIR)'/libtree-sitter.dll
|
||||
install -m755 libtree-sitter.dll.a '$(DESTDIR)$(LIBDIR)'/libtree-sitter.dll.a
|
||||
else
|
||||
install -m755 libtree-sitter.$(SOEXT) '$(DESTDIR)$(LIBDIR)'/libtree-sitter.$(SOEXTVER)
|
||||
ln -sf libtree-sitter.$(SOEXTVER) '$(DESTDIR)$(LIBDIR)'/libtree-sitter.$(SOEXTVER_MAJOR)
|
||||
ln -sf libtree-sitter.$(SOEXTVER_MAJOR) '$(DESTDIR)$(LIBDIR)'/libtree-sitter.$(SOEXT)
|
||||
endif
|
||||
|
||||
uninstall:
|
||||
$(RM) '$(DESTDIR)$(LIBDIR)'/libtree-sitter.a \
|
||||
|
|
|
|||
Loading…
Reference in a new issue