Make 忽略了编译器标志

Make is ignoring compiler flags

我有一个项目,我可以在 Ubuntu 上毫无问题地进行编译。 https://github.com/avalon-lang/avaloni/blob/master/Makefile 处的 Makefile 是我试图为 Windows 10.
改编的 Makefile 我安装了 MingW-w64 和 GNU Make-32。
当我 运行 make 针对 Makefile 时,传递给编译器的 CFLAGS 和其他标志不会显示,在回显输出中留下空格而不是编译器标志。因此,找不到成功编译所需的文件。

我尝试用它们的内容替换变量 CFLAGS、SYSINC 和 INC,但没有任何改变。它们被简单地忽略了,就好像 make 删除了它们一样。

cc          := g++
cflags      := -std=c++11 -g -Wall -pedantic -DDEBUG -fopenmp
ldpaths     := -LC:/Boost/lib
rdpaths     := -Wl,-rpath=C:/Boost/lib
ldflags     := -lboost_filesystem-mgw81-mt-x64-1_68 -lboost_system-mgw81-mt-x64-1_68 -fopenmp
src_dir     := src
inc         := -Isrc -Ideps/qpp
sysinc      := -isystem deps/boost -isystem deps/eigen
build_dir   := build
bin_dir     := bin
target      := $(bin_dir)/avaloni.exe

src_ext     := cpp
sources     := $(shell dir $(src_dir)\*.$(src_ext) /b /s)
objects     := $(patsubst $(src_dir)\%,$(build_dir)\%,$(sources:.$(src_ext)=.o))

install_dir := C:/Avalon
sdk_path    := C:/Avalon/AvalonSdk


.PHONY: all
all: setup $(target)

$(target): $(objects)
    $(cc) $^ -o $(target) $(ldpaths) $(ldflags) $(rdpaths)

$(build_dir)\%.o: $(src_dir)\%.$(src_ext)
    @if not exist "$(dir $@)" mkdir $(dir $@)
    $(cc) $(cflags) $(sysinc) $(inc) -c -o $@ $< #!!! This is the problem line.

在编译过程中,我希望有如下一行:

g++ -std=c++11 -g -Wall -pedantic -DDEBUG -fopenmp -isystem deps/boost -isystem deps/eigen -Isrc -Ideps/qpp -c -o file.o file.cpp

但我得到:

g++    -c -o file.o file.cpp

原因是 (a) 您正在使用非标准变量来保存您的编译器标志,并且 (b) 您的模式规则不匹配。

由于 (b),make 选择了用于创建目标文件的内置规则,并且由于 (a),内置规则中使用了您的 none 标志。

您的模式规则不匹配的原因是 GNU make 不支持路径名中的反斜杠。您必须在所有规则中使用正斜杠:

$(build_dir)/%.o: $(src_dir)/%.$(src_ext)
  ...