The preprocessor should provide a means for
determining whether or not a file exists, so
that one can conditionalize %INCLUDEs with-
out having to rely on Makefile trickery that
feeds -D options to NASM.
For example:
%IFFILE "source.inc"
%INCLUDE "source.inc"
%ENDIF
See
http://sourceforge.net/mailarchive/message.php?msg_id=1
0447614
for the request on the nasm-users list.
Attached find a diff with one implementation.
I went for %(EL)IF(N)FILE, not %(EL)IF(N)EXISTS
since I found EXISTS misleading.
required changes
Logged In: YES
user_id=804543
The user manual will also need to
document that %(EL)IF(N)FILE can
lead to phase errors. See the 2nd
attached diff.
required changes, part 2
Logged In: YES
user_id=762255
I'd prefer to see an option that duplicates gcc's -MG
option, which, in the above case, would add source.inc to
source.o's dependancies, without erroring, even if
source.inc did not exist. AFAICT, the %(EL)IF(N)FILE
directive would not be able to do that. Attached is a rather
hacky diff that simply changes nasm's -M to behave as gcc's
-MG. This is sufficient for my purposes, but may not be the
correct solution.
Furthermore, there is a race condition in the %(EL)IF(N)FILE
code: If source.inc is created or removed between the
%(EL)IF(N)FILE and the %INCLUDE, an unexpected result may
occur. In the positive case, the %(EL)IFFILE can hold the
FILE* and get the %INCLUDE to return that FILE*, rather than
reopening the file, but I am aware of no such solution for
%(EL)IFNFILE.
Logged In: YES
user_id=762255
Well, SF.net isn't showing me the file upload options, but
the diff can be found (gzipped for historical reasons) at
http://svn.ttdpatch.net/trac/browser/trunk/nasm/nasm-0.98.39-assume-autogen.gz?format=raw
Logged In: YES
user_id=804543
> I'd prefer to see an option that duplicates
> gcc's -MG option [...]
The downside is that -MG doesn't (read: can't)
deal with nesting, i.e. files included from an
auto-generated file won't make it into the de-
pendency list, if said autogenerated file does
not exist at the time -MG is used.
> Attached is a rather hacky diff that simply
> changes nasm's -M to behave as gcc's -MG. This
> is sufficient for my purposes, but may not be
> the correct solution.
Yeah, the proper solution would be to add -MG.
Which isn't too difficult -- it's just another
option that needs to be handed to pp->reset().
> race condition in the %(EL)IF(N)FILE
Absolutely.
Said directive only tells you whether the file
did (or didn't) exist at the time you asked --
if it shows up or disappears afterwards, you'd
of course be out of luck.
Logged In: YES
user_id=762255
> The downside is that -MG doesn't (read: can't)
> deal with nesting,
In the context I'm using it, this is not an issue, for two
reasons:
1) The autogenerated files do not %INCLUDE anything.
2) One of the Makefile steps for assembling source.asm
recreates source.o.d, which contains the dependencies as
generated by NASM. Should an auto-gen file someday %INCLUDE
something, the absence of/changes in auto-gen.inc will force
make to (re)make source.o, thereby updating source.o.d to
contain the proper dependency list.
> Yeah, the proper solution would be to add -MG.
> Which isn't too difficult -- it's just another
> option that needs to be handed to pp->reset().
That would be the correct solution. As I said, "sufficient
for my purposes". And, as I didn't say, "first attempt to
change the NASM sources". When I finish my current project,
I'll come back to this, and work on making it right, in its
own feature request (where it really should have gone in the
first place).
Logged In: YES
user_id=804543
I have filed SF RFE #1564264 for the -MG option.
Fwiw, dalestan's proposed -MG changes suffered from a
memory leak, because origline wasn't freed properly.