shell/gen-makefile.sh

31 lines
772 B
Bash
Executable File

#!/bin/bash
mv Makefile Makefile.bak
echo -e "# Autogenerated at $(date +'%d.%m.%Y %H:%M') by ${BASH_SOURCE[0]}\n" > Makefile
for file in ./install/*.sh; do
name=${file##*/}
name=${name%.sh}
desc=$(cat ${file} | sed -n 2p | sed -n 's/^##makedesc: //p')
[ -z "$desc" ] && desc='<no description>'
echo -e "## ${name}: ${desc}\n${name}:\n\t${file}\n" >> Makefile
done;
cat << EOF >> Makefile
## help: Show this help message
help: Makefile
@echo "Usage:"
@echo "\tmake <goal>\n"
@echo "Available goals:"
@sed -n 's/^##//p' $< | column -t -s ':' | sed -e "s/^/\t/"
## <goal>_: Same as 'cat ./install/<goal>.sh'
%_:
@cat ./install/\$*.sh
EOF
echo "New ./Makefile has been generated!"
echo "Old one has been saved as ./Makefile.bak"
echo
make help