Force gnu make to rebuild objects affected by compiler definition

前端 未结 1 1319
一个人的身影
一个人的身影 2020-12-03 01:07

I have a makefile that takes options at the command line

make OPTION_1=1

Based on the value it will add additional compiler definitions to

相关标签:
1条回答
  • 2020-12-03 01:59

    I use a file to remember the last value of such options, like this:

    .PHONY: force
    compiler_flags: force
        echo '$(CC_FLAGS)' | cmp -s - $@ || echo '$(CC_FLAGS)' > $@
    

    The cmp || echo bit means the file compiler_flags is only touched when the setting changes, so now you can write something like

    $(OBJECTS): compiler_flags
    

    to cause a rebuild of $(OBJECTS) whenever the compiler flags change. The rule for compiler_flags will be executed every time you run make, but a rebuild of $(OBJECTS) will be triggered only if the compiler_flags file was actually modified.

    0 讨论(0)
提交回复
热议问题