2021-01-04 03:48:29 +01:00
# Binaries
ECHO = echo
KODEV = kodev
MKDIR = mkdir -p
COPY = cp
RM = rm -f
SPP = spp
2021-01-16 21:59:22 +01:00
CD = cd
2022-02-20 01:12:52 +01:00
AWK = awk
GREP = grep
SORT = sort
2023-06-10 04:06:42 +02:00
TEST = test
2023-08-17 00:04:50 +02:00
CAT = cat
TRBLDOC = trbldoc
2021-01-04 03:48:29 +01:00
2020-05-17 18:05:00 +02:00
# Config
2023-04-06 23:27:28 +02:00
worker_chroot = $( smr_var) /kore_worker
kmgr_chroot = $( smr_var) /kore_kmgr
parent_chroot = $( smr_var) /kore_parent
2023-03-12 17:24:22 +01:00
conf_path = /etc/smr
2023-04-06 23:27:28 +02:00
smr_bin_path = /usr/local/lib
2023-05-17 23:18:24 +02:00
app_root = $( worker_chroot) /var/smr
2023-04-06 23:27:28 +02:00
i f e q ( $( DEV ) , t r u e )
worker_chroot = ./kore_chroot
kmgr_chroot = ./kore_chroot
parent_chroot = ./kore_chroot
conf_path = ./kore_chroot/conf
smr_bin_path = ./kore_chroot
2023-05-17 23:18:24 +02:00
app_root = ./kore_chroot/app
2023-03-12 17:24:22 +01:00
e n d i f
2023-04-06 23:27:28 +02:00
2020-05-17 18:05:00 +02:00
mirror = http://dl-cdn.alpinelinux.org/alpine/
arch = aarch64
2023-03-12 17:24:22 +01:00
version = 2.12.9
2020-08-13 19:59:33 +02:00
certbot_email = --register-unsafely-without-email
#certbot_email=-m you@cock.li
2021-01-04 03:48:29 +01:00
user = robin
port = 8888
domain = test.monster:$( port)
2023-04-06 23:27:28 +02:00
server_cert = /root/cert/server.pem
server_key = /root/cert/key.pem
2020-05-17 18:05:00 +02:00
2023-05-17 23:18:24 +02:00
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) "
2022-02-20 01:12:52 +01:00
# squelch prints, flip to print verbose information
2023-03-12 17:24:22 +01:00
#Q=@
Q =
2023-05-17 23:18:24 +02:00
LUAROCKS_FLAGS = --tree $( worker_chroot) /usr/lib/luarocks --lua-version 5.1
2023-03-12 17:24:22 +01:00
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
2021-01-04 03:48:29 +01:00
# Probably don't change stuff past here if you're just using smr
2023-05-17 23:18:24 +02:00
lua_files = $( shell find src/lua/*.lua -type f) $( shell find src/lua/endpoints -type f)
2020-05-17 18:05:00 +02:00
src_files = $( shell find src -type f) $( shell find conf -type f)
sql_files = $( shell find src/sql -type f)
2023-05-17 23:18:24 +02:00
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)
2023-04-06 23:27:28 +02:00
part_files = $( shell find src/pages/parts/*.etlua -type f)
2023-05-17 23:18:24 +02:00
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)
2020-12-21 05:22:22 +01:00
built = $( built_files) $( built_sql) $( built_pages) $( built_tests)
2023-08-10 00:28:48 +02:00
sql_create_table_files = $( sql_files:src/sql/create_table_%.sql= doc/schema/%.dot)
sql_docs = $( sql_create_table_files)
2023-03-12 17:24:22 +01:00
initscript = /lib/systemd/system/smr.service
config = $( conf_path) /smr.conf
2023-04-06 23:27:28 +02:00
built_bin = $( smr_bin_path) /smr.so
2020-05-17 18:05:00 +02:00
2023-03-12 20:13:18 +01:00
APK_aarch64_HASH = 0164d47954c8a52e8ed10db1633174974a3b1e4182a1993a5a8343e394ee1bbc
2023-03-12 20:20:11 +01:00
APK_x86_64_HASH = 5176da3d4c41f12a08b82809aca8e7e2e383b7930979651b8958eca219815af5
2023-03-12 20:13:18 +01:00
apk_hash := $( APK_$( arch) _HASH)
2022-02-20 01:12:52 +01:00
help : ## Print this help
2023-03-12 17:24:22 +01:00
$( Q) $( GREP) -E '^[a-zA-Z_-]+:.*?## .*$$' $( MAKEFILE_LIST) | $( SORT) | $( AWK) 'BEGIN {FS = ":.*?## "}; {printf "%-10s %s\n", $$1, $$2}'
2022-02-20 01:12:52 +01:00
2023-05-17 23:18:24 +02:00
all : $( app_root ) smr .so $( built_files ) $( built_pages ) $( built_sql ) ## Build and run smr in a chroot
2020-05-17 18:05:00 +02:00
2020-08-13 19:59:33 +02:00
apk-tools-static-$(version).apk :
2023-03-12 17:24:22 +01:00
wget -q $( mirror) latest-stable/main/$( arch) /apk-tools-static-$( version) .apk
2020-05-17 18:05:00 +02:00
2022-02-20 01:12:52 +01:00
clean : ## clean up all the files generated by this makefile
2021-01-04 03:48:29 +01:00
$( Q) $( ECHO) " [clean] $@ "
$( Q) $( KODEV) clean
$( Q) $( RM) $( page_files)
2021-10-11 02:54:15 +02:00
$( Q) $( RM) $( asset_files)
2023-04-06 23:27:28 +02:00
$( Q) $( RM) smr.so
2021-01-04 03:48:29 +01:00
2023-05-17 23:18:24 +02:00
install : $( app_root ) $( kmgr_chroot ) $( parent_chroot ) $( initscript ) $( config ) smr .so $( built_files ) $( built_pages ) $( built_sql ) ## Install smr into a new host system
2023-04-06 23:27:28 +02:00
$( Q) $( COPY) smr.so $( built_bin)
2023-03-12 17:24:22 +01:00
$(config) : conf /smr .conf
2023-04-06 23:27:28 +02:00
$( Q) $( MKDIR) $( conf_path)
2023-06-10 04:06:42 +02:00
$( Q) $( TEST) ! -e $@ && $( COPY) $< $@
2023-03-12 17:24:22 +01:00
$(initscript) : packaging /systemd /smr .service
$( Q) $( COPY) $< $@
2022-02-20 01:12:52 +01:00
cloc : ## calculate source lines of code in smr
2023-06-10 04:06:42 +02:00
cloc --force-lang= "html" ,etlua --force-lang= "lua" ,lua src assets Makefile
2020-05-17 18:05:00 +02:00
2023-05-17 23:18:24 +02:00
$(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
2020-05-17 18:05:00 +02:00
2023-03-12 17:24:22 +01:00
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
2023-03-12 20:13:18 +01:00
$( 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) " ; \
2023-03-13 04:47:04 +01:00
./alpine-chroot-install -d $@ -a $( arch) $( chroot_packages)
2023-03-12 17:24:22 +01:00
2020-05-17 18:05:00 +02:00
code : $( built_files )
2023-05-17 23:18:24 +02:00
$(built_files) : $( app_root ) /%.lua : src /lua /%.lua $( app_root )
2021-01-04 03:48:29 +01:00
$( Q) $( ECHO) " [copy] $@ "
2023-03-12 17:24:22 +01:00
$( Q) $( COPY) $< $@
2020-05-17 18:05:00 +02:00
2023-05-17 23:18:24 +02:00
$(built_pages) : $( app_root ) /pages /%.etlua : src /pages /%.etlua $( app_root )
2021-01-04 03:48:29 +01:00
$( Q) $( ECHO) " [copy] $@ "
2023-04-06 23:27:28 +02:00
$( Q) $( COPY) $< $@
2021-01-04 03:48:29 +01:00
2023-05-17 23:18:24 +02:00
$(built_parts) : $( app_root ) /% : src /%
$( Q) $( ECHO) " [copy] $@ "
$( Q) $( COPY) $< $@
2021-01-04 03:48:29 +01:00
2023-05-17 23:18:24 +02:00
$(built_sql) : $( app_root ) /sql /%.sql : src /sql /%.sql
2021-01-04 03:48:29 +01:00
$( Q) $( ECHO) " [copy] $@ "
$( Q) $( COPY) $^ $@
2020-05-17 18:05:00 +02:00
2023-06-10 04:06:42 +02:00
$(built_tests) : $( app_root ) /spec /% : spec /% $( app_root ) /spec
2021-01-04 03:48:29 +01:00
$( Q) $( ECHO) " [copy] $@ "
2023-05-17 23:18:24 +02:00
$( Q) $( COPY) $< $@
2020-12-21 05:22:22 +01:00
2023-05-17 23:18:24 +02:00
$(app_root)/spec : $( app_root )
$( Q) $( MKDIR) $@
$( Q) $( MKDIR) $@ /parser_tests
2021-10-11 02:54:15 +02:00
2023-06-10 04:06:42 +02:00
smr.so : $( src_files ) conf /build .conf $( asset_files )
2021-01-04 03:48:29 +01:00
$( Q) $( ECHO) " [build] $@ "
$( Q) $( KODEV) build
2020-12-21 05:22:22 +01:00
2023-06-10 04:06:42 +02:00
test : $( built ) ## run the unit tests
2023-05-17 23:18:24 +02:00
$( Q) $( CD) $( app_root) && busted -v --no-keep-going --exclude-tags "slow,todo,working"
2021-09-12 19:37:12 +02:00
2023-06-10 04:06:42 +02:00
cov : $( built ) ## code coverage (based on unit tests)
2023-08-10 00:28:48 +02:00
$( 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. "
2023-06-10 04:06:42 +02:00
2023-08-10 00:28:48 +02:00
$(sql_docs) : doc /schema /%.dot : src /sql /create_table_ %.sql
2023-08-17 00:04:50 +02:00
$( Q) $( CAT) $< | tools/doc_sql.sh > $@
2023-08-10 00:28:48 +02:00
doc : $( sql_docs )
2023-08-17 00:04:50 +02:00
$( Q) $( RM) -rf .trblcache
$( Q) $( TRBLDOC) doc src README.md
# cd .trblcache/built && python3 -m http.server
2023-06-10 04:06:42 +02:00
.PHONY : doc