[Omake] omake equivalent of make's $?

Jason Hickey jyh at cs.caltech.edu
Sun Jul 15 17:12:20 PDT 2007


Bryce,

I not sure if the $? variable makes a lot of sense in omake, but let  
me explain.  Suppose we set up a function to compute $?, producing  
the same result as make.  Here's the code, where we just stat each of  
the files to get their date.  We can't define $? (syntax error), so  
let's call it $N.

     #
     # Get the last-modified date, or 0 if the file
     # does not exist.
     #
     try-file-date(node) =
         try
             info = $(stat $@)
             value $(info.mtime)
         default
             float(0)

     #
     # Find the files in $+ that are newer than $@
     #
     N() =
         target-date = $(try-file-date $@)
         files[] =
         foreach(x, $+)
             if $(gt $(try-file-date $x), $(target-date))
                 files[] += $x
                 export
             export
         value $(files)

Then we can do the same kind of stuff as in make, but use $N instead  
of $?

     lib.a: a.o b.o
         ar cr $@ $N
         ranlib $@

The problem is, in OMake the commands-text is also examined during  
dependency analysis--if the commands change, the rule is considered  
out of date.  So the first time you build the project it will run "ar  
cr lib.a a.o b.o", and the next time it will run "ar cr lib.a", which  
is undesirable.  make ignores the commands-text in the analysis, so  
the second null-operation wouldn't happen (but other bad things  
happen instead).

To fix this, you could wrap the command in an alias that takes all  
the files, and then selects only the ones that are important.  OMake  
doesn't look inside aliases during dependency analysis.  Here is  
actual part of the OMakefile.

     # Make the alias "ar-newer"
     Shell. +=
         ar-newer(argv) =
             files = $N
             if $(files)
                 ar cr $@ $(files)

     lib.a: a.o b.o
         ar-newer

     .DEFAULT: lib.a

For installing, you may wish to use file digests instead of  
modification times.  This will be faster if the files are large.

     Shell. +=
        copy-if-newer(argv) =
            src = $(nth 0, $(argv))
            dst = $(nth 1, $(argv))
            if $(not $(equal $(digest-optional $(dst)), $(digest $ 
(src))))
                cp $(src) $(dst)

     .PHONY: install

     install: progA progB
         cp-if-newer progA /usr/local/bin/progA
         cp-if-newer progB /usr/local/bin/progB

Finally, you can use file-exists, ls, or glob to check for files that  
you previously installed, but should no longer exist.

Jason

On Jul 14, 2007, at 11:24 PM, Bryce Nichols wrote:

> Hi all,
>
> I'm trying to set up something for my projects so that when I type  
> "omake install", then only the changed files are copied, and also  
> if any files that were previously installed but that are no longer  
> part of the install set will be removed.
>
> The point is to be a bit more efficient and keep from polluting the  
> filesystem as the project evolves.
>
> The problem is, I don't know how to learn from omake which files  
> have changed.  With make, I could just use the automatic variable  
> $? to get the list of dependencies which had changed.  omake  
> doesn't seem to have this feature.
>
> So is there a way to get the list of only the changed dependencies  
> in the body of an omake rule?
>
> Also, if anyone has comments or insight about my idea for tracking  
> installed files, I'd love to hear from you.
>
> Thanks!
>
> --bryce
>
> _______________________________________________
> Omake mailing list
> Omake at metaprl.org
> https://lists.metaprl.org/mailman/listinfo/omake

--
Jason Hickey                  http://www.cs.caltech.edu/~jyh
Caltech Computer Science      Tel: 626-395-6568 FAX: 626-792-4257





More information about the Omake mailing list