chore: Makefile and dist scripts

This commit is contained in:
Alexandre Pasmantier 2024-11-09 21:43:29 +01:00
parent b913eac4ae
commit 9bdbf44f35
2 changed files with 115 additions and 0 deletions

91
Makefile Normal file
View File

@ -0,0 +1,91 @@
VERSION=0.2.13
NAME=television
EXEC=tv
PREFIX=$(HOME)/.local
default: build_release
setup:
@echo "Setting up $(NAME)"
@echo "Installing git hooks"
@mkdir -p .git/hooks
@echo "make fix" > .git/hooks/pre-commit
@chmod +x .git/hooks/pre-commit
@echo "Done"
clean:
@echo "Cleaning build dir"
@rm -rf target/*
@echo "Cleaning using cargo"
@cargo clean
check:
@echo "Checking $(NAME)"
@cargo check
build_release:
@echo "Building release: $(VERSION)"
@cargo build --release
build_debug:
@echo "Building debug"
@cargo build
format:
@echo "Formatting $(NAME)"
@cargo fmt --all
lint:
@echo "Linting $(NAME)"
@cargo clippy
fix: format
@echo "Fixing $(NAME)"
@cargo fix --allow-staged
run:
@echo "Running debug"
@RUST_LOG=debug cargo run
test:
@echo "Testing $(NAME)"
@cargo test
install_debug: build_debug
@echo "Installing debug"
@cp target/debug/$(EXEC) $(PREFIX)/bin
install: build_release
@echo "Installing release: $(VERSION)"
@cp target/release/$(EXEC) $(PREFIX)/bin
dist: build_release
@if [ ! -d ./pkg ]; \
then \
mkdir ./pkg; \
fi
@if [ -d ./pkg/$(NAME)-$(VERSION) ]; \
then \
echo "Current version number already exists! Removing old files!"; \
rm -rf ./pkg/$(NAME)-$(VERSION); \
fi
@mkdir ./pkg/$(NAME)-$(VERSION)
@cp ./dist-scripts/install.sh ./pkg/$(NAME)-$(VERSION)/
@sed -i 's#{prefix}#$(PREFIX)#g' ./pkg/$(NAME)-$(VERSION)/install.sh
@sed -i 's#{version}#$(VERSION)#g' ./pkg/$(NAME)-$(VERSION)/install.sh
@sed -i 's#{name}#$(NAME)#g' ./pkg/$(NAME)-$(VERSION)/install.sh
@sed -i 's#{exec}#$(EXEC)#g' ./pkg/$(NAME)-$(VERSION)/install.sh
@mkdir ./pkg/$(NAME)-$(VERSION)/files
@cp target/release/$(EXEC) ./pkg/$(NAME)-$(VERSION)/files/
@strip ./pkg/$(NAME)-$(VERSION)/files/$(EXEC)
@cp LICENSE ./pkg/$(NAME)-$(VERSION)/
@cd ./pkg && tar -czf ./$(NAME)-$(VERSION).tar.gz ./$(NAME)-$(VERSION)
@echo "Cleaning up"
@rm -rf ./pkg/$(NAME)-$(VERSION)

24
dist-scripts/install.sh Normal file
View File

@ -0,0 +1,24 @@
#!/bin/sh
PREFIX={prefix}
VERSION={version}
NAME={name}
EXEC={exec}
if [ $1 == "uninstall" ]
then
echo "Uninstalling $NAME"
rm -rf $PREFIX/bin/$EXEC
exit
fi
if [ $1 == "help" ]
then
echo "\`./install.sh uninstall' to uninstall the program."
echo "\`./install.sh' or \`./install.sh install' to install the program."
echo "\`./install.sh' help to show this page."
exit
fi
echo "Installing $NAME, version: $VERSION, into: $PREFIX/bin/$EXEC"
cp files/$EXEC $PREFIX/bin/