smr/Makefile

191 lines
5.8 KiB
Makefile

# Binaries
ECHO=echo
KODEV=kodev
MKDIR=mkdir -p
COPY=cp
RM=rm -f
SPP=spp
CD=cd
AWK=awk
GREP=grep
SORT=sort
TEST=test
CAT=cat
TRBLDOC=trbldoc
# Config
worker_chroot = $(smr_var)/kore_worker
kmgr_chroot = $(smr_var)/kore_kmgr
parent_chroot = $(smr_var)/kore_parent
conf_path = /etc/smr
smr_bin_path = /usr/local/lib
app_root=$(worker_chroot)/var/smr
ifeq ($(DEV),true)
worker_chroot = ./kore_chroot
kmgr_chroot = ./kore_chroot
parent_chroot = ./kore_chroot
conf_path = ./kore_chroot/conf
smr_bin_path = ./kore_chroot
app_root=./kore_chroot/app
endif
mirror=http://dl-cdn.alpinelinux.org/alpine/
arch=aarch64
version=2.12.9
certbot_email=--register-unsafely-without-email
#certbot_email=-m you@cock.li
user=robin
port=8888
domain=test.monster:$(port)
server_cert=/root/cert/server.pem
server_key=/root/cert/key.pem
SPPFLAGS=-D port=$(port) -D kore_chroot=$(worker_chroot) -D chuser=$(user) -D domain=$(domain) -D bin_path="$(bin_path)" -D server_cert="$(server_cert)" -D server_key="$(server_key)" -D worker_chroot="$(worker_chroot)" -D kmgr_chroot="$(kmgr_chroot)"
# squelch prints, flip to print verbose information
#Q=@
Q=
LUAROCKS_FLAGS=--tree $(worker_chroot)/usr/lib/luarocks --lua-version 5.1
chroot_packages=\
-p luarocks5.1 \
-p "build-base" \
-p "ca-certificates" \
-p ssl_client \
-p luajit \
-p "lua5.1-dev" \
-p "luajit-dev" \
-p sqlite \
-p "sqlite-dev" \
-p certbot \
-p zlib \
-p "zlib-dev" \
-p git
lua_packages = \
lsqlite3 \
etlua \
lpeg \
zlib
# Probably don't change stuff past here if you're just using smr
lua_files=$(shell find src/lua/*.lua -type f) $(shell find src/lua/endpoints -type f)
src_files=$(shell find src -type f) $(shell find conf -type f)
sql_files=$(shell find src/sql -type f)
test_files=$(shell find spec -type f) $(shell find spec/parser_tests -type f)
page_files=$(shell find src/pages -type f)
built_tests=$(test_files:%=$(app_root)/%)
built_files=$(lua_files:src/lua/%.lua=$(app_root)/%.lua)
part_files=$(shell find src/pages/parts/*.etlua -type f)
built_parts=$(part_files:src/%=$(app_root)/%)
built_pages=$(page_files:src/pages/%.etlua=$(app_root)/pages/%.etlua)
built_sql=$(sql_files:src/sql/%.sql=$(app_root)/sql/%.sql)
built=$(built_files) $(built_sql) $(built_pages) $(built_tests)
sql_create_table_files=$(sql_files:src/sql/create_table_%.sql=doc/schema/%.dot)
sql_docs=$(sql_create_table_files)
initscript=/lib/systemd/system/smr.service
config=$(conf_path)/smr.conf
built_bin=$(smr_bin_path)/smr.so
APK_aarch64_HASH=0164d47954c8a52e8ed10db1633174974a3b1e4182a1993a5a8343e394ee1bbc
APK_x86_64_HASH=5176da3d4c41f12a08b82809aca8e7e2e383b7930979651b8958eca219815af5
apk_hash := $(APK_$(arch)_HASH)
help: ## Print this help
$(Q)$(GREP) -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | $(SORT) | $(AWK) 'BEGIN {FS = ":.*?## "}; {printf "%-10s %s\n", $$1, $$2}'
all: $(app_root) smr.so $(built_files) $(built_pages) $(built_sql) ## Build and run smr in a chroot
apk-tools-static-$(version).apk:
wget -q $(mirror)latest-stable/main/$(arch)/apk-tools-static-$(version).apk
clean: ## clean up all the files generated by this makefile
$(Q)$(ECHO) "[clean] $@"
$(Q)$(KODEV) clean
$(Q)$(RM) $(page_files)
$(Q)$(RM) $(asset_files)
$(Q)$(RM) smr.so
install: $(app_root) $(kmgr_chroot) $(parent_chroot) $(initscript) $(config) smr.so $(built_files) $(built_pages) $(built_sql) ## Install smr into a new host system
$(Q)$(COPY) smr.so $(built_bin)
$(config) : conf/smr.conf
$(Q)$(MKDIR) $(conf_path)
$(Q)$(TEST) ! -e $@ && $(COPY) $< $@
$(initscript) : packaging/systemd/smr.service
$(Q)$(COPY) $< $@
cloc: ## calculate source lines of code in smr
cloc --force-lang="html",etlua --force-lang="lua",lua src assets Makefile
$(app_root):
$(Q)$(MKDIR) $(app_root)
$(app_root): $(worker_chroot)
$(Q)$(MKDIR) $(app_root)
$(Q)$(MKDIR) $(app_root)/pages
$(Q)$(MKDIR) $(app_root)/pages/parts
$(Q)$(MKDIR) $(app_root)/sql
$(Q)$(MKDIR) $(app_root)/data
$(Q)$(MKDIR) $(app_root)/data/archive
$(Q)$(MKDIR) $(app_root)/endpoints
alpine-chroot-install:
$(Q)wget https://raw.githubusercontent.com/alpinelinux/alpine-chroot-install/v0.14.0/alpine-chroot-install \
&& echo 'ccbf65f85cdc351851f8ad025bb3e65bae4d5b06 alpine-chroot-install' | sha1sum -c \
|| exit 1
$(Q)chmod +x alpine-chroot-install
$(worker_chroot) $(kmgr_chroot) $(parent_chroot): alpine-chroot-install
$(Q)export APK_TOOLS_URI="https://gitlab.alpinelinux.org/api/v4/projects/5/packages/generic/v2.12.9/$(arch)/apk.static"; \
export APK_TOOLS_SHA256="$(apk_hash)"; \
./alpine-chroot-install -d $@ -a $(arch) $(chroot_packages)
code : $(built_files)
$(built_files): $(app_root)/%.lua : src/lua/%.lua $(app_root)
$(Q)$(ECHO) "[copy] $@"
$(Q)$(COPY) $< $@
$(built_pages): $(app_root)/pages/%.etlua : src/pages/%.etlua $(app_root)
$(Q)$(ECHO) "[copy] $@"
$(Q)$(COPY) $< $@
$(built_parts): $(app_root)/% : src/%
$(Q)$(ECHO) "[copy] $@"
$(Q)$(COPY) $< $@
$(built_sql): $(app_root)/sql/%.sql : src/sql/%.sql
$(Q)$(ECHO) "[copy] $@"
$(Q)$(COPY) $^ $@
$(built_tests): $(app_root)/spec/% : spec/% $(app_root)/spec
$(Q)$(ECHO) "[copy] $@"
$(Q)$(COPY) $< $@
$(app_root)/spec: $(app_root)
$(Q)$(MKDIR) $@
$(Q)$(MKDIR) $@/parser_tests
smr.so: $(src_files) conf/build.conf $(asset_files)
$(Q)$(ECHO) "[build] $@"
$(Q)$(KODEV) build
test: $(built) ## run the unit tests
$(Q)$(CD) $(app_root) && busted -v --no-keep-going --exclude-tags "slow,todo,working"
cov: $(built) ## code coverage (based on unit tests)
$(Q)$(RM) $(app_root)/luacov.stats.out
$(Q)$(CD) $(app_root) && busted -v -c --no-keep-going --exclude-tags "slow,todo,working"
$(Q)$(CD) $(app_root) && luacov endpoints/
$(Q)$(ECHO) "open $(app_root)/luacov.report.out to view coverage results."
$(sql_docs) : doc/schema/%.dot : src/sql/create_table_%.sql
$(Q)$(CAT) $< | tools/doc_sql.sh > $@
doc: $(sql_docs)
$(Q)$(RM) -rf .trblcache
$(Q)$(TRBLDOC) doc src README.md
# cd .trblcache/built && python3 -m http.server
.PHONY: doc