cl-deck-builder2/Makefile
2024-03-05 22:11:33 -05:00

135 lines
4.5 KiB
Makefile

################################################################################
# Target Host Architecture
ARCH ?= x86_64
# docker / podman
DOCKER ?= podman
DOCKER_COMPOSE ?= podman-compose
# Other programs
LISP ?= sbcl
RM ?= rm -f
################################################################################
# Git Revision Info
GIT_REV ?= $(shell git rev-parse master)
# Influences the Docker Image Name
IMAGE_NAME ?= cl-deck-builder2-$(GIT_REV)
# For bind to this external address for docker-run
EXTERNAL_ADDR ?= 5005
EXTERNAL_SLYNK_ADDR ?= 4005
# Platform passed to Dockerfile
PLATFORM.x86_64 ?= linux/amd64
PLATFORM.aarch64 ?= linux/arm64/v8
PLATFORM ?= $(PLATFORM.$(ARCH))
################################################################################
# Code Borrwed from openbookstore <https://gitlab.com/myopenbookstore/openbookstore>
# List lisp files, unless they contains a #
SRC += $(shell find src/ -name '*.lisp' -a ! -name '*#*')
HTML += $(shell find templates/ -name '*.html' -a ! -name '*#*')
DEPS += $(SRC) $(HTML) $(wildcard *.asd)
# list of supported locales
LOCALES := en_US
# Example of how the variable should look after adding a new locale:
# LOCALES := en_US en_GB fr_FR es_ES
# list of .po files (computed from the LOCALES variable)
PO_FILES := $(foreach locale,$(LOCALES),locale/$(locale)/LC_MESSAGES/cl-deck-builder2.po)
# list of .mo files (computed from the LOCALES variable)
MO_FILES := $(foreach locale,$(LOCALES),locale/$(locale)/LC_MESSAGES/cl-deck-builder2.mo)
################################################################################
all:
docker-build: Dockerfile test
$(DOCKER) buildx build --platform $(PLATFORM) -t $(IMAGE_NAME) .
docker-run:
$(DOCKER) run --platform $(PLATFORM) \
--rm -it -P -p $(EXTERNAL_SLYNK_ADDR):4005 -p $(EXTERNAL_ADDR):5005 \
--userns=keep-id -v $(HOME)/public:/home/quicklisp/public:z $(IMAGE_NAME)
docker-clean:
-$(DOCKER) image rm -f $(IMAGE_NAME)
clean-fasl:
-find -name '*.fasl' | xargs $(RM) -fv
clean: clean-fasl
-find -name '*~' | xargs $(RM) -fv
$(RM) -rf bin/
# I use a feature flag, bc using djula:*recompile-templates-on-change*
# requires to load Djula before our app, and it isn't exactly the same meaning.
build-lisp-image: ${MO_FILES}
$(LISP) --non-interactive \
--eval '(ql:quickload "deploy")' \
--load cl-deck-builder2.asd \
--eval '(push :djula-binary *features*)' \
--eval '(ql:quickload :cl-deck-builder2)' \
--eval '(asdf:make :cl-deck-builder2)'
# This must use a custom-built SBCL with a special parameter,
# see linux-packaging README.
# I have it under ~/.local/bin/bin/sbcl
build-package:
$(LISP) --non-interactive \
--load cl-deck-builder2.asd \
--eval '(ql:quickload :cl-deck-builder2)' \
--eval '(setf *debugger-hook* (lambda (c h) (declare (ignore h)) (format t "~A~%" c) (sb-ext:quit :unix-status -1)))' \
--eval '(asdf:make :cl-deck-builder2)'
# build-gui:
# $(LISP) --non-interactive \
# --load cl-deck-builder2.asd \
# --eval '(ql:quickload :bookshops/gui)' \
# --eval '(asdf:make :bookshops/gui)'
test:
$(LISP) --non-interactive \
--load cl-deck-builder2.asd \
--load cl-deck-builder2-test.asd \
--eval "(ql:quickload '(:cl-deck-builder2 :cl-deck-builder2-test))" \
--eval "(asdf:test-system :cl-deck-builder2)"
.PHONY: tr
tr: ${MO_FILES}
PO_TEMPLATE_DIR := locale/templates/LC_MESSAGES
PO_TEMPLATE := ${PO_TEMPLATE_DIR}/cl-deck-builder2.pot
# Rule to extract translatable strings from SRC
${PO_TEMPLATE_DIR}/lisp.pot: $(SRC)
mkdir -p $(@D)
xgettext -k_ -kN_ --language=lisp -o $@ $^
# Rule to extract translatable strings from djula templates
${PO_TEMPLATE_DIR}/djula.pot: $(HTML) src/i18n.lisp
$(LISP) --non-interactive \
--eval '(ql:quickload "deploy")' \
--eval '(asdf:load-asd (truename "cl-deck-builder2.asd"))' \
--eval '(push :djula-binary *features*)' \
--eval '(ql:quickload :cl-deck-builder2)' \
--eval '(cl-deck-builder2.i18n:update-djula.pot)'
# Rule to combine djula.pot and lisp.pot into cl-deck-builder2.pot
${PO_TEMPLATE}: ${PO_TEMPLATE_DIR}/djula.pot ${PO_TEMPLATE_DIR}/lisp.pot
msgcat --use-first $^ > $@
# Rule to generate or update the .po files from the .pot file
locale/%/LC_MESSAGES/cl-deck-builder2.po: ${PO_TEMPLATE}
mkdir -p $(@D)
[ -f $@ ] || msginit --locale=$* \
--no-translator \
-i $< \
-o $@ \
&& msgmerge --update $@ $<
# Rule to create the .mo files from the .po files
locale/%/LC_MESSAGES/cl-deck-builder2.mo: locale/%/LC_MESSAGES/cl-deck-builder2.po
mkdir -p $(@D)
msgfmt -o $@ $<