diff --git a/Makefile b/Makefile index 1b946107df04469fe748a3246e1e85c0c3303d46..37470e7788fc8a2eff6c90d651e2dfc546851f0d 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ help: .help demo: .assure -build-app: # Build the application +build-app: clean-cache # Build the application @echo "Building the application..." clean-cache: # Clean the cache diff --git a/README.md b/README.md index 3176763bc51bdddd338bd25febfc76fbe4daa1ad..0b430548addb479a502c95e4490fabc6fd0b34f9 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,68 @@ - Enhanced help message generation with support for custom descriptions. - Automatic description inclusion in help message. - Automatic license inclusion in help message. +## How to use + +First you will need to download `makext.mk` file from the repository to +the same directory where you have `Makefile`. + +```sh +wget -O makext.mk https://github.com/mitjafelicijan/makext/raw/master/makext.mk +``` + +Now you can include it in your `Makefile`. + +```make +include makext.mk + +help: .help +``` + +> [!IMPORTANT] +> Make sure you create first target `help: .help` before any other +> targets in your `Makefile`. GNU Make will execute first target if +> no target provided as an argument when calling `make`. + +### Help extension + +This is all that is needed to start using `makext`. One of the extensions +is `.help` which displays all the targets in the `Makefile` and their +descriptions which are provided as comments next to the target definition. + +Lets check how and example `Makefile` would look. + +```make +include makext.mk + +help: .help + +build-app: clean-cache # Build the application + @echo "Building the application..." + +clean-cache: # Clean the cache + @echo "Cleaning the cache..." + +deploy-prod: # Deploy to production + @echo "Deploying to production..." + +run-tests: + @echo "Running tests..." +``` + +This will give us under we execute command `make` the following result. + +``` +Targets: + build-app Build the application + clean-cache Clean the cache + deploy-prod Deploy to production + run-tests Run tests +``` + +- Targets without defined comments next to the target will be ignored + from help list. +- Targets that start with `.` will also be ignored. + ## Acknowledgement - https://stackoverflow.com/a/59087509 diff --git a/makext.mk b/makext.mk index cf25906037595e43dbf6302c7e1f6523acad8d9f..58bd23bffa7875d2a2be52824e0adedb27834beb 100644 --- a/makext.mk +++ b/makext.mk @@ -17,7 +17,7 @@ ifdef MK_DESCRIPTION @echo "$(MK_DESCRIPTION)\n" | fmt endif @echo "Targets:" - @grep -vE '^[[:space:]]' $(MAKEFILE_LIST) | grep -E '^.*:.* #' | sed -E 's/(.*):.*#(.*)/ \1###\2/' | column -t -s '###' + @grep -vE '^[[:space:]]' $(MAKEFILE_LIST) | grep -E '^.*:.* #' | sed -E 's/(.*):(.*):.*#(.*)/ \2###\3/' | column -t -s '###' ifdef MK_LICENSE @echo "\n$(MK_LICENSE)" | fmt endif