从调用脚本做,只有当main.c中被修改 [英] Call make from script, only if main.c is modified

查看:156
本文介绍了从调用脚本做,只有当main.c中被修改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题:我想只运行一个脚本(如run.sh),如果这将决定我的制作应该叫(如果需要调用它)然后运行可执行文件。

The problem: I want to run only a script (e.g. run.sh), which will decide for me if make should be called (and call it if needed) and then run the executable.

我的项目只有一个文件,即main.c中然而,仅仅链接让我稍等一下,什么,当我调试,我很渴望要运行的程序,我不喜欢。我想这样的事情到run.sh:

My project has only one file, that is main.c. However, just the linking makes me wait a bit, something that I do not like when I debug and I am eager for the program to run. I would like something like this into run.sh:

#!/bin/bash
if[ main.c has changed from the last time make was called] then
  make > compile.txt
fi
./a.out

,使制作仅当main.c中被修改调用。通过修改,人们可以认为时间戳被改变(即使可能不是实际条件)取。这是可行的?

so that the make is called only if main.c is modified. By modified, one could take that the timestamp is changed (even if that may not the actual criterion). Is this feasible?

如果是这样,我看到这个回答,这让我觉得我每次进入if语句体的呼叫作出,main.c中的一个拷贝将被创建,或该文件的时间戳将被存储(在可能的文件),以便脚本在下一次运行时,其将恢复该信息,如果状态检查看看时间戳不同。所以,第二个问题是,该怎么办呢?

If so, I saw this answer, which made me think that every time I enter the body of the if statement that calls make, a copy of main.c would be created, or the timestamp of the file would be stored (in a file maybe), so that the next time the script runs, it will restore that information and check the if condition to see if timestamps differ. So, the second question is, how to do it?

推荐答案

简单

#!/bin/bash

if [ a.out -ot main.c ]; then
    make > compile.txt
fi

./a.out

-ot 等同于比老

但是,此行为是由使自己的预期。我想preFER像一个makefile

However, this behaviour is expected from make itself. I would prefer a makefile like

CC = gcc
CFLAGS = -Wall -W

main: main.c
    $(CC) $(CFLAGS) -o $@ $^

如果的main.c 最后被更新后的规则将只运行制作

The main rule would run only if main.c is updated after last make

这篇关于从调用脚本做,只有当main.c中被修改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