my-env/gen-makefile

63 lines
1.4 KiB
Bash
Executable File

#!/bin/bash
mv Makefile Makefile.bak
cat << EOF >> Makefile
# Autogenerated at $(date +'%d.%m.%Y %H:%M') using ${BASH_SOURCE[0]}
.DEFAULT_GOAL := help
#===============================================
# Scripts listed in ./packs
#===============================================
EOF
for file in ./packs/*; do
cat "$file" >> Makefile
echo >> Makefile
done;
cat << EOF >> Makefile
#===============================================
# Scripts listed in ./install
#===============================================
EOF
for file in ./install/*; do
name=${file##*/}
name=${name%.sh}
desc=$(grep -m 1 -oP "(?<=^##makedesc:\s).*$" ${file})
[ -z "$desc" ] && desc='<no description>'
echo -e "##${name}: ${desc}\n${name}:\n\t@${file}\n" >> Makefile
done;
cat << "EOF" >> Makefile
self:
@./gen-makefile
help: Makefile
@echo "Ubuntu software installator"
@echo
@echo "Usage:"
@echo "\tmake help\t - Show this help"
@echo "\tmake GOAL\t - Install software"
@echo "\tmake ^GOAL\t - Upgrade software"
@echo "\tmake @GOAL\t - Uninstall software"
@echo
@echo "You can combine GOALs, e.g. 'make @docker docker' will reinstall docker."
@echo
@echo "Available GOALs:"
@sed -n 's/^##//p' $< | column -ts ':' | sed -e "s/^/\t/"
+%:
@$(MAKE) $*
^%:
@./upgrade/$*
@%:
@./uninstall/$*
EOF
echo "New ./Makefile has been generated!"
echo "Old one has been saved as ./Makefile.bak"
echo
make -s help