-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #602 from eli-schwartz/makefile
Add a simple Makefile-based build system.
- Loading branch information
Showing
3 changed files
with
84 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
VERSION := 0.6.3 | ||
|
||
# install directory layout | ||
PREFIX ?= /usr/local | ||
INCLUDEDIR ?= $(PREFIX)/include | ||
LIBDIR ?= $(PREFIX)/lib | ||
PCLIBDIR ?= $(LIBDIR)/pkgconfig | ||
|
||
# collect sources | ||
ifneq ($(AMALGAMATED),1) | ||
SRC := $(wildcard lib/src/*.c) | ||
# do not double-include amalgamation | ||
SRC := $(filter-out lib/src/lib.c,$(SRC)) | ||
else | ||
# use amalgamated build | ||
SRC := lib/src/lib.c | ||
endif | ||
OBJ := $(SRC:.c=.o) | ||
|
||
# define default flags, and override to append mandatory flags | ||
CFLAGS ?= -O3 | ||
override CFLAGS += -std=gnu99 -fPIC -Ilib/src -Ilib/include | ||
|
||
# ABI versioning | ||
SONAME_MAJOR := 0 | ||
SONAME_MINOR := 0 | ||
|
||
# OS-specific bits | ||
ifeq ($(shell uname),Darwin) | ||
SOEXT = dylib | ||
SOEXTVER_MAJOR = $(SONAME_MAJOR).dylib | ||
SOEXTVER = $(SONAME_MAJOR).$(SONAME_MINOR).dylib | ||
LINKSHARED += -dynamiclib -Wl,-install_name,$(LIBDIR)/libtree-sitter.$(SONAME_MAJOR).dylib | ||
else | ||
SOEXT = so | ||
SOEXTVER_MAJOR = so.$(SONAME_MAJOR) | ||
SOEXTVER = so.$(SONAME_MAJOR).$(SONAME_MINOR) | ||
LINKSHARED += -shared -Wl,-soname,libtree-sitter.so.$(SONAME_MAJOR) | ||
endif | ||
ifneq (,$(filter $(shell uname),FreeBSD NetBSD DragonFly)) | ||
PCLIBDIR := $(PREFIX)/libdata/pkgconfig | ||
endif | ||
|
||
all: libtree-sitter.a libtree-sitter.$(SOEXTVER) | ||
|
||
libtree-sitter.a: $(OBJ) | ||
$(AR) rcs $@ $^ | ||
|
||
libtree-sitter.$(SOEXTVER): $(OBJ) | ||
$(CC) $(LDFLAGS) $(LINKSHARED) $^ $(LDLIBS) -o $@ | ||
ln -sf $@ libtree-sitter.$(SOEXT) | ||
ln -sf $@ libtree-sitter.$(SOEXTVER_MAJOR) | ||
|
||
install: all | ||
install -d '$(DESTDIR)$(LIBDIR)' | ||
install -m755 libtree-sitter.a '$(DESTDIR)$(LIBDIR)'/libtree-sitter.a | ||
install -m755 libtree-sitter.$(SOEXTVER) '$(DESTDIR)$(LIBDIR)'/libtree-sitter.$(SOEXTVER) | ||
ln -sf libtree-sitter.$(SOEXTVER) '$(DESTDIR)$(LIBDIR)'/libtree-sitter.$(SOEXTVER_MAJOR) | ||
ln -sf libtree-sitter.$(SOEXTVER) '$(DESTDIR)$(LIBDIR)'/libtree-sitter.$(SOEXT) | ||
install -d '$(DESTDIR)$(INCLUDEDIR)'/tree_sitter | ||
install -m644 lib/include/tree_sitter/*.h '$(DESTDIR)$(INCLUDEDIR)'/tree_sitter/ | ||
install -d '$(DESTDIR)$(PCLIBDIR)' | ||
sed -e 's|@LIBDIR@|$(LIBDIR)|;s|@INCLUDEDIR@|$(INCLUDEDIR)|;s|@VERSION@|$(VERSION)|' \ | ||
-e 's|=$(PREFIX)|=$${prefix}|' \ | ||
-e 's|@PREFIX@|$(PREFIX)|' \ | ||
tree-sitter.pc.in > '$(DESTDIR)$(PCLIBDIR)'/tree-sitter.pc | ||
|
||
clean: | ||
rm -f lib/src/*.o libtree-sitter.a libtree-sitter.$(SOEXT) libtree-sitter.$(SOEXTVER_MAJOR) libtree-sitter.$(SOEXTVER) | ||
|
||
.PHONY: all install clean |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
prefix=@PREFIX@ | ||
libdir=@LIBDIR@ | ||
includedir=@INCLUDEDIR@ | ||
|
||
Name: tree-sitter | ||
Description: An incremental parsing system for programming tools | ||
URL: https://tree-sitter.github.io/ | ||
Version: @VERSION@ | ||
Libs: -L${libdir} -ltree-sitter | ||
Cflags: -I${includedir} |