为什么Make Make 3.8.1与Make 4.1不同?

时间:2016-01-25 11:09:05

标签: c++ gcc makefile

我正在使用带有C ++的gcc构建嵌入式ARM项目:

11:01:29 ○⨠ arm-none-eabi-gcc --version
arm-none-eabi-gcc (GNU Tools for ARM Embedded Processors) 4.9.3 20150529 (release) [ARM/embedded-4_9-branch revision 224288]
Copyright (C) 2014 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is  NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

并制作:

17:11:17 ○⨠ make --version
GNU Make 3.81
Copyright (C) 2006  Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.

This program built for i386-apple-darwin11.3.0

我正在构建最近的一段代码,而根本不是为我工作 - 代码构建和部署很好,但功能不存在。 Tt没有意义,因为代码看起来完全没问题。

一位同事对我进行了审核,我们发现代码没有任何问题,所以为了笑,我们决定让他构建和部署它。

工作得很好!

因此,检查我们的版本时,他正在运行make 4.1。我升级到这个,嘿presto,它工作正常。

11:06:15 ○⨠ make --version
GNU Make 4.1
Built for x86_64-apple-darwin14.3.0
Copyright (C) 1988-2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

我们使用3.81进行了更多播放,并推断出优化可能是问题所在。

但是两个实例都将-Os传递给gcc

所以,我的问题是 - 为什么Make会对编译器产生影响?!

1 个答案:

答案 0 :(得分:0)

当“ Makefiles remade”发生时,Gnu make在3.8.2和4.1版本之间的行为略有不同。 例如,执行以下命令:

----- commands ----
rm ./sub.mk ./add_rule ; make -f test.mk HOSTCC=GCC

----- test.mk -----
$(info ===== test.mk(lv $(MAKELEVEL)) ==== )
$(info origin=$(origin HOSTCC))
HOSTCC = cc
$(info HOSTCC=$(HOSTCC))
$(info ------------------ )

.PHONY: all sub sub2

all:
    @echo "... build $@ ..."
    touch ./add_rule 
    @echo "*** using HOSTCC=$(HOSTCC) at all: ***"
    $(MAKE) -f ./test.mk sub
    @echo "*** using HOSTCC=$(HOSTCC) at all: ***"

sub:
    @echo "... build $@ ..."
    @echo "*** using HOSTCC=$(HOSTCC) at sub: ***"

-include sub.mk
ifneq ($(wildcard ./add_rule),)
sub.mk:
    @echo "... build $@ ..."
    echo "\$$$ (info --- $@(included) ---)" > $@
endif
----- end of test.mk -----

使用Ver 3.8.2 Gnu Make,控制台输出的最后几行是:

....
===== test.mk(lv 1) ==== 
origin=environment
HOSTCC=cc
------------------ 
--- sub.mk(included) ---
make[1]: Entering directory `/home/user/make-test'
... build sub ...
*** using HOSTCC=cc at sub: ***
make[1]: Leaving directory `/home/user/make-test'
*** using HOSTCC=GCC at all: ***

使用4.1版,“ cc”不会显示,但只有GCC在其中。

重点是:

在3.8.2版的Gnu make中,sub:recipe中的变量“ HOSTCC”没有被覆盖,     即使它是在命令行中指定的。

(我在构建u-boot时注意到了这种现象。   有关“重新制作Makefile”的更多信息,   请参阅制作手册“ 3.5如何重新制作Makefile”。)

这种差异似乎来自3.8.2 gnu make的main.c(第2091行)。

在4.1版代码中,putenv()不存在。

/* Reset makeflags in case they were changed.  */
{
  const char *pv = define_makeflags (1, 1);
  char *p = alloca (sizeof ("MAKEFLAGS=") + strlen (pv) + 1);
  sprintf (p, "MAKEFLAGS=%s", pv);
  putenv (p); //<<=== the different point.
}