How to pass macro definition from “make” command line arguments (-D) to C source code?

前端 未结 6 1936
醉话见心
醉话见心 2020-12-04 07:40

I usually pass macro definitions from \"make command line\" to a \"makefile\" using the option : -Dname=value. The definition is accessible inside the makefile.

I al

6条回答
  •  醉酒成梦
    2020-12-04 08:19

    Just use a specific variable for that.

    $ cat Makefile 
    all:
        echo foo | gcc $(USER_DEFINES) -E -xc - 
    
    $ make USER_DEFINES="-Dfoo=one"
    echo foo | gcc -Dfoo=one -E -xc - 
    ...
    one
    
    $ make USER_DEFINES="-Dfoo=bar"
    echo foo | gcc -Dfoo=bar -E -xc - 
    ...
    bar
    
    $ make 
    echo foo | gcc  -E -xc - 
    ...
    foo
    

提交回复
热议问题