Makefile无法在Windows上运行(mingw32-make,错误255,此时意外)

时间:2015-10-30 16:38:52

标签: windows makefile mingw32

我有一个在Cygwin下运行的makefile但是当我尝试从cmd.exe运行Mingw32-make.exe时遇到错误:

all: my_file

my_file: \
  static/XML/head.xml \
  ../lib/Dependencies/common/1.0 ../lib/Dependencies/licensing/1.0 ../lib/Dependencies/json/1.0 \
  src/common \
  src/MainFolder \
  static/XML/tail.xml
  $(build-file)

# Simple file and directory concatenation.
define build-file
@for dep in $^; do \
  if [ -d $$dep ]; then \
    for file in $$dep/*.lua; \
    do \
      cat $$file; \
      echo; \
    done \
  else \
    cat $$dep; \
    echo; \
  fi \
done > bin/$@.lua
@echo 'BUILT $@'
endef

当我尝试运行mingw32-make.exe时出现以下错误:

dep was unexpected at this time.
Makefile:9: recipe for target 'my_file' failed
mingw32-make: *** [my_file] Error 255

文件的缩进设置为标签。

到目前为止,我没有尝试过任何工作。有人可以帮忙吗?我该怎么做才能让这个工作?

1 个答案:

答案 0 :(得分:1)

定义define build-file... endef中的代码 将由主机系统中的shell执行。

bash脚本,bash是通常的shell linux(和cygwin)。当您尝试执行时 Windows make本地mingw32-make.exe, shell是Windows shell cmd.exe,它是 不理解bash脚本。

要工作,你的品牌需要检测(或被告知)是否 主机系统是Windows或Linux(类似)。然后你可以 有条件地为build-file选择一个可行的定义,例如

ifdef WINDOWS
define build-file
    ... cmd commands ...
endef
else
define build-file
    ... bash commands ...
endef
endif

<强>有感

或者,如果您的Windows bash.exe中有来自Cygwin的PATH, 你应该只能把SHELL = bash.exe放在顶部 你的makefile为你的make做了bash shell。