smr/Makefile

177 lines
5.5 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
# 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
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
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=$(build_dir) -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 $(build_dir)/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_in_files=$(shell find src/lua/*.in -type f)
lua_files=$(shell find src/lua/*.lua -type f) $(shell find src/lua/endpoints -type f) $(lua_in_files:%.in=%)
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)
built_tests=$(test_files:%=$(build_dir)%)
built_files=$(lua_files:src/lua/%.lua=$(build_dir)%.lua)
in_page_files=$(shell find src/pages/*.in -type f)
page_files=$(in_page_files:%.in=%)
part_files=$(shell find src/pages/parts/*.etlua -type f)
built_pages=$(page_files:src/pages/%.etlua=$(build_dir)pages/%.etlua)
built_sql=$(sql_files:src/sql/%.sql=$(build_dir)sql/%.sql)
built=$(built_files) $(built_sql) $(built_pages) $(built_tests)
asset_in_files=$(wildcard assets/*.in -type f)
asset_files=$(asset_in_files:%.in=%)
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: $(build_dir) 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: $(worker_chroot) $(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)$(COPY) $< $@
$(initscript) : packaging/systemd/smr.service
$(Q)$(COPY) $< $@
cloc: ## calculate source lines of code in smr
cloc --force-lang="html",etlua.in --force-lang="html",etlua --force-lang="lua",lua.in src assets Makefile
$(build_dir):
$(Q)$(MKDIR) $(build_dir)
$(Q)$(MKDIR) $(build_dir)/pages
$(Q)$(MKDIR) $(build_dir)/sql
$(Q)$(MKDIR) $(build_dir)/data
$(Q)$(MKDIR) $(build_dir)/data/archive
$(Q)$(MKDIR) $(build_dir)/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): $(build_dir)%.lua : src/lua/%.lua $(build_dir)
$(Q)$(ECHO) "[copy] $@"
$(Q)$(COPY) $< $@
$(built_pages): $(build_dir)pages/%.etlua : src/pages/%.etlua $(build_dir)
$(Q)$(ECHO) "[copy] $@"
$(Q)$(COPY) $< $@
src/lua/config.lua : src/lua/config.lua.in Makefile
$(Q)$(ECHO) "[preprocess] $@"
$(Q)$(SPP) $(SPPFLAGS) -o $@ $<
$(page_files) : % : %.in $(part_files)
$(Q)$(ECHO) "[preprocess] $@"
$(Q)$(SPP) $(SPPFLAGS) -o $@ $<
$(built_sql): $(build_dir)sql/%.sql : src/sql/%.sql
$(Q)$(ECHO) "[copy] $@"
$(Q)$(COPY) $^ $@
$(built_tests) : $(build_dir)% : src/spec/%
$(Q)$(ECHO) "[copy] $@"
$(Q)$(COPY) $^ $@
$(asset_files) : % : %.in
$(Q)$(ECHO) "[preprocess] $@"
$(Q)$(SPP) $(SPPFLAGS) -o $@ $<
smr.so : $(src_files) conf/build.conf $(asset_files)
$(Q)$(ECHO) "[build] $@"
$(Q)$(KODEV) build
test : $(built) ## run the unit tests
$(Q)$(CD) kore_chroot && busted -v --no-keep-going #--exclude-tags slow
cov : $(built) ## code coverage (based on unit tests)
$(Q)$(RM) $(kore_chroot)/luacov.stats.out
$(Q)$(CD) $(kore_chroot) && busted -v -c --no-keep-going #--exclude-tags slow
$(Q)$(CD) $(kore_chroot) && luacov endpoints/
$(Q)$(ECHO) "open kore_chroot/luacov.report.out to view coverage results."