简体   繁体   中英

Make: copy file from remote server rather than remake

I'd like to copy a file from a remote server rather than recompute it if possible when using gnu make. To do this I've been keeping a local "dummy" file which records (via timestamp) when the file was last created and copied to the remote server. The gist of what I want to do is below. computed.file is the file itself and computed.file.remote is the dummy.

computed.file: computed.file.remote
    <copy computed.file from remote server>

computed.file.remote:
    <command to create computed.file>
    <copy computed.file to remote server>
    touch computed.file.remote

However, this will force the file to be copied to and from the remote server if both rules are invoked, even though it exists when the file is created in the second rule.

Is there another way to do this?

Well, you can do something like this:

computed.file: computed.file.remote
        if [ $< -nt $@ ]; then <copy computed.file from remote server>; fi

computed.file.remote:
        <command to create computed.file>
        <copy computed.file to remote server>
        touch -r computed.file $@

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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