help-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Can the exit status of the code block in @(...) be obtained from out


From: Hongyi Zhao
Subject: Re: Can the exit status of the code block in @(...) be obtained from outside the @() structure?
Date: Sat, 22 Jan 2022 09:40:44 +0800

On Sat, Jan 22, 2022 at 9:28 AM Hongyi Zhao <hongyi.zhao@gmail.com> wrote:
>
> On Sat, Jan 22, 2022 at 3:05 AM Paul Smith <psmith@gnu.org> wrote:
> > [...]
> > As mentioned before, the entire script must be contained in a single
> > logical line if you want the same shell to interpret it all.  So you'll
> > have to add "\" to combine all these into a single logical line:
>
> Thank you for your above knowledgeable and thorough analysis. Got it.
>
> >   define download_and_unpack
> >     package='$(1)' ; \
> >     package_URL='$(2)' ; \
> >     package_directory='$(3)' ; \
> >     package_code='$(4)' ; \
> >     package_archive=../archive/`echo "$(package)" | sed 's/.*\///;s/.*=//'` 
> > ; \
> >     ( \
> >     if ! gzip -t $(package_archive) > /dev/null 2>&1 ; then \
>
> I tried with your above trick, but noticed that the variable
> package_archive can be expanded correctly:
>
> $ make -j44 w90
> [...]
> package='wannier90-3.1.0';
> package_URL='https://codeload.github.com/wannier-developers/wannier90/tar.gz/v3.1.0';
> package_directory='W90'; package_code='wannier90';
> package_archive=../archive/`echo "" | sed 's/.*\///;s/.*=//'`;
>
> As you can see, the following command:
>
> package_archive=../archive/`echo "$(package)" | sed 's/.*\///;s/.*=//'`; \
>
> will be passed as:
>
> package_archive=../archive/`echo "" | sed 's/.*\///;s/.*=//'`;
>
> As you can see, the expansion of "$(package)" has been lost. Based on
> tries, it seems the following form fixes this problem:
>
> package_archive=../archive/`echo "$$(package)" | sed 's/.*\///;s/.*=//'`; \

Sorry, it should be written as follows:

package_archive=../archive/`echo "$${package}" | sed 's/.*\///;s/.*=//'`; \

And then refer to these variables using the following formats:

$${package}
$${package_URL}
$${package_directory}
$${package_code}
$${package_archive}

The above conclusion comes from the following script snippet:

=== begin ===
define download_and_unpack
  package='$(1)'; \
  package_URL='$(2)'; \
  package_directory='$(3)'; \
  package_code='$(4)'; \
  package_archive=../archive/`echo "$${package}" | sed 's/.*\///;s/.*=//'`; \
  (if ! gzip -t $(package_archive) > /dev/null 2>&1; then \
      echo 1 $(1) $${package}; \
      echo 2 $(2) $${package_URL}; \
      echo 3 $(3) $${package_directory}; \
      echo 4 $(4) $${package_code}; \
      echo 5 $${package_archive}; \
      rm -fr $(package_archive) ; \
      wget -O $package_archive $(2) > /dev/null 2>&1; \
      if [ $$? -ne 0 ]; then \
        curl -o ../archive/`echo "$(2)" | sed 's/.*\///;s/.*=//'` $(2)
> /dev/null 2>&1; \
        if [ $$? -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; \
   else \
      exit 0; \
   fi \
   ); \
  if [ $$? -eq 0 -a ! -e ../$(3) ]; then \
    (gzip -dc ../archive/`echo "$(2)" | sed 's/.*\///;s/.*=//'` | \
    (cd ../ ; tar -xvf - )) ; \
    if [ $$? -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
=== end ===

Regards,
HZ



reply via email to

[Prev in Thread] Current Thread [Next in Thread]