115 lines
3.6 KiB
Makefile
115 lines
3.6 KiB
Makefile
|
ifeq ($(OS),Windows_NT)
|
||
|
$(error Windows is not supported)
|
||
|
endif
|
||
|
|
||
|
VERSION := 0.0.1
|
||
|
|
||
|
LANGUAGE_NAME := tree-sitter-jrpc
|
||
|
|
||
|
# repository
|
||
|
SRC_DIR := src
|
||
|
|
||
|
PARSER_REPO_URL := $(shell git -C $(SRC_DIR) remote get-url origin 2>/dev/null)
|
||
|
|
||
|
ifeq ($(PARSER_URL),)
|
||
|
PARSER_URL := $(subst .git,,$(PARSER_REPO_URL))
|
||
|
ifeq ($(shell echo $(PARSER_URL) | grep '^[a-z][-+.0-9a-z]*://'),)
|
||
|
PARSER_URL := $(subst :,/,$(PARSER_URL))
|
||
|
PARSER_URL := $(subst git@,https://,$(PARSER_URL))
|
||
|
endif
|
||
|
endif
|
||
|
|
||
|
TS ?= tree-sitter
|
||
|
|
||
|
# install directory layout
|
||
|
PREFIX ?= /usr/local
|
||
|
INCLUDEDIR ?= $(PREFIX)/include
|
||
|
LIBDIR ?= $(PREFIX)/lib
|
||
|
PCLIBDIR ?= $(LIBDIR)/pkgconfig
|
||
|
|
||
|
# source/object files
|
||
|
PARSER := $(SRC_DIR)/parser.c
|
||
|
EXTRAS := $(filter-out $(PARSER),$(wildcard $(SRC_DIR)/*.c))
|
||
|
OBJS := $(patsubst %.c,%.o,$(PARSER) $(EXTRAS))
|
||
|
|
||
|
# flags
|
||
|
ARFLAGS ?= rcs
|
||
|
override CFLAGS += -I$(SRC_DIR) -std=c11 -fPIC
|
||
|
|
||
|
# ABI versioning
|
||
|
SONAME_MAJOR := $(word 1,$(subst ., ,$(VERSION)))
|
||
|
SONAME_MINOR := $(shell sed -n 's/#define LANGUAGE_VERSION //p' $(PARSER))
|
||
|
|
||
|
# OS-specific bits
|
||
|
ifeq ($(shell uname),Darwin)
|
||
|
SOEXT = dylib
|
||
|
SOEXTVER_MAJOR = $(SONAME_MAJOR).$(SOEXT)
|
||
|
SOEXTVER = $(SONAME_MAJOR).$(SONAME_MINOR).$(SOEXT)
|
||
|
LINKSHARED := $(LINKSHARED)-dynamiclib -Wl,
|
||
|
ifneq ($(ADDITIONAL_LIBS),)
|
||
|
LINKSHARED := $(LINKSHARED)$(ADDITIONAL_LIBS),
|
||
|
endif
|
||
|
LINKSHARED := $(LINKSHARED)-install_name,$(LIBDIR)/lib$(LANGUAGE_NAME).$(SOEXTVER),-rpath,@executable_path/../Frameworks
|
||
|
else
|
||
|
SOEXT = so
|
||
|
SOEXTVER_MAJOR = $(SOEXT).$(SONAME_MAJOR)
|
||
|
SOEXTVER = $(SOEXT).$(SONAME_MAJOR).$(SONAME_MINOR)
|
||
|
LINKSHARED := $(LINKSHARED)-shared -Wl,
|
||
|
ifneq ($(ADDITIONAL_LIBS),)
|
||
|
LINKSHARED := $(LINKSHARED)$(ADDITIONAL_LIBS)
|
||
|
endif
|
||
|
LINKSHARED := $(LINKSHARED)-soname,lib$(LANGUAGE_NAME).$(SOEXTVER)
|
||
|
endif
|
||
|
ifneq ($(filter $(shell uname),FreeBSD NetBSD DragonFly),)
|
||
|
PCLIBDIR := $(PREFIX)/libdata/pkgconfig
|
||
|
endif
|
||
|
|
||
|
all: lib$(LANGUAGE_NAME).a lib$(LANGUAGE_NAME).$(SOEXT) $(LANGUAGE_NAME).pc
|
||
|
|
||
|
lib$(LANGUAGE_NAME).a: $(OBJS)
|
||
|
$(AR) $(ARFLAGS) $@ $^
|
||
|
|
||
|
lib$(LANGUAGE_NAME).$(SOEXT): $(OBJS)
|
||
|
$(CC) $(LDFLAGS) $(LINKSHARED) $^ $(LDLIBS) -o $@
|
||
|
ifneq ($(STRIP),)
|
||
|
$(STRIP) $@
|
||
|
endif
|
||
|
|
||
|
$(LANGUAGE_NAME).pc: bindings/c/$(LANGUAGE_NAME).pc.in
|
||
|
sed -e 's|@URL@|$(PARSER_URL)|' \
|
||
|
-e 's|@VERSION@|$(VERSION)|' \
|
||
|
-e 's|@LIBDIR@|$(LIBDIR)|' \
|
||
|
-e 's|@INCLUDEDIR@|$(INCLUDEDIR)|' \
|
||
|
-e 's|@REQUIRES@|$(REQUIRES)|' \
|
||
|
-e 's|@ADDITIONAL_LIBS@|$(ADDITIONAL_LIBS)|' \
|
||
|
-e 's|=$(PREFIX)|=$${prefix}|' \
|
||
|
-e 's|@PREFIX@|$(PREFIX)|' $< > $@
|
||
|
|
||
|
$(PARSER): $(SRC_DIR)/grammar.json
|
||
|
$(TS) generate --no-bindings $^
|
||
|
|
||
|
install: all
|
||
|
install -d '$(DESTDIR)$(INCLUDEDIR)'/tree_sitter '$(DESTDIR)$(PCLIBDIR)' '$(DESTDIR)$(LIBDIR)'
|
||
|
install -m644 bindings/c/$(LANGUAGE_NAME).h '$(DESTDIR)$(INCLUDEDIR)'/tree_sitter/$(LANGUAGE_NAME).h
|
||
|
install -m644 $(LANGUAGE_NAME).pc '$(DESTDIR)$(PCLIBDIR)'/$(LANGUAGE_NAME).pc
|
||
|
install -m644 lib$(LANGUAGE_NAME).a '$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).a
|
||
|
install -m755 lib$(LANGUAGE_NAME).$(SOEXT) '$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).$(SOEXTVER)
|
||
|
ln -sf lib$(LANGUAGE_NAME).$(SOEXTVER) '$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).$(SOEXTVER_MAJOR)
|
||
|
ln -sf lib$(LANGUAGE_NAME).$(SOEXTVER_MAJOR) '$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).$(SOEXT)
|
||
|
|
||
|
uninstall:
|
||
|
$(RM) '$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).a \
|
||
|
'$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).$(SOEXTVER) \
|
||
|
'$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).$(SOEXTVER_MAJOR) \
|
||
|
'$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).$(SOEXT) \
|
||
|
'$(DESTDIR)$(INCLUDEDIR)'/tree_sitter/$(LANGUAGE_NAME).h \
|
||
|
'$(DESTDIR)$(PCLIBDIR)'/$(LANGUAGE_NAME).pc
|
||
|
|
||
|
clean:
|
||
|
$(RM) $(OBJS) $(LANGUAGE_NAME).pc lib$(LANGUAGE_NAME).a lib$(LANGUAGE_NAME).$(SOEXT)
|
||
|
|
||
|
test:
|
||
|
$(TS) test
|
||
|
|
||
|
.PHONY: all install uninstall clean test
|