Search code examples
makefilegnu-make

What kind of variable is cflags.debug?


I was looking for alternatives for compiling C-code using Makefile with conditional CFLAGS. For which I found this option. It worked perfectly.

Now, I want to understand what kind of variable is cflag.debug, etc. Or rather, what the dot notation means in this case. I look through the GNU Make Manual and couldn't find an answer. I'll appreciate some insight.


Solution

  • Dots in variable names have no syntactical significance to GNU Make. You may prefer to write cxxflags.debug rather than, say, cxxflags_debug. It makes no difference to make.

    But be careful. Shell variables can't contain dots. So it will make a difference if you export a Make variable containing a dot to a sub-shell. See:

    $ cat Makefile 
    .PHONY: foo bar
    
    export cxxflags_debug := -g -march=native
    export cxxflags.release := -g -O3 -march=native -DNDEBUG
    
    foo:
        @echo Make variable cxxflags_debug = $(cxxflags_debug)
        @echo Make variable cxxflags.release = $(cxxflags.release)
    
    bar:
        @echo Exported shell variable cxxflags_debug = $$cxxflags_debug
        @echo Exported shell variable cxxflags.release = $$cxxflags.release
        
        
    $ make foo
    Make variable cxxflags_debug = -g -march=native
    Make variable cxxflags.release = -g -O3 -march=native -DNDEBUG
    
    $ make bar
    Exported shell variable cxxflags_debug = -g -march=native
    Exported shell variable cxxflags.release = .release