有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java Makefile:“多个目标模式。停止。”

我当然又变傻了

谁能告诉我为什么会这样

$(shell compileJava.bat)

没有任何变量、特殊字符、不需要的空格、冒号等的表达式将导致错误Makefile:70: *** multiple target patterns. Stop.

我在整个互联网上搜寻答案

我想做的事

我正在做一个涉及本地人的Java项目。我有这样的结构

+ root (project)
  -+ build
     -+ natives (for the built native libraries like dlls)
     -+ classes (for the built java classes)
     -+ generated (gradles compileJava task automatically generates jni header files)
  -+ src
    -+ main
      -+ java (all of the java source)
      -+ resources
      -+ c
        -+ Makefile (will be called to compile and link the c(++) code)
  -+ Makefile (the general makefile, error occurs in here at line 70)
  -+ compileJava.bat (calls gradlew compileJava with a jdk argument, but since im using 
      windows and make doesnt support colons, like C:, i had to put it in a batch file) 

根Makefile应该遵循这个过程

[1] call "compileJava.bat" to compile the java code & gen the headers (error occurs here)
[2] call "make -C src/main/c" to run the native build makefile
[3] call "jar cf <name> <contents>" to package all java code (and the natives) into a jar

链接

My whole root Makefile: Pastebin

compileJava.bat: Pastebin


共 (1) 个答案

  1. # 1 楼答案

    $(shell ...)做什么?它调用一个shell命令,并计算为命令的标准输出

    如果您编写这样的makefile:

    $(shell true)
    

    然后,shell命令不打印任何内容,因此它将扩展为不打印内容,然后make尝试不计算任何内容,结果什么也没有发生

    如果您编写这样的makefile:

    $(shell echo hi)
    

    然后shell comand打印“hi”,这个函数将扩展为字符串“hi”,就像编写了一个makefile:

    hi
    

    当然,这不是一个有效的生成文件

    因此:

    $(shell make -C src/...)
    

    扩展到运行make的整个输出,这显然根本不是有效的make文件

    可以通过将结果放入变量中来避免这种情况:

    _tmp := $(shell make -C src/...)
    

    但是,我真的认为你需要重新考虑你的整个方法。Makefiles不是像shell脚本那样的程序程序