简体   繁体   English

从 makefile 运行 a.tcl 命令

[英]Run a .tcl command from a makefile

I am new to writing a makefile which will be executed on a linux machine.我是编写 makefile 的新手,它将在 linux 机器上执行。

I have the following tasks to do in a makefile: 1)check if the files in the path/directory are exists and modified recently 2)run a.tcl file我在 makefile 中有以下任务要做:1)检查路径/目录中的文件是否存在并最近修改 2)运行 a.tcl 文件

I have written the following piece of code..can you please help me.我写了下面的代码..你能帮帮我吗? PATH =/work/source/路径 =/工作/来源/

task1:
    ifeq (,$(PATH))
         @echo "error file does not exist!"
    endif

    #check for files modified
    
    #run the .tcl command
    run evaltest.tcl


reports :@echo "reports tbd"


.PHONY : all 
 all: task1 reports

Please let me know what changes are required for it to run as expected.请让我知道它需要进行哪些更改才能按预期运行。

You seem to be planning to do way too much work yourself.你似乎计划自己做太多的工作。 Your task #1 is typically what make does.你的任务 #1 通常是 make 所做的。 So that only leaves task #2.所以只剩下任务#2。 If a Tcl script has the excutable permission and starts with a valid hashbang, you can just execute it.如果 Tcl 脚本具有可执行权限并以有效的 hashbang 开头,则可以执行它。 Otherwise invoke tclsh to run it.否则调用 tclsh 来运行它。

Another problem could be that you redefined the PATH variable.另一个问题可能是您重新定义了 PATH 变量。 On linux, the PATH variable normally contains a list of directories where executable commands can be found.在 linux 上,PATH 变量通常包含可以找到可执行命令的目录列表。 To point to your sources, better use a different variable name, like SRCPATH or so.要指向您的来源,最好使用不同的变量名称,例如 SRCPATH 左右。 By redefining PATH, the tclsh command can not be found, unless it is in /work/source.通过重新定义 PATH,找不到 tclsh 命令,除非它在 /work/source 中。

So the task1 rule of your Makefile could be reduced to:因此,您的 Makefile 的 task1 规则可以简化为:

task1: sourcefile1 sourcefile2
        tclsh evaltest.tcl
        # Or ./evaltest.tcl

This will execute evaltest.tcl if either sourcefile1 or sourcefile2 is newer than a file called task1.如果 sourcefile1 或 sourcefile2 比名为 task1 的文件新,这将执行 evaltest.tcl。 It is assumed that evaltest.tcl will create the task1 file.假定 evaltest.tcl 将创建 task1 文件。 If either sourcefile doesn't exist and there is no rule to create it, make will tell you about that.如果任何一个源文件都不存在并且没有创建它的规则,make 会告诉你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM