syphilis has asked for the wisdom of the Perl Monks concerning the following question:

Hi,
The latest OPenGL subversion source (available from http://graphcomp.com/opengl/index.cgi?v=0111s5m1&r=s1m1) builds straight out of the box using nmake and Visual Studio. To have it build straight out of the box on Strawberry Perl (ie using dmake and MinGW), it's necessary to replace nmake syntax with dmake syntax in a small makefile (utils/makefile.mak). I'm nearly there, but there's one section of the makefile.mak that I haven't been able to successfully rewrite. In its current (nmake syntax) form that section is:
clean: if exist glversion.txt del glversion.txt if exist glversion.exe del glversion.exe if exist glversion.txt del glversion.obj
Looking at the Win32/makefile.mk that comes with the perl source, I thought the following would work (but it doesn't):
clean: -if exist glversion.txt del glversion.txt -if exist glversion.exe del glversion.exe -if exist glversion.txt del glversion.o
With one version of dmake that produces the following warnings (which don't prevent the build from completing successfully, but probably *do* mean that 'dmake clean' doesn't work correctly):
dmake: Error executing 'if': No such file or directory (Ignored) dmake: Error executing 'if': No such file or directory (Ignored) dmake: Error executing 'if': No such file or directory (Ignored)
With another version of dmake, however, the same section produces a fatal error which *does* prevent the build from completing successfully.

Any advice on how that section needs to be rewritten for dmake would be appreciated. In the meantime, I'll keep digging.

Cheers,
Rob

Replies are listed 'Best First'.
Re: [OT] Makefiles - nmake syntax v dmake syntax
by ikegami (Patriarch) on Jul 16, 2008 at 07:37 UTC
    if is not a program but a shell (cmd) builtin, so invoke the shell.
    clean: -cmd /c if exist glversion.txt del glversion.txt -cmd /c if exist glversion.exe del glversion.exe -cmd /c if exist glversion.o del glversion.o

    By the way, I fixed the file name in the last one.

      By the way, I fixed the file name in the last one.

      Yeah ... I was wunderin' how come glversion.o never got removed :-)

      Your solution works fine, btw - thanks. At some stage (in a rare moment of enlightened inspiration) I also got around to trying:
      clean: -if exist "glversion.txt" del "glversion.txt" -if exist "glversion.exe" del "glversion.exe" -if exist "glversion.o" del "glversion.o"
      and that works, too. I was surprised that those double quotes would have such a marked effect on the way that the commands are parsed.

      Reading through the rest of the thread I'm struck with the notion that TMTOWTDI .... which would be sooooo typical of this place :-)

      Thanks guys.

      Cheers,
      Rob

        I was surprised that those double quotes would have such a marked effect on the way that the commands are parsed.

        system does the same thing in Perl. The presence of shell meta characters forces the invocation of the shell.

Re: [OT] Makefiles - nmake syntax v dmake syntax
by BrowserUk (Patriarch) on Jul 16, 2008 at 07:55 UTC

    Isn't the if exist file del file syntax from the nmake example simply executing the standard cmd.exe if exist built-in command?

    And so, for the dmake example, could you not convert that to an equivalent syntax, that the default command processor it uses, understands?

    For example, for sh, you might use test -f file && unlink file or similar.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      The rules in make scripts are executed in the default shell - overrideable by an appropriate setting of the SHELL macro in the make script.

      BTW, in your example, if you use test -f ... in a make rule and the file doesn't exist, make(1) will abort since it traps all non-success error codes and quits.

      The prefixing of any line with a -, avoids this.

      Update Using straight shell i.e. no perl available, I tend to use shell expansion together with a case statement - which returns no status, thus avoiding upsetting make(1) - so in this case ...

      target: case "filename*" in \ \*) : ;; \ *) rm file ;; \ esac
      Of course if you're using sh, the easiest solution is to use rm -f file...

      HTH ,

      At last, a user level that overstates my experience :-))
Re: [OT] Makefiles - nmake syntax v dmake syntax
by Corion (Patriarch) on Jul 16, 2008 at 08:41 UTC

    Personally, I try to avoid using the shell whenever I have a supposedly functional Perl available:

    $PERL -e "for(@ARGV){-f and unlink or warn qq(Can't delete $_: $!)}" g +lversion.txt glversion.exe glversion.o

    I think this version should even be fairly safe against shells that interpolate $, as the variables only appear in the error message part.

Re: [OT] Makefiles - nmake syntax v dmake syntax
by moritz (Cardinal) on Jul 16, 2008 at 08:53 UTC
    The unixy way of doing things is this:
    clean: rm -f glversion.txt glversion.exe glversion.o

    The -f option tells rm (among other things) that it's not an error if some of the files don't exist. Maybe there's a similar option for del?

    Another way is it let the command fail, and ignore the failure by prepending a dash to the command:

    clean: - rm glversion.txt glversion.exe glversion.o

    This way rm will fail if some of these files don't exist, but make will ignore that error. Again I don't know if the various make dialects understand that.

    To me it seems overkill to both add the leading dash and have the if exists in the makefile.

      Except that rm is not available under Windows. If you don't want to use my hand-rolled Perl solution, ExtUtils::Command has the rm_f subroutine which does what my oneliner does, except likely better:

      perl -MExtUtils::Command -e rm_f glversion.txt glversion.exe glversion +.o