Hi
Reading Makefiles especially in big projects like coreboot is a constant. pain. One of the big issues is that conditionals are very hard to read since we cannot use tabs for indentation. Has anyone ever thought about using whitespaces as indentation for conditionals in our Makefiles or is that connected to known problems?
greetings Max
Hi,
the odd thing about Makefiles is that those use two different syntax': Everything that's indented by a tab is shell syntax and everything else is Makefile syntax. So we can't just indent the Makefile syntax part with tabs to make it look nicer and mixing tabs and spaces which do different things here if I'm not mistaken doesn't sound too good to me either. I'd say that we should add some comments to the else and endif to point out to which ifeq/ifneq those belong in cases where there are multiple nested if(n)eq or where the else/endif is far away from the if(n)eq. Separating unrelated if(n)eq blocks by a newline also helps a bit. Maybe there's a better way that I'm not aware of though.
Regards, Felix
On 23/11/2023 02:51, Maximilian Brune wrote:
Hi
Reading Makefiles especially in big projects like coreboot is a constant. pain. One of the big issues is that conditionals are very hard to read since we cannot use tabs for indentation. Has anyone ever thought about using whitespaces as indentation for conditionals in our Makefiles or is that connected to known problems?
greetings Max
coreboot mailing list -- coreboot@coreboot.org To unsubscribe send an email to coreboot-leave@coreboot.org
I believe Max was proposing to use spaces for makefile syntax control flow, not tabs. That seems like it would work, I've seen it done on other projects.
On Thu, Nov 23, 2023 at 10:26 AM Felix Held felix-coreboot@felixheld.de wrote:
Hi,
the odd thing about Makefiles is that those use two different syntax': Everything that's indented by a tab is shell syntax and everything else is Makefile syntax. So we can't just indent the Makefile syntax part with tabs to make it look nicer and mixing tabs and spaces which do different things here if I'm not mistaken doesn't sound too good to me either. I'd say that we should add some comments to the else and endif to point out to which ifeq/ifneq those belong in cases where there are multiple nested if(n)eq or where the else/endif is far away from the if(n)eq. Separating unrelated if(n)eq blocks by a newline also helps a bit. Maybe there's a better way that I'm not aware of though.
Regards, Felix
On 23/11/2023 02:51, Maximilian Brune wrote:
Hi
Reading Makefiles especially in big projects like coreboot is a constant. pain. One of the big issues is that conditionals are very hard to read since we cannot use tabs for indentation. Has anyone ever thought about using whitespaces as indentation for conditionals in our Makefiles or is that connected to known problems?
greetings Max
coreboot mailing list -- coreboot@coreboot.org To unsubscribe send an email to coreboot-leave@coreboot.org
coreboot mailing list -- coreboot@coreboot.org To unsubscribe send an email to coreboot-leave@coreboot.org
Hi Max, list,
Could you please show the world a simple example of what you mean? It would certainly help everyone understand your proposal.
Best regards, Angel
On Thu, Nov 23, 2023 at 8:11 PM ron minnich rminnich@gmail.com wrote:
I believe Max was proposing to use spaces for makefile syntax control flow, not tabs. That seems like it would work, I've seen it done on other projects.
On Thu, Nov 23, 2023 at 10:26 AM Felix Held felix-coreboot@felixheld.de wrote:
Hi,
the odd thing about Makefiles is that those use two different syntax': Everything that's indented by a tab is shell syntax and everything else is Makefile syntax. So we can't just indent the Makefile syntax part with tabs to make it look nicer and mixing tabs and spaces which do different things here if I'm not mistaken doesn't sound too good to me either. I'd say that we should add some comments to the else and endif to point out to which ifeq/ifneq those belong in cases where there are multiple nested if(n)eq or where the else/endif is far away from the if(n)eq. Separating unrelated if(n)eq blocks by a newline also helps a bit. Maybe there's a better way that I'm not aware of though.
Regards, Felix
On 23/11/2023 02:51, Maximilian Brune wrote:
Hi
Reading Makefiles especially in big projects like coreboot is a constant. pain. One of the big issues is that conditionals are very hard to read since we cannot use tabs for indentation. Has anyone ever thought about using whitespaces as indentation for conditionals in our Makefiles or is that connected to known problems?
greetings Max
coreboot mailing list -- coreboot@coreboot.org To unsubscribe send an email to coreboot-leave@coreboot.org
coreboot mailing list -- coreboot@coreboot.org To unsubscribe send an email to coreboot-leave@coreboot.org
coreboot mailing list -- coreboot@coreboot.org To unsubscribe send an email to coreboot-leave@coreboot.org
On November 23, 2023 12:11:08 p.m. MST, ron minnich rminnich@gmail.com wrote:
I believe Max was proposing to use spaces for makefile syntax control flow, not tabs. That seems like it would work, I've seen it done on other projects.
I did try this out the other day and it does seem to work, but I think the point Felix was making was that having tabs for indenting some things (shell syntax in recipes) and spaces for indenting other things (visual indents of Makefile syntax) sounds like a bad idea. In most other contexts you don't need to worry about the exact type of whitespace, as it only serves one purpose. For instance, in languages like C, whitespace is purely visual, and most projects stick to only one of tabs or spaces for discrete indentation levels. In languages like Python, whitespace serves the functional purpose of separating blocks of code (similar to curly braces in C), which also doubles as a visual indent. Generally you also only stick to one of either tabs or spaces. In the Makefile case the type of whitespace actually matters, where one type is used functionally and the other is used visually. That said, I think make is pretty good at erroring on invalid indentations (you can't use spaces to indent a make recipe after a target, only tabs) so perhaps it isn't too bad. It's probably the sort of thing where you'd want your editor to display tabs and spaces with a visual character.
On Thu, Nov 23, 2023 at 10:26 AM Felix Held felix-coreboot@felixheld.de wrote:
Hi,
the odd thing about Makefiles is that those use two different syntax': Everything that's indented by a tab is shell syntax and everything else is Makefile syntax. So we can't just indent the Makefile syntax part with tabs to make it look nicer and mixing tabs and spaces which do different things here if I'm not mistaken doesn't sound too good to me either. I'd say that we should add some comments to the else and endif to point out to which ifeq/ifneq those belong in cases where there are multiple nested if(n)eq or where the else/endif is far away from the if(n)eq. Separating unrelated if(n)eq blocks by a newline also helps a bit. Maybe there's a better way that I'm not aware of though.
Regards, Felix
On 23/11/2023 02:51, Maximilian Brune wrote:
Hi
Reading Makefiles especially in big projects like coreboot is a constant. pain. One of the big issues is that conditionals are very hard to read since we cannot use tabs for indentation. Has anyone ever thought about using whitespaces as indentation for conditionals in our Makefiles or is that connected to known problems?
greetings Max
coreboot mailing list -- coreboot@coreboot.org To unsubscribe send an email to coreboot-leave@coreboot.org
coreboot mailing list -- coreboot@coreboot.org To unsubscribe send an email to coreboot-leave@coreboot.org
Nicholas
Indenting pre-receipe sections with spaces seems to work fine based on an initial test. Once we get to any conditionals inside a target, you'll need to change things up.
So that we don't have issues with whitespace, we can update the .RECIPEPREFIX value to change away from indenting with tabs for the targets. See this discussion: https://stackoverflow.com/questions/54820007/why-doesnt-make-allow-indented-...
``` organize the makefile to have conditionals first, then rules, i.e. no TAB indentation after rules anymore except for recipes, or always make sure to use SPACEs for conditional, variable assignment and rule lines. set .RECIPEPREFIX to a non-whitespace character, e.g. > and use that to indicate recipe lines. ``` If we do go this route for indentation, could we standardize on either 2-space 4-space indentation per level? The Makefile lines are long enough without indentation.
Martin
Nov 22, 2023, 16:50 by maximilian.brune@9elements.com:
Hi
Reading Makefiles especially in big projects like coreboot is a constant. pain. One of the big issues is that conditionals are very hard to read since we cannot use tabs for indentation. Has anyone ever thought about using whitespaces as indentation for conditionals in our Makefiles or is that connected to known problems?
greetings Max
On 23/11/2023 20:50, Martin Roth via coreboot wrote:
If we do go this route for indentation, could we standardize on either 2-space 4-space indentation per level? The Makefile lines are long enough without indentation.
I was initially thinking of 4 or 8 spaces vs tabs which isn't necessarily easy to visually differentiate, so I didn't like the idea too much. A 2 spaces indentation might be much better and something to look into; at least that's sufficiently visually different from the tabs for any usual tab size to not mix those up.
Regards, Felix