Split makefile into many files.

This commit is contained in:
Philippe Pittoli 2024-11-30 12:02:01 +01:00
parent 4c79c78e60
commit 029b0532bc
7 changed files with 87 additions and 85 deletions

View File

@ -3,88 +3,9 @@ all: build-server
Q ?= @
OPTS ?= --progress
NAME ?= John
EMAIL ?= john@example.com
# For requests where authentication is required.
LOGIN ?=
ifeq ($(LOGIN),)
LOGIN_OPT =
else
LOGIN_OPT = -l $(LOGIN)
endif
SOURCE_FILES = $(wildcard src/*.cr src/*/*.cr src/*/*/*.cr)
##################
### SETUP COMMANDS
##################
PASSWORD_FILE ?= /tmp/PASSWORD
setup:
@[ -f $(PASSWORD_FILE) ] || echo -n "coucou" > $(PASSWORD_FILE)
DATA_DIRECTORY ?= /tmp/DATA-AUTHD
run-authd:
./bin/authd -R -E --storage $(DATA_DIRECTORY)
test-authd: setup
./bin/authd -k $(PASSWORD_FILE) -R -E --storage $(DATA_DIRECTORY)
# First user always is the admin.
add-first-user:
./bin/authc bootstrap $(NAME) $(EMAIL)
####################
### REQUEST EXAMPLES
####################
ACTIVATION_KEY ?= put-your-key-here
add-user:; $(Q)./bin/authc user add $(NAME) $(EMAIL) $(LOGIN_OPT)
register:; $(Q)./bin/authc user register $(NAME) $(EMAIL)
validate:; $(Q)./bin/authc user validate $(NAME) $(ACTIVATION_KEY)
get-user:; $(Q)./bin/authc user get $(NAME) $(LOGIN_OPT)
SERVICE ?= 'auth'
RESOURCE ?= '*'
UID ?= 1000
PERMISSION ?= Read
permission-check:; ./bin/authc permission check $(UID) $(SERVICE) $(RESOURCE) $(LOGIN_OPT)
permission-set:; ./bin/authc permission set $(UID) $(SERVICE) $(RESOURCE) $(PERMISSION) $(LOGIN_OPT)
###################
### DEVELOPER TOOLS
###################
bin/authd: $(SOURCE_FILES); $(Q)shards build authd $(OPTS)
bin/authc: $(SOURCE_FILES); $(Q)shards build authc $(OPTS)
build-server: bin/authd
build-client: bin/authc
build: build-server build-client
doc:
crystal docs
HTTPD_ACCESS_LOGS ?= /tmp/access-authd-docs.log
HTTPD_ADDR ?= 127.0.0.1
HTTPD_PORT ?= 9000
DIR ?= docs
serve-doc:
darkhttpd $(DIR) --addr $(HTTPD_ADDR) --port $(HTTPD_PORT) --log $(HTTPD_ACCESS_LOGS)
print-messages:; cat src/requests/*.cr | ./bin/get-messages.awk
print-message-numbers:; make -s print-messages | grep -E "^[0-9]" | sort -n
print-messages-no-comments:; make -s print-messages | grep -vE '^[[:blank:]]+#'
print-response-messages:; cat src/responses/*.cr | ./bin/get-messages.awk
print-response-message-numbers:; make -s print-response-messages | grep -E "^[0-9]" | sort -n
print-response-messages-no-comments:; make -s print-response-messages | grep -vE '^[[:blank:]]+#'
wipe-db:
rm -r $(DATA_DIRECTORY)
release:
make build-server OPTS="--progress --release"
-include migration.mk
include mk/build.mk
include mk/install.mk
include mk/setup.mk
include mk/commands.mk
-include mk/migration.mk
-include mk/dev.mk

10
mk/build.mk Normal file
View File

@ -0,0 +1,10 @@
SOURCE_FILES = $(wildcard src/*.cr src/*/*.cr src/*/*/*.cr)
CRFLAGS ?= --progress
bin/authd: $(SOURCE_FILES); $(Q)shards build authd $(CRFLAGS)
bin/authc: $(SOURCE_FILES); $(Q)shards build authc $(CRFLAGS)
build-server: bin/authd
build-client: bin/authc
build: build-server build-client
release:; make build-server CRFLAGS="--progress --release"

