我知道 windows 上最快和最轻量级的二进制文件只生成 msvc 编译器
msvc Express 版是免费的 http://www.microsoft.com/express/windows/
但是如何使用 cl.exe 而不是 g++.exe 呢?
是否可以通过使用 GNU make 变量共同生成可与 cl.exe 和 g++ 一起使用的 makefile?
例如 http://msdn.microsoft.com/en-us/library/19z1t1wy(v=VS.80).aspx
export CC = path/to/cl.exe
export COMPILE_WITHOUT_LINKING = /c
export OBJECT_FILE = /Fo
Run Code Online (Sandbox Code Playgroud)
还是 cl 和 g++ 的概念非常不同?
假设我在 makefile 中有以下通配符匹配项:
data-files = $(wildcard $(ptdf)/*.png) \
$(wildcard $(ptdf)/*.gif) \
$(wildcard $(ptdf)/*.bmp) \
$(wildcard $(ptdf)/*.jpg) \
$(wildcard $(ptdf)/*.ico) \
$(wildcard $(ptdf)/*.dist) \
$(wildcard $(ptdf)/*.html)
Run Code Online (Sandbox Code Playgroud)
通配符语法能否让我能够像正则表达式\w{1,2}那样匹配包含 1 到 2 个字母的文件名?没有文件扩展名?
如果没有,我该如何使用 linux 命令(例如find,等)使用其他语法来做到这一点?
我在makefile中有以下内容:
.PHONY: preq_test a b c d
a b c d:
@echo building $@
preq_test : a b | c d
@echo preq prequisites are: $^;
Run Code Online (Sandbox Code Playgroud)
现在,$^应该根据文档列出所有先决条件(除了重复):
$^
$+
The names of all the prerequisites, with spaces between them. For prerequisites
which are archive members, only the named member is used (see Archives). The value
of $^ omits duplicate prerequisites, while $+ retains them and preserves their
order.
Run Code Online (Sandbox Code Playgroud)
但仅限订单的先决条件不会出现在$^:
building a
building b
building c
building …Run Code Online (Sandbox Code Playgroud) 这是我运行的命令
make -d -f dump.makefile
Run Code Online (Sandbox Code Playgroud)
我得到的错误:
Reading makefile `dump.makefile'...
dump.makefile:31: *** commands commence before first target. Stop.
Run Code Online (Sandbox Code Playgroud)
ifneq (,)
This makefile requires GNU Make.
endif
# force use of Bash
SHELL := /bin/bash
# function
today=$(shell date '+%Y-%m:%b-%d')
update-latest=$(shell ln -nf {$(call today),latest}.cfdict-"$(1)".localhot.sql)
# variables
credentials="$$HOME/.my.cfdict.cnf"
default: data-only structure-only csv-only all
data-only: what=data
argList=( --defaults-file="${credentials}" --no-create-db --no-create-info ) \
mysqldump "$${argList[@]}" cfdict > $(call today).cfdict-"${what}".localhot.sql
$(call update-latest,${what})
Run Code Online (Sandbox Code Playgroud)
触发错误的行是$(call update-latest,${what})调用update-latest函数。
完整的要点可在 github 上找到。
我有一个makefile设置,它接受一个命令行参数,该参数在构建时被解析以确定使用哪个编译器CPULIST.
所以,我计划通过以下命令构建:make all CPULIST="arm x86".然后我创建了一些虚假的规则,以便make all循环并有效地执行:
make all CPULIST=x86
make all CPULIST=arm
Run Code Online (Sandbox Code Playgroud)
规则:
.PHONY: all
all:
@echo "Detected CPULIST:${CPULIST_DETECTED}"
@echo "CPULIST:${CPULIST}"
@for cpu in $(CPULIST_DETECTED); do \
echo "CPU:$${cpu}"; \
variant_$${cpu}=abc; \
echo "variant_$${cpu}: $${variant_x86}"; \
$(MAKE) build CPULIST=$$cpu; \
done
@true
.PHONY: build
build: sanity_check $(TARGET)
@true
Run Code Online (Sandbox Code Playgroud)
如果这是一个bash脚本,我会使用variant_${cpu}它,例如,让它动态创建变量名称和赋值,如:
variant_x86=abc;
variant_arm=abc;
Run Code Online (Sandbox Code Playgroud)
似乎我没有让转义序列正确,至少在GNU make语法中是这样.
构建list_algorithms.o的依赖项文件
Detected CPULIST:x86 arm
CPULIST:test arm x86
CPU:x86
/bin/sh: 3: variant_x86=abc: not found
variant_x86:
make[1]: Entering directory `/home/svn/public/lib/libMYLib'
CPULIST:x86 …Run Code Online (Sandbox Code Playgroud) 我有兴趣学习Makefile项目的艺术.但是,我有一个问题.
对于后台:在我的计算机上,我已经nmake安装了,我假设在安装它时附带了Visual Studio.我可能正在考虑让我的C++项目使用makefile结构nmake.但是,如果我想转向其他流行的make版本呢?gmake?这引出了我的主要问题:
如果我学习了make(nmake,gmake)的一个实现并转移到另一个实现,我可以在多大程度上预期makefile语法的差异?在惯例/实践中?
如果每个实现之间存在实质性差异,我会有一个后续问题(有点自以为是):
make我应该首先学习哪种实施?为什么?
有人可以提供一个使用递归扩展变量 (REV) 的真实示例吗?在文档或各种博客文章中,人们只给出了无用的玩具示例,例如
foo = $(bar)
bar = $(ugh)
ugh = Huh?
Run Code Online (Sandbox Code Playgroud)
除了使用$(call). 我还发现,过去人们使用 REV 为特定目标的编译器提供附加参数,但现在认为这种技巧已经过时,因为 GNU Make 具有特定于目标的变量。
我正在尝试向我的 makefile 添加一条警告消息。Make 无法找到右括号。
以下内容来自我的 GNUmakefile:
341 ALIGNED_ACCESS = $(shell cat config.h | $(EGREP) -c "^#define NO_UNALIGNED_DATA_ACCESS")
342 ifeq ($(ALIGNED_ACCESS),0)
343 $(info WARNING: NO_UNALIGNED_DATA_ACCESS is not defined in config.h)
344 endif
Run Code Online (Sandbox Code Playgroud)
提出投诉:
$ make
GNUmakefile:341: *** unterminated call to function 'shell': missing ')'. Stop.
Run Code Online (Sandbox Code Playgroud)
我真的在 makefile 中另外 25 次,所以我不确定为什么它找不到上面 shell 的正确括号。
我还将命令移到第 1 行进行测试,我得到了相同的消息(以行号更改为模)。为了好玩,我添加了一个不平衡的右括号,但我得到了同样的信息。
为什么找不到正确的括号?
如何强制执行命令?
我有这个Makefile:
TMP_DIR := tmp
RUN_OR_NOT := $(shell date '+%y%m%d%H%M')
all: version
version:
ifeq ($(shell test -d ${TMP_DIR} && echo -n "yes";),yes)
$(shell echo ${TMP_DIR} already exists ...)
else
$(shell mkdir -p ${TMP_DIR})
endif
Run Code Online (Sandbox Code Playgroud)
我想首先检查目录是否tmp存在,如果它不存在,只创建它.这有效,但有一个奇怪的错误:
ifeq (yes,yes)
/bin/sh: 1: Syntax error: word unexpected (expecting ")")
Makefile:7: die Regel für Ziel „version“ scheiterte
make: *** [version] Fehler 2
Run Code Online (Sandbox Code Playgroud)
为什么会出现这个奇怪的/bin/sh: 1: Syntax error: word unexpected (expecting ")")错误?以及如何解决这个问题?
因此,在Powershell中,我键入
$ Set-Variable FOO
Run Code Online (Sandbox Code Playgroud)
然后,在我的makefile中,
.PHONY: show-foo
show-foo:
@echo ${FOO}
Run Code Online (Sandbox Code Playgroud)
输出空白行。
我尝试使用$ profile之类的系统变量,似乎没有任何环境变量传递到makefile中。
有人可以告诉我我在做什么错吗?
在Windows 10上,使用make 4.2.1