79 lines
2.7 KiB
Makefile
79 lines
2.7 KiB
Makefile
# PatchBay top-level Makefile
|
|
|
|
PREFIX ?= /usr/local
|
|
SBINDIR ?= $(PREFIX)/sbin
|
|
LIBDIR ?= $(PREFIX)/lib/patchbay
|
|
DESTDIR ?=
|
|
|
|
CC ?= cc
|
|
CFLAGS ?= -O2 -g
|
|
CFLAGS += -std=c99 -D_GNU_SOURCE -Wall -Wextra -Wno-unused-parameter
|
|
PKGS := libssh2 sqlite3
|
|
PKG_CFLAGS := $(shell pkg-config --cflags $(PKGS))
|
|
PKG_LIBS := $(shell pkg-config --libs $(PKGS))
|
|
|
|
BUILD := build
|
|
SRC := backend/src
|
|
COMMON := config log net proto json services db stats
|
|
OBJS_ALL := $(addprefix $(BUILD)/,$(addsuffix .o,$(COMMON) hub client relay main))
|
|
OBJS_TEST := $(addprefix $(BUILD)/,$(addsuffix .o,config log net proto json services))
|
|
|
|
PYTHON ?= python3
|
|
|
|
.PHONY: all test test-c test-web install clean docker-test check-deps
|
|
|
|
all: $(BUILD)/patchbayd
|
|
|
|
$(BUILD):
|
|
mkdir -p $(BUILD)
|
|
|
|
# Fails early with a hint instead of a missing-header compiler error.
|
|
check-deps:
|
|
@pkg-config --exists $(PKGS) || { \
|
|
echo "missing build dependencies (pkg-config cannot find: $(PKGS))" >&2; \
|
|
echo " APT: sudo apt-get install build-essential pkg-config libssh2-1-dev libsqlite3-dev" >&2; \
|
|
echo " XBPS: sudo xbps-install base-devel pkg-config libssh2-devel sqlite-devel" >&2; \
|
|
echo " or: sudo ./install.sh --role client|target (keeps an existing config)" >&2; \
|
|
exit 1; }
|
|
|
|
# Embed schema.sql as a C string so the daemon has no runtime file dependency.
|
|
$(BUILD)/schema.h: schema.sql | $(BUILD)
|
|
{ printf 'static const char pb_schema_sql[] =\n'; \
|
|
sed -e 's/\\/\\\\/g' -e 's/"/\\"/g' -e 's/^/"/' -e 's/$$/\\n"/' $<; \
|
|
printf ';\n'; } > $@
|
|
|
|
$(BUILD)/%.o: $(SRC)/%.c $(wildcard $(SRC)/*.h) $(BUILD)/schema.h | $(BUILD) check-deps
|
|
$(CC) $(CFLAGS) $(PKG_CFLAGS) -I$(BUILD) -c -o $@ $<
|
|
|
|
$(BUILD)/patchbayd: $(OBJS_ALL)
|
|
$(CC) $(CFLAGS) -o $@ $^ $(PKG_LIBS)
|
|
|
|
$(BUILD)/test_runner: backend/tests/test_main.c $(OBJS_TEST)
|
|
$(CC) $(CFLAGS) $(PKG_CFLAGS) -I$(BUILD) -o $@ $^ $(PKG_LIBS)
|
|
|
|
test: test-c test-web
|
|
|
|
# Single C test: make test-c T=services_parse
|
|
test-c: $(BUILD)/test_runner
|
|
$(BUILD)/test_runner $(T)
|
|
|
|
# Single web test: make test-web T=tests.test_auth.AuthTest.test_login_2fa
|
|
test-web:
|
|
cd web && $(PYTHON) -m unittest $(if $(T),$(T),discover -s tests -t .) -v
|
|
|
|
install: all
|
|
install -Dm755 $(BUILD)/patchbayd $(DESTDIR)$(SBINDIR)/patchbayd
|
|
install -Dm755 sshd/patchbay-sshd $(DESTDIR)$(LIBDIR)/patchbay-sshd
|
|
install -Dm644 sshd/sshd_config.in $(DESTDIR)$(LIBDIR)/sshd_config.in
|
|
mkdir -p $(DESTDIR)$(LIBDIR)/web
|
|
cp -r web/patchbay_web $(DESTDIR)$(LIBDIR)/web/
|
|
install -Dm644 schema.sql $(DESTDIR)$(LIBDIR)/web/patchbay_web/schema.sql
|
|
rm -rf $(DESTDIR)$(LIBDIR)/web/patchbay_web/__pycache__
|
|
|
|
# Builds the images and runs the target + clients integration test.
|
|
docker-test:
|
|
docker/run-tests.sh
|
|
|
|
clean:
|
|
rm -rf $(BUILD)
|