Added a for subtargets and updated readme

Author Mitja Felicijan <mitja.felicijan@gmail.com> 2024-05-12 02:23:03 +0200
Committer Mitja Felicijan <mitja.felicijan@gmail.com> 2024-05-12 02:23:03 +0200
Commit 36f3bb9c47de6bb8046a2fea19b74aedb9195a5b (patch)
-rw-r--r-- Makefile 2
-rw-r--r-- README.md 62
-rw-r--r-- makext.mk 2
3 files changed, 64 insertions, 2 deletions
diff --git a/Makefile b/Makefile
...
7
  
7
  
8
demo: .assure
8
demo: .assure
9
  
9
  
10
build-app: # Build the application
10
build-app: clean-cache # Build the application
11
	@echo "Building the application..."
11
	@echo "Building the application..."
12
  
12
  
13
clean-cache: # Clean the cache
13
clean-cache: # Clean the cache
...
diff --git a/README.md b/README.md
...
17
- Automatic description inclusion in help message.
17
- Automatic description inclusion in help message.
18
- Automatic license inclusion in help message.
18
- Automatic license inclusion in help message.
19
  
19
  
  
20
## How to use
  
21
  
  
22
First you will need to download `makext.mk` file from the repository to
  
23
the same directory where you have `Makefile`.
  
24
  
  
25
```sh
  
26
wget -O makext.mk https://github.com/mitjafelicijan/makext/raw/master/makext.mk
  
27
```
  
28
  
  
29
Now you can include it in your `Makefile`.
  
30
  
  
31
```make
  
32
include makext.mk
  
33
  
  
34
help: .help
  
35
```
  
36
  
  
37
> [!IMPORTANT]
  
38
> Make sure you create first target `help: .help` before any other
  
39
> targets in your `Makefile`. GNU Make will execute first target if
  
40
> no target provided as an argument when calling `make`.
  
41
  
  
42
### Help extension
  
43
  
  
44
This is all that is needed to start using `makext`. One of the extensions
  
45
is `.help` which displays all the targets in the `Makefile` and their
  
46
descriptions which are provided as comments next to the target definition.
  
47
  
  
48
Lets check how and example `Makefile` would look.
  
49
  
  
50
```make
  
51
include makext.mk
  
52
  
  
53
help: .help
  
54
  
  
55
build-app: clean-cache # Build the application
  
56
	@echo "Building the application..."
  
57
  
  
58
clean-cache: # Clean the cache
  
59
	@echo "Cleaning the cache..."
  
60
  
  
61
deploy-prod: # Deploy to production
  
62
	@echo "Deploying to production..."
  
63
  
  
64
run-tests:
  
65
	@echo "Running tests..."
  
66
```
  
67
  
  
68
This will give us under we execute command `make` the following result.
  
69
  
  
70
```
  
71
Targets:
  
72
  build-app                 Build the application
  
73
  clean-cache               Clean the cache
  
74
  deploy-prod               Deploy to production
  
75
  run-tests                 Run tests
  
76
```
  
77
  
  
78
- Targets without defined comments next to the target will be ignored
  
79
  from help list.
  
80
- Targets that start with `.` will also be ignored.
  
81
  
20
## Acknowledgement
82
## Acknowledgement
21
  
83
  
22
- https://stackoverflow.com/a/59087509
84
- https://stackoverflow.com/a/59087509
...
diff --git a/makext.mk b/makext.mk
...
17
	@echo "$(MK_DESCRIPTION)\n" | fmt
17
	@echo "$(MK_DESCRIPTION)\n" | fmt
18
endif
18
endif
19
	@echo "Targets:"
19
	@echo "Targets:"
20
	@grep -vE '^[[:space:]]' $(MAKEFILE_LIST) | grep -E '^.*:.* #' | sed -E 's/(.*):.*#(.*)/  \1###\2/' | column -t -s '###'
20
	@grep -vE '^[[:space:]]' $(MAKEFILE_LIST) | grep -E '^.*:.* #' | sed -E 's/(.*):(.*):.*#(.*)/  \2###\3/' | column -t -s '###'
21
ifdef MK_LICENSE
21
ifdef MK_LICENSE
22
	@echo "\n$(MK_LICENSE)" | fmt
22
	@echo "\n$(MK_LICENSE)" | fmt
23
endif
23
endif