code / bp

Lines4.3K C3.3K Markdown541 YAML273 make110 Shell77 Lua54
(119 lines)
1 ifeq ($(wildcard config.mk),)
2 all: config.mk
3 $(MAKE) all
4 install: config.mk
5 $(MAKE) install
6 install-files: config.mk
7 $(MAKE) install-files
8 install-lib: config.mk
9 $(MAKE) install-lib
10 test: config.mk
11 $(MAKE) test
12 config.mk: configure.sh
13 bash ./configure.sh
14 else
16 include config.mk
17 NAME=bp
18 CC=cc
19 CFLAGS=-std=c2x -Werror -D_GNU_SOURCE -fPIC -flto=auto -fvisibility=hidden \
20 -fsanitize=signed-integer-overflow -fno-sanitize-recover -DBP_PREFIX='"$(PREFIX)"'
21 CWARN=-Wall -Wextra -Wno-format -Wshadow
22 # -Wpedantic -Wsign-conversion -Wtype-limits -Wunused-result -Wnull-dereference \
23 # -Waggregate-return -Walloc-zero -Walloca -Warith-conversion -Wcast-align -Wcast-align=strict \
24 # -Wdangling-else -Wdate-time -Wdisabled-optimization -Wdouble-promotion -Wduplicated-branches \
25 # -Wduplicated-cond -Wexpansion-to-defined -Wfloat-conversion -Wfloat-equal -Wformat-nonliteral \
26 # -Wformat-security -Wformat-signedness -Wframe-address -Winline -Winvalid-pch -Wjump-misses-init \
27 # -Wlogical-op -Wlong-long -Wmissing-format-attribute -Wmissing-include-dirs -Wmissing-noreturn \
28 # -Wnull-dereference -Woverlength-strings -Wpacked -Wpacked-not-aligned -Wpointer-arith \
29 # -Wredundant-decls -Wshadow -Wshadow=compatible-local -Wshadow=global -Wshadow=local \
30 # -Wsign-conversion -Wstack-protector -Wsuggest-attribute=const -Wswitch-default -Wswitch-enum \
31 # -Wsync-nand -Wtrampolines -Wundef -Wunsuffixed-float-constants -Wunused -Wunused-but-set-variable \
32 # -Wunused-const-variable -Wunused-local-typedefs -Wunused-macros -Wvariadic-macros -Wvector-operation-performance \
33 # -Wvla -Wwrite-strings
34 OSFLAGS != case $$(uname -s) in *BSD|Darwin) echo '-D_BSD_SOURCE';; Linux) echo '-D_GNU_SOURCE';; *) echo '-D_DEFAULT_SOURCE';; esac
35 EXTRA=
36 G=
37 O=-O3
38 ALL_FLAGS=$(CFLAGS) $(OSFLAGS) -DBP_NAME="\"$(NAME)\"" $(EXTRA) $(CWARN) $(G) $(O)
40 LIBFILE=lib$(NAME).so
41 CFILES=pattern.c utils.c match.c files.c printmatch.c utf8.c
42 HFILES=files.h match.h pattern.h printmatch.h utf8.h utils.h
43 OBJFILES=$(CFILES:.c=.o)
45 $(NAME): $(OBJFILES) bp.c
46 $(CC) $(ALL_FLAGS) -o $@ $(OBJFILES) bp.c
48 $(LIBFILE): pattern.o utils.o match.o utf8.o
49 $(CC) $^ $(ALL_FLAGS) -Wl,-soname,$(LIBFILE) -shared -o $@
51 all: $(NAME) bp.1
53 %.o: %.c %.h utf8.h
54 $(CC) -c $(ALL_FLAGS) -o $@ $<
56 bp.1: bp.1.md
57 pandoc --lua-filter=.pandoc/bold-code.lua -s $< -t man -o $@
59 tags: $(CFILES) bp.c
60 ctags *.c *.h
62 clean:
63 rm -f $(NAME) $(OBJFILES)
64 @cd Lua && make clean
66 lua:
67 @cd Lua && make
69 luatest:
70 @cd Lua && make test
72 test: $(NAME)
73 ./$(NAME) Comment -r '[@0]' >/dev/null
74 ./$(NAME) -g ./grammars/bp.bp '{Grammar}' ./grammars/bp.bp >/dev/null
75 for test in tests/*.sh; do \
76 PATH=".:$$PATH" sh "$$test" <"$${test/.sh/.in}" | diff -q - "$${test/.sh/.out}" ||\
77 PATH=".:$$PATH" sh "$$test" <"$${test/.sh/.in}" | diff -y --color=always - "$${test/.sh/.out}"; \
78 done
80 tutorial:
81 ./tutorial.sh
83 leaktest: bp
84 valgrind --leak-check=full ./bp -l -g ./grammars/bp.bp '{Grammar}' ./grammars/bp.bp
86 splint:
87 splint -posix-lib -weak -unrecog -initallelements -fullinitblock $(CFILES) bp.c
89 #splint:
90 # splint -posix-lib -checks -mustfreefresh -mustfreeonly -temptrans -immediatetrans -branchstate \
91 # -compmempass -nullret -nullpass -nullderef -kepttrans -boolops -initallelements -fullinitblock \
92 # -compdef -usereleased -unrecog -dependenttrans -predboolothers -ownedtrans -unqualifiedtrans \
93 # -onlytrans -usedef -nullassign -compdestroy -globstate -nullstate -statictrans -predboolint \
94 # $(CFILES) bp.c
96 install: $(NAME) bp.1
97 mkdir -p -m 755 "$(PREFIX)/man/man1" "$(PREFIX)/bin" "$(PREFIX)/share/$(NAME)"
98 cp -r grammars "$(PREFIX)/share/$(NAME)/"
99 cp bp.1 "$(PREFIX)/man/man1/$(NAME).1"
100 rm -f "$(PREFIX)/bin/$(NAME)"
101 cp $(NAME) "$(PREFIX)/bin/"
103 install-lib: $(LIBFILE) bp.1
104 mkdir -p -m 755 "$(PREFIX)/lib" "$(PREFIX)/include/$(NAME)"
105 cp $(LIBFILE) "$(PREFIX)/lib"
106 cp pattern.h match.h "$(PREFIX)/include/$(NAME)"
108 uninstall:
109 rm -rf "$(PREFIX)/bin/$(NAME)" "$(PREFIX)/man/man1/$(NAME).1" "$(PREFIX)/share/$(NAME)"
111 profile_grammar: bp
112 perf stat -r 100 -e L1-dcache-loads,L1-dcache-load-misses,L1-dcache-stores -e cycles ./bp -f plain -g bp -p Grammar grammars/bp.bp >/dev/null
114 profile_pattern: bp
115 perf stat -r 1 -e L1-dcache-loads,L1-dcache-load-misses,L1-dcache-stores -e cycles ./bp -f plain -p 'id parens' /usr/include/*.h >/dev/null
117 endif
119 .PHONY: all clean install install-lib uninstall leaktest splint test tutorial lua profile luatest