spi*_*ace 1 linux makefile gnu-make
这是一个Makefile:
.PHONY: all
ifeq ($(OS),Windows_NT)
DETECTED_OS := Windows
else
DETECTED_OS := $(shell uname -s)
endif
$(info DETECTED_OS is set to '$(DETECTED_OS)')
Run Code Online (Sandbox Code Playgroud)
当用制表符缩进时,它会打印
DETECTED_OS is set to ''
但是当缩进 0 个或多个空格时,它会打印
DETECTED_OS is set to 'Linux'
但是如果你删除第一行,.PHONY: all它会打印
DETECTED_OS is set to 'Linux'
无论是制表符还是空格。
所以第一个版本被破坏了,因为它DETECTED_OS没有设置。这是为什么?
我的版本:
GNU Make 4.1
Built for x86_64-pc-linux-gnu
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.
Run Code Online (Sandbox Code Playgroud)
当您使用 TAB 缩进一行时,make 假定它是前一个目标的配方的一部分(如果有的话)。在这种情况下,有.PHONY目标,所以 make 假设这两行是.PHONY目标配方的一部分(从未使用过)。因此,这些 make 变量赋值不会运行。
makefile 的简单规则是,总是用 TAB 缩进配方行,不要用 TAB 缩进任何其他行。
| 归档时间: |
|
| 查看次数: |
746 次 |
| 最近记录: |