-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
80 lines (65 loc) · 3.03 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
70
71
72
73
74
75
76
77
78
79
80
.POSIX:
# just in case FreeBSD's make implementation screws up the current directory
.OBJDIR: ./
.SUFFIXES:
CC = gcc
NAME = peg4c
ASTNODE_ADD_PARENT = 0
SUB_MAKE_ARGS = CC=$(CC) SANITIZE=$(SANITIZE) ASTNODE_ADD_PARENT=$(ASTNODE_ADD_PARENT)
# for use in specifying a PCRE2 path and (for linux) overriding GNU_regex
PCRE2 =
COMMON_CFLAGS = -Wall -Werror -Wextra -pedantic -Wno-unused -Wno-unused-parameter -std=gnu99 -fPIC -g3 -DASTNODE_ADD_PARENT=$(ASTNODE_ADD_PARENT)
DBG_CFLAGS = $(COMMON_CFLAGS) -O0
CFLAGS = $(COMMON_CFLAGS) -O2 -DNDEBUG
COMMON_IFLAGS = -Iinclude -Ilib/TypeMemPools/include/
DBG_IFLAGS = $(COMMON_IFLAGS)
IFLAGS = $(COMMON_IFLAGS)
COMMON_LFLAGS = -Lbin '-Wl,-rpath,$$ORIGIN/.'
LIB_LFLAGS = $(COMMON_LFLAGS) -L/usr/local/lib
DBG_LFLAGS = $(COMMON_LFLAGS) -lpeg4cd
LFLAGS = $(COMMON_LFLAGS) -lpeg4c
EXT_LIB_OBJS = lib/TypeMemPools/src/mempool.o
DBG_EXT_LIB_OBJS = lib/TypeMemPools/src/mempool.do
LIB_OBJS = src/astnode.o src/hash_utils.o src/packrat_cache.o src/parser.o src/rule.o src/token.o src/utils.o
DBG_LIB_OBJS = src/astnode.do src/hash_utils.do src/packrat_cache.do src/parser.do src/rule.do src/token.do src/utils.do
EXE_OBJS = src/peg4c.o src/peg4cparser.o src/peg4cstring.o src/peg4cbuild.o src/peg4ctransform.o
all: build_paths bin/lib$(NAME).so bin/lib$(NAME)d.so bin/$(NAME) bin/test
# OpenBSD weirdness
.MAIN: all
install:
cp bin/lib*.so /usr/local/lib
bin/test: bin/lib$(NAME)d.so
@touch examples/peg4c/peg4c.grmr
@(cd tests && unset MAKELEVEL && make $(SUB_MAKE_ARGS))
@(echo "running tests")
$@ --verbose
@(cd examples/peg4c && touch peg4c.grmr && unset MAKELEVEL && make $(SUB_MAKE_ARGS) test)
ext_libs: $(EXT_LIB_OBJS) $(DBG_EXT_LIB_OBJS)
@(cd lib/TypeMemPools && unset MAKELEVEL && make $(SUB_MAKE_ARGS))
@cp lib/TypeMemPools/include/* include/peg4c/
clean:
@rm -f src/*.o src/*.do src/*.ast include/peg4c/mempool.h
@rm -rf bin
@(cd tests && unset MAKELEVEL && make clean)
@(cd lib/TypeMemPools && unset MAKELEVEL && make clean)
@(cd examples/peg4c && unset MAKELEVEL && make clean)
build_paths:
@mkdir -p bin
bin/lib$(NAME).so: build_paths ext_libs $(LIB_OBJS)
@echo building library $@
@if [ -n "$$USE_PCRE2"] || [ $$(uname -s) != "Linux" ] ; then export USE_PCRE2="-lpcre2-8" ; else export USE_PCRE2="" ; fi ; \
$(CC) -shared -fPIC $(LIB_OBJS) $(EXT_LIB_OBJS) -o $@ $(LIB_LFLAGS) $$USE_PCRE2
bin/lib$(NAME)d.so: build_paths ext_libs $(DBG_LIB_OBJS)
@echo building debug library $@
@if [ $$(uname -s) != "Linux" ] ; then export USE_PCRE2="-lpcre2-8" ; else export USE_PCRE2="" ; fi ; \
$(CC) -shared -fPIC $(DBG_LIB_OBJS) $(DBG_EXT_LIB_OBJS) -o $@ $(LIB_LFLAGS) $$USE_PCRE2
bin/$(NAME): build_paths bin/lib$(NAME).so $(EXE_OBJS)
@echo building peg4c executable $@
@$(CC) $(CFLAGS) $(IFLAGS) $(EXE_OBJS) -o $@ $(LFLAGS)
.SUFFIXES: .c .o .do
# should build in a compile flag to use PCRE2 if USE_PCRE2 is set
.c.o:
@$(CC) $(CFLAGS) $(IFLAGS) -c $< -o $@
.c.do:
@if [ -n "$(SANITIZE)" ] ; then export DBGOPT="-fsanitize=address,undefined"; else export DBGOPT="" ; fi ; \
$(CC) $(DBG_CFLAGS) $$DBGOPT $(DBG_IFLAGS) -c $< -o $@