Makefile generation improved

master
Anthony Axenov 2022-08-26 08:25:55 +08:00
parent c1150af922
commit 8ffc2dfe32
Signed by: anthony
GPG Key ID: EA9EC32FF7CCD4EC
5 changed files with 86 additions and 42 deletions

View File

@ -1,4 +1,4 @@
# Autogenerated at 25.08.2022 22:32 using ./gen-makefile # Autogenerated at 26.08.2022 08:21 using ./gen-makefile
.DEFAULT_GOAL := help .DEFAULT_GOAL := help
#=============================================== #===============================================
@ -159,6 +159,29 @@ zint:
zsh: zsh:
@./install/zsh @./install/zsh
#===============================================
# Scripts listed in ./upgrade
#===============================================
# Upgrade omz
^omz:
@./upgrade/omz
#===============================================
# Scripts listed in ./uninstall
#===============================================
# Uninstall docker
/docker:
@./uninstall/docker
# Uninstall omz
/omz:
@./uninstall/omz
#===============================================
# Service goals
#===============================================
self: self:
@./gen-makefile @./gen-makefile
@ -166,20 +189,9 @@ self:
help: Makefile help: Makefile
@echo "Ubuntu software installator" @echo "Ubuntu software installator"
@echo @echo
@echo "Usage:" @echo "Usage:\n make help|- show this help\n make self|- regenerate Makefile (alias of ./gen-makefile)\n make GOAL|- install software\n make ^GOAL|- upgrade software\n make /GOAL|- uninstall software" | column -ts '|'
@echo "\tmake help\t - Show this help" @echo "\nYou can combine GOALs, here are some examples:"
@echo "\tmake self\t - Regenerate Makefile (alias of ./gen-makefile)" @echo "\tmake @docker docker"
@echo "\tmake GOAL\t - Install software" @echo "\tmake php @docker ^omz"
@echo "\tmake ^GOAL\t - Upgrade software" @echo "\nAvailable GOALs:"
@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 '/^#/{N;s/# *\(.*\)\n\([^# .].*:\)/\t\2\1/p}' $< | column -ts ':' @sed -n '/^#/{N;s/# *\(.*\)\n\([^# .].*:\)/\t\2\1/p}' $< | column -ts ':'
+%:
@$(MAKE) $*
^%:
@./upgrade/$*
@%:
@./uninstall/$*

View File

@ -43,16 +43,20 @@ wget -qO - https://git.axenov.dev/anthony/my-env/raw/branch/master/install/apt |
./install/apt ./install/apt
``` ```
## How to add a new software script? ## How to add my script?
1. Create new `./install/*` script. 1. Create a new shell script in `./install`, `./upgrade` or `./uninstall` directory.
At the beggining of a file you must write these two lines: At the beggining of a file you must write these two lines:
```shell ```shell
#!/bin/bash #!/bin/bash
##makedesc: Your description for Makefile ##makedesc: Your description for Makefile
``` ```
2. Test your script 2. Make this script executable, e.g.:
3. Run `./gen-makefile` to generate new `./Makefile` ```shell
sudo chmod a+x ./install/myscript
```
3. Test your script
4. Run `make self` to generate new `./Makefile`
## How to create packs? ## How to create packs?

View File

@ -1,5 +1,7 @@
#!/bin/bash #!/bin/bash
mv Makefile Makefile.bak mv Makefile Makefile.bak
CHR_UPGRADE='^'
CHR_UNINSTALL='/'
cat << EOF >> Makefile cat << EOF >> Makefile
# Autogenerated at $(date +'%d.%m.%Y %H:%M') using ${BASH_SOURCE[0]} # Autogenerated at $(date +'%d.%m.%Y %H:%M') using ${BASH_SOURCE[0]}
@ -31,7 +33,40 @@ for file in ./install/*; do
echo -e "# ${desc}\n${name}:\n\t@${file}\n" >> Makefile echo -e "# ${desc}\n${name}:\n\t@${file}\n" >> Makefile
done; done;
cat << "EOF" >> Makefile cat << EOF >> Makefile
#===============================================
# Scripts listed in ./upgrade
#===============================================
EOF
for file in ./upgrade/*; do
name=${file##*/}
name=${name%.sh}
desc=$(grep -m 1 -oP "(?<=^##makedesc:\s).*$" ${file})
[ -z "$desc" ] && desc='<no description>'
echo -e "# ${desc}\n${CHR_UPGRADE}${name}:\n\t@${file}\n" >> Makefile
done;
cat << EOF >> Makefile
#===============================================
# Scripts listed in ./uninstall
#===============================================
EOF
for file in ./uninstall/*; do
name=${file##*/}
name=${name%.sh}
desc=$(grep -m 1 -oP "(?<=^##makedesc:\s).*$" ${file})
[ -z "$desc" ] && desc='<no description>'
echo -e "# ${desc}\n${CHR_UNINSTALL}${name}:\n\t@${file}\n" >> Makefile
done;
cat << EOF >> Makefile
#===============================================
# Service goals
#===============================================
self: self:
@./gen-makefile @./gen-makefile
@ -39,26 +74,19 @@ self:
help: Makefile help: Makefile
@echo "Ubuntu software installator" @echo "Ubuntu software installator"
@echo @echo
@echo "Usage:" @echo "Usage:\n \
@echo "\tmake help\t - Show this help" make help|- show this help\n \
@echo "\tmake self\t - Regenerate Makefile (alias of ./gen-makefile)" make self|- regenerate Makefile (alias of ./gen-makefile)\n \
@echo "\tmake GOAL\t - Install software" make GOAL|- install software\n \
@echo "\tmake ^GOAL\t - Upgrade software" make ${CHR_UPGRADE}GOAL|- upgrade software\n \
@echo "\tmake @GOAL\t - Uninstall software" make ${CHR_UNINSTALL}GOAL|- uninstall software" | column -ts '|'
@echo @echo "\nYou can combine GOALs, here are some examples:"
@echo "You can combine GOALs, e.g. 'make @docker docker' will reinstall docker." @echo "\tmake @docker docker"
@echo @echo "\tmake php @docker ^omz"
@echo "Available GOALs:" @echo "\nAvailable GOALs:"
@sed -n '/^#/{N;s/# *\(.*\)\n\([^# .].*:\)/\t\2\1/p}' $< | column -ts ':' @sed -n '/^#/{N;s/# *\(.*\)\n\([^# .].*:\)/\t\2\1/p}' $< | column -ts ':'
+%:
@$(MAKE) $*
^%:
@./upgrade/$*
@%:
@./uninstall/$*
EOF EOF
echo "New ./Makefile has been generated!" echo "New ./Makefile has been generated!"
echo "Old one has been saved as ./Makefile.bak" echo "Old one has been saved as ./Makefile.bak"
echo echo "Now run 'make' to get help"
make

View File

@ -1,5 +1,5 @@
#!/bin/bash #!/bin/bash
##makedesc: Uninstalling omz ##makedesc: Uninstall omz
echo echo
echo "===============================================" echo "==============================================="

View File

@ -1,5 +1,5 @@
#!/bin/bash #!/bin/bash
##makedesc: Upgrading omz ##makedesc: Upgrade omz
echo echo
echo "===============================================" echo "==============================================="