(119 lines)
1 ifeq ($(wildcard config.mk),)2 all: config.mk3 $(MAKE) all4 install: config.mk5 $(MAKE) install6 install-files: config.mk7 $(MAKE) install-files8 install-lib: config.mk9 $(MAKE) install-lib10 test: config.mk11 $(MAKE) test12 config.mk: configure.sh13 bash ./configure.sh14 else16 include config.mk17 NAME=bp18 CC=cc19 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 -Wshadow22 # -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-strings34 OSFLAGS != case $$(uname -s) in *BSD|Darwin) echo '-D_BSD_SOURCE';; Linux) echo '-D_GNU_SOURCE';; *) echo '-D_DEFAULT_SOURCE';; esac35 EXTRA=36 G=37 O=-O338 ALL_FLAGS=$(CFLAGS) $(OSFLAGS) -DBP_NAME="\"$(NAME)\"" $(EXTRA) $(CWARN) $(G) $(O)40 LIBFILE=lib$(NAME).so41 CFILES=pattern.c utils.c match.c files.c printmatch.c utf8.c42 HFILES=files.h match.h pattern.h printmatch.h utf8.h utils.h43 OBJFILES=$(CFILES:.c=.o)45 $(NAME): $(OBJFILES) bp.c46 $(CC) $(ALL_FLAGS) -o $@ $(OBJFILES) bp.c48 $(LIBFILE): pattern.o utils.o match.o utf8.o49 $(CC) $^ $(ALL_FLAGS) -Wl,-soname,$(LIBFILE) -shared -o $@51 all: $(NAME) bp.153 %.o: %.c %.h utf8.h54 $(CC) -c $(ALL_FLAGS) -o $@ $<56 bp.1: bp.1.md57 pandoc --lua-filter=.pandoc/bold-code.lua -s $< -t man -o $@59 tags: $(CFILES) bp.c60 ctags *.c *.h62 clean:63 rm -f $(NAME) $(OBJFILES)64 @cd Lua && make clean66 lua:67 @cd Lua && make69 luatest:70 @cd Lua && make test72 test: $(NAME)73 ./$(NAME) Comment -r '[@0]' >/dev/null74 ./$(NAME) -g ./grammars/bp.bp '{Grammar}' ./grammars/bp.bp >/dev/null75 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 done80 tutorial:81 ./tutorial.sh83 leaktest: bp84 valgrind --leak-check=full ./bp -l -g ./grammars/bp.bp '{Grammar}' ./grammars/bp.bp86 splint:87 splint -posix-lib -weak -unrecog -initallelements -fullinitblock $(CFILES) bp.c89 #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.c96 install: $(NAME) bp.197 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.1104 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: bp112 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/null114 profile_pattern: bp115 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/null117 endif119 .PHONY: all clean install install-lib uninstall leaktest splint test tutorial lua profile luatest