feat: multiple output modes and less logs at boot
This commit is contained in:
+163
@@ -0,0 +1,163 @@
|
||||
# ENV
|
||||
|
||||
ifeq (,$(shell which uv))
|
||||
ifeq (,$(shell python3 -m uv --help||python3 -m pip install --user uv)) # detect uv install
|
||||
UV ?= false
|
||||
endif
|
||||
UV ?= python3 -m uv
|
||||
endif
|
||||
|
||||
UV ?= uv
|
||||
RUFF ?= $(UV) run --active ruff
|
||||
TY ?= $(UV) run --active ty
|
||||
|
||||
RASP_USER ?= forge
|
||||
RASP_BOOTFS ?= /run/media/$(shell whoami)/bootfs
|
||||
RASP_ROOTFS ?= /run/media/$(shell whoami)/rootfs
|
||||
RELATIVE_PROJECT_PATH ?= /opt/forge-invar
|
||||
RASP_PROJECT_PATH ?= $(RASP_ROOTFS)$(RELATIVE_PROJECT_PATH)
|
||||
|
||||
# DOCS
|
||||
|
||||
.PHONY: help
|
||||
help: ## show this message
|
||||
@echo "Usage: $(MAKE) [target1] [target2] ..."
|
||||
@echo ""
|
||||
@echo "Commands/Targets:"
|
||||
@cat $(MAKEFILE_LIST) | grep -E '(^[a-zA-Z0-9_%-]+:.*?##.*$$)|(^##)' | awk 'BEGIN {FS = ":.*?## "}{printf "\033[32m%-20s\033[0m %s\n", $$1, $$2}' | sed -e 's/\[32m##/[33m/'
|
||||
@echo ""
|
||||
@echo "Environment:"
|
||||
@cat $(MAKEFILE_LIST) | grep -E '^[a-zA-Z0-9_-]+\s*\??=.*$$' | grep -Eo '^[a-zA-Z0-9_-]+' | xargs -I {} $(MAKE) -s print-{} 2> /dev/null
|
||||
|
||||
.PHONY: print-%
|
||||
print-%:
|
||||
@echo -e '\033[32m$*\033[0m = $($*)'
|
||||
|
||||
# FILES
|
||||
|
||||
.venv: uv.lock
|
||||
$(MAKE) -s uv-sync
|
||||
|
||||
# ACTIONS
|
||||
|
||||
.PHONY: init
|
||||
init: uv-sync git-submodule-init git-submodule-update ## install project
|
||||
|
||||
.PHONY: update
|
||||
update: uv-upgrade ## update project dependencies
|
||||
|
||||
.PHONY: format
|
||||
format: ruff-fix ruff-format ## format project
|
||||
|
||||
.PHONY: lint
|
||||
lint: ruff ruff-format-check ty ## lint project
|
||||
|
||||
.PHONY: rasp-init
|
||||
rasp-init: rasp-chmod-opt rasp-rsync rasp-unmount ## init raspberry
|
||||
|
||||
.PHONY: rasp-install
|
||||
rasp-install: rasp-install-pal ## setup raspberry
|
||||
|
||||
.PHONY: rasp-install-%
|
||||
rasp-install-%: ## setup raspberry (PAL/NTSC/HDMI)
|
||||
make git-submodule-update rasp-rsync rasp-setup-config-$* rasp-setup-cmdline-$* rasp-setup-start-$* rasp-unmount
|
||||
|
||||
.PHONY: rasp-reset
|
||||
rasp-reset: rasp-reset-config rasp-reset-cmdline rasp-reset-start rasp-unmount ## reset raspberry to console mode
|
||||
|
||||
# TOOLS
|
||||
|
||||
.PHONY: uv-sync
|
||||
uv-sync: ## uv sync
|
||||
$(UV) sync --active
|
||||
|
||||
.PHONY: uv-update
|
||||
uv-upgrade: ## uv sync upgrade
|
||||
$(UV) sync --active --upgrade
|
||||
|
||||
.PHONY: ruff
|
||||
ruff: .venv ## ruff check
|
||||
$(RUFF) check
|
||||
|
||||
.PHONY: ruff-fix
|
||||
ruff-fix: .venv ## ruff check (and fix)
|
||||
$(RUFF) check --fix --unsafe-fixes
|
||||
|
||||
.PHONY: ruff-format
|
||||
ruff-format: .venv ## ruff format
|
||||
$(RUFF) format
|
||||
|
||||
.PHONY: ruff-format-check
|
||||
ruff-format-check: .venv ## ruff format (check only)
|
||||
$(RUFF) format --check
|
||||
|
||||
.PHONY: ty
|
||||
ty: .venv ## ty check
|
||||
$(TY) check
|
||||
|
||||
.PHONY: git-submodule-update
|
||||
git-submodule-update: ## prepare git submodules
|
||||
git submodule update --init --recursive
|
||||
|
||||
.PHONY: rasp-chmod-opt
|
||||
rasp-chmod-opt: ## chmod remote project
|
||||
sudo chmod -R a+rwx $(RASP_ROOTFS)/opt
|
||||
|
||||
.PHONY: rasp-remove-motd
|
||||
rasp-remove-motd: ##
|
||||
sudo rm -rf $(RASP_ROOTFS)/etc/motd
|
||||
sudo rm -rf $(RASP_ROOTFS)/etc/issue
|
||||
sudo rm -rf $(RASP_ROOTFS)/etc/update-motd.d/*
|
||||
|
||||
.PHONY: rasp-rsync
|
||||
rasp-rsync: ## sync remote project
|
||||
rsync -av --del --exclude='*/.git/*' --exclude-from=.gitignore $(PWD) $(RASP_ROOTFS)/opt
|
||||
|
||||
.PHONY: rasp-setup-custom-%
|
||||
rasp-setup-custom-%: ## setup custom remote config.txt
|
||||
cp $(PROJECT_DIR)/system/$*/config.ini $(RASP_BOOTFS)/custom.txt
|
||||
|
||||
.PHONY: rasp-reset-config
|
||||
rasp-reset-config: ## remove include in remote config.txt
|
||||
sed -i '/include custom.txt/d' $(RASP_BOOTFS)/config.txt
|
||||
|
||||
.PHONY: rasp-setup-config-%
|
||||
rasp-setup-config-%: ## setup include in remote config.txt
|
||||
make rasp-setup-custom-$* rasp-reset-config
|
||||
echo "include custom.txt" >> $(RASP_BOOTFS)/config.txt
|
||||
|
||||
.PHONY: rasp-reset-cmdline
|
||||
rasp-reset-cmdline: ## remove custom line from remove cmdline.txt
|
||||
sed -i '2,$$d' $(RASP_BOOTFS)/cmdline.txt
|
||||
sed -i 's/console=tty3/console=tty1/g' $(RASP_BOOTFS)/cmdline.txt
|
||||
|
||||
.PHONY: rasp-setup-cmdline-%
|
||||
rasp-setup-cmdline-%: rasp-reset-cmdline ## add custom line to remove cmdline.txt
|
||||
sed -i 's/console=tty1/console=tty3/g' $(RASP_BOOTFS)/cmdline.txt
|
||||
cat $(PROJECT_DIR)/system/$*/cmdline.txt >> $(RASP_BOOTFS)/cmdline.txt
|
||||
|
||||
.PHONY: rasp-reset-start
|
||||
rasp-reset-start: ## remove custom .bashrc start
|
||||
rm -f $(RASP_ROOTFS)/home/$(RASP_USER)/.bash_aliases
|
||||
|
||||
.PHONY: rasp-setup-start
|
||||
rasp-setup-start: rasp-reset-start ## install custom .bashrc start
|
||||
echo "touch $(RELATIVE_PROJECT_PATH)/*" >> $(RASP_ROOTFS)/home/$(RASP_USER)/.bash_aliases
|
||||
echo "make -C $(RELATIVE_PROJECT_PATH) --silent --no-print-directory start" >> $(RASP_ROOTFS)/home/$(RASP_USER)/.bash_aliases
|
||||
|
||||
.PHONY: rasp-setup-start-hmdi
|
||||
rasp-setup-start-%: rasp-reset-start ## install custom .bashrc start
|
||||
cp -f $(PROJECT_DIR)/system/$*/start.sh $(RASP_ROOTFS)/home/$(RASP_USER)/.bash_aliases
|
||||
|
||||
.PHONY: rasp-unmount
|
||||
rasp-unmount: ## unmount rootfs/bootfs
|
||||
sudo umount -R $(RASP_BOOTFS)
|
||||
sudo umount -R $(RASP_ROOTFS)
|
||||
|
||||
.PHONY: rasp-force-rebuild
|
||||
rasp-force-rebuild: ## rm remote project/build
|
||||
rm -rf $(RASP_PROJECT_PATH)/build
|
||||
|
||||
.PHONY: rasp-import-logs
|
||||
rasp-import-logs: ## import remote logs
|
||||
cp -f $(RASP_PROJECT_PATH)/*.log .
|
||||
Reference in New Issue
Block a user