[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Idea: Allow $(name ...) as an abbrevation of $(call name ....)
From: |
Masahiro Yamada |
Subject: |
Re: Idea: Allow $(name ...) as an abbrevation of $(call name ....) |
Date: |
Fri, 14 Jun 2019 11:12:16 +0900 |
On Fri, Jun 14, 2019 at 4:16 AM Tim Murphy <address@hidden> wrote:
>
> builtin functions can check their arguments to some extent. Interesting to
> wonder if user defined ones can.
> we don't even have $(equals) or a way to know the number of arguments that
> were supplied or any mathematical operations with which to compare. So when
> something is called wongly it charges on to the end, evaluating blindly to
> who knows what and we can spend hours trying to tease out the cause of a
> missing compiler option .... but.....we are focused on the saving of a tiny
> bit of typing.
You can check the number of arguments for user-defined functions if you like.
-------------------(sample code)----------------------
# my-dummy takes 1 or 2 arguments
my-dummy = $(if $(1),,$(error too few arguments))$(if $(3),$(error too
many arguments))echo $(1) $(2)
test1:
@$(call my-dummy)
test2:
@$(call my-dummy,hello)
test3:
@$(call my-dummy,hello,world)
test4:
@$(call my-dummy,see,you,later)
-------------------(sample code end)----------------------
$ make test1
Makefile:4: *** too few arguments. Stop.
$ make test2
hello
$ make test3
hello world
$ make test4
Makefile:13: *** too many arguments. Stop.
If it is tedious to duplicate this check for every user-defined function,
you can macrofy it.
-------------------(sample code 2)----------------------
# Usage: $(eval $(call arg-check,min,max-1))
arg-check = $$(if $$($(1)),,$$(error too few arguments))$$(if
$$($(2)),$$(error too many arguments))
my-dummy = $(eval $(call arg-check,1,3))echo $(1) $(2)
-------------------(sample code 2 end)----------------------
--
Best Regards
Masahiro Yamada
- Re: Idea: Allow $(name ...) as an abbrevation of $(call name ....), (continued)
- Re: Idea: Allow $(name ...) as an abbrevation of $(call name ....), Masahiro Yamada, 2019/06/10
- Re: Idea: Allow $(name ...) as an abbrevation of $(call name ....), Masahiro Yamada, 2019/06/11
- Re: Idea: Allow $(name ...) as an abbrevation of $(call name ....), David A. Wheeler, 2019/06/11
- Re: Idea: Allow $(name ...) as an abbrevation of $(call name ....), Tim Murphy, 2019/06/13
- Re: Idea: Allow $(name ...) as an abbrevation of $(call name ....), David A. Wheeler, 2019/06/13
- Re: Idea: Allow $(name ...) as an abbrevation of $(call name ....), Masahiro Yamada, 2019/06/13
- Re: Idea: Allow $(name ...) as an abbrevation of $(call name ....), Tim Murphy, 2019/06/14
- Re: Idea: Allow $(name ...) as an abbrevation of $(call name ....),
Masahiro Yamada <=