-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Makefile
69 lines (56 loc) · 2.1 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# copyright: This parser build is created and provided by Panic inc
# You do not require this file in order to use the tree-sitter-blade
# This is only for .dylib generation for Nova extension development
# Repository
SRC_DIR := src
PARSER_REPO_URL ?= $(shell git -C $(SRC_DIR) remote get-url origin )
# the # in the sed pattern has to be escaped or it will be interpreted as a comment
PARSER_NAME ?= $(shell basename $(PARSER_REPO_URL) | cut -d '-' -f3 | sed 's\#.git\#\#')
UPPER_PARSER_NAME := $(shell echo $(PARSER_NAME) | tr a-z A-Z )
# install directory layout
PREFIX ?= /usr/local
INCLUDEDIR ?= $(PREFIX)/include
LIBDIR ?= $(PREFIX)/lib
# collect sources, and link if necessary
# Some Tree Sitter grammars include .cc files directly in others,
# so we shouldn't just wildcard select them all.
# Only collect known file names.
ifneq ("$(wildcard $(SRC_DIR)/parser.c)", "")
SRC += $(SRC_DIR)/parser.c
endif
ifneq ("$(wildcard $(SRC_DIR)/scanner.c)", "")
SRC += $(SRC_DIR)/scanner.c
endif
ifneq ("$(wildcard $(SRC_DIR)/parser.cc)", "")
CPPSRC += $(SRC_DIR)/parser.cc
endif
ifneq ("$(wildcard $(SRC_DIR)/scanner.cc)", "")
CPPSRC += $(SRC_DIR)/scanner.cc
endif
ifeq (, $(CPPSRC))
ADDITIONALLIBS :=
else
ADDITIONALLIBS := -lc++
endif
SRC += $(CPPSRC)
OBJ := $(addsuffix .o,$(basename $(SRC)))
CFLAGS ?= -O3 -Wall -Wextra -I$(SRC_DIR)
CXXFLAGS ?= -O3 -Wall -Wextra -I$(SRC_DIR)
override CFLAGS += -std=gnu99 -fPIC
override CXXFLAGS += -fPIC
LINKSHARED := $(LINKSHARED)-dynamiclib -Wl,
ifneq ($(ADDITIONALLIBS),)
LINKSHARED := $(LINKSHARED)$(ADDITIONALLIBS),
endif
LINKSHARED := $(LINKSHARED)-install_name,$(LIBDIR)/libtree-sitter-$(PARSER_NAME).dylib,-rpath,@executable_path/../Frameworks
all: libtree-sitter-$(PARSER_NAME).dylib
libtree-sitter-$(PARSER_NAME).dylib: $(OBJ)
$(CC) $(LDFLAGS) $(LINKSHARED) $^ $(LDLIBS) -o $@
install: all
install -d '$(DESTDIR)$(LIBDIR)'
install -m755 libtree-sitter-$(PARSER_NAME).dylib '$(DESTDIR)$(LIBDIR)'/libtree-sitter-$(PARSER_NAME).dylib
install -d '$(DESTDIR)$(INCLUDEDIR)'/tree_sitter
clean:
rm -f $(OBJ) libtree-sitter-$(PARSER_NAME).dylib
rm -rf build/
.PHONY: all install clean