Re:Makefiles – Best Practices
by aaaaaaaaaaab on Friday February 01, 2019 @11:40AM
(#19055644)
What's the point of the first line? Why not just:
[ Parent
| on HN ]
If turns CFLAGS from a recursive variable to a simple one. Hence it will not be re-expanded every time it is used. This is a speed optimization.
$ cat Makefile
CFLAGS = -Wall
$(info $(flavor CFLAGS))
CFLAGS := $(CFLAGS)
$(info $(flavor CFLAGS))
$ make
recursive
simple
But TFA says that the author is using := to prevent a recursive definition. It's unclear why the author doesn't just += without doing = or := (unless they want the recursive to simple conversion I talk about above). My guess is the author sligthly misunderstood the handling of the environment inside a Makefile.
Re:Makefiles – Best Practices
by smitherfield on Friday February 01, 2019 @02:52PM
(#19057812)
Speaking of, why both -ansi and -std=99 [sic[1]]?
[1] should be -std=c99
Re:Makefiles – Best Practices
by danyspin97 on Saturday February 02, 2019 @09:57AM
(#19063261)
I've used these comments[1] as source for writing the CFLAGS. Did I misunderstood?
Because CFLAGS may not be set in the environment, resulting in concatenation to an undefined variable error.
No such error occurs.
$ cat Makefile
FOO += foo
all: ; @echo $(FOO)
$ make
fooMy bad, I felt like I've seen that error pop up before in my Makefiles, but I should have double-checked before commenting.
Re:Makefiles – Best Practices
by jschwartzi on Friday February 01, 2019 @05:26PM
(#19059368)
There's no such thing as an undefined variable in Make. The variable expands to text. Variables which are not defined by definition expand to no text.
My bad, I felt like I've seen that error pop up before in my Makefiles, but I should have double-checked before commenting.
My guess is that the left hand side is a make variable while the right hand side is an environment variable. However the make manual says “Every environment variable that make sees when it starts up is transformed into a make variable with the same name and value.“ so maybe it’s not necessary?...