我有一个主 makefile,其中包含通用设置,以及一个子 makefile,其中包含项目特定设置。
从我的另一个问题来看覆盖 makefile 中的变量 https://stackoverflow.com/q/18869628/24949,我了解到我可以在我的主 makefile 中使用以下代码:
CC ?= avr-gcc
CXX ?= avr-g++
在子 makefile 中,我使用colorgcc https://github.com/colorgcc/colorgcc并覆盖这些变量:
CC ?= color-avr-gcc
CXX ?= color-avr-g++
一切正常。
但是,如果我从子 makefile 中删除上述行,make 就会开始使用gcc
and g++
代替avr-gcc
and avr-g++
.
我想两者都有CC
and CXX
受到不同的对待,并且 make 为它们提供了默认值,我无法使用以下语句为它们分配默认值:
CC ?= avr-gcc
CXX ?= avr-g++
我的问题:
- 我的假设正确吗?
- 如果是,是否有其他方法可以提供默认值
CC
and CXX
在主 makefile 中并让 make 使用它,如果我不在子 makefile 中覆盖它们?
Edit:
As per 时空狐 https://stackoverflow.com/users/539810/chrono-kitsune的建议我做了以下
主生成文件
CC = avr-gcc
CXX = avr-g++
# Add other master macros here.
# Add other master targets here.
子生成文件
CC ?= color-avr-gcc
CXX ?= color-avr-g++
# There are no child macros or targets
include master.mk
不幸的是,即使这样也不起作用。当我跑步时make child.mk
它正在拾取CC
and CXX
在 master 中定义。
PS:顺便说一句,我的主 makefile 是 Arduino 的 makefile,完整的源代码可在github https://github.com/sudar/Arduino-Makefile/blob/master/arduino-mk/Arduino.mk.