DJGPP Utilities Reference

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

11. update

update is a fancy copy-if-needed program. Basically, it compares the two files you give it, and if they differ, copies one to the other. This is useful in makefiles where a file is generated often, but its contents changes rarely, and other files depend on it. For example, bison emits a header file each time it parses the grammar. The header rarely changes, but the grammar changes often. So, you use update to copy the header to its real name only when it changes, and everything else won't need to be recompiled each time.

Usage: update new_file copied_to


foo.c foo.h : foo.y
        bison foo.y
        update y_tab.h foo.h
        update y_tab.c foo.c

Another use of update might be to validate (and replace if necessary) a local copy of some master data file:

.PHONY: foo.dat
foo.dat:    /master/data/foo.dat
            [ -f $@ ] && cmp -s $< $@ || cp -f $< $@ && touch $@

update is similar to the GNU-standard shell script move-if-change that comes with some GNU packages (e.g., GCC, binutils). The two are not functionally equivalent, however; in particular, move-if-change always removes the source file in the process of updating the target, whereas update leaves the source file intact.

If you need a portable replacement for update, there are several options:

An important feature of update is that copied_to is created with the current timestamp. If you are certain that cp on your system is not aliased to cp -p or cp --preserve (to preserve timestamps), then you can omit the `&& touch copied_to' bit in the above command strings.

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

  webmaster     delorie software   privacy  
  Copyright © 2004     Updated Nov 2004