【问题标题】:Make: syntax error near unexpected token `--initialization'制作:意外标记'--initialization'附近的语法错误
【发布时间】:2018-06-14 06:35:57
【问题描述】:

我正在尝试在我们的一个 make 文件中编写 'if' check in define 指令。 实际上我正在尝试检查平台并继续进行环境设置。

define templ_32
mkdir -p $(@D)
if [ "$(PLAT)" = "x86_64" ]; then env PERLLIB=$(EXTLIBS)/$(PLAT32)/lib/perl5/site_perl/5.10.0 --template $<; fi
if [ "$(PLAT)" = "aarch64" ]; then env PERLLIB=$(EXTLIBS)/$(PLAT32)/lib/perl5/site_perl/5.8.0 --template $<; fi 
endef

我在我的目标配方之一中使用上述定义指令,如下所示。

some/%.c: test/tmpl-%.c $(NEW_DATA32)
    $(templ_32) --initialization $(NEW_DATA32)

当我运行具有上述更改的构建时。我收到错误:

/bin/sh: -c: line 0: syntax error near unexpected token `--initialization'

而且从日志中我看到的整个“如果”条件如下。

if [ "aarch64" = "x86_64" ]; then env PERLLIB=$(EXTLIBS)/$(PLAT32)/lib/perl5/site_perl/5.8.0 --template /test/deploy/tmpl-kt.c ; fi --initialization /work/deploy/test.pl 

从我的成功日志中,我只能看到没有共同的“if”语句

env PERLLIB=$(EXTLIBS)/$(PLAT32)/lib/perl5/site_perl/5.8.0 --template /test/deploy/tmpl-kt.c --initialization /work/deploy/test.pl

我不想让 'if' 检查与 'env' 命令一起使用。我只对

env PERLLIB=$(EXTLIBS)/$(PLAT32)/lib/perl5/site_perl/5.8.0 --template  

我该如何解决这个问题?

【问题讨论】:

    标签: makefile gnu-make


    【解决方案1】:

    您可以使用 make 条件而不是 shell if 语句:

    ifeq ($(PLAT),x86_64)
    PERLVERSION = 5.10.0
    else ifeq ($(PLAT),aarch64)
    PERLVERSION = 5.8.0
    else
    $(error "Unknown arhictecture: $(PLAT)")
    endif
    

    然后:

    PERLLIB = $(EXTLIBS)/$(PLAT32)/lib/perl5/site_perl/$(PERLVERSION)
    
    some/%.c: test/tmpl-%.c $(NEW_DATA32)
        mkdir -p $(@D); \
        env PERLLIB=$(PERLLIB) --template $< --initialization $(NEW_DATA32)
    

    【讨论】:

    • Tq.. 它有帮助:)
    【解决方案2】:

    您应该为此使用构造的宏名称。例如:

    PLATFORMS := x86_64 aarch64
    
    $(or $(filter $(PLAT),$(PLATFORMS)),$(error Unknown architecture: $(PLAT)))
    
    x86_64_PERLVER := 5.10.0
    aarch64_PERLVER := 5.8.0
    
    PERLLIB = $(EXTLIBS)/$(PLAT32)/lib/perl5/site_perl/$($(PLAT)_PERLVER)
    

    更多关于here

    【讨论】:

      猜你喜欢
      • 2012-08-31
      • 2012-10-20
      • 2012-09-29
      • 2013-12-11
      • 1970-01-01
      • 1970-01-01
      • 2014-09-01
      • 2014-02-26
      相关资源
      最近更新 更多