Skip to content
Repos

mologram

Makefile 3.4 KB85 lines Opens in site

Directory Raw Download

# mologram: thin wrapper over CMake. Every target assures its own build directory.
BUILD ?= build
VERSION := $(shell cat VERSION)
CONTAINER ?= $(shell command -v podman 2>/dev/null || command -v docker 2>/dev/null)
IMAGE ?= mologram
NAME ?= mologram
DATA ?= $(HOME)/.local/share/mologram
RUNDIR ?= $(DATA)/run
JOBS ?= $(shell nproc 2>/dev/null || echo 4)

.PHONY: live-ui-write build test run clean check deps live live-media dist image image-check up down logs lint

deps:
	$(MAKE) -C ../grrbackupclankertelegram/tapi build

$(BUILD)/Makefile: CMakeLists.txt VERSION
	cmake -S . -B $(BUILD)

build: $(BUILD)/Makefile
	cmake --build $(BUILD) -j$(JOBS)

test: build
	./$(BUILD)/run_tests

live: build
	flock /tmp/mologram-live.lock ./$(BUILD)/live_tapi

live-ui-write: build
	flock /tmp/mologram-live.lock ./$(BUILD)/live_ui_write ../grrbackupclankertelegram/.env.json /tmp/probe_auth.tsv

live-media: build
	flock /tmp/mologram-live.lock ./$(BUILD)/live_media ../grrbackupclankertelegram/.env.json /tmp/probe_auth.tsv

run: build
	./$(BUILD)/mologram

check: test
	./$(BUILD)/mologram --help >/dev/null
	./$(BUILD)/mologram --version
	./$(BUILD)/mologram --dump-config >/dev/null
	@for b in mologram mologramd; do ldd ./$(BUILD)/$$b 2>&1 | grep -q 'not a dynamic executable' && echo "static $$b: ok" || (echo "static $$b: FAILED"; exit 1); done
	./$(BUILD)/mologramd --help >/dev/null

clean:
	rm -rf $(BUILD) dist

# ---- packaging (ADR 0004, ADR 0014): stripped static binaries, a scratch image that only holds them ----

dist: build
	mkdir -p dist
	strip -o dist/mologram $(BUILD)/mologram
	strip -o dist/mologramd $(BUILD)/mologramd
	@ls -l dist/mologram dist/mologramd

image: dist
	@test -n "$(CONTAINER)" || (echo "image: neither podman nor docker found"; exit 1)
	$(CONTAINER) build -f Containerfile -t $(IMAGE):$(VERSION) -t $(IMAGE):latest .

# Proof of the static gate: both binaries start in an image with no libraries and no shell at all.
image-check: image
	$(CONTAINER) run --rm --entrypoint /usr/local/bin/mologram $(IMAGE):latest --version
	$(CONTAINER) run --rm --entrypoint /usr/local/bin/mologramd $(IMAGE):latest --version
	$(CONTAINER) run --rm --entrypoint /usr/local/bin/mologram $(IMAGE):latest --help >/dev/null
	$(CONTAINER) run --rm --entrypoint /usr/local/bin/mologramd $(IMAGE):latest --help >/dev/null
	@echo "image-check: ok"

# The daemon in a container. The UI runs on the host: mologram --socket $(RUNDIR)/mologram.sock
up: image
	@test -f .env.json || (echo "up: copy the credentials first, see README.md Setup (.env.json is missing)"; exit 1)
	mkdir -p $(DATA) $(RUNDIR)
	$(CONTAINER) run -d --name $(NAME) -v $(DATA):/data -v $(RUNDIR):/run/mologram -v $(CURDIR)/.env.json:/data/.env.json:ro $(IMAGE):latest --socket /run/mologram/mologram.sock --config /data/.env.json --foreground
	@echo "up: daemon started, UI: build/mologram --socket $(RUNDIR)/mologram.sock"

down:
	-$(CONTAINER) stop $(NAME)
	-$(CONTAINER) rm $(NAME)

logs:
	$(CONTAINER) logs $(NAME)

# Documentation and style gates: the docs tests, and no U+2014 anywhere in the sources or documents.
lint: build
	./$(BUILD)/run_tests --tags docs
	@if grep -rnF "$$(printf '\342\200\224')" --include=*.md --include=*.cpp --include=*.hpp --include=*.txt --include=Makefile --include=Containerfile --exclude=prompt.md --exclude-dir=build --exclude-dir=dist --exclude-dir=.claude --exclude-dir='.g*' . ; then echo "lint: U+2014 found"; exit 1; fi
	@echo "lint: ok"
42.9ms