diff mbox series

[v4,05/11] rules.mak: Add base-arch() rule

Message ID 20200522163759.11480-6-philmd@redhat.com
State New
Headers show
Series accel: Allow targets to use Kconfig | expand

Commit Message

Philippe Mathieu-Daudé May 22, 2020, 4:37 p.m. UTC
Add a rule to return the base architecture for a QEMU target.

The current list of TARGET_BASE_ARCH is:

  $ git grep  TARGET_BASE_ARCH configure
  configure:7785:TARGET_BASE_ARCH=""
  configure:7795:    TARGET_BASE_ARCH=i386
  configure:7813:    TARGET_BASE_ARCH=arm
  configure:7846:    TARGET_BASE_ARCH=mips
  configure:7854:    TARGET_BASE_ARCH=mips
  configure:7864:    TARGET_BASE_ARCH=openrisc
  configure:7871:    TARGET_BASE_ARCH=ppc
  configure:7879:    TARGET_BASE_ARCH=ppc
  configure:7887:    TARGET_BASE_ARCH=ppc
  configure:7894:    TARGET_BASE_ARCH=riscv
  configure:7900:    TARGET_BASE_ARCH=riscv
  configure:7920:    TARGET_BASE_ARCH=sparc
  configure:7925:    TARGET_BASE_ARCH=sparc

The rule can be tested calling 'print-base-arch-$TARGET':

  $ make \
      print-base-arch-openrisc \
      print-base-arch-aarch64 \
      print-base-arch-x86_64 \
      print-base-arch-mips64el \
      print-base-arch-ppc64
  openrisc=openrisc
  aarch64=arm
  x86_64=i386
  mips64el=mips
  ppc64=ppc

Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
v4:
- use startwith()
- fix openrisc (rth)
---
 rules.mak | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

Comments

Richard Henderson June 1, 2020, 2:13 a.m. UTC | #1
On 5/22/20 9:37 AM, Philippe Mathieu-Daudé wrote:
> +		      $(if $(call startwith,risc,$1),risc,\

Should be "riscv" not "risc".  Especially the substitution.

> +		        $(if $(call startwith,aarch64,$1),arm,\
> +		          $(if $(call startwith,x86_64,$1),i386,\

We don't have an exact equality function?


r~
Philippe Mathieu-Daudé June 1, 2020, 7:26 a.m. UTC | #2
On 6/1/20 4:13 AM, Richard Henderson wrote:
> On 5/22/20 9:37 AM, Philippe Mathieu-Daudé wrote:
>> +		      $(if $(call startwith,risc,$1),risc,\
> 
> Should be "riscv" not "risc".  Especially the substitution.

Indeed.

> 
>> +		        $(if $(call startwith,aarch64,$1),arm,\
>> +		          $(if $(call startwith,x86_64,$1),i386,\
> 
> We don't have an exact equality function?

There is this one which returns y/n:

  # String testing functions: inputs to these can be any string;
  # the output is always either "y" or "n". Leading and trailing whitespace
  # is ignored when comparing strings.
  # String equality
  eq = $(if $(subst $2,,$1)$(subst $1,,$2),n,y)

I'll add a simpler strequal().
Philippe Mathieu-Daudé June 5, 2020, 7:27 a.m. UTC | #3
On 6/1/20 9:26 AM, Philippe Mathieu-Daudé wrote:
> On 6/1/20 4:13 AM, Richard Henderson wrote:
>> On 5/22/20 9:37 AM, Philippe Mathieu-Daudé wrote:
>>> +		      $(if $(call startwith,risc,$1),risc,\
>>
>> Should be "riscv" not "risc".  Especially the substitution.
> 
> Indeed.
> 
>>
>>> +		        $(if $(call startwith,aarch64,$1),arm,\
>>> +		          $(if $(call startwith,x86_64,$1),i386,\
>>
>> We don't have an exact equality function?

For aarch64_be we want to use startwith(). I'll update x86_64.

> 
> There is this one which returns y/n:
> 
>   # String testing functions: inputs to these can be any string;
>   # the output is always either "y" or "n". Leading and trailing whitespace
>   # is ignored when comparing strings.
>   # String equality
>   eq = $(if $(subst $2,,$1)$(subst $1,,$2),n,y)
> 
> I'll add a simpler strequal().
>
diff mbox series

Patch

diff --git a/rules.mak b/rules.mak
index e39bee93d5..2ce527e885 100644
--- a/rules.mak
+++ b/rules.mak
@@ -445,3 +445,30 @@  atomic = $(eval $1: $(call sentinel,$1) ; @:) \
 
 print-%:
 	@echo '$*=$($*)'
+
+# base-arch
+# Usage: $(call base-arch, target)
+#
+# @target: the target architecture.
+#
+# This macro will return the base architecture for a target.
+#
+# As example, $(call base-arch, aarch64) returns 'arm'.
+base-arch = $(strip \
+		$(if $(call startwith,mips,$1),mips,\
+		  $(if $(call startwith,ppc,$1),ppc,\
+		    $(if $(call startwith,sparc,$1),sparc,\
+		      $(if $(call startwith,risc,$1),risc,\
+		        $(if $(call startwith,aarch64,$1),arm,\
+		          $(if $(call startwith,x86_64,$1),i386,\
+		            $1\
+		           )\
+		         )\
+		       )\
+		     )\
+		   )\
+		 )\
+		)
+
+print-base-arch-%:
+	@echo '$*=$(call base-arch, $*)'