• Can the exit status of the code block in @(...) be obtained from outsid

    From hongyi.zhao@gmail.com@21:1/5 to All on Mon Jan 17 23:30:02 2022
    I'm trying to enhance the robustness of `install/install_utils` script
    in quantum espresso package, with the following make file script as
    described here[1]:

    ```

    # Copyright (C) 2001-2016 Quantum ESPRESSO group
    #
    # This program is free software; you can redistribute it and/or
    # modify it under the terms of the GNU General Public License
    # as published by the Free Software Foundation; either version 2
    # of the License. See the file `License' in the root directory
    # of the present distribution.
    #
    # Utilities

    ###########################################################
    # Template function
    # $(1) = package name
    # $(2) = package URL
    # $(3) = directory name
    # $(4) = plugin/code name ###########################################################

    define download_and_unpack
    @(if ! gzip -t ../archive/`echo "$(2)" | sed 's/.*\///;s/.*=//'` >
    /dev/null 2>&1 ; then \
    rm -fr ../archive/`echo "$(2)" | sed 's/.*\///;s/.*=//'`; \
    rm -fr ../$(3); \
    wget -O ../archive/`echo "$(2)" | sed 's/.*\///;s/.*=//'` $(2) >
    /dev/null 2>&1; \
    if test "`echo $$?`" -ne "0" ; then \
    curl -o ../archive/`echo "$(2)" | sed 's/.*\///;s/.*=//'` $(2) >
    /dev/null 2>&1; \
    if test "`echo $$?`" -ne "0" ; then \
    echo "*** Unable to download $(4). Test whether curl or wget is
    installed and working," ; \
    echo "*** if you have direct access to internet. If not, copy into
    archive/ the file" ; \
    echo "*** located here $(2)" ; \
    exit 1 ; fi ; fi ; fi)
    if test $? -eq 0 -a ! -e ../$(3); then \
    (gzip -dc ../archive/`echo "$(2)" | sed 's/.*\///;s/.*=//'` | \
    (cd ../ ; tar -xvf - ) ) ; \
    if test "`echo $$?`" -ne "0" ; then \
    echo "*** Unable to download $(2)." ; \
    echo "*** Verify that the url is correct." ; \
    exit 1 ; \
    else \
    (cd ../ ; ln -s $(1) $(3)) ; fi ; fi
    endef
    ```

    But it seems that the `$?' used above can't obtain the exit status of
    the code block in @(...) when used from outside the @() structure [2].
    So, I want to know if I can reliably obtain the exit status of the
    code block in @(...) from outside the @() structure. Any hints will be
    greatly appreciated. Also see here [3] for relevant discussion.

    [1] https://gitlab.com/QEF/q-e/-/issues/435
    [2] https://gitlab.com/QEF/q-e/-/merge_requests/1713#note_812794803
    [3] https://lists.gnu.org/archive/html/help-make/2022-01/msg00016.html

    Regards,
    HZ

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Janis Papanagnou@21:1/5 to hongy...@gmail.com on Tue Jan 18 09:32:33 2022
    On 18.01.2022 08:30, hongy...@gmail.com wrote:
    I'm trying to enhance the robustness of [...]

    This is a joke, isn't it?


    [ shell-like but actually non-shell code deleted ]

    Please make clear in the subject line if you refer in your post to
    specific tools with non-shell syntax and name the respective tool.
    (If possible post in a tool-specific forum.)

    BTW, isn't it possible to create a shell script for all that shell
    stuff instead of twisting the shell code to fit into that tool?

    Janis

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From hongyi.zhao@gmail.com@21:1/5 to Janis Papanagnou on Tue Jan 18 01:05:48 2022
    On Tuesday, January 18, 2022 at 4:32:38 PM UTC+8, Janis Papanagnou wrote:
    On 18.01.2022 08:30, hongy...@gmail.com wrote:
    I'm trying to enhance the robustness of [...]

    This is a joke, isn't it?

    This is a serious question I don't understand. Why do you say that?

    [ shell-like but actually non-shell code deleted ]

    Please make clear in the subject line if you refer in your post to
    specific tools with non-shell syntax and name the respective tool.
    (If possible post in a tool-specific forum.)

    BTW, isn't it possible to create a shell script for all that shell
    stuff instead of twisting the shell code to fit into that tool?

    It's called by gnu make command, and I also don't know why the original author of this script wrote it so obscurely.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From John-Paul Stewart@21:1/5 to hongy...@gmail.com on Tue Jan 18 14:49:44 2022
    On 2022-01-18 02:30, hongy...@gmail.com wrote:
    I'm trying to enhance the robustness of `install/install_utils` script
    in quantum espresso package, with the following make file script as
    described here[1]:

    As the other poster alluded to, this is NOT a shell question. It is a
    question about Makefile syntax. You are asking if the exit status of
    shell code inside a Makefile can be accessed elsewhere in the Makefile.
    In other words, completely outside the shell. So that makes it a
    question for Makefile experts (maybe there is a mailing list for that)
    rather than the shell experts in this newsgroup.

    It is also easily answered by reading the documentation for (GNU) make
    or a quick Google search. Both are things you should do before posting
    here or anywhere else.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From hongyi.zhao@gmail.com@21:1/5 to John-Paul Stewart on Tue Jan 18 18:23:46 2022
    On Wednesday, January 19, 2022 at 3:49:52 AM UTC+8, John-Paul Stewart wrote:
    On 2022-01-18 02:30, hongy...@gmail.com wrote:
    I'm trying to enhance the robustness of `install/install_utils` script
    in quantum espresso package, with the following make file script as described here[1]:
    As the other poster alluded to, this is NOT a shell question. It is a question about Makefile syntax. You are asking if the exit status of
    shell code inside a Makefile can be accessed elsewhere in the Makefile.
    In other words, completely outside the shell. So that makes it a
    question for Makefile experts (maybe there is a mailing list for that)
    rather than the shell experts in this newsgroup.

    It is also easily answered by reading the documentation for (GNU) make
    or a quick Google search. Both are things you should do before posting
    here or anywhere else.

    Thank you very much, I found the following example here [1]:

    === begin ===
    To those who can't still fix it, the original snippet in the question missed a semicolon after mycommand. So, the working example is:

    mycommand; \ # <<== here's the missing semicolon
    if [ $$? -ne 0 ]; \
    then \
    echo "mycommand failed"; \
    false; \
    fi
    === end ===

    [1] https://stackoverflow.com/a/70105815

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From John-Paul Stewart@21:1/5 to hongy...@gmail.com on Wed Jan 19 18:53:05 2022
    On 2022-01-18 21:23, hongy...@gmail.com wrote:

    Thank you very much, I found the following example

    Which has nothing to do with your specific question. Adding semicolons
    will not help you obtain a shell's exit status in a Makefile. You
    missed the relevant info on the page you cited AND you missed the point
    in my previous post (and Janis' post) that this is not the place to
    discuss Makefile syntax.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From hongyi.zhao@gmail.com@21:1/5 to John-Paul Stewart on Wed Jan 19 18:11:49 2022
    On Thursday, January 20, 2022 at 7:53:11 AM UTC+8, John-Paul Stewart wrote:
    On 2022-01-18 21:23, hongy...@gmail.com wrote:

    Thank you very much, I found the following example
    Which has nothing to do with your specific question. Adding semicolons
    will not help you obtain a shell's exit status in a Makefile. You
    missed the relevant info on the page you cited AND you missed the point
    in my previous post (and Janis' post) that this is not the place to
    discuss Makefile syntax.

    Anyway, I've figured out the problem based on the comments given by Paul Smith here [1].

    [1] https://lists.gnu.org/archive/html/help-make/2022-01/msg00019.html

    HZ

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)