You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

249 lines
6.3 KiB
Makefile

2 years ago
ifdef DEBUG
2 years ago
DBGCFLAGS=-fno-omit-frame-pointer -fsanitize=address #-fsanitize=undefined -fsanitize=leak
DBGLDFLAGS=-lasan -lrt -lasan #-lubsan -llsan
2 years ago
endif
RM ?= rm -f
FIND ?= find
2 years ago
INCLUDES=-Ilibstrophe -Ideps -Ideps/optional/include -Ideps/range-v3/include -Ideps/fmt/include \
2 years ago
$(shell xml2-config --cflags) \
$(shell pkg-config --cflags gpgme) \
2 years ago
$(shell pkg-config --cflags libsignal-protocol-c)
2 years ago
CFLAGS+=$(DBGCFLAGS) \
-fno-omit-frame-pointer -fPIC \
2 years ago
-fvisibility=hidden -fvisibility-inlines-hidden \
-fdebug-prefix-map=.=$(shell readlink -f .) \
2 years ago
-std=gnu99 -gdwarf-4 \
2 years ago
-Wall -Wextra -pedantic \
-Werror-implicit-function-declaration \
-Wno-missing-field-initializers \
-D_XOPEN_SOURCE=700 \
$(INCLUDES)
2 years ago
ifeq ($(CC),gcc)
CFLAGS+= -fkeep-inline-functions
else ifeq ($(CC),clang)
CFLAGS+=
endif
CPPFLAGS+=$(DBGCFLAGS) -O0 \
2 years ago
-fno-omit-frame-pointer -fPIC \
2 years ago
-fvisibility=hidden -fvisibility-inlines-hidden \
-std=c++23 -gdwarf-4 \
2 years ago
-Wall -Wextra -pedantic \
-Wno-missing-field-initializers \
$(INCLUDES)
# -DDOCTEST_CONFIG_DISABLE
2 years ago
ifeq ($(CXX),g++)
CPPFLAGS+= -fkeep-inline-functions
else ifeq ($(CXX),clang)
CPPFLAGS+=
endif
2 years ago
LDFLAGS+=$(DBGLDFLAGS) \
-shared -gdwarf-4 \
$(DBGCFLAGS)
LDLIBS=-lstrophe \
-lpthread \
$(shell xml2-config --libs) \
$(shell pkg-config --libs gpgme) \
2 years ago
$(shell pkg-config --libs libsignal-protocol-c) \
2 years ago
-lgcrypt \
2 years ago
-llmdb -lfl
2 years ago
PREFIX ?= /usr/local
LIBDIR ?= $(PREFIX)/lib
HDRS=plugin.hh \
2 years ago
account.hh \
buffer.hh \
channel.hh \
command.hh \
completion.hh \
config.hh \
connection.hh \
input.hh \
message.hh \
omemo.hh \
pgp.hh \
user.hh \
util.hh \
2 years ago
config/breadcrumb.hh \
config/file.hh \
config/section.hh \
config/account.hh \
config/option.hh \
2 years ago
xmpp/stanza.hh \
xmpp/ns.hh \
xmpp/node.hh \
2 years ago
SRCS=plugin.cpp \
account.cpp \
2 years ago
buffer.cpp \
channel.cpp \
command.cpp \
2 years ago
completion.cpp \
2 years ago
config.cpp \
connection.cpp \
2 years ago
input.cpp \
message.cpp \
omemo.cpp \
pgp.cpp \
user.cpp \
util.cpp \
2 years ago
config/breadcrumb.cpp \
config/file.cpp \
config/section.cpp \
config/account.cpp \
config/option.cpp \
xmpp/presence.cpp \
xmpp/iq.cpp \
xmpp/node.cpp \
2 years ago
DEPS=deps/diff/libdiff.a \
2 years ago
deps/fmt/libfmt.a \
2 years ago
sexp/sexp.a \
2 years ago
2 years ago
OBJS=$(patsubst %.cpp,.%.o,$(patsubst %.c,.%.o,$(patsubst config/%.cpp,config/.%.o,$(patsubst xmpp/%.cpp,xmpp/.%.o,$(SRCS)))))
COVS=$(patsubst %.cpp,.%.cov.o,$(patsubst config/%.cpp,config/.%.cov.o,$(patsubst xmpp/%.cpp,xmpp/.%.cov.o,$(SRCS))))
2 years ago
2 years ago
SUFFIX=$(shell date +%s)
2 years ago
.PHONY: all
2 years ago
all:
make depend
make weechat-xmpp && make test
2 years ago
.PHONY: weechat-xmpp release
2 years ago
weechat-xmpp: $(DEPS) xmpp.so
2 years ago
release: xmpp.so
cp xmpp.so .xmpp.so.$(SUFFIX)
ln -sf .xmpp.so.$(SUFFIX) .xmpp.so
2 years ago
xmpp.so: $(DEPS) $(OBJS) $(HDRS)
2 years ago
$(CXX) $(LDFLAGS) -o $@ $(OBJS) $(DEPS) $(LDLIBS)
2 years ago
git ls-files | xargs ls -d | xargs tar cz | objcopy --add-section .source=/dev/stdin xmpp.so
#objcopy --dump-section .source=/dev/stdout xmpp.so | tar tz
2 years ago
2 years ago
sexp/sexp.a: sexp/parser.o sexp/lexer.o sexp/driver.o
2 years ago
ar -r $@ $^
sexp/parser.o: sexp/parser.yy
cd sexp && bison -t -d -v parser.yy
$(CXX) $(CPPFLAGS) -c sexp/parser.tab.cc -o $@
sexp/lexer.o: sexp/lexer.l
cd sexp && flex -d --outfile=lexer.yy.cc lexer.l
$(CXX) $(CPPFLAGS) -c sexp/lexer.yy.cc -o $@
sexp/driver.o: sexp/driver.cpp
$(CXX) $(CPPFLAGS) -c $< -o $@
2 years ago
.%.o: %.c
$(eval GIT_REF=$(shell git describe --abbrev=6 --always --dirty 2>/dev/null || true))
$(CC) -DGIT_COMMIT=$(GIT_REF) $(CFLAGS) -c $< -o $@
2 years ago
2 years ago
.%.o: %.cpp
$(eval GIT_REF=$(shell git describe --abbrev=6 --always --dirty 2>/dev/null || true))
$(CXX) -DGIT_COMMIT=$(GIT_REF) $(CPPFLAGS) -c $< -o $@
2 years ago
.%.cov.o: %.cpp
@$(CXX) --coverage $(CPPFLAGS) -O0 -c $< -o $@
2 years ago
2 years ago
config/.%.o: config/%.cpp
$(CXX) $(CPPFLAGS) -c $< -o $@
config/.%.cov.o: config/%.cpp
@$(CXX) --coverage $(CPPFLAGS) -O0 -c $< -o $@
xmpp/.%.o: xmpp/%.cpp
2 years ago
$(CXX) $(CPPFLAGS) -c $< -o $@
xmpp/.%.cov.o: xmpp/%.cpp
@$(CXX) --coverage $(CPPFLAGS) -O0 -c $< -o $@
2 years ago
.PHONY: diff fmt
2 years ago
deps/diff/libdiff.a:
git submodule update --init --recursive
cd deps/diff && env -u MAKEFLAGS ./configure
$(MAKE) -C deps/diff CFLAGS=-fPIC
diff: deps/diff/libdiff.a
2 years ago
deps/fmt/libfmt.a:
git submodule update --init --recursive
env -u MAKEFLAGS cmake -S deps/fmt -B deps/fmt \
-DCMAKE_POSITION_INDEPENDENT_CODE=ON
$(MAKE) -C deps/fmt fmt
fmt: deps/fmt/libfmt.a
2 years ago
tests/xmpp.cov.so: $(COVS) $(DEPS) $(HDRS)
2 years ago
$(CXX) --coverage -O0 $(LDFLAGS) -o tests/xmpp.cov.so $(COVS) $(DEPS) $(LDLIBS) -lstdc++
2 years ago
tests/run: $(COVS) tests/main.cc tests/xmpp.cov.so
env --chdir tests $(CXX) $(CPPFLAGS) -o run ./xmpp.cov.so main.cc $(LDLIBS)
2 years ago
2 years ago
.PHONY: test
2 years ago
test: tests/run
2 years ago
env --chdir tests ./run -s
2 years ago
2 years ago
.PHONY: coverage
2 years ago
coverage: tests/run
2 years ago
gcov -m -abcfu -rqk -i .*.gcda config/.*.gcda xmpp/.*.gcda
2 years ago
2 years ago
.PHONY: debug
2 years ago
debug: xmpp.so
env LD_PRELOAD=$(DEBUG) gdb -ex "handle SIGPIPE nostop noprint pass" --args \
weechat -a -P 'alias,buflist,exec,irc,relay' -r '/plugin load ./xmpp.so'
2 years ago
2 years ago
.PHONY: depend
depend: $(DEPS) $(SRCS) $(HDRS)
2 years ago
$(RM) -f ./.depend
echo > ./.depend
for src in $(SRCS) ; do \
if [[ $$src == *.cpp ]]; then \
g++ $(CPPFLAGS) -MM -MMD -MP -MF - \
-MT .$${src/.cpp/.o} $$src >> ./.depend || true ; \
2 years ago
elif [[ $$src == *.c ]]; then \
gcc $(CFLAGS) -MM -MMD -MP -MF - \
-MT .$${src/.c/.o} $$src >> ./.depend || true ; \
2 years ago
fi \
done
sed -i 's/\.\([a-z]*\/\)/\1./' .depend
2 years ago
.PHONY: tidy
2 years ago
tidy:
$(FIND) . -name "*.o" -delete
2 years ago
$(FIND) . -name "*.gcno" -delete
$(FIND) . -name "*.gcda" -delete
2 years ago
2 years ago
.PHONY: clean
2 years ago
clean:
2 years ago
$(RM) -f $(OBJS) $(COVS) \
sexp/parser.tab.cc sexp/parser.tab.hh \
sexp/location.hh sexp/position.hh \
sexp/stack.hh sexp/parser.output sexp/parser.o \
sexp/lexer.o sexp/lexer.yy.cc sexp/sexp.a
2 years ago
$(MAKE) -C deps/diff clean || true
2 years ago
$(MAKE) -C deps/fmt clean || true
2 years ago
git submodule foreach --recursive git clean -xfd || true
git submodule foreach --recursive git reset --hard || true
2 years ago
.PHONY: distclean
2 years ago
distclean: clean
$(RM) *~ .depend
2 years ago
.PHONY: install
2 years ago
install: xmpp.so
ifeq ($(shell id -u),0)
mkdir -p $(DESTDIR)$(LIBDIR)/weechat/plugins
cp xmpp.so $(DESTDIR)$(LIBDIR)/weechat/plugins/xmpp.so
chmod 644 $(DESTDIR)$(LIBDIR)/weechat/plugins/xmpp.so
else
mkdir -p ~/.weechat/plugins
cp xmpp.so ~/.weechat/plugins/xmpp.so
chmod 755 ~/.weechat/plugins/xmpp.so
endif
2 years ago
.PHONY: check
2 years ago
check:
clang-check --analyze *.c *.cc *.cpp
include .depend