Re: Macro question
> From: Gisle Vanem > Date: Wed, 9 Dec 2015 20:41:33 +0100 > > It's a PITA to capture stderr on cmd. Not for some years. Just use 2>, like you'd do with a Unixy shell. (But as you say, this is unrelated to the issue at hand.) ___ Bug-make mailing list Bug-make@gnu.org https://lists.gnu.org/mailman/listinfo/bug-make
Re: Macro question
David Boyce wrote: > First, I think there’s some missing context as you seem to have an > unusual environment. You’re mixing Unix (cat, rm) and Windows (link) > invocations; is it Cygwin, GNUWin32, MKS, ??? Thanks for replying. I'm on Windows 10 using CygWin32 tools together with MSVC tools. (no problem even with CygWin's link.exe on my PATH; it's after MSVC's link.exe). Since I had big tool-problems using MSys1 and Msys2 after upgrading to Win10, I've so far settled on Cygwin32 for it's sh, binutils etc. (but that is probably off-topic here). > Second, I suspect the macro is a red herring and thus this is not > really a “Macro question”. The macro should just expand to the same > text you’d get by typing it out. What happens when the macro is > replaced by the equivalent 3-line recipe? The same result. I tried changing the command to: .ONESHELL: wiretap.dll SHELL = cmd.exe wiretap.dll: $(WIRETAP_OBJ) link $(LDFLAGS) -dll -out:wiretap.dll -implib:wiretap_imp.lib \ -pdb:wiretap.pdb -map:wiretap.map $^ $(EXTRA_LIBS) > link.tmp echo ERRORLEVEL: %? cat link.tmp >> wiretap.map rm -f wiretap_imp.exp The ERRORLEVEL prints some 11xx code in case of error. So 'link' do pass an exit-code as it should. But in this .ONESHELL case, I'm not sure gmake should stop. > Third, there should be nothing you have to do differently because this > should work as desired. Since you’re not joining the 3 lines together > with && and \, the result should be a 3-line recipe in which each line > should abort the recipe on failure. But it doesn't. I tried a "set GNUMAKEFLAGS=--debug=jobs". The output wasn't much help. > Two other little notes: (1) I don’t understand how you can be > capturing error messages with > redirection, unless link.exe is dumb > enough to send errors to stdout. Many MS tools behaves that way. And that is correct IMHO when I've specified 'link -verbose'. It's a PITA to capture stderr on cmd. What would gmake have done if link had printed to 'stderr' instead? I think this is unrelated and the result would have been the same. > And (2) the second and third macro > lines could be a little more robust by using $(basename $1) rather > than assuming the extensions to be .dll and .lib. I know. My macro was a bit simplified. The full version of it is: define do_link_DLL link $(LDFLAGS) -dll -subsystem:console,5.02 -out:$(strip $(1)) -implib:$(strip $(2)) \ -pdb:$(basename $(1)).pdb -map:$(basename $(1)).map $(3) > link.tmp cat link.tmp >> $(1:.dll=.map) cat link.tmp >> make.log rm -f $(2:.lib=.exp) link.tmp endef I use $(strip ..) so I can call it with spaces: $(call do_link_DLL, wiretap.dll, wiretap_imp.lib, $^ $(EXTRA_LIBS)) --gv ___ Bug-make mailing list Bug-make@gnu.org https://lists.gnu.org/mailman/listinfo/bug-make
Re: Macro question
> From: Gisle Vanem > Date: Wed, 9 Dec 2015 18:20:47 +0100 > > Eli Zaretskii wrote: > > > The Windows shell understands || and && between 2 commands. I think > > you already know that, so I'm quite sure I'm missing something here, > > because that's the first thing I'd try. > > There is no Windows shell (cmd nor 4nt) involved here. I don't > have any 'SHELL' in the Makefile (nor environment) and sh is on PATH. If you use these characters in the command line, Make will invoke the shell. Something like link && cat && rm will cause the command to be invoked via the shell, and then I think you will get what you want. Or maybe I'm missing something. > Isn't 'sh' supposed to be used then? Yes, and sh also supports that, of course. ___ Bug-make mailing list Bug-make@gnu.org https://lists.gnu.org/mailman/listinfo/bug-make
Re: Macro question
Eli Zaretskii wrote: > The Windows shell understands || and && between 2 commands. I think > you already know that, so I'm quite sure I'm missing something here, > because that's the first thing I'd try. There is no Windows shell (cmd nor 4nt) involved here. I don't have any 'SHELL' in the Makefile (nor environment) and sh is on PATH. Isn't 'sh' supposed to be used then? --gv ___ Bug-make mailing list Bug-make@gnu.org https://lists.gnu.org/mailman/listinfo/bug-make
Re: Macro question
> From: Gisle Vanem > Date: Wed, 9 Dec 2015 16:19:39 +0100 > > I have a question regarding a GNU-make macro like this > (which I use to link a MSVC .dll): > > define do_link_DLL > link $(LDFLAGS) -dll -out:$(1) -implib:$(2) \ > -pdb:$(1:.dll=.pdb) -map:$(1:.dll=.map) $(3) > link.tmp > cat link.tmp >> $(1:.dll=.map) > rm -f $(2:.lib=.exp) link.tmp > endef > > Using this as (in a Wireshark makefile): > > wiretap.dll: $(WIRETAP_OBJ) > $(call do_link_DLL,wiretap.dll,wiretap_imp.lib, $^ $(EXTRA_LIBS)) > > AFAICS, if the 'link' stage fails, the rule continues to the 'cat' + 'rm' part > regardless. But from gmake's perspective all the commands succeeds (since > cat+rm returns 0). No? > > How can I define my macro for gmake to quit on 'link' error? > Can the macro be written into a Perl-like: > exec("link $args") || die "link failed"; > > If so, how? The Windows shell understands || and && between 2 commands. I think you already know that, so I'm quite sure I'm missing something here, because that's the first thing I'd try. ___ Bug-make mailing list Bug-make@gnu.org https://lists.gnu.org/mailman/listinfo/bug-make
Re: Macro question
First, I think there’s some missing context as you seem to have an unusual environment. You’re mixing Unix (cat, rm) and Windows (link) invocations; is it Cygwin, GNUWin32, MKS, ??? Second, I suspect the macro is a red herring and thus this is not really a “Macro question”. The macro should just expand to the same text you’d get by typing it out. What happens when the macro is replaced by the equivalent 3-line recipe? Third, there should be nothing you have to do differently because this should work as desired. Since you’re not joining the 3 lines together with && and \, the result should be a 3-line recipe in which each line should abort the recipe on failure. I suspect the problem will turn out to be an interaction between the shell you use and the Win32 make build you use, but you should start by disentangling it from the macro. Two other little notes: (1) I don’t understand how you can be capturing error messages with > redirection, unless link.exe is dumb enough to send errors to stdout. And (2) the second and third macro lines could be a little more robust by using $(basename $1) rather than assuming the extensions to be .dll and .lib. -David Boyce On Wed, Dec 9, 2015 at 7:19 AM, Gisle Vanem wrote: > I have a question regarding a GNU-make macro like this > (which I use to link a MSVC .dll): > > define do_link_DLL > link $(LDFLAGS) -dll -out:$(1) -implib:$(2) \ > -pdb:$(1:.dll=.pdb) -map:$(1:.dll=.map) $(3) > link.tmp > cat link.tmp >> $(1:.dll=.map) > rm -f $(2:.lib=.exp) link.tmp > endef > > Using this as (in a Wireshark makefile): > > wiretap.dll: $(WIRETAP_OBJ) > $(call do_link_DLL,wiretap.dll,wiretap_imp.lib, $^ $(EXTRA_LIBS)) > > AFAICS, if the 'link' stage fails, the rule continues to the 'cat' + 'rm' part > regardless. But from gmake's perspective all the commands succeeds (since > cat+rm returns 0). No? > > How can I define my macro for gmake to quit on 'link' error? > Can the macro be written into a Perl-like: > exec("link $args") || die "link failed"; > > If so, how? > > PS. Since I have '-verbose' in LDFLAGS, it is handy to redirect those > (error) messages into 'link.tmp' in case of a link-failure. > > -- > --gv > > ___ > Bug-make mailing list > Bug-make@gnu.org > https://lists.gnu.org/mailman/listinfo/bug-make ___ Bug-make mailing list Bug-make@gnu.org https://lists.gnu.org/mailman/listinfo/bug-make
Macro question
I have a question regarding a GNU-make macro like this (which I use to link a MSVC .dll): define do_link_DLL link $(LDFLAGS) -dll -out:$(1) -implib:$(2) \ -pdb:$(1:.dll=.pdb) -map:$(1:.dll=.map) $(3) > link.tmp cat link.tmp >> $(1:.dll=.map) rm -f $(2:.lib=.exp) link.tmp endef Using this as (in a Wireshark makefile): wiretap.dll: $(WIRETAP_OBJ) $(call do_link_DLL,wiretap.dll,wiretap_imp.lib, $^ $(EXTRA_LIBS)) AFAICS, if the 'link' stage fails, the rule continues to the 'cat' + 'rm' part regardless. But from gmake's perspective all the commands succeeds (since cat+rm returns 0). No? How can I define my macro for gmake to quit on 'link' error? Can the macro be written into a Perl-like: exec("link $args") || die "link failed"; If so, how? PS. Since I have '-verbose' in LDFLAGS, it is handy to redirect those (error) messages into 'link.tmp' in case of a link-failure. -- --gv ___ Bug-make mailing list Bug-make@gnu.org https://lists.gnu.org/mailman/listinfo/bug-make