Menu

#85 add support for %(EL)IF(N)FILE

open
nobody
1
2005-01-16
2005-01-16
No

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.

Discussion

  • nasm64developer

    nasm64developer - 2005-01-16

    required changes

     
  • nasm64developer

    nasm64developer - 2005-07-30

    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.

     
  • nasm64developer

    nasm64developer - 2005-07-30

    required changes, part 2

     
  • Dale

    Dale - 2006-09-15

    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.

     
  • nasm64developer

    nasm64developer - 2006-09-16

    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.

     
  • Dale

    Dale - 2006-09-16

    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).

     
  • nasm64developer

    nasm64developer - 2006-09-23

    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.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.