[Omake] 2 questions about .SCANNER rules and a possible bug report
Aleksey Nogin
nogin at metaprl.org
Tue Jan 9 11:06:35 PST 2007
On 08.01.2007 20:03, Nick wrote:
> I have confirmed by experimentation 2 things that are not explicitly
> stated in section 7.6 of the documentation.
> 1) the output of the command in a .SCANNER rule is supposed to go to
> stdout.
Yes, the section 3.4.3 states it much more explicitly - "The result of
executing the <commands> should be a sequence of dependencies in OMake
format, printed to the standard output.". The section 7.6 ought to be
more clear - I've updated the documentation accordingly.
> Somehow it's captured from stdout and stored somewhere.
> Q: if I wanted to analyze that output how would I be able to extract
> it other than
> running the same command in my shell?
You have two options - either pipe it to a command that would duplicate
the results on stderr, or use debug flags (such as -debug-deps and/or
-debug-scanner).
> 2) See the sed command in the snippet below?
> It was required because the scanner command returns the dependencies
> like so
>
> prog.o: ctrprog/yprog_eod/main.c 3rdparty/bstr/bstr.h \
> ctrprog/include/db_iface.h
>
> but I need a $(ROOTDIR)/$(PLATFORM)/ or similar prefix in front of
> prog.o .
[...]
> left = $(nth $i, $(F4))
> right = $(nth $i, $(cfiles))
> $(left): $(right)
> $(create_dir $(nth $i, $(F2)))
> $(CC) -o $(left) -c $(CFLAGS) $(right)
> dir = $(nth $i, $(F2))
> .SCANNER: $(left) : $(right)
> $(CC) -MM $(CFLAGS) $(right) | sed -e "s@^@$(dir)@"
I would suggest using the .SUBDIRS construct to make sure the thing is
grounded in the right place. The only issue is that you would have to
create the directory beforehand (so the directories will be created
while the OMakefiles are being read, not when the project is being built).
left = $(file $(nth $i, $(F4)))
right = $(file $(nth $i, $(cfiles)))
target_dir = $(dirof $(left))
mkdir -p $(target_dir)
.SUBDIRS: $(target_dir)
$(left): $(right)
$(CC) -o $@ -c $(CFLAGS) $<
.SCANNER: $(left) : $(right) :value: $(digest-in-path-optional
$(INCLUDES), $&)
$(CC) -MM $(CFLAGS) $<
Note:
- You need to use the "file" function above to make sure the right
relative paths are still used after the .SUBDIRS relocates you to a
different directory
- It is always better to use $@ and $< in place of explicit target
names to avoid mistakes.
- See the Section 7.6 of the documentation for the explanation of the
":value: ..." part (note that using it would require a correct INCLUDES)
- It is better not to use variable names like "dir" that would then
shadow a built-in function that you might want later (this is supposed
to be flagged in the future 0.9.9+ versions of OMake, but this is not
there yet).
> One final note: if the indentation of "i = $(add $i, 1) " matches the
> indentation of "while" the program goes into unbounded recursion and
> gobbles up all available memory (>2GB on my machine).
> Obviously such indentation is wrong but nevertheless I consider the
> omake behaviour in that case a bug.
I would disagree - you wrote a "valid" piece of code instructing OMake
to run in an infinite loop, constantly adding new rules. Of course,
OMake runs out of memory...
Aleksey
More information about the Omake
mailing list