Hacker News new | past | comments | ask | show | jobs | submit login

    CFLAGS := ${CFLAGS}
    CFLAGS += -ansi -std=99
What's the point of the first line? Why not just:

    CFLAGS += -ansi -std=99



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.


Speaking of, why both -ansi and -std=99 [sic[1]]?

[1] should be -std=c99


I've used these comments[1] as source for writing the CFLAGS. Did I misunderstood?

[1] https://stackoverflow.com/a/2193647


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
    foo


My bad, I felt like I've seen that error pop up before in my Makefiles, but I should have double-checked before commenting.


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?...


This reminds me why I stopped visiting HN. People down vote you for trying to help! Screw whoever asshole that downvoted me even though I prefixed my answer with “My GUESS is...”.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: