help-make
[Top][All Lists]
Advanced

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

Re: Rename positional parameters in customized GNU make functions to enh


From: Hongyi Zhao
Subject: Re: Rename positional parameters in customized GNU make functions to enhance readability and maintainability.
Date: Fri, 21 Jan 2022 21:41:33 +0800

On Fri, Jan 21, 2022 at 6:34 PM Hongyi Zhao <hongyi.zhao@gmail.com> wrote:
>
> I try to redefine the download_and_unpack function used here [1] as follows:
>
> ```
> define download_and_unpack
>   @package := $(1)
>   @package_URL := $(2)
>   @package_directory := $(3)
>   @package_code := $(4)
>   @package_archive := ../archive/`echo "$(package)" | sed 's/.*\///;s/.*=//'`
> [...]
> endef
> ```
> As you can see, I try to rename the positional parameters in
> customized GNU make functions to enhance readability and
> maintainability. But when I run my revised version, the following
> error will be triggered:
>
> ```
> $ make -j44 w90
> test -d bin || mkdir bin
> cd install ; make -f extlibs_makefile liblapack
> make[1]: Entering directory '/home/werner/q-e/install'
> make[1]: Nothing to be done for 'liblapack'.
> make[1]: Leaving directory '/home/werner/q-e/install'
> ( cd install ; make -f plugins_makefile w90 || exit 1 )
> make[1]: Entering directory '/home/werner/q-e/install'
> make[1]: package: Command not found
> make[1]: *** [plugins_makefile:94: uncompress-w90] Error 127
> make[1]: Leaving directory '/home/werner/q-e/install'
> make: *** [Makefile:239: w90] Error 1
> ```
>
> Is it possible to achieve the purpose I described above? If possible,
> any hints for fixing the problem?

I've noticed a presumably helpful example here [1]:

```
PATH = /tmp/

define myfn
processed_input=${PATH}/$(2)
processed_more=$(shell echo $(processed_input))
# could be "if condition", "for loop" or any further shell expression
# Notice that: the output of the shell function is the stdout/stderr,
for more advanced usage
# Either use a file communication, or better, another scriptfile
(shell, python or whatever)
$(1) := $$(processed_more)
# NOTE: Uncommenting dummy_target will fail the main my_target unless
$(value ..) got used between the $(eval ..) and $(call ..)
# NOTE: we should not use the $(value ..) here to avoid incorrect assignment
#dummy_target:
# further targets could be added here
# Notice that, ```define``` keyword defines a multi-line expression
that is very like another makefile
# with it's own variables and targets
endef

mytarget:
$(eval FILE=myfile)
# using value here to avoid unwanted expansion will result in the
return not being correctly assigned
$(eval $(call myfn,abs_filename,$(FILE)))
/bin/echo ${abs_filename} # Path2 will be printed
```

But I still can't find the inspiration to solve my problem here.

[1] 
https://gist.github.com/weshouman/f44f330227972073371e1baa510c0d37#file-3-correct-complex-mk

HZ



reply via email to

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