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

问题描述 投票:1回答:1

我正在使用带有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会对编译器产生影响?!

c++ gcc makefile
1个回答
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: ***

使用ver 4.1,'cc'没有显示,但只有GCC存在。

重点是:

在版本3.8.2 Gnu make中,变量'HOSTCC'不会在sub:recipe中被覆盖,即使它是在命令行中指定的。

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

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

在ver 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.
}
© www.soinside.com 2019 - 2024. All rights reserved.