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.

187 lines
4.3 KiB
Makefile

#!/usr/bin/env -S gmake all
# vim: set noexpandtab:
3 years ago
ifdef DEBUG
DBGCFLAGS=-DDEBUG -fno-omit-frame-pointer -fsanitize=address #-fsanitize=undefined -fsanitize=leak
3 years ago
DBGLDFLAGS=-lasan -lrt -lasan #-lubsan -llsan
3 years ago
endif
CC ?= gcc
CXX ?= g++
SHELL ?= bash
RM ?= rm -f
FIND ?= find
3 years ago
INCLUDES=-Ilibstrophe -Ideps \
3 years ago
$(shell xml2-config --cflags) \
$(shell pkg-config --cflags gpgme) \
3 years ago
$(shell pkg-config --cflags libsignal-protocol-c)
3 years ago
CFLAGS+=$(DBGCFLAGS) \
-fno-omit-frame-pointer -fPIC \
3 years ago
-fvisibility=hidden -fvisibility-inlines-hidden \
-fdebug-prefix-map=.=$(shell readlink -f .) \
3 years ago
-std=gnu99 -gdwarf-4 \
3 years ago
-Wall -Wextra -pedantic \
-Werror-implicit-function-declaration \
-Wno-missing-field-initializers \
-D_XOPEN_SOURCE=700 \
$(INCLUDES)
ifeq ($(CC),clang)
3 years ago
CFLAGS+=
else
CFLAGS+=
3 years ago
endif
CPPFLAGS+=$(DBGCFLAGS) \
3 years ago
-fno-omit-frame-pointer -fPIC \
3 years ago
-fvisibility=hidden -fvisibility-inlines-hidden \
-std=c++23 -gdwarf-4 \
3 years ago
-Wall -Wextra -pedantic \
-Wno-missing-field-initializers \
$(INCLUDES)
# -DDOCTEST_CONFIG_DISABLE
ifeq ($(CXX),clang)
3 years ago
CPPFLAGS+=
else
CPPFLAGS+=
3 years ago
endif
3 years ago
LDFLAGS+=$(DBGLDFLAGS) \
-std=c++23 -gdwarf-4 \
-fuse-ld=mold \
3 years ago
$(DBGCFLAGS)
LDLIBS=-lstrophe \
-lpthread \
$(shell xml2-config --libs) \
$(shell pkg-config --libs gpgme) \
3 years ago
$(shell pkg-config --libs libsignal-protocol-c) \
3 years ago
-lgcrypt \
-llmdb -lfl -lfmt
3 years ago
PREFIX ?= /usr/local
LIBDIR ?= $(PREFIX)/lib
HDRS=plugin.hh \
3 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 \
data/omemo.hh \
data/capability.hh \
3 years ago
xmpp/stanza.hh \
xmpp/ns.hh \
xmpp/node.hh \
3 years ago
SRCS=plugin.cpp \
account.cpp \
3 years ago
buffer.cpp \
channel.cpp \
command.cpp \
3 years ago
completion.cpp \
3 years ago
config.cpp \
connection.cpp \
3 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 \
data/omemo.cpp \
data/capability.cpp \
xmpp/presence.cpp \
xmpp/iq.cpp \
xmpp/node.cpp \
3 years ago
DEPS=deps/diff/libdiff.a \
3 years ago
sexp/sexp.a \
3 years ago
OBJS=$(patsubst %.cpp,.%.o,$(patsubst %.c,.%.o,$(patsubst config/%.cpp,config/.%.o,$(patsubst data/%.cpp,data/.%.o,$(patsubst xmpp/%.cpp,xmpp/.%.o,$(SRCS))))))
COVS=$(patsubst %.cpp,.%.cov.o,$(patsubst config/%.cpp,config/.%.cov.o,$(patsubst data/%.cpp,data/.%.cov.o,$(patsubst xmpp/%.cpp,xmpp/.%.cov.o,$(SRCS)))))
3 years ago
3 years ago
SUFFIX=$(shell date +%s)
$(eval GIT_REF=$(shell git describe --abbrev=6 --always --dirty 2>/dev/null || true))
.DEFAULT_GOAL := all
include test.mk
include install.mk
include clean.mk
include depend.mk
3 years ago
.PHONY: all
all: depend
$(MAKE) weechat-xmpp && $(MAKE) test
3 years ago
.PHONY: weechat-xmpp
3 years ago
weechat-xmpp: $(DEPS) xmpp.so
xmpp.so: $(DEPS) $(OBJS) $(HDRS)
$(CXX) -shared $(LDFLAGS) -o $@ -Wl,--as-needed $(OBJS) $(DEPS) $(LDLIBS)
3 years ago
git ls-files | xargs ls -d | xargs tar cz | objcopy --add-section .source=/dev/stdin xmpp.so
3 years ago
3 years ago
sexp/sexp.a: sexp/parser.o sexp/lexer.o sexp/driver.o
3 years ago
ar -r $@ $^
sexp/parser.o: sexp/parser.yy
cd sexp && bison -t -d -v parser.yy
$(CXX) $(CPPFLAGS) -fvisibility=default -c sexp/parser.tab.cc -o $@
3 years ago
sexp/lexer.o: sexp/lexer.l
cd sexp && flex -d --outfile=lexer.yy.cc lexer.l
$(CXX) $(CPPFLAGS) -fvisibility=default -c sexp/lexer.yy.cc -o $@
3 years ago
sexp/driver.o: sexp/driver.cpp
$(CXX) $(CPPFLAGS) -fvisibility=default -c $< -o $@
3 years ago
3 years ago
.%.o: %.c
$(CC) -DGIT_COMMIT=$(GIT_REF) $(CFLAGS) -c $< -o $@
3 years ago
3 years ago
.%.o: %.cpp
$(CXX) -DGIT_COMMIT=$(GIT_REF) $(CPPFLAGS) -c $< -o $@
3 years ago
.%.cov.o: %.cpp
@$(CXX) --coverage $(CPPFLAGS) -c $< -o $@
3 years ago
2 years ago
config/.%.o: config/%.cpp
$(CXX) $(CPPFLAGS) -c $< -o $@
config/.%.cov.o: config/%.cpp
@$(CXX) --coverage $(CPPFLAGS) -c $< -o $@
2 years ago
data/.%.o: data/%.cpp
$(CXX) $(CPPFLAGS) -c $< -o $@
data/.%.cov.o: data/%.cpp
@$(CXX) --coverage $(CPPFLAGS) -c $< -o $@
xmpp/.%.o: xmpp/%.cpp
3 years ago
$(CXX) $(CPPFLAGS) -c $< -o $@
xmpp/.%.cov.o: xmpp/%.cpp
@$(CXX) --coverage $(CPPFLAGS) -c $< -o $@
.PHONY: diff
3 years ago
deps/diff/libdiff.a:
git submodule update --init --recursive deps/diff
3 years ago
cd deps/diff && env -u MAKEFLAGS ./configure
$(MAKE) -C deps/diff CFLAGS=-fPIC
diff: deps/diff/libdiff.a