Change Makefile variable value inside the target body

前端 未结 6 1548
夕颜
夕颜 2020-12-29 00:43

Is there a way to reassign Makefile variable value inside of the target body?

What I am trying to do is to add some extra flags for debug compilation:



        
6条回答
  •  独厮守ぢ
    2020-12-29 01:20

    Edit: As explained by Beta in the other answer, it is possible.


    No. There is no way to do this in the Makefile. You can however change the value of a variable on the make command line. If you rewrite your Makefile as follows:

    ERLCFLAGS += $(ERLCFLAGSADDED)
    
    %.erl: %.beam
        $(ERLC) $(ERLCFLAGS) -o ebin $<
    
    test: clean compile compile_test
    

    Then, you can invoke make to perform your tests using:

    make ERLCFLAGSADDED=-DTEST test
    

提交回复
热议问题