View previous topic :: View next topic |
Author |
Message |
juniper l33t
Joined: 22 Oct 2004 Posts: 959 Location: we the north
|
Posted: Wed Mar 20, 2024 4:45 pm Post subject: [Solved] Makefile: listing targets |
|
|
I am trying to make a makefile. I read that make doesn't have a default command to list targets so I put
Code: |
list:###list all targets
@grep '^[^#[:space:]].*:' makefile
|
This does the trick, but I want to understand the command. Does it look for anything and then a colon? I would like to modify this command. I want it to only print certain targets, and the targets I want it to print are ones that I have a comment after. So it would find
target: dependency ###this target does X
rather than just
target: dependency
How would I modify the grep command? Thanks.
Last edited by juniper on Mon Apr 01, 2024 7:27 pm; edited 1 time in total |
|
Back to top |
|
|
szatox Advocate
Joined: 27 Aug 2013 Posts: 3408
|
Posted: Wed Mar 20, 2024 6:01 pm Post subject: |
|
|
means:
^ at the start of line find
[^ exactly 1 character NOT listed (therefore anything but # and variants of horizontal white spaces) ]
.* any string (including 0-length)
: a literal colon
So, it is looking for colons which are not a part of comments.
It might be a good idea to drop the start of line anchor (initial ^ ) to filter out lines containing a command followed by a comment, if makefile syntax allows their existence.
E.g. the regex you posted
matches line 'this is fine' # Oppsie: insert "room on fire" meme here
but_NOT_this_line: starting with a space
Quote: | target: dependency ###this target does X |
grep '^[^#]\{1,\}:[^#].*#'
[^#]\{1,\} means from 1 to any occurrences of not # _________________ Make Computing Fun Again |
|
Back to top |
|
|
Zucca Moderator
Joined: 14 Jun 2007 Posts: 3685 Location: Rasi, Finland
|
Posted: Wed Mar 20, 2024 11:09 pm Post subject: Re: Makefile: listing targets |
|
|
juniper wrote: | I am trying to make a makefile. I read that make doesn't have a default command to list targets | ... Maybe not quite: Jose Quinteiro wrote: | FreeBSD and NetBSD make(1) have a built-in variable called .ALLTARGETS. You can print out its contents like this
Code: | make -V .ALLTARGETS |
| and Timmmm wrote: | As of Jan 8th, 2024, Make has a --print-targets option that should do this properly without hacky regexes. The current version is Make 4.4.1 so the next release after that will have this feature. |
Also there are lot's of these workarounds. ;) _________________ ..: Zucca :..
My gentoo installs: | init=/sbin/openrc-init
-systemd -logind -elogind seatd |
Quote: | I am NaN! I am a man! |
|
|
Back to top |
|
|
juniper l33t
Joined: 22 Oct 2004 Posts: 959 Location: we the north
|
Posted: Thu Mar 21, 2024 5:30 pm Post subject: |
|
|
hmmmm. make -V .ALLTARGETS (is that a period before ALLTARGETS?) doesn't seem to work.
I sort of like szatox's hacky version because, using comments, I can control which targets are printed and with comments. |
|
Back to top |
|
|
Hu Administrator
Joined: 06 Mar 2007 Posts: 22601
|
Posted: Thu Mar 21, 2024 5:49 pm Post subject: |
|
|
Yes, that is a leading period. Leading periods are a common convention for Makefile pseudo-targets. With which make did you try that? The quote only says FreeBSD and NetBSD make have it. On typical Gentoo systems, the most likely make is GNU make. |
|
Back to top |
|
|
juniper l33t
Joined: 22 Oct 2004 Posts: 959 Location: we the north
|
Posted: Mon Apr 01, 2024 7:27 pm Post subject: |
|
|
I am using the default make on gentoo. So no it's not working
I am using szatox's hacky make. Works like a charm for me! |
|
Back to top |
|
|
JustAnother Apprentice
Joined: 23 Sep 2016 Posts: 191
|
Posted: Fri Apr 05, 2024 2:26 am Post subject: |
|
|
Try this:
|
|
Back to top |
|
|
Zucca Moderator
Joined: 14 Jun 2007 Posts: 3685 Location: Rasi, Finland
|
Posted: Sun Apr 07, 2024 9:19 am Post subject: |
|
|
JustAnother,I think Juniper was looking a way to accomplish this with the system provided make. In this case, GNU make. _________________ ..: Zucca :..
My gentoo installs: | init=/sbin/openrc-init
-systemd -logind -elogind seatd |
Quote: | I am NaN! I am a man! |
|
|
Back to top |
|
|
juniper l33t
Joined: 22 Oct 2004 Posts: 959 Location: we the north
|
Posted: Mon Apr 08, 2024 4:46 pm Post subject: |
|
|
Zucca wrote: | JustAnother,I think Juniper was looking a way to accomplish this with the system provided make. In this case, GNU make. |
Zucca is correct. I am using the make that comes standard with gentoo.
@JustAnother. that didn't work. |
|
Back to top |
|
|
Zucca Moderator
Joined: 14 Jun 2007 Posts: 3685 Location: Rasi, Finland
|
Posted: Mon Apr 08, 2024 6:40 pm Post subject: |
|
|
GNU make 4.4.2 should have support for --print-targets, but if users of your software use stable distros (your users use non-rolling, stable distros, like debian, RH, etc) you're better off with the hacks. _________________ ..: Zucca :..
My gentoo installs: | init=/sbin/openrc-init
-systemd -logind -elogind seatd |
Quote: | I am NaN! I am a man! |
|
|
Back to top |
|
|
Zucca Moderator
Joined: 14 Jun 2007 Posts: 3685 Location: Rasi, Finland
|
Posted: Thu Sep 12, 2024 8:26 pm Post subject: |
|
|
I recently had a need for this too so I came up with this: Code: | list: # List targets
@awk '/^[[:alnum:]]+[^[:space:]]+:/ {printf "%s",substr($$1,1,length($$1)-1); if (match($$0,/#/)) {desc=substr($$0,RSTART+1); sub(/^[[:space:]]+/,"",desc); printf " - %s\n",desc} else printf "\n" }' "$(firstword $(MAKEFILE_LIST))" |
_________________ ..: Zucca :..
My gentoo installs: | init=/sbin/openrc-init
-systemd -logind -elogind seatd |
Quote: | I am NaN! I am a man! |
|
|
Back to top |
|
|
|