25
mk/commands.mk Normal file
View File

@ -0,0 +1,25 @@
# REQUEST EXAMPLES
NAME ?= John
EMAIL ?= john@example.com
# For requests where authentication is required.
LOGIN ?=
ifeq ($(LOGIN),)
LOGIN_OPT =
else
LOGIN_OPT = -l $(LOGIN)
endif
ACTIVATION_KEY ?= put-your-key-here
add-user:; $(Q)$(LOC)authc user add $(NAME) $(EMAIL) $(LOGIN_OPT)
register:; $(Q)$(LOC)authc user register $(NAME) $(EMAIL)
validate:; $(Q)$(LOC)authc user validate $(NAME) $(ACTIVATION_KEY)
get-user:; $(Q)$(LOC)authc user get $(NAME) $(LOGIN_OPT)
SERVICE ?= 'auth'
RESOURCE ?= '*'
UID ?= 1000
PERMISSION ?= Read
permission-check:; $(LOC)authc permission check $(UID) $(SERVICE) $(RESOURCE) $(LOGIN_OPT)
permission-set:; $(LOC)authc permission set $(UID) $(SERVICE) $(RESOURCE) $(PERMISSION) $(LOGIN_OPT)

15
mk/dev.mk Normal file
View File

@ -0,0 +1,15 @@
# DEVELOPER TOOLS
print-messages:; cat src/requests/*.cr | ./bin/get-messages.awk
print-message-numbers:; make -s print-messages | grep -E "^[0-9]" | sort -n
print-messages-no-comments:; make -s print-messages | grep -vE '^[[:blank:]]+#'
print-response-messages:; cat src/responses/*.cr | ./bin/get-messages.awk
print-response-message-numbers:; make -s print-response-messages | grep -E "^[0-9]" | sort -n
print-response-messages-no-comments:; make -s print-response-messages | grep -vE '^[[:blank:]]+#'
HTTPD_ACCESS_LOGS ?= /tmp/access-authd-docs.log
HTTPD_ADDR ?= 127.0.0.1
HTTPD_PORT ?= 9000
DIR ?= docs
serve-doc:
darkhttpd $(DIR) --addr $(HTTPD_ADDR) --port $(HTTPD_PORT) --log $(HTTPD_ACCESS_LOGS)

20
mk/install.mk Normal file
View File

@ -0,0 +1,20 @@
# DESTDIR envvar is a way to install the application in a different root (for building packages for example).
PREFIX ?= $(DESTDIR)/usr/local/
BINDIR ?= $(PREFIX)/bin
SHAREDIR ?= $(PREFIX)/share
DOCDIR ?= $(SHAREDIR)/doc/authd
MANDIR ?= $(SHAREDIR)/man
install-authd: build-server ; install -D -m 555 ./bin/authd $(BINDIR)/authd
install-authc: build-client ; install -D -m 555 ./bin/authc $(BINDIR)/authc
install-binaries: install-authd install-authc
install-man-authd:; install -D -m 444 ./man/authd.1 $(MANDIR)/authd.1
install-man-authc:; install -D -m 444 ./man/authc.1 $(MANDIR)/authc.1
install-man: install-man-authd install-man-authc
doc:; crystal docs
install-dev-doc: doc ; install -D docs/ $(DOCDIR)
# By default, dev documentation isn't installed.
install: install-binaries install-man #install-dev-doc

11
mk/setup.mk Normal file
View File

@ -0,0 +1,11 @@
PASSWORD_FILE ?= /tmp/PASSWORD
DATA_DIRECTORY ?= /tmp/DATA-AUTHD
run-authd:; setup; $(Q)$(LOC)authd -k $(PASSWORD_FILE) -R -E --storage $(DATA_DIRECTORY)
# First user always is the admin.
add-first-user:; $(Q)$(LOC)authc bootstrap $(NAME) $(EMAIL)
setup:; @[ -f $(PASSWORD_FILE) ] || echo -n "coucou" > $(PASSWORD_FILE)
wipe-db:; rm -r $(DATA_DIRECTORY)