diff mbox series

[v3,01/10] capstone: Convert Makefile bits to meson bits

Message ID 20200917235720.2685978-2-richard.henderson@linaro.org
State New
Headers show
Series capstone + disassembler patches | expand

Commit Message

Richard Henderson Sept. 17, 2020, 11:57 p.m. UTC
There are better ways to do this, e.g. meson cmake subproject,
but that requires cmake 3.7 and some of our CI environments
only provide cmake 3.5.

Nor can we add a meson.build file to capstone/, because the git
submodule would then always report "untracked files".  Fixing that
would require creating our own branch on the qemu git mirror, at
which point we could just as easily create a native meson subproject.

Instead, build the library via the main meson.build.

This improves the current state of affairs in that we will re-link
the qemu executables against a changed libcapstone.a, which we wouldn't
do before-hand.  In addition, the use of the configuration header file
instead of command-line -DEFINES means that we will rebuild the
capstone objects with changes to meson.build.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
Cc: Paolo Bonzini <pbonzini@redhat.com>
v2: Further reduce probing in configure (paolo),
    Drop state 'internal' and use 'git' even when it isn't git.
    Move CONFIG_CAPSTONE to config_host_data.
v3: Add Submodules separator; fix default in meson_options.txt.
---
 configure         |  61 +++----------------------
 Makefile          |  16 -------
 meson.build       | 111 +++++++++++++++++++++++++++++++++++++++++++---
 meson_options.txt |   4 ++
 4 files changed, 115 insertions(+), 77 deletions(-)

Comments

罗勇刚(Yonggang Luo) Sept. 18, 2020, 8:12 a.m. UTC | #1
On Fri, Sep 18, 2020 at 7:59 AM Richard Henderson <
richard.henderson@linaro.org> wrote:
>

> There are better ways to do this, e.g. meson cmake subproject,

> but that requires cmake 3.7 and some of our CI environments

> only provide cmake 3.5.

>

> Nor can we add a meson.build file to capstone/, because the git

> submodule would then always report "untracked files".  Fixing that

> would require creating our own branch on the qemu git mirror, at

> which point we could just as easily create a native meson subproject.

>

> Instead, build the library via the main meson.build.

>

> This improves the current state of affairs in that we will re-link

> the qemu executables against a changed libcapstone.a, which we wouldn't

> do before-hand.  In addition, the use of the configuration header file

> instead of command-line -DEFINES means that we will rebuild the

> capstone objects with changes to meson.build.

>

> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>

> ---

> Cc: Paolo Bonzini <pbonzini@redhat.com>

> v2: Further reduce probing in configure (paolo),

>     Drop state 'internal' and use 'git' even when it isn't git.

>     Move CONFIG_CAPSTONE to config_host_data.

> v3: Add Submodules separator; fix default in meson_options.txt.

> ---

>  configure         |  61 +++----------------------

>  Makefile          |  16 -------

>  meson.build       | 111 +++++++++++++++++++++++++++++++++++++++++++---

>  meson_options.txt |   4 ++

>  4 files changed, 115 insertions(+), 77 deletions(-)

>

> diff --git a/configure b/configure

> index 7564479008..76636c430d 100755

> --- a/configure

> +++ b/configure

> @@ -478,7 +478,7 @@ opengl=""

>  opengl_dmabuf="no"

>  cpuid_h="no"

>  avx2_opt=""

> -capstone=""

> +capstone="auto"

>  lzo=""

>  snappy=""

>  bzip2=""

> @@ -1580,7 +1580,7 @@ for opt do

>    ;;

>    --enable-capstone) capstone="yes"

>    ;;

> -  --enable-capstone=git) capstone="git"

> +  --enable-capstone=git) capstone="internal"

>    ;;

>    --enable-capstone=system) capstone="system"

>    ;;

> @@ -5128,51 +5128,11 @@ fi

>  # capstone

>

>  case "$capstone" in

> -  "" | yes)

> -    if $pkg_config capstone; then

> -      capstone=system

> -    elif test -e "${source_path}/.git" && test $git_update = 'yes' ; then

> -      capstone=git

> -    elif test -e "${source_path}/capstone/Makefile" ; then

> -      capstone=internal

> -    elif test -z "$capstone" ; then

> -      capstone=no

> -    else

> -      feature_not_found "capstone" "Install capstone devel or git

submodule"
> -    fi

> -    ;;

> -

> -  system)

> -    if ! $pkg_config capstone; then

> -      feature_not_found "capstone" "Install capstone devel"

> -    fi

> -    ;;

> -esac

> -

> -case "$capstone" in

> -  git | internal)

> -    if test "$capstone" = git; then

> +  auto | yes | internal)

> +    # Simpler to always update submodule, even if not needed.

> +    if test -e "${source_path}/.git" && test $git_update = 'yes' ; then

>        git_submodules="${git_submodules} capstone"

>      fi

> -    mkdir -p capstone

> -    if test "$mingw32" = "yes"; then

> -      LIBCAPSTONE=capstone.lib

> -    else

> -      LIBCAPSTONE=libcapstone.a

> -    fi

> -    capstone_libs="-Lcapstone -lcapstone"

> -    capstone_cflags="-I${source_path}/capstone/include"

> -    ;;

> -

> -  system)

> -    capstone_libs="$($pkg_config --libs capstone)"

> -    capstone_cflags="$($pkg_config --cflags capstone)"

> -    ;;

> -

> -  no)

> -    ;;

> -  *)

> -    error_exit "Unknown state for capstone: $capstone"

>      ;;

>  esac

>

> @@ -7292,11 +7252,6 @@ fi

>  if test "$ivshmem" = "yes" ; then

>    echo "CONFIG_IVSHMEM=y" >> $config_host_mak

>  fi

> -if test "$capstone" != "no" ; then

> -  echo "CONFIG_CAPSTONE=y" >> $config_host_mak

> -  echo "CAPSTONE_CFLAGS=$capstone_cflags" >> $config_host_mak

> -  echo "CAPSTONE_LIBS=$capstone_libs" >> $config_host_mak

> -fi

>  if test "$debug_mutex" = "yes" ; then

>    echo "CONFIG_DEBUG_MUTEX=y" >> $config_host_mak

>  fi

> @@ -7819,9 +7774,6 @@ done # for target in $targets

>  if [ "$fdt" = "git" ]; then

>    subdirs="$subdirs dtc"

>  fi

> -if [ "$capstone" = "git" -o "$capstone" = "internal" ]; then

> -  subdirs="$subdirs capstone"

> -fi

>  echo "SUBDIRS=$subdirs" >> $config_host_mak

>  if test -n "$LIBCAPSTONE"; then

>    echo "LIBCAPSTONE=$LIBCAPSTONE" >> $config_host_mak

These  LIBCAPSTONE should be removed, as they are empty and have no meaning
now
> @@ -8008,7 +7960,8 @@ NINJA=${ninja:-$PWD/ninjatool} $meson setup \

>          -Db_coverage=$(if test "$gcov" = yes; then echo true; else echo

false; fi) \
>         -Dsdl=$sdl -Dsdl_image=$sdl_image \

>         -Dvnc=$vnc -Dvnc_sasl=$vnc_sasl -Dvnc_jpeg=$vnc_jpeg

-Dvnc_png=$vnc_png \
> -       -Dgettext=$gettext -Dxkbcommon=$xkbcommon -Du2f=$u2f\

> +       -Dgettext=$gettext -Dxkbcommon=$xkbcommon -Du2f=$u2f \

> +       -Dcapstone=$capstone \

These lines should ident with 8 space instead of two tab.
There is four lines of them
 -Dsdl=$sdl -Dsdl_image=$sdl_image \
-Dvnc=$vnc -Dvnc_sasl=$vnc_sasl -Dvnc_jpeg=$vnc_jpeg -Dvnc_png=$vnc_png \
-Dgettext=$gettext -Dxkbcommon=$xkbcommon -Du2f=$u2f \
-Dcapstone=$capstone \

>          $cross_arg \

>          "$PWD" "$source_path"

>

> diff --git a/Makefile b/Makefile

> index 7c60b9dcb8..f3da1760ad 100644

> --- a/Makefile

> +++ b/Makefile

> @@ -156,22 +156,6 @@ dtc/all: .git-submodule-status dtc/libfdt

>  dtc/%: .git-submodule-status

>         @mkdir -p $@

>

> -# Overriding CFLAGS causes us to lose defines added in the sub-makefile.

> -# Not overriding CFLAGS leads to mis-matches between compilation modes.

> -# Therefore we replicate some of the logic in the sub-makefile.

> -# Remove all the extra -Warning flags that QEMU uses that Capstone

doesn't;
> -# no need to annoy QEMU developers with such things.

> -CAP_CFLAGS = $(patsubst -W%,,$(CFLAGS) $(QEMU_CFLAGS)) $(CAPSTONE_CFLAGS)

> -CAP_CFLAGS += -DCAPSTONE_USE_SYS_DYN_MEM

> -CAP_CFLAGS += -DCAPSTONE_HAS_ARM

> -CAP_CFLAGS += -DCAPSTONE_HAS_ARM64

> -CAP_CFLAGS += -DCAPSTONE_HAS_POWERPC

> -CAP_CFLAGS += -DCAPSTONE_HAS_X86

> -

> -.PHONY: capstone/all

> -capstone/all: .git-submodule-status

> -       $(call quiet-command,$(MAKE) -C $(SRC_PATH)/capstone

CAPSTONE_SHARED=no BUILDDIR="$(BUILD_DIR)/capstone" CC="$(CC)" AR="$(AR)"
LD="$(LD)" RANLIB="$(RANLIB)" CFLAGS="$(CAP_CFLAGS)" $(SUBDIR_MAKEFLAGS)
$(BUILD_DIR)/capstone/$(LIBCAPSTONE))
> -

>  .PHONY: slirp/all

>  slirp/all: .git-submodule-status

>         $(call quiet-command,$(MAKE) -C $(SRC_PATH)/slirp               \

> diff --git a/meson.build b/meson.build

> index f4d1ab1096..f23273693d 100644

> --- a/meson.build

> +++ b/meson.build

> @@ -10,6 +10,7 @@ else

>    keyval = import('unstable-keyval')

>  endif

>  ss = import('sourceset')

> +fs = import('fs')

>

>  sh = find_program('sh')

>  cc = meson.get_compiler('c')

> @@ -409,11 +410,6 @@ if 'CONFIG_USB_LIBUSB' in config_host

>    libusb = declare_dependency(compile_args:

config_host['LIBUSB_CFLAGS'].split(),
>                                link_args:

config_host['LIBUSB_LIBS'].split())
>  endif

> -capstone = not_found

> -if 'CONFIG_CAPSTONE' in config_host

> -  capstone = declare_dependency(compile_args:

config_host['CAPSTONE_CFLAGS'].split(),
> -                                link_args:

config_host['CAPSTONE_LIBS'].split())
> -endif

>  libpmem = not_found

>  if 'CONFIG_LIBPMEM' in config_host

>    libpmem = declare_dependency(compile_args:

config_host['LIBPMEM_CFLAGS'].split(),
> @@ -470,7 +466,6 @@ foreach k, v: config_host

>      config_host_data.set(k, v == 'y' ? 1 : v)

>    endif

>  endforeach

> -genh += configure_file(output: 'config-host.h', configuration:

config_host_data)
>

>  minikconf = find_program('scripts/minikconf.py')

>  config_all_devices = {}

> @@ -610,6 +605,108 @@ config_all += {

>    'CONFIG_ALL': true,

>  }

>

> +# Submodules

> +

> +capstone = not_found

> +capstone_opt = get_option('capstone')

> +if capstone_opt == 'no'

> +  capstone_opt = false

> +elif capstone_opt in ['yes', 'auto', 'system']

> +  have_internal = fs.exists('capstone/Makefile')

> +  capstone = dependency('capstone', static: enable_static,

> +                        required: capstone_opt == 'system' or

> +                                  capstone_opt == 'yes' and not

have_internal)
> +  if capstone.found()

> +    capstone_opt = 'system'

> +  elif have_internal

> +    capstone_opt = 'internal'

> +  else

> +    capstone_opt = false

> +  endif

> +endif

> +if capstone_opt == 'internal'

> +  capstone_data = configuration_data()

> +  capstone_data.set('CAPSTONE_USE_SYS_DYN_MEM', '1')

> +

> +  capstone_files = files(

> +    'capstone/cs.c',

> +    'capstone/MCInst.c',

> +    'capstone/MCInstrDesc.c',

> +    'capstone/MCRegisterInfo.c',

> +    'capstone/SStream.c',

> +    'capstone/utils.c'

> +  )

> +

> +  if 'CONFIG_ARM_DIS' in config_all_disas

> +    capstone_data.set('CAPSTONE_HAS_ARM', '1')

> +    capstone_files += files(

> +      'capstone/arch/ARM/ARMDisassembler.c',

> +      'capstone/arch/ARM/ARMInstPrinter.c',

> +      'capstone/arch/ARM/ARMMapping.c',

> +      'capstone/arch/ARM/ARMModule.c'

> +    )

> +  endif

> +

> +  # FIXME: This config entry currently depends on a c++ compiler.

> +  # Which is needed for building libvixl, but not for capstone.

> +  if 'CONFIG_ARM_A64_DIS' in config_all_disas

> +    capstone_data.set('CAPSTONE_HAS_ARM64', '1')

> +    capstone_files += files(

> +      'capstone/arch/AArch64/AArch64BaseInfo.c',

> +      'capstone/arch/AArch64/AArch64Disassembler.c',

> +      'capstone/arch/AArch64/AArch64InstPrinter.c',

> +      'capstone/arch/AArch64/AArch64Mapping.c',

> +      'capstone/arch/AArch64/AArch64Module.c'

> +    )

> +  endif

> +

> +  if 'CONFIG_PPC_DIS' in config_all_disas

> +    capstone_data.set('CAPSTONE_HAS_POWERPC', '1')

> +    capstone_files += files(

> +      'capstone/arch/PowerPC/PPCDisassembler.c',

> +      'capstone/arch/PowerPC/PPCInstPrinter.c',

> +      'capstone/arch/PowerPC/PPCMapping.c',

> +      'capstone/arch/PowerPC/PPCModule.c'

> +    )

> +  endif

> +

> +  if 'CONFIG_I386_DIS' in config_all_disas

> +    capstone_data.set('CAPSTONE_HAS_X86', 1)

> +    capstone_files += files(

> +      'capstone/arch/X86/X86Disassembler.c',

> +      'capstone/arch/X86/X86DisassemblerDecoder.c',

> +      'capstone/arch/X86/X86ATTInstPrinter.c',

> +      'capstone/arch/X86/X86IntelInstPrinter.c',

> +      'capstone/arch/X86/X86Mapping.c',

> +      'capstone/arch/X86/X86Module.c'

> +    )

> +  endif

> +

> +  configure_file(output: 'capstone-defs.h', configuration: capstone_data)

> +

> +  capstone_cargs = [

> +    # FIXME: There does not seem to be a way to completely replace the

c_args
> +    # that come from add_project_arguments() -- we can only add to them.

> +    # So: disable all warnings with a big hammer.

> +    '-Wno-error', '-w',

> +

> +    # Include all configuration defines via a header file, which will

wind up
> +    # as a dependency on the object file, and thus changes here will

result
> +    # in a rebuild.

> +    '-include', 'capstone-defs.h'

> +  ]

> +

> +  libcapstone = static_library('capstone',

> +                               sources: capstone_files,

> +                               c_args: capstone_cargs,

> +                               include_directories: 'capstone/include')

> +  capstone = declare_dependency(link_with: libcapstone,

> +                                include_directories: 'capstone/include')

> +endif

> +config_host_data.set('CONFIG_CAPSTONE', capstone.found())

> +

> +genh += configure_file(output: 'config-host.h', configuration:

config_host_data)
> +

>  # Generators

>

>  hxtool = find_program('scripts/hxtool')

> @@ -1512,7 +1609,7 @@ summary_info += {'vvfat support':

config_host.has_key('CONFIG_VVFAT')}
>  summary_info += {'qed support':       config_host.has_key('CONFIG_QED')}

>  summary_info += {'parallels support':

config_host.has_key('CONFIG_PARALLELS')}
>  summary_info += {'sheepdog support':

 config_host.has_key('CONFIG_SHEEPDOG')}
> -summary_info += {'capstone':

 config_host.has_key('CONFIG_CAPSTONE')}
> +summary_info += {'capstone':          capstone_opt}

>  summary_info += {'libpmem support':

config_host.has_key('CONFIG_LIBPMEM')}
>  summary_info += {'libdaxctl support':

config_host.has_key('CONFIG_LIBDAXCTL')}
>  summary_info += {'libudev':

config_host.has_key('CONFIG_LIBUDEV')}
> diff --git a/meson_options.txt b/meson_options.txt

> index 543cf70043..e650a937e7 100644

> --- a/meson_options.txt

> +++ b/meson_options.txt

> @@ -22,3 +22,7 @@ option('vnc_sasl', type : 'feature', value : 'auto',

>         description: 'SASL authentication for VNC server')

>  option('xkbcommon', type : 'feature', value : 'auto',

>         description: 'xkbcommon support')

> +

> +option('capstone', type: 'combo', value: 'auto',

> +       choices: ['no', 'yes', 'auto', 'system', 'internal'],

> +       description: 'Whether and how to find the capstone library')

> --

> 2.25.1

>

>



--
         此致
礼
罗勇刚
Yours
    sincerely,
Yonggang Luo
<div dir="ltr"><br><br>On Fri, Sep 18, 2020 at 7:59 AM Richard Henderson &lt;<a href="mailto:richard.henderson@linaro.org">richard.henderson@linaro.org</a>&gt; wrote:<br>&gt;<br>&gt; There are better ways to do this, e.g. meson cmake subproject,<br>&gt; but that requires cmake 3.7 and some of our CI environments<br>&gt; only provide cmake 3.5.<br>&gt;<br>&gt; Nor can we add a meson.build file to capstone/, because the git<br>&gt; submodule would then always report &quot;untracked files&quot;.  Fixing that<br>&gt; would require creating our own branch on the qemu git mirror, at<br>&gt; which point we could just as easily create a native meson subproject.<br>&gt;<br>&gt; Instead, build the library via the main meson.build.<br>&gt;<br>&gt; This improves the current state of affairs in that we will re-link<br>&gt; the qemu executables against a changed libcapstone.a, which we wouldn&#39;t<br>&gt; do before-hand.  In addition, the use of the configuration header file<br>&gt; instead of command-line -DEFINES means that we will rebuild the<br>&gt; capstone objects with changes to meson.build.<br>&gt;<br>&gt; Signed-off-by: Richard Henderson &lt;<a href="mailto:richard.henderson@linaro.org">richard.henderson@linaro.org</a>&gt;<br>&gt; ---<br>&gt; Cc: Paolo Bonzini &lt;<a href="mailto:pbonzini@redhat.com">pbonzini@redhat.com</a>&gt;<br>&gt; v2: Further reduce probing in configure (paolo),<br>&gt;     Drop state &#39;internal&#39; and use &#39;git&#39; even when it isn&#39;t git.<br>&gt;     Move CONFIG_CAPSTONE to config_host_data.<br>&gt; v3: Add Submodules separator; fix default in meson_options.txt.<br>&gt; ---<br>&gt;  configure         |  61 +++----------------------<br>&gt;  Makefile          |  16 -------<br>&gt;  meson.build       | 111 +++++++++++++++++++++++++++++++++++++++++++---<br>&gt;  meson_options.txt |   4 ++<br>&gt;  4 files changed, 115 insertions(+), 77 deletions(-)<br>&gt;<br>&gt; diff --git a/configure b/configure<br>&gt; index 7564479008..76636c430d 100755<br>&gt; --- a/configure<br>&gt; +++ b/configure<br>&gt; @@ -478,7 +478,7 @@ opengl=&quot;&quot;<br>&gt;  opengl_dmabuf=&quot;no&quot;<br>&gt;  cpuid_h=&quot;no&quot;<br>&gt;  avx2_opt=&quot;&quot;<br>&gt; -capstone=&quot;&quot;<br>&gt; +capstone=&quot;auto&quot;<br>&gt;  lzo=&quot;&quot;<br>&gt;  snappy=&quot;&quot;<br>&gt;  bzip2=&quot;&quot;<br>&gt; @@ -1580,7 +1580,7 @@ for opt do<br>&gt;    ;;<br>&gt;    --enable-capstone) capstone=&quot;yes&quot;<br>&gt;    ;;<br>&gt; -  --enable-capstone=git) capstone=&quot;git&quot;<br>&gt; +  --enable-capstone=git) capstone=&quot;internal&quot;<br>&gt;    ;;<br>&gt;    --enable-capstone=system) capstone=&quot;system&quot;<br>&gt;    ;;<br>&gt; @@ -5128,51 +5128,11 @@ fi<br>&gt;  # capstone<br>&gt;<br>&gt;  case &quot;$capstone&quot; in<br>&gt; -  &quot;&quot; | yes)<br>&gt; -    if $pkg_config capstone; then<br>&gt; -      capstone=system<br>&gt; -    elif test -e &quot;${source_path}/.git&quot; &amp;&amp; test $git_update = &#39;yes&#39; ; then<br>&gt; -      capstone=git<br>&gt; -    elif test -e &quot;${source_path}/capstone/Makefile&quot; ; then<br>&gt; -      capstone=internal<br>&gt; -    elif test -z &quot;$capstone&quot; ; then<br>&gt; -      capstone=no<br>&gt; -    else<br>&gt; -      feature_not_found &quot;capstone&quot; &quot;Install capstone devel or git submodule&quot;<br>&gt; -    fi<br>&gt; -    ;;<br>&gt; -<br>&gt; -  system)<br>&gt; -    if ! $pkg_config capstone; then<br>&gt; -      feature_not_found &quot;capstone&quot; &quot;Install capstone devel&quot;<br>&gt; -    fi<br>&gt; -    ;;<br>&gt; -esac<br>&gt; -<br>&gt; -case &quot;$capstone&quot; in<br>&gt; -  git | internal)<br>&gt; -    if test &quot;$capstone&quot; = git; then<br>&gt; +  auto | yes | internal)<br>&gt; +    # Simpler to always update submodule, even if not needed.<br>&gt; +    if test -e &quot;${source_path}/.git&quot; &amp;&amp; test $git_update = &#39;yes&#39; ; then<br>&gt;        git_submodules=&quot;${git_submodules} capstone&quot;<br>&gt;      fi<br>&gt; -    mkdir -p capstone<br>&gt; -    if test &quot;$mingw32&quot; = &quot;yes&quot;; then<br>&gt; -      LIBCAPSTONE=capstone.lib<br>&gt; -    else<br>&gt; -      LIBCAPSTONE=libcapstone.a<br>&gt; -    fi<br>&gt; -    capstone_libs=&quot;-Lcapstone -lcapstone&quot;<br>&gt; -    capstone_cflags=&quot;-I${source_path}/capstone/include&quot;<br>&gt; -    ;;<br>&gt; -<br>&gt; -  system)<br>&gt; -    capstone_libs=&quot;$($pkg_config --libs capstone)&quot;<br>&gt; -    capstone_cflags=&quot;$($pkg_config --cflags capstone)&quot;<br>&gt; -    ;;<br>&gt; -<br>&gt; -  no)<br>&gt; -    ;;<br>&gt; -  *)<br>&gt; -    error_exit &quot;Unknown state for capstone: $capstone&quot;<br>&gt;      ;;<br>&gt;  esac<br>&gt;<br>&gt; @@ -7292,11 +7252,6 @@ fi<br>&gt;  if test &quot;$ivshmem&quot; = &quot;yes&quot; ; then<br>&gt;    echo &quot;CONFIG_IVSHMEM=y&quot; &gt;&gt; $config_host_mak<br>&gt;  fi<br>&gt; -if test &quot;$capstone&quot; != &quot;no&quot; ; then<br>&gt; -  echo &quot;CONFIG_CAPSTONE=y&quot; &gt;&gt; $config_host_mak<br>&gt; -  echo &quot;CAPSTONE_CFLAGS=$capstone_cflags&quot; &gt;&gt; $config_host_mak<br>&gt; -  echo &quot;CAPSTONE_LIBS=$capstone_libs&quot; &gt;&gt; $config_host_mak<br>&gt; -fi<br>&gt;  if test &quot;$debug_mutex&quot; = &quot;yes&quot; ; then<br>&gt;    echo &quot;CONFIG_DEBUG_MUTEX=y&quot; &gt;&gt; $config_host_mak<br>&gt;  fi<br>&gt; @@ -7819,9 +7774,6 @@ done # for target in $targets<br>&gt;  if [ &quot;$fdt&quot; = &quot;git&quot; ]; then<br>&gt;    subdirs=&quot;$subdirs dtc&quot;<br>&gt;  fi<br>&gt; -if [ &quot;$capstone&quot; = &quot;git&quot; -o &quot;$capstone&quot; = &quot;internal&quot; ]; then<br>&gt; -  subdirs=&quot;$subdirs capstone&quot;<br>&gt; -fi<br>&gt;  echo &quot;SUBDIRS=$subdirs&quot; &gt;&gt; $config_host_mak<br>&gt;  if test -n &quot;$LIBCAPSTONE&quot;; then<br>&gt;    echo &quot;LIBCAPSTONE=$LIBCAPSTONE&quot; &gt;&gt; $config_host_mak<div>These 

LIBCAPSTONE should be removed, as they are empty and have no meaning now<br>&gt; @@ -8008,7 +7960,8 @@ NINJA=${ninja:-$PWD/ninjatool} $meson setup \<br>&gt;          -Db_coverage=$(if test &quot;$gcov&quot; = yes; then echo true; else echo false; fi) \<br>&gt;         -Dsdl=$sdl -Dsdl_image=$sdl_image \<br>&gt;         -Dvnc=$vnc -Dvnc_sasl=$vnc_sasl -Dvnc_jpeg=$vnc_jpeg -Dvnc_png=$vnc_png \<br>&gt; -       -Dgettext=$gettext -Dxkbcommon=$xkbcommon -Du2f=$u2f\<br>&gt; +       -Dgettext=$gettext -Dxkbcommon=$xkbcommon -Du2f=$u2f \<br>&gt; +       -Dcapstone=$capstone \</div><div>These lines should ident with 8 space instead of two tab.</div><div>There is four lines of them</div><div> -Dsdl=$sdl -Dsdl_image=$sdl_image \<br>	-Dvnc=$vnc -Dvnc_sasl=$vnc_sasl -Dvnc_jpeg=$vnc_jpeg -Dvnc_png=$vnc_png \<br>	-Dgettext=$gettext -Dxkbcommon=$xkbcommon -Du2f=$u2f \<br>	-Dcapstone=$capstone \</div><div><br>&gt;          $cross_arg \<br>&gt;          &quot;$PWD&quot; &quot;$source_path&quot;<br>&gt;<br>&gt; diff --git a/Makefile b/Makefile<br>&gt; index 7c60b9dcb8..f3da1760ad 100644<br>&gt; --- a/Makefile<br>&gt; +++ b/Makefile<br>&gt; @@ -156,22 +156,6 @@ dtc/all: .git-submodule-status dtc/libfdt<br>&gt;  dtc/%: .git-submodule-status<br>&gt;         @mkdir -p $@<br>&gt;<br>&gt; -# Overriding CFLAGS causes us to lose defines added in the sub-makefile.<br>&gt; -# Not overriding CFLAGS leads to mis-matches between compilation modes.<br>&gt; -# Therefore we replicate some of the logic in the sub-makefile.<br>&gt; -# Remove all the extra -Warning flags that QEMU uses that Capstone doesn&#39;t;<br>&gt; -# no need to annoy QEMU developers with such things.<br>&gt; -CAP_CFLAGS = $(patsubst -W%,,$(CFLAGS) $(QEMU_CFLAGS)) $(CAPSTONE_CFLAGS)<br>&gt; -CAP_CFLAGS += -DCAPSTONE_USE_SYS_DYN_MEM<br>&gt; -CAP_CFLAGS += -DCAPSTONE_HAS_ARM<br>&gt; -CAP_CFLAGS += -DCAPSTONE_HAS_ARM64<br>&gt; -CAP_CFLAGS += -DCAPSTONE_HAS_POWERPC<br>&gt; -CAP_CFLAGS += -DCAPSTONE_HAS_X86<br>&gt; -<br>&gt; -.PHONY: capstone/all<br>&gt; -capstone/all: .git-submodule-status<br>&gt; -       $(call quiet-command,$(MAKE) -C $(SRC_PATH)/capstone CAPSTONE_SHARED=no BUILDDIR=&quot;$(BUILD_DIR)/capstone&quot; CC=&quot;$(CC)&quot; AR=&quot;$(AR)&quot; LD=&quot;$(LD)&quot; RANLIB=&quot;$(RANLIB)&quot; CFLAGS=&quot;$(CAP_CFLAGS)&quot; $(SUBDIR_MAKEFLAGS) $(BUILD_DIR)/capstone/$(LIBCAPSTONE))<br>&gt; -<br>&gt;  .PHONY: slirp/all<br>&gt;  slirp/all: .git-submodule-status<br>&gt;         $(call quiet-command,$(MAKE) -C $(SRC_PATH)/slirp               \<br>&gt; diff --git a/meson.build b/meson.build<br>&gt; index f4d1ab1096..f23273693d 100644<br>&gt; --- a/meson.build<br>&gt; +++ b/meson.build<br>&gt; @@ -10,6 +10,7 @@ else<br>&gt;    keyval = import(&#39;unstable-keyval&#39;)<br>&gt;  endif<br>&gt;  ss = import(&#39;sourceset&#39;)<br>&gt; +fs = import(&#39;fs&#39;)<br>&gt;<br>&gt;  sh = find_program(&#39;sh&#39;)<br>&gt;  cc = meson.get_compiler(&#39;c&#39;)<br>&gt; @@ -409,11 +410,6 @@ if &#39;CONFIG_USB_LIBUSB&#39; in config_host<br>&gt;    libusb = declare_dependency(compile_args: config_host[&#39;LIBUSB_CFLAGS&#39;].split(),<br>&gt;                                link_args: config_host[&#39;LIBUSB_LIBS&#39;].split())<br>&gt;  endif<br>&gt; -capstone = not_found<br>&gt; -if &#39;CONFIG_CAPSTONE&#39; in config_host<br>&gt; -  capstone = declare_dependency(compile_args: config_host[&#39;CAPSTONE_CFLAGS&#39;].split(),<br>&gt; -                                link_args: config_host[&#39;CAPSTONE_LIBS&#39;].split())<br>&gt; -endif<br>&gt;  libpmem = not_found<br>&gt;  if &#39;CONFIG_LIBPMEM&#39; in config_host<br>&gt;    libpmem = declare_dependency(compile_args: config_host[&#39;LIBPMEM_CFLAGS&#39;].split(),<br>&gt; @@ -470,7 +466,6 @@ foreach k, v: config_host<br>&gt;      config_host_data.set(k, v == &#39;y&#39; ? 1 : v)<br>&gt;    endif<br>&gt;  endforeach<br>&gt; -genh += configure_file(output: &#39;config-host.h&#39;, configuration: config_host_data)<br>&gt;<br>&gt;  minikconf = find_program(&#39;scripts/minikconf.py&#39;)<br>&gt;  config_all_devices = {}<br>&gt; @@ -610,6 +605,108 @@ config_all += {<br>&gt;    &#39;CONFIG_ALL&#39;: true,<br>&gt;  }<br>&gt;<br>&gt; +# Submodules<br>&gt; +<br>&gt; +capstone = not_found<br>&gt; +capstone_opt = get_option(&#39;capstone&#39;)<br>&gt; +if capstone_opt == &#39;no&#39;<br>&gt; +  capstone_opt = false<br>&gt; +elif capstone_opt in [&#39;yes&#39;, &#39;auto&#39;, &#39;system&#39;]<br>&gt; +  have_internal = fs.exists(&#39;capstone/Makefile&#39;)<br>&gt; +  capstone = dependency(&#39;capstone&#39;, static: enable_static,<br>&gt; +                        required: capstone_opt == &#39;system&#39; or<br>&gt; +                                  capstone_opt == &#39;yes&#39; and not have_internal)<br>&gt; +  if capstone.found()<br>&gt; +    capstone_opt = &#39;system&#39;<br>&gt; +  elif have_internal<br>&gt; +    capstone_opt = &#39;internal&#39;<br>&gt; +  else<br>&gt; +    capstone_opt = false<br>&gt; +  endif<br>&gt; +endif<br>&gt; +if capstone_opt == &#39;internal&#39;<br>&gt; +  capstone_data = configuration_data()<br>&gt; +  capstone_data.set(&#39;CAPSTONE_USE_SYS_DYN_MEM&#39;, &#39;1&#39;)<br>&gt; +<br>&gt; +  capstone_files = files(<br>&gt; +    &#39;capstone/cs.c&#39;,<br>&gt; +    &#39;capstone/MCInst.c&#39;,<br>&gt; +    &#39;capstone/MCInstrDesc.c&#39;,<br>&gt; +    &#39;capstone/MCRegisterInfo.c&#39;,<br>&gt; +    &#39;capstone/SStream.c&#39;,<br>&gt; +    &#39;capstone/utils.c&#39;<br>&gt; +  )<br>&gt; +<br>&gt; +  if &#39;CONFIG_ARM_DIS&#39; in config_all_disas<br>&gt; +    capstone_data.set(&#39;CAPSTONE_HAS_ARM&#39;, &#39;1&#39;)<br>&gt; +    capstone_files += files(<br>&gt; +      &#39;capstone/arch/ARM/ARMDisassembler.c&#39;,<br>&gt; +      &#39;capstone/arch/ARM/ARMInstPrinter.c&#39;,<br>&gt; +      &#39;capstone/arch/ARM/ARMMapping.c&#39;,<br>&gt; +      &#39;capstone/arch/ARM/ARMModule.c&#39;<br>&gt; +    )<br>&gt; +  endif<br>&gt; +<br>&gt; +  # FIXME: This config entry currently depends on a c++ compiler.<br>&gt; +  # Which is needed for building libvixl, but not for capstone.<br>&gt; +  if &#39;CONFIG_ARM_A64_DIS&#39; in config_all_disas<br>&gt; +    capstone_data.set(&#39;CAPSTONE_HAS_ARM64&#39;, &#39;1&#39;)<br>&gt; +    capstone_files += files(<br>&gt; +      &#39;capstone/arch/AArch64/AArch64BaseInfo.c&#39;,<br>&gt; +      &#39;capstone/arch/AArch64/AArch64Disassembler.c&#39;,<br>&gt; +      &#39;capstone/arch/AArch64/AArch64InstPrinter.c&#39;,<br>&gt; +      &#39;capstone/arch/AArch64/AArch64Mapping.c&#39;,<br>&gt; +      &#39;capstone/arch/AArch64/AArch64Module.c&#39;<br>&gt; +    )<br>&gt; +  endif<br>&gt; +<br>&gt; +  if &#39;CONFIG_PPC_DIS&#39; in config_all_disas<br>&gt; +    capstone_data.set(&#39;CAPSTONE_HAS_POWERPC&#39;, &#39;1&#39;)<br>&gt; +    capstone_files += files(<br>&gt; +      &#39;capstone/arch/PowerPC/PPCDisassembler.c&#39;,<br>&gt; +      &#39;capstone/arch/PowerPC/PPCInstPrinter.c&#39;,<br>&gt; +      &#39;capstone/arch/PowerPC/PPCMapping.c&#39;,<br>&gt; +      &#39;capstone/arch/PowerPC/PPCModule.c&#39;<br>&gt; +    )<br>&gt; +  endif<br>&gt; +<br>&gt; +  if &#39;CONFIG_I386_DIS&#39; in config_all_disas<br>&gt; +    capstone_data.set(&#39;CAPSTONE_HAS_X86&#39;, 1)<br>&gt; +    capstone_files += files(<br>&gt; +      &#39;capstone/arch/X86/X86Disassembler.c&#39;,<br>&gt; +      &#39;capstone/arch/X86/X86DisassemblerDecoder.c&#39;,<br>&gt; +      &#39;capstone/arch/X86/X86ATTInstPrinter.c&#39;,<br>&gt; +      &#39;capstone/arch/X86/X86IntelInstPrinter.c&#39;,<br>&gt; +      &#39;capstone/arch/X86/X86Mapping.c&#39;,<br>&gt; +      &#39;capstone/arch/X86/X86Module.c&#39;<br>&gt; +    )<br>&gt; +  endif<br>&gt; +<br>&gt; +  configure_file(output: &#39;capstone-defs.h&#39;, configuration: capstone_data)<br>&gt; +<br>&gt; +  capstone_cargs = [<br>&gt; +    # FIXME: There does not seem to be a way to completely replace the c_args<br>&gt; +    # that come from add_project_arguments() -- we can only add to them.<br>&gt; +    # So: disable all warnings with a big hammer.<br>&gt; +    &#39;-Wno-error&#39;, &#39;-w&#39;,<br>&gt; +<br>&gt; +    # Include all configuration defines via a header file, which will wind up<br>&gt; +    # as a dependency on the object file, and thus changes here will result<br>&gt; +    # in a rebuild.<br>&gt; +    &#39;-include&#39;, &#39;capstone-defs.h&#39;<br>&gt; +  ]<br>&gt; +<br>&gt; +  libcapstone = static_library(&#39;capstone&#39;,<br>&gt; +                               sources: capstone_files,<br>&gt; +                               c_args: capstone_cargs,<br>&gt; +                               include_directories: &#39;capstone/include&#39;)<br>&gt; +  capstone = declare_dependency(link_with: libcapstone,<br>&gt; +                                include_directories: &#39;capstone/include&#39;)<br>&gt; +endif<br>&gt; +config_host_data.set(&#39;CONFIG_CAPSTONE&#39;, capstone.found())<br>&gt; +<br>&gt; +genh += configure_file(output: &#39;config-host.h&#39;, configuration: config_host_data)<br>&gt; +<br>&gt;  # Generators<br>&gt;<br>&gt;  hxtool = find_program(&#39;scripts/hxtool&#39;)<br>&gt; @@ -1512,7 +1609,7 @@ summary_info += {&#39;vvfat support&#39;:     config_host.has_key(&#39;CONFIG_VVFAT&#39;)}<br>&gt;  summary_info += {&#39;qed support&#39;:       config_host.has_key(&#39;CONFIG_QED&#39;)}<br>&gt;  summary_info += {&#39;parallels support&#39;: config_host.has_key(&#39;CONFIG_PARALLELS&#39;)}<br>&gt;  summary_info += {&#39;sheepdog support&#39;:  config_host.has_key(&#39;CONFIG_SHEEPDOG&#39;)}<br>&gt; -summary_info += {&#39;capstone&#39;:          config_host.has_key(&#39;CONFIG_CAPSTONE&#39;)}<br>&gt; +summary_info += {&#39;capstone&#39;:          capstone_opt}<br>&gt;  summary_info += {&#39;libpmem support&#39;:   config_host.has_key(&#39;CONFIG_LIBPMEM&#39;)}<br>&gt;  summary_info += {&#39;libdaxctl support&#39;: config_host.has_key(&#39;CONFIG_LIBDAXCTL&#39;)}<br>&gt;  summary_info += {&#39;libudev&#39;:           config_host.has_key(&#39;CONFIG_LIBUDEV&#39;)}<br>&gt; diff --git a/meson_options.txt b/meson_options.txt<br>&gt; index 543cf70043..e650a937e7 100644<br>&gt; --- a/meson_options.txt<br>&gt; +++ b/meson_options.txt<br>&gt; @@ -22,3 +22,7 @@ option(&#39;vnc_sasl&#39;, type : &#39;feature&#39;, value : &#39;auto&#39;,<br>&gt;         description: &#39;SASL authentication for VNC server&#39;)<br>&gt;  option(&#39;xkbcommon&#39;, type : &#39;feature&#39;, value : &#39;auto&#39;,<br>&gt;         description: &#39;xkbcommon support&#39;)<br>&gt; +<br>&gt; +option(&#39;capstone&#39;, type: &#39;combo&#39;, value: &#39;auto&#39;,<br>&gt; +       choices: [&#39;no&#39;, &#39;yes&#39;, &#39;auto&#39;, &#39;system&#39;, &#39;internal&#39;],<br>&gt; +       description: &#39;Whether and how to find the capstone library&#39;)<br>&gt; --<br>&gt; 2.25.1<br>&gt;<br>&gt;<br><br><br>--<br>         此致<br>礼<br>罗勇刚<br>Yours<br>    sincerely,<br>Yonggang Luo</div></div>
Paolo Bonzini Sept. 18, 2020, 8:13 a.m. UTC | #2
On 18/09/20 01:57, Richard Henderson wrote:
> There are better ways to do this, e.g. meson cmake subproject,

> but that requires cmake 3.7 and some of our CI environments

> only provide cmake 3.5.

> 

> Nor can we add a meson.build file to capstone/, because the git

> submodule would then always report "untracked files".  Fixing that

> would require creating our own branch on the qemu git mirror, at

> which point we could just as easily create a native meson subproject.

> 

> Instead, build the library via the main meson.build.

> 

> This improves the current state of affairs in that we will re-link

> the qemu executables against a changed libcapstone.a, which we wouldn't

> do before-hand.  In addition, the use of the configuration header file

> instead of command-line -DEFINES means that we will rebuild the

> capstone objects with changes to meson.build.

> 

> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>

> ---

> Cc: Paolo Bonzini <pbonzini@redhat.com>

> v2: Further reduce probing in configure (paolo),

>     Drop state 'internal' and use 'git' even when it isn't git.

>     Move CONFIG_CAPSTONE to config_host_data.

> v3: Add Submodules separator; fix default in meson_options.txt.

> ---


Acked-by: Paolo Bonzini <pbonzini@redhat.com>


Thanks!  That's also a nice blueprint if anyone wants to do the same on
libfdt.

Paolo


>  configure         |  61 +++----------------------

>  Makefile          |  16 -------

>  meson.build       | 111 +++++++++++++++++++++++++++++++++++++++++++---

>  meson_options.txt |   4 ++

>  4 files changed, 115 insertions(+), 77 deletions(-)

> 

> diff --git a/configure b/configure

> index 7564479008..76636c430d 100755

> --- a/configure

> +++ b/configure

> @@ -478,7 +478,7 @@ opengl=""

>  opengl_dmabuf="no"

>  cpuid_h="no"

>  avx2_opt=""

> -capstone=""

> +capstone="auto"

>  lzo=""

>  snappy=""

>  bzip2=""

> @@ -1580,7 +1580,7 @@ for opt do

>    ;;

>    --enable-capstone) capstone="yes"

>    ;;

> -  --enable-capstone=git) capstone="git"

> +  --enable-capstone=git) capstone="internal"

>    ;;

>    --enable-capstone=system) capstone="system"

>    ;;

> @@ -5128,51 +5128,11 @@ fi

>  # capstone

>  

>  case "$capstone" in

> -  "" | yes)

> -    if $pkg_config capstone; then

> -      capstone=system

> -    elif test -e "${source_path}/.git" && test $git_update = 'yes' ; then

> -      capstone=git

> -    elif test -e "${source_path}/capstone/Makefile" ; then

> -      capstone=internal

> -    elif test -z "$capstone" ; then

> -      capstone=no

> -    else

> -      feature_not_found "capstone" "Install capstone devel or git submodule"

> -    fi

> -    ;;

> -

> -  system)

> -    if ! $pkg_config capstone; then

> -      feature_not_found "capstone" "Install capstone devel"

> -    fi

> -    ;;

> -esac

> -

> -case "$capstone" in

> -  git | internal)

> -    if test "$capstone" = git; then

> +  auto | yes | internal)

> +    # Simpler to always update submodule, even if not needed.

> +    if test -e "${source_path}/.git" && test $git_update = 'yes' ; then

>        git_submodules="${git_submodules} capstone"

>      fi

> -    mkdir -p capstone

> -    if test "$mingw32" = "yes"; then

> -      LIBCAPSTONE=capstone.lib

> -    else

> -      LIBCAPSTONE=libcapstone.a

> -    fi

> -    capstone_libs="-Lcapstone -lcapstone"

> -    capstone_cflags="-I${source_path}/capstone/include"

> -    ;;

> -

> -  system)

> -    capstone_libs="$($pkg_config --libs capstone)"

> -    capstone_cflags="$($pkg_config --cflags capstone)"

> -    ;;

> -

> -  no)

> -    ;;

> -  *)

> -    error_exit "Unknown state for capstone: $capstone"

>      ;;

>  esac

>  

> @@ -7292,11 +7252,6 @@ fi

>  if test "$ivshmem" = "yes" ; then

>    echo "CONFIG_IVSHMEM=y" >> $config_host_mak

>  fi

> -if test "$capstone" != "no" ; then

> -  echo "CONFIG_CAPSTONE=y" >> $config_host_mak

> -  echo "CAPSTONE_CFLAGS=$capstone_cflags" >> $config_host_mak

> -  echo "CAPSTONE_LIBS=$capstone_libs" >> $config_host_mak

> -fi

>  if test "$debug_mutex" = "yes" ; then

>    echo "CONFIG_DEBUG_MUTEX=y" >> $config_host_mak

>  fi

> @@ -7819,9 +7774,6 @@ done # for target in $targets

>  if [ "$fdt" = "git" ]; then

>    subdirs="$subdirs dtc"

>  fi

> -if [ "$capstone" = "git" -o "$capstone" = "internal" ]; then

> -  subdirs="$subdirs capstone"

> -fi

>  echo "SUBDIRS=$subdirs" >> $config_host_mak

>  if test -n "$LIBCAPSTONE"; then

>    echo "LIBCAPSTONE=$LIBCAPSTONE" >> $config_host_mak

> @@ -8008,7 +7960,8 @@ NINJA=${ninja:-$PWD/ninjatool} $meson setup \

>          -Db_coverage=$(if test "$gcov" = yes; then echo true; else echo false; fi) \

>  	-Dsdl=$sdl -Dsdl_image=$sdl_image \

>  	-Dvnc=$vnc -Dvnc_sasl=$vnc_sasl -Dvnc_jpeg=$vnc_jpeg -Dvnc_png=$vnc_png \

> -	-Dgettext=$gettext -Dxkbcommon=$xkbcommon -Du2f=$u2f\

> +	-Dgettext=$gettext -Dxkbcommon=$xkbcommon -Du2f=$u2f \

> +	-Dcapstone=$capstone \

>          $cross_arg \

>          "$PWD" "$source_path"

>  

> diff --git a/Makefile b/Makefile

> index 7c60b9dcb8..f3da1760ad 100644

> --- a/Makefile

> +++ b/Makefile

> @@ -156,22 +156,6 @@ dtc/all: .git-submodule-status dtc/libfdt

>  dtc/%: .git-submodule-status

>  	@mkdir -p $@

>  

> -# Overriding CFLAGS causes us to lose defines added in the sub-makefile.

> -# Not overriding CFLAGS leads to mis-matches between compilation modes.

> -# Therefore we replicate some of the logic in the sub-makefile.

> -# Remove all the extra -Warning flags that QEMU uses that Capstone doesn't;

> -# no need to annoy QEMU developers with such things.

> -CAP_CFLAGS = $(patsubst -W%,,$(CFLAGS) $(QEMU_CFLAGS)) $(CAPSTONE_CFLAGS)

> -CAP_CFLAGS += -DCAPSTONE_USE_SYS_DYN_MEM

> -CAP_CFLAGS += -DCAPSTONE_HAS_ARM

> -CAP_CFLAGS += -DCAPSTONE_HAS_ARM64

> -CAP_CFLAGS += -DCAPSTONE_HAS_POWERPC

> -CAP_CFLAGS += -DCAPSTONE_HAS_X86

> -

> -.PHONY: capstone/all

> -capstone/all: .git-submodule-status

> -	$(call quiet-command,$(MAKE) -C $(SRC_PATH)/capstone CAPSTONE_SHARED=no BUILDDIR="$(BUILD_DIR)/capstone" CC="$(CC)" AR="$(AR)" LD="$(LD)" RANLIB="$(RANLIB)" CFLAGS="$(CAP_CFLAGS)" $(SUBDIR_MAKEFLAGS) $(BUILD_DIR)/capstone/$(LIBCAPSTONE))

> -

>  .PHONY: slirp/all

>  slirp/all: .git-submodule-status

>  	$(call quiet-command,$(MAKE) -C $(SRC_PATH)/slirp		\

> diff --git a/meson.build b/meson.build

> index f4d1ab1096..f23273693d 100644

> --- a/meson.build

> +++ b/meson.build

> @@ -10,6 +10,7 @@ else

>    keyval = import('unstable-keyval')

>  endif

>  ss = import('sourceset')

> +fs = import('fs')

>  

>  sh = find_program('sh')

>  cc = meson.get_compiler('c')

> @@ -409,11 +410,6 @@ if 'CONFIG_USB_LIBUSB' in config_host

>    libusb = declare_dependency(compile_args: config_host['LIBUSB_CFLAGS'].split(),

>                                link_args: config_host['LIBUSB_LIBS'].split())

>  endif

> -capstone = not_found

> -if 'CONFIG_CAPSTONE' in config_host

> -  capstone = declare_dependency(compile_args: config_host['CAPSTONE_CFLAGS'].split(),

> -                                link_args: config_host['CAPSTONE_LIBS'].split())

> -endif

>  libpmem = not_found

>  if 'CONFIG_LIBPMEM' in config_host

>    libpmem = declare_dependency(compile_args: config_host['LIBPMEM_CFLAGS'].split(),

> @@ -470,7 +466,6 @@ foreach k, v: config_host

>      config_host_data.set(k, v == 'y' ? 1 : v)

>    endif

>  endforeach

> -genh += configure_file(output: 'config-host.h', configuration: config_host_data)

>  

>  minikconf = find_program('scripts/minikconf.py')

>  config_all_devices = {}

> @@ -610,6 +605,108 @@ config_all += {

>    'CONFIG_ALL': true,

>  }

>  

> +# Submodules

> +

> +capstone = not_found

> +capstone_opt = get_option('capstone')

> +if capstone_opt == 'no'

> +  capstone_opt = false

> +elif capstone_opt in ['yes', 'auto', 'system']

> +  have_internal = fs.exists('capstone/Makefile')

> +  capstone = dependency('capstone', static: enable_static,

> +                        required: capstone_opt == 'system' or

> +                                  capstone_opt == 'yes' and not have_internal)

> +  if capstone.found()

> +    capstone_opt = 'system'

> +  elif have_internal

> +    capstone_opt = 'internal'

> +  else

> +    capstone_opt = false

> +  endif

> +endif

> +if capstone_opt == 'internal'

> +  capstone_data = configuration_data()

> +  capstone_data.set('CAPSTONE_USE_SYS_DYN_MEM', '1')

> +

> +  capstone_files = files(

> +    'capstone/cs.c',

> +    'capstone/MCInst.c',

> +    'capstone/MCInstrDesc.c',

> +    'capstone/MCRegisterInfo.c',

> +    'capstone/SStream.c',

> +    'capstone/utils.c'

> +  )

> +

> +  if 'CONFIG_ARM_DIS' in config_all_disas

> +    capstone_data.set('CAPSTONE_HAS_ARM', '1')

> +    capstone_files += files(

> +      'capstone/arch/ARM/ARMDisassembler.c',

> +      'capstone/arch/ARM/ARMInstPrinter.c',

> +      'capstone/arch/ARM/ARMMapping.c',

> +      'capstone/arch/ARM/ARMModule.c'

> +    )

> +  endif

> +

> +  # FIXME: This config entry currently depends on a c++ compiler.

> +  # Which is needed for building libvixl, but not for capstone.

> +  if 'CONFIG_ARM_A64_DIS' in config_all_disas

> +    capstone_data.set('CAPSTONE_HAS_ARM64', '1')

> +    capstone_files += files(

> +      'capstone/arch/AArch64/AArch64BaseInfo.c',

> +      'capstone/arch/AArch64/AArch64Disassembler.c',

> +      'capstone/arch/AArch64/AArch64InstPrinter.c',

> +      'capstone/arch/AArch64/AArch64Mapping.c',

> +      'capstone/arch/AArch64/AArch64Module.c'

> +    )

> +  endif

> +

> +  if 'CONFIG_PPC_DIS' in config_all_disas

> +    capstone_data.set('CAPSTONE_HAS_POWERPC', '1')

> +    capstone_files += files(

> +      'capstone/arch/PowerPC/PPCDisassembler.c',

> +      'capstone/arch/PowerPC/PPCInstPrinter.c',

> +      'capstone/arch/PowerPC/PPCMapping.c',

> +      'capstone/arch/PowerPC/PPCModule.c'

> +    )

> +  endif

> +

> +  if 'CONFIG_I386_DIS' in config_all_disas

> +    capstone_data.set('CAPSTONE_HAS_X86', 1)

> +    capstone_files += files(

> +      'capstone/arch/X86/X86Disassembler.c',

> +      'capstone/arch/X86/X86DisassemblerDecoder.c',

> +      'capstone/arch/X86/X86ATTInstPrinter.c',

> +      'capstone/arch/X86/X86IntelInstPrinter.c',

> +      'capstone/arch/X86/X86Mapping.c',

> +      'capstone/arch/X86/X86Module.c'

> +    )

> +  endif

> +

> +  configure_file(output: 'capstone-defs.h', configuration: capstone_data)

> +

> +  capstone_cargs = [

> +    # FIXME: There does not seem to be a way to completely replace the c_args

> +    # that come from add_project_arguments() -- we can only add to them.

> +    # So: disable all warnings with a big hammer.

> +    '-Wno-error', '-w',

> +

> +    # Include all configuration defines via a header file, which will wind up

> +    # as a dependency on the object file, and thus changes here will result

> +    # in a rebuild.

> +    '-include', 'capstone-defs.h'

> +  ]

> +

> +  libcapstone = static_library('capstone',

> +                               sources: capstone_files,

> +                               c_args: capstone_cargs,

> +                               include_directories: 'capstone/include')

> +  capstone = declare_dependency(link_with: libcapstone,

> +                                include_directories: 'capstone/include')

> +endif

> +config_host_data.set('CONFIG_CAPSTONE', capstone.found())

> +

> +genh += configure_file(output: 'config-host.h', configuration: config_host_data)

> +

>  # Generators

>  

>  hxtool = find_program('scripts/hxtool')

> @@ -1512,7 +1609,7 @@ summary_info += {'vvfat support':     config_host.has_key('CONFIG_VVFAT')}

>  summary_info += {'qed support':       config_host.has_key('CONFIG_QED')}

>  summary_info += {'parallels support': config_host.has_key('CONFIG_PARALLELS')}

>  summary_info += {'sheepdog support':  config_host.has_key('CONFIG_SHEEPDOG')}

> -summary_info += {'capstone':          config_host.has_key('CONFIG_CAPSTONE')}

> +summary_info += {'capstone':          capstone_opt}

>  summary_info += {'libpmem support':   config_host.has_key('CONFIG_LIBPMEM')}

>  summary_info += {'libdaxctl support': config_host.has_key('CONFIG_LIBDAXCTL')}

>  summary_info += {'libudev':           config_host.has_key('CONFIG_LIBUDEV')}

> diff --git a/meson_options.txt b/meson_options.txt

> index 543cf70043..e650a937e7 100644

> --- a/meson_options.txt

> +++ b/meson_options.txt

> @@ -22,3 +22,7 @@ option('vnc_sasl', type : 'feature', value : 'auto',

>         description: 'SASL authentication for VNC server')

>  option('xkbcommon', type : 'feature', value : 'auto',

>         description: 'xkbcommon support')

> +

> +option('capstone', type: 'combo', value: 'auto',

> +       choices: ['no', 'yes', 'auto', 'system', 'internal'],

> +       description: 'Whether and how to find the capstone library')

>
罗勇刚(Yonggang Luo) Sept. 18, 2020, 8:42 a.m. UTC | #3
On Fri, Sep 18, 2020 at 4:19 PM Paolo Bonzini <pbonzini@redhat.com> wrote:
>

> On 18/09/20 01:57, Richard Henderson wrote:

> > There are better ways to do this, e.g. meson cmake subproject,

> > but that requires cmake 3.7 and some of our CI environments

> > only provide cmake 3.5.

> >

> > Nor can we add a meson.build file to capstone/, because the git

> > submodule would then always report "untracked files".  Fixing that

> > would require creating our own branch on the qemu git mirror, at

> > which point we could just as easily create a native meson subproject.

> >

> > Instead, build the library via the main meson.build.

> >

> > This improves the current state of affairs in that we will re-link

> > the qemu executables against a changed libcapstone.a, which we wouldn't

> > do before-hand.  In addition, the use of the configuration header file

> > instead of command-line -DEFINES means that we will rebuild the

> > capstone objects with changes to meson.build.

> >

> > Signed-off-by: Richard Henderson <richard.henderson@linaro.org>

> > ---

> > Cc: Paolo Bonzini <pbonzini@redhat.com>

> > v2: Further reduce probing in configure (paolo),

> >     Drop state 'internal' and use 'git' even when it isn't git.

> >     Move CONFIG_CAPSTONE to config_host_data.

> > v3: Add Submodules separator; fix default in meson_options.txt.

> > ---

>

> Acked-by: Paolo Bonzini <pbonzini@redhat.com>

>

> Thanks!  That's also a nice blueprint if anyone wants to do the same on

> libfdt.

>

> Paolo

>

>

> >  configure         |  61 +++----------------------

> >  Makefile          |  16 -------

> >  meson.build       | 111 +++++++++++++++++++++++++++++++++++++++++++---

> >  meson_options.txt |   4 ++

> >  4 files changed, 115 insertions(+), 77 deletions(-)

> >

> > diff --git a/configure b/configure

> > index 7564479008..76636c430d 100755

> > --- a/configure

> > +++ b/configure

> > @@ -478,7 +478,7 @@ opengl=""

> >  opengl_dmabuf="no"

> >  cpuid_h="no"

> >  avx2_opt=""

> > -capstone=""

> > +capstone="auto"

> >  lzo=""

> >  snappy=""

> >  bzip2=""

> > @@ -1580,7 +1580,7 @@ for opt do

> >    ;;

> >    --enable-capstone) capstone="yes"

> >    ;;

> > -  --enable-capstone=git) capstone="git"

> > +  --enable-capstone=git) capstone="internal"

> >    ;;

> >    --enable-capstone=system) capstone="system"

> >    ;;

> > @@ -5128,51 +5128,11 @@ fi

> >  # capstone

> >

> >  case "$capstone" in

> > -  "" | yes)

> > -    if $pkg_config capstone; then

> > -      capstone=system

> > -    elif test -e "${source_path}/.git" && test $git_update = 'yes' ;

then
> > -      capstone=git

> > -    elif test -e "${source_path}/capstone/Makefile" ; then

> > -      capstone=internal

> > -    elif test -z "$capstone" ; then

> > -      capstone=no

> > -    else

> > -      feature_not_found "capstone" "Install capstone devel or git

submodule"
> > -    fi

> > -    ;;

> > -

> > -  system)

> > -    if ! $pkg_config capstone; then

> > -      feature_not_found "capstone" "Install capstone devel"

> > -    fi

> > -    ;;

> > -esac

> > -

> > -case "$capstone" in

> > -  git | internal)

> > -    if test "$capstone" = git; then

> > +  auto | yes | internal)

> > +    # Simpler to always update submodule, even if not needed.

> > +    if test -e "${source_path}/.git" && test $git_update = 'yes' ; then

> >        git_submodules="${git_submodules} capstone"

> >      fi

> > -    mkdir -p capstone

> > -    if test "$mingw32" = "yes"; then

> > -      LIBCAPSTONE=capstone.lib

> > -    else

> > -      LIBCAPSTONE=libcapstone.a

> > -    fi

> > -    capstone_libs="-Lcapstone -lcapstone"

> > -    capstone_cflags="-I${source_path}/capstone/include"

> > -    ;;

> > -

> > -  system)

> > -    capstone_libs="$($pkg_config --libs capstone)"

> > -    capstone_cflags="$($pkg_config --cflags capstone)"

> > -    ;;

> > -

> > -  no)

> > -    ;;

> > -  *)

> > -    error_exit "Unknown state for capstone: $capstone"

> >      ;;

> >  esac

> >

> > @@ -7292,11 +7252,6 @@ fi

> >  if test "$ivshmem" = "yes" ; then

> >    echo "CONFIG_IVSHMEM=y" >> $config_host_mak

> >  fi

> > -if test "$capstone" != "no" ; then

> > -  echo "CONFIG_CAPSTONE=y" >> $config_host_mak

> > -  echo "CAPSTONE_CFLAGS=$capstone_cflags" >> $config_host_mak

> > -  echo "CAPSTONE_LIBS=$capstone_libs" >> $config_host_mak

> > -fi

> >  if test "$debug_mutex" = "yes" ; then

> >    echo "CONFIG_DEBUG_MUTEX=y" >> $config_host_mak

> >  fi

> > @@ -7819,9 +7774,6 @@ done # for target in $targets

> >  if [ "$fdt" = "git" ]; then

> >    subdirs="$subdirs dtc"

> >  fi

> > -if [ "$capstone" = "git" -o "$capstone" = "internal" ]; then

> > -  subdirs="$subdirs capstone"

> > -fi

> >  echo "SUBDIRS=$subdirs" >> $config_host_mak

> >  if test -n "$LIBCAPSTONE"; then

> >    echo "LIBCAPSTONE=$LIBCAPSTONE" >> $config_host_mak

> > @@ -8008,7 +7960,8 @@ NINJA=${ninja:-$PWD/ninjatool} $meson setup \

> >          -Db_coverage=$(if test "$gcov" = yes; then echo true; else

echo false; fi) \
> >       -Dsdl=$sdl -Dsdl_image=$sdl_image \

> >       -Dvnc=$vnc -Dvnc_sasl=$vnc_sasl -Dvnc_jpeg=$vnc_jpeg

-Dvnc_png=$vnc_png \
> > -     -Dgettext=$gettext -Dxkbcommon=$xkbcommon -Du2f=$u2f\

> > +     -Dgettext=$gettext -Dxkbcommon=$xkbcommon -Du2f=$u2f \

> > +     -Dcapstone=$capstone \

> >          $cross_arg \

> >          "$PWD" "$source_path"

> >

> > diff --git a/Makefile b/Makefile

> > index 7c60b9dcb8..f3da1760ad 100644

> > --- a/Makefile

> > +++ b/Makefile

> > @@ -156,22 +156,6 @@ dtc/all: .git-submodule-status dtc/libfdt

> >  dtc/%: .git-submodule-status

> >       @mkdir -p $@

> >

> > -# Overriding CFLAGS causes us to lose defines added in the

sub-makefile.
> > -# Not overriding CFLAGS leads to mis-matches between compilation modes.

> > -# Therefore we replicate some of the logic in the sub-makefile.

> > -# Remove all the extra -Warning flags that QEMU uses that Capstone

doesn't;
> > -# no need to annoy QEMU developers with such things.

> > -CAP_CFLAGS = $(patsubst -W%,,$(CFLAGS) $(QEMU_CFLAGS))

$(CAPSTONE_CFLAGS)
> > -CAP_CFLAGS += -DCAPSTONE_USE_SYS_DYN_MEM

> > -CAP_CFLAGS += -DCAPSTONE_HAS_ARM

> > -CAP_CFLAGS += -DCAPSTONE_HAS_ARM64

> > -CAP_CFLAGS += -DCAPSTONE_HAS_POWERPC

> > -CAP_CFLAGS += -DCAPSTONE_HAS_X86

> > -

> > -.PHONY: capstone/all

> > -capstone/all: .git-submodule-status

> > -     $(call quiet-command,$(MAKE) -C $(SRC_PATH)/capstone

CAPSTONE_SHARED=no BUILDDIR="$(BUILD_DIR)/capstone" CC="$(CC)" AR="$(AR)"
LD="$(LD)" RANLIB="$(RANLIB)" CFLAGS="$(CAP_CFLAGS)" $(SUBDIR_MAKEFLAGS)
$(BUILD_DIR)/capstone/$(LIBCAPSTONE))
> > -

> >  .PHONY: slirp/all

> >  slirp/all: .git-submodule-status

> >       $(call quiet-command,$(MAKE) -C $(SRC_PATH)/slirp               \

> > diff --git a/meson.build b/meson.build

> > index f4d1ab1096..f23273693d 100644

> > --- a/meson.build

> > +++ b/meson.build

> > @@ -10,6 +10,7 @@ else

> >    keyval = import('unstable-keyval')

> >  endif

> >  ss = import('sourceset')

> > +fs = import('fs')

> >

> >  sh = find_program('sh')

> >  cc = meson.get_compiler('c')

> > @@ -409,11 +410,6 @@ if 'CONFIG_USB_LIBUSB' in config_host

> >    libusb = declare_dependency(compile_args:

config_host['LIBUSB_CFLAGS'].split(),
> >                                link_args:

config_host['LIBUSB_LIBS'].split())
> >  endif

> > -capstone = not_found

> > -if 'CONFIG_CAPSTONE' in config_host

> > -  capstone = declare_dependency(compile_args:

config_host['CAPSTONE_CFLAGS'].split(),
> > -                                link_args:

config_host['CAPSTONE_LIBS'].split())
> > -endif

> >  libpmem = not_found

> >  if 'CONFIG_LIBPMEM' in config_host

> >    libpmem = declare_dependency(compile_args:

config_host['LIBPMEM_CFLAGS'].split(),
> > @@ -470,7 +466,6 @@ foreach k, v: config_host

> >      config_host_data.set(k, v == 'y' ? 1 : v)

> >    endif

> >  endforeach

> > -genh += configure_file(output: 'config-host.h', configuration:

config_host_data)
> >

> >  minikconf = find_program('scripts/minikconf.py')

> >  config_all_devices = {}

> > @@ -610,6 +605,108 @@ config_all += {

> >    'CONFIG_ALL': true,

> >  }

> >

> > +# Submodules

> > +

> > +capstone = not_found

> > +capstone_opt = get_option('capstone')

> > +if capstone_opt == 'no'

> > +  capstone_opt = false

> > +elif capstone_opt in ['yes', 'auto', 'system']

> > +  have_internal = fs.exists('capstone/Makefile')

> > +  capstone = dependency('capstone', static: enable_static,

> > +                        required: capstone_opt == 'system' or

> > +                                  capstone_opt == 'yes' and not

have_internal)
> > +  if capstone.found()

> > +    capstone_opt = 'system'

> > +  elif have_internal

> > +    capstone_opt = 'internal'

> > +  else

> > +    capstone_opt = false

> > +  endif

> > +endif

> > +if capstone_opt == 'internal'

> > +  capstone_data = configuration_data()

> > +  capstone_data.set('CAPSTONE_USE_SYS_DYN_MEM', '1')

> > +

> > +  capstone_files = files(

> > +    'capstone/cs.c',

> > +    'capstone/MCInst.c',

> > +    'capstone/MCInstrDesc.c',

> > +    'capstone/MCRegisterInfo.c',

> > +    'capstone/SStream.c',

> > +    'capstone/utils.c'

> > +  )

> > +

> > +  if 'CONFIG_ARM_DIS' in config_all_disas

> > +    capstone_data.set('CAPSTONE_HAS_ARM', '1')

> > +    capstone_files += files(

> > +      'capstone/arch/ARM/ARMDisassembler.c',

> > +      'capstone/arch/ARM/ARMInstPrinter.c',

> > +      'capstone/arch/ARM/ARMMapping.c',

> > +      'capstone/arch/ARM/ARMModule.c'

> > +    )

> > +  endif

> > +

> > +  # FIXME: This config entry currently depends on a c++ compiler.

> > +  # Which is needed for building libvixl, but not for capstone.

> > +  if 'CONFIG_ARM_A64_DIS' in config_all_disas

> > +    capstone_data.set('CAPSTONE_HAS_ARM64', '1')

> > +    capstone_files += files(

> > +      'capstone/arch/AArch64/AArch64BaseInfo.c',

> > +      'capstone/arch/AArch64/AArch64Disassembler.c',

> > +      'capstone/arch/AArch64/AArch64InstPrinter.c',

> > +      'capstone/arch/AArch64/AArch64Mapping.c',

> > +      'capstone/arch/AArch64/AArch64Module.c'

> > +    )

> > +  endif

> > +

> > +  if 'CONFIG_PPC_DIS' in config_all_disas

> > +    capstone_data.set('CAPSTONE_HAS_POWERPC', '1')

> > +    capstone_files += files(

> > +      'capstone/arch/PowerPC/PPCDisassembler.c',

> > +      'capstone/arch/PowerPC/PPCInstPrinter.c',

> > +      'capstone/arch/PowerPC/PPCMapping.c',

> > +      'capstone/arch/PowerPC/PPCModule.c'

> > +    )

> > +  endif

> > +

> > +  if 'CONFIG_I386_DIS' in config_all_disas

> > +    capstone_data.set('CAPSTONE_HAS_X86', 1)

> > +    capstone_files += files(

> > +      'capstone/arch/X86/X86Disassembler.c',

> > +      'capstone/arch/X86/X86DisassemblerDecoder.c',

> > +      'capstone/arch/X86/X86ATTInstPrinter.c',

> > +      'capstone/arch/X86/X86IntelInstPrinter.c',

> > +      'capstone/arch/X86/X86Mapping.c',

> > +      'capstone/arch/X86/X86Module.c'

> > +    )

> > +  endif

> > +

> > +  configure_file(output: 'capstone-defs.h', configuration:

capstone_data)
> > +

> > +  capstone_cargs = [

> > +    # FIXME: There does not seem to be a way to completely replace the

c_args
> > +    # that come from add_project_arguments() -- we can only add to

them.
> > +    # So: disable all warnings with a big hammer.

> > +    '-Wno-error', '-w',

> > +

> > +    # Include all configuration defines via a header file, which will

wind up
> > +    # as a dependency on the object file, and thus changes here will

result
> > +    # in a rebuild.

> > +    '-include', 'capstone-defs.h'

> > +  ]

> > +

> > +  libcapstone = static_library('capstone',

> > +                               sources: capstone_files,

> > +                               c_args: capstone_cargs,

> > +                               include_directories: 'capstone/include')

> > +  capstone = declare_dependency(link_with: libcapstone,

> > +                                include_directories:

'capstone/include')
> > +endif

> > +config_host_data.set('CONFIG_CAPSTONE', capstone.found())

> > +

> > +genh += configure_file(output: 'config-host.h', configuration:

config_host_data)
> > +

> >  # Generators

> >

> >  hxtool = find_program('scripts/hxtool')

> > @@ -1512,7 +1609,7 @@ summary_info += {'vvfat support':

config_host.has_key('CONFIG_VVFAT')}
> >  summary_info += {'qed support':

config_host.has_key('CONFIG_QED')}
> >  summary_info += {'parallels support':

config_host.has_key('CONFIG_PARALLELS')}
> >  summary_info += {'sheepdog support':

 config_host.has_key('CONFIG_SHEEPDOG')}
> > -summary_info += {'capstone':

 config_host.has_key('CONFIG_CAPSTONE')}
> > +summary_info += {'capstone':          capstone_opt}

> >  summary_info += {'libpmem support':

config_host.has_key('CONFIG_LIBPMEM')}
> >  summary_info += {'libdaxctl support':

config_host.has_key('CONFIG_LIBDAXCTL')}
> >  summary_info += {'libudev':

config_host.has_key('CONFIG_LIBUDEV')}
> > diff --git a/meson_options.txt b/meson_options.txt

> > index 543cf70043..e650a937e7 100644

> > --- a/meson_options.txt

> > +++ b/meson_options.txt

> > @@ -22,3 +22,7 @@ option('vnc_sasl', type : 'feature', value : 'auto',

> >         description: 'SASL authentication for VNC server')

> >  option('xkbcommon', type : 'feature', value : 'auto',

> >         description: 'xkbcommon support')

> > +

> > +option('capstone', type: 'combo', value: 'auto',

> > +       choices: ['no', 'yes', 'auto', 'system', 'internal'],

> > +       description: 'Whether and how to find the capstone library')

> >

>

>

I also have a question that how about convert
  --disable-capstone) capstone="no"
  ;;
  --enable-capstone) capstone="yes"
  ;;
to
    --disable-capstone) capstone="disabled"
  ;;
  --enable-capstone) capstone="enabled"
  ;;

for consistence with meson
--
         此致
礼
罗勇刚
Yours
    sincerely,
Yonggang Luo
<div dir="ltr"><br><br>On Fri, Sep 18, 2020 at 4:19 PM Paolo Bonzini &lt;<a href="mailto:pbonzini@redhat.com">pbonzini@redhat.com</a>&gt; wrote:<br>&gt;<br>&gt; On 18/09/20 01:57, Richard Henderson wrote:<br>&gt; &gt; There are better ways to do this, e.g. meson cmake subproject,<br>&gt; &gt; but that requires cmake 3.7 and some of our CI environments<br>&gt; &gt; only provide cmake 3.5.<br>&gt; &gt;<br>&gt; &gt; Nor can we add a meson.build file to capstone/, because the git<br>&gt; &gt; submodule would then always report &quot;untracked files&quot;.  Fixing that<br>&gt; &gt; would require creating our own branch on the qemu git mirror, at<br>&gt; &gt; which point we could just as easily create a native meson subproject.<br>&gt; &gt;<br>&gt; &gt; Instead, build the library via the main meson.build.<br>&gt; &gt;<br>&gt; &gt; This improves the current state of affairs in that we will re-link<br>&gt; &gt; the qemu executables against a changed libcapstone.a, which we wouldn&#39;t<br>&gt; &gt; do before-hand.  In addition, the use of the configuration header file<br>&gt; &gt; instead of command-line -DEFINES means that we will rebuild the<br>&gt; &gt; capstone objects with changes to meson.build.<br>&gt; &gt;<br>&gt; &gt; Signed-off-by: Richard Henderson &lt;<a href="mailto:richard.henderson@linaro.org">richard.henderson@linaro.org</a>&gt;<br>&gt; &gt; ---<br>&gt; &gt; Cc: Paolo Bonzini &lt;<a href="mailto:pbonzini@redhat.com">pbonzini@redhat.com</a>&gt;<br>&gt; &gt; v2: Further reduce probing in configure (paolo),<br>&gt; &gt;     Drop state &#39;internal&#39; and use &#39;git&#39; even when it isn&#39;t git.<br>&gt; &gt;     Move CONFIG_CAPSTONE to config_host_data.<br>&gt; &gt; v3: Add Submodules separator; fix default in meson_options.txt.<br>&gt; &gt; ---<br>&gt;<br>&gt; Acked-by: Paolo Bonzini &lt;<a href="mailto:pbonzini@redhat.com">pbonzini@redhat.com</a>&gt;<br>&gt;<br>&gt; Thanks!  That&#39;s also a nice blueprint if anyone wants to do the same on<br>&gt; libfdt.<br>&gt;<br>&gt; Paolo<br>&gt;<br>&gt;<br>&gt; &gt;  configure         |  61 +++----------------------<br>&gt; &gt;  Makefile          |  16 -------<br>&gt; &gt;  meson.build       | 111 +++++++++++++++++++++++++++++++++++++++++++---<br>&gt; &gt;  meson_options.txt |   4 ++<br>&gt; &gt;  4 files changed, 115 insertions(+), 77 deletions(-)<br>&gt; &gt;<br>&gt; &gt; diff --git a/configure b/configure<br>&gt; &gt; index 7564479008..76636c430d 100755<br>&gt; &gt; --- a/configure<br>&gt; &gt; +++ b/configure<br>&gt; &gt; @@ -478,7 +478,7 @@ opengl=&quot;&quot;<br>&gt; &gt;  opengl_dmabuf=&quot;no&quot;<br>&gt; &gt;  cpuid_h=&quot;no&quot;<br>&gt; &gt;  avx2_opt=&quot;&quot;<br>&gt; &gt; -capstone=&quot;&quot;<br>&gt; &gt; +capstone=&quot;auto&quot;<br>&gt; &gt;  lzo=&quot;&quot;<br>&gt; &gt;  snappy=&quot;&quot;<br>&gt; &gt;  bzip2=&quot;&quot;<br>&gt; &gt; @@ -1580,7 +1580,7 @@ for opt do<br>&gt; &gt;    ;;<br>&gt; &gt;    --enable-capstone) capstone=&quot;yes&quot;<br>&gt; &gt;    ;;<br>&gt; &gt; -  --enable-capstone=git) capstone=&quot;git&quot;<br>&gt; &gt; +  --enable-capstone=git) capstone=&quot;internal&quot;<br>&gt; &gt;    ;;<br>&gt; &gt;    --enable-capstone=system) capstone=&quot;system&quot;<br>&gt; &gt;    ;;<br>&gt; &gt; @@ -5128,51 +5128,11 @@ fi<br>&gt; &gt;  # capstone<br>&gt; &gt; <br>&gt; &gt;  case &quot;$capstone&quot; in<br>&gt; &gt; -  &quot;&quot; | yes)<br>&gt; &gt; -    if $pkg_config capstone; then<br>&gt; &gt; -      capstone=system<br>&gt; &gt; -    elif test -e &quot;${source_path}/.git&quot; &amp;&amp; test $git_update = &#39;yes&#39; ; then<br>&gt; &gt; -      capstone=git<br>&gt; &gt; -    elif test -e &quot;${source_path}/capstone/Makefile&quot; ; then<br>&gt; &gt; -      capstone=internal<br>&gt; &gt; -    elif test -z &quot;$capstone&quot; ; then<br>&gt; &gt; -      capstone=no<br>&gt; &gt; -    else<br>&gt; &gt; -      feature_not_found &quot;capstone&quot; &quot;Install capstone devel or git submodule&quot;<br>&gt; &gt; -    fi<br>&gt; &gt; -    ;;<br>&gt; &gt; -<br>&gt; &gt; -  system)<br>&gt; &gt; -    if ! $pkg_config capstone; then<br>&gt; &gt; -      feature_not_found &quot;capstone&quot; &quot;Install capstone devel&quot;<br>&gt; &gt; -    fi<br>&gt; &gt; -    ;;<br>&gt; &gt; -esac<br>&gt; &gt; -<br>&gt; &gt; -case &quot;$capstone&quot; in<br>&gt; &gt; -  git | internal)<br>&gt; &gt; -    if test &quot;$capstone&quot; = git; then<br>&gt; &gt; +  auto | yes | internal)<br>&gt; &gt; +    # Simpler to always update submodule, even if not needed.<br>&gt; &gt; +    if test -e &quot;${source_path}/.git&quot; &amp;&amp; test $git_update = &#39;yes&#39; ; then<br>&gt; &gt;        git_submodules=&quot;${git_submodules} capstone&quot;<br>&gt; &gt;      fi<br>&gt; &gt; -    mkdir -p capstone<br>&gt; &gt; -    if test &quot;$mingw32&quot; = &quot;yes&quot;; then<br>&gt; &gt; -      LIBCAPSTONE=capstone.lib<br>&gt; &gt; -    else<br>&gt; &gt; -      LIBCAPSTONE=libcapstone.a<br>&gt; &gt; -    fi<br>&gt; &gt; -    capstone_libs=&quot;-Lcapstone -lcapstone&quot;<br>&gt; &gt; -    capstone_cflags=&quot;-I${source_path}/capstone/include&quot;<br>&gt; &gt; -    ;;<br>&gt; &gt; -<br>&gt; &gt; -  system)<br>&gt; &gt; -    capstone_libs=&quot;$($pkg_config --libs capstone)&quot;<br>&gt; &gt; -    capstone_cflags=&quot;$($pkg_config --cflags capstone)&quot;<br>&gt; &gt; -    ;;<br>&gt; &gt; -<br>&gt; &gt; -  no)<br>&gt; &gt; -    ;;<br>&gt; &gt; -  *)<br>&gt; &gt; -    error_exit &quot;Unknown state for capstone: $capstone&quot;<br>&gt; &gt;      ;;<br>&gt; &gt;  esac<br>&gt; &gt; <br>&gt; &gt; @@ -7292,11 +7252,6 @@ fi<br>&gt; &gt;  if test &quot;$ivshmem&quot; = &quot;yes&quot; ; then<br>&gt; &gt;    echo &quot;CONFIG_IVSHMEM=y&quot; &gt;&gt; $config_host_mak<br>&gt; &gt;  fi<br>&gt; &gt; -if test &quot;$capstone&quot; != &quot;no&quot; ; then<br>&gt; &gt; -  echo &quot;CONFIG_CAPSTONE=y&quot; &gt;&gt; $config_host_mak<br>&gt; &gt; -  echo &quot;CAPSTONE_CFLAGS=$capstone_cflags&quot; &gt;&gt; $config_host_mak<br>&gt; &gt; -  echo &quot;CAPSTONE_LIBS=$capstone_libs&quot; &gt;&gt; $config_host_mak<br>&gt; &gt; -fi<br>&gt; &gt;  if test &quot;$debug_mutex&quot; = &quot;yes&quot; ; then<br>&gt; &gt;    echo &quot;CONFIG_DEBUG_MUTEX=y&quot; &gt;&gt; $config_host_mak<br>&gt; &gt;  fi<br>&gt; &gt; @@ -7819,9 +7774,6 @@ done # for target in $targets<br>&gt; &gt;  if [ &quot;$fdt&quot; = &quot;git&quot; ]; then<br>&gt; &gt;    subdirs=&quot;$subdirs dtc&quot;<br>&gt; &gt;  fi<br>&gt; &gt; -if [ &quot;$capstone&quot; = &quot;git&quot; -o &quot;$capstone&quot; = &quot;internal&quot; ]; then<br>&gt; &gt; -  subdirs=&quot;$subdirs capstone&quot;<br>&gt; &gt; -fi<br>&gt; &gt;  echo &quot;SUBDIRS=$subdirs&quot; &gt;&gt; $config_host_mak<br>&gt; &gt;  if test -n &quot;$LIBCAPSTONE&quot;; then<br>&gt; &gt;    echo &quot;LIBCAPSTONE=$LIBCAPSTONE&quot; &gt;&gt; $config_host_mak<br>&gt; &gt; @@ -8008,7 +7960,8 @@ NINJA=${ninja:-$PWD/ninjatool} $meson setup \<br>&gt; &gt;          -Db_coverage=$(if test &quot;$gcov&quot; = yes; then echo true; else echo false; fi) \<br>&gt; &gt;       -Dsdl=$sdl -Dsdl_image=$sdl_image \<br>&gt; &gt;       -Dvnc=$vnc -Dvnc_sasl=$vnc_sasl -Dvnc_jpeg=$vnc_jpeg -Dvnc_png=$vnc_png \<br>&gt; &gt; -     -Dgettext=$gettext -Dxkbcommon=$xkbcommon -Du2f=$u2f\<br>&gt; &gt; +     -Dgettext=$gettext -Dxkbcommon=$xkbcommon -Du2f=$u2f \<br>&gt; &gt; +     -Dcapstone=$capstone \<br>&gt; &gt;          $cross_arg \<br>&gt; &gt;          &quot;$PWD&quot; &quot;$source_path&quot;<br>&gt; &gt; <br>&gt; &gt; diff --git a/Makefile b/Makefile<br>&gt; &gt; index 7c60b9dcb8..f3da1760ad 100644<br>&gt; &gt; --- a/Makefile<br>&gt; &gt; +++ b/Makefile<br>&gt; &gt; @@ -156,22 +156,6 @@ dtc/all: .git-submodule-status dtc/libfdt<br>&gt; &gt;  dtc/%: .git-submodule-status<br>&gt; &gt;       @mkdir -p $@<br>&gt; &gt; <br>&gt; &gt; -# Overriding CFLAGS causes us to lose defines added in the sub-makefile.<br>&gt; &gt; -# Not overriding CFLAGS leads to mis-matches between compilation modes.<br>&gt; &gt; -# Therefore we replicate some of the logic in the sub-makefile.<br>&gt; &gt; -# Remove all the extra -Warning flags that QEMU uses that Capstone doesn&#39;t;<br>&gt; &gt; -# no need to annoy QEMU developers with such things.<br>&gt; &gt; -CAP_CFLAGS = $(patsubst -W%,,$(CFLAGS) $(QEMU_CFLAGS)) $(CAPSTONE_CFLAGS)<br>&gt; &gt; -CAP_CFLAGS += -DCAPSTONE_USE_SYS_DYN_MEM<br>&gt; &gt; -CAP_CFLAGS += -DCAPSTONE_HAS_ARM<br>&gt; &gt; -CAP_CFLAGS += -DCAPSTONE_HAS_ARM64<br>&gt; &gt; -CAP_CFLAGS += -DCAPSTONE_HAS_POWERPC<br>&gt; &gt; -CAP_CFLAGS += -DCAPSTONE_HAS_X86<br>&gt; &gt; -<br>&gt; &gt; -.PHONY: capstone/all<br>&gt; &gt; -capstone/all: .git-submodule-status<br>&gt; &gt; -     $(call quiet-command,$(MAKE) -C $(SRC_PATH)/capstone CAPSTONE_SHARED=no BUILDDIR=&quot;$(BUILD_DIR)/capstone&quot; CC=&quot;$(CC)&quot; AR=&quot;$(AR)&quot; LD=&quot;$(LD)&quot; RANLIB=&quot;$(RANLIB)&quot; CFLAGS=&quot;$(CAP_CFLAGS)&quot; $(SUBDIR_MAKEFLAGS) $(BUILD_DIR)/capstone/$(LIBCAPSTONE))<br>&gt; &gt; -<br>&gt; &gt;  .PHONY: slirp/all<br>&gt; &gt;  slirp/all: .git-submodule-status<br>&gt; &gt;       $(call quiet-command,$(MAKE) -C $(SRC_PATH)/slirp               \<br>&gt; &gt; diff --git a/meson.build b/meson.build<br>&gt; &gt; index f4d1ab1096..f23273693d 100644<br>&gt; &gt; --- a/meson.build<br>&gt; &gt; +++ b/meson.build<br>&gt; &gt; @@ -10,6 +10,7 @@ else<br>&gt; &gt;    keyval = import(&#39;unstable-keyval&#39;)<br>&gt; &gt;  endif<br>&gt; &gt;  ss = import(&#39;sourceset&#39;)<br>&gt; &gt; +fs = import(&#39;fs&#39;)<br>&gt; &gt; <br>&gt; &gt;  sh = find_program(&#39;sh&#39;)<br>&gt; &gt;  cc = meson.get_compiler(&#39;c&#39;)<br>&gt; &gt; @@ -409,11 +410,6 @@ if &#39;CONFIG_USB_LIBUSB&#39; in config_host<br>&gt; &gt;    libusb = declare_dependency(compile_args: config_host[&#39;LIBUSB_CFLAGS&#39;].split(),<br>&gt; &gt;                                link_args: config_host[&#39;LIBUSB_LIBS&#39;].split())<br>&gt; &gt;  endif<br>&gt; &gt; -capstone = not_found<br>&gt; &gt; -if &#39;CONFIG_CAPSTONE&#39; in config_host<br>&gt; &gt; -  capstone = declare_dependency(compile_args: config_host[&#39;CAPSTONE_CFLAGS&#39;].split(),<br>&gt; &gt; -                                link_args: config_host[&#39;CAPSTONE_LIBS&#39;].split())<br>&gt; &gt; -endif<br>&gt; &gt;  libpmem = not_found<br>&gt; &gt;  if &#39;CONFIG_LIBPMEM&#39; in config_host<br>&gt; &gt;    libpmem = declare_dependency(compile_args: config_host[&#39;LIBPMEM_CFLAGS&#39;].split(),<br>&gt; &gt; @@ -470,7 +466,6 @@ foreach k, v: config_host<br>&gt; &gt;      config_host_data.set(k, v == &#39;y&#39; ? 1 : v)<br>&gt; &gt;    endif<br>&gt; &gt;  endforeach<br>&gt; &gt; -genh += configure_file(output: &#39;config-host.h&#39;, configuration: config_host_data)<br>&gt; &gt; <br>&gt; &gt;  minikconf = find_program(&#39;scripts/minikconf.py&#39;)<br>&gt; &gt;  config_all_devices = {}<br>&gt; &gt; @@ -610,6 +605,108 @@ config_all += {<br>&gt; &gt;    &#39;CONFIG_ALL&#39;: true,<br>&gt; &gt;  }<br>&gt; &gt; <br>&gt; &gt; +# Submodules<br>&gt; &gt; +<br>&gt; &gt; +capstone = not_found<br>&gt; &gt; +capstone_opt = get_option(&#39;capstone&#39;)<br>&gt; &gt; +if capstone_opt == &#39;no&#39;<br>&gt; &gt; +  capstone_opt = false<br>&gt; &gt; +elif capstone_opt in [&#39;yes&#39;, &#39;auto&#39;, &#39;system&#39;]<br>&gt; &gt; +  have_internal = fs.exists(&#39;capstone/Makefile&#39;)<br>&gt; &gt; +  capstone = dependency(&#39;capstone&#39;, static: enable_static,<br>&gt; &gt; +                        required: capstone_opt == &#39;system&#39; or<br>&gt; &gt; +                                  capstone_opt == &#39;yes&#39; and not have_internal)<br>&gt; &gt; +  if capstone.found()<br>&gt; &gt; +    capstone_opt = &#39;system&#39;<br>&gt; &gt; +  elif have_internal<br>&gt; &gt; +    capstone_opt = &#39;internal&#39;<br>&gt; &gt; +  else<br>&gt; &gt; +    capstone_opt = false<br>&gt; &gt; +  endif<br>&gt; &gt; +endif<br>&gt; &gt; +if capstone_opt == &#39;internal&#39;<br>&gt; &gt; +  capstone_data = configuration_data()<br>&gt; &gt; +  capstone_data.set(&#39;CAPSTONE_USE_SYS_DYN_MEM&#39;, &#39;1&#39;)<br>&gt; &gt; +<br>&gt; &gt; +  capstone_files = files(<br>&gt; &gt; +    &#39;capstone/cs.c&#39;,<br>&gt; &gt; +    &#39;capstone/MCInst.c&#39;,<br>&gt; &gt; +    &#39;capstone/MCInstrDesc.c&#39;,<br>&gt; &gt; +    &#39;capstone/MCRegisterInfo.c&#39;,<br>&gt; &gt; +    &#39;capstone/SStream.c&#39;,<br>&gt; &gt; +    &#39;capstone/utils.c&#39;<br>&gt; &gt; +  )<br>&gt; &gt; +<br>&gt; &gt; +  if &#39;CONFIG_ARM_DIS&#39; in config_all_disas<br>&gt; &gt; +    capstone_data.set(&#39;CAPSTONE_HAS_ARM&#39;, &#39;1&#39;)<br>&gt; &gt; +    capstone_files += files(<br>&gt; &gt; +      &#39;capstone/arch/ARM/ARMDisassembler.c&#39;,<br>&gt; &gt; +      &#39;capstone/arch/ARM/ARMInstPrinter.c&#39;,<br>&gt; &gt; +      &#39;capstone/arch/ARM/ARMMapping.c&#39;,<br>&gt; &gt; +      &#39;capstone/arch/ARM/ARMModule.c&#39;<br>&gt; &gt; +    )<br>&gt; &gt; +  endif<br>&gt; &gt; +<br>&gt; &gt; +  # FIXME: This config entry currently depends on a c++ compiler.<br>&gt; &gt; +  # Which is needed for building libvixl, but not for capstone.<br>&gt; &gt; +  if &#39;CONFIG_ARM_A64_DIS&#39; in config_all_disas<br>&gt; &gt; +    capstone_data.set(&#39;CAPSTONE_HAS_ARM64&#39;, &#39;1&#39;)<br>&gt; &gt; +    capstone_files += files(<br>&gt; &gt; +      &#39;capstone/arch/AArch64/AArch64BaseInfo.c&#39;,<br>&gt; &gt; +      &#39;capstone/arch/AArch64/AArch64Disassembler.c&#39;,<br>&gt; &gt; +      &#39;capstone/arch/AArch64/AArch64InstPrinter.c&#39;,<br>&gt; &gt; +      &#39;capstone/arch/AArch64/AArch64Mapping.c&#39;,<br>&gt; &gt; +      &#39;capstone/arch/AArch64/AArch64Module.c&#39;<br>&gt; &gt; +    )<br>&gt; &gt; +  endif<br>&gt; &gt; +<br>&gt; &gt; +  if &#39;CONFIG_PPC_DIS&#39; in config_all_disas<br>&gt; &gt; +    capstone_data.set(&#39;CAPSTONE_HAS_POWERPC&#39;, &#39;1&#39;)<br>&gt; &gt; +    capstone_files += files(<br>&gt; &gt; +      &#39;capstone/arch/PowerPC/PPCDisassembler.c&#39;,<br>&gt; &gt; +      &#39;capstone/arch/PowerPC/PPCInstPrinter.c&#39;,<br>&gt; &gt; +      &#39;capstone/arch/PowerPC/PPCMapping.c&#39;,<br>&gt; &gt; +      &#39;capstone/arch/PowerPC/PPCModule.c&#39;<br>&gt; &gt; +    )<br>&gt; &gt; +  endif<br>&gt; &gt; +<br>&gt; &gt; +  if &#39;CONFIG_I386_DIS&#39; in config_all_disas<br>&gt; &gt; +    capstone_data.set(&#39;CAPSTONE_HAS_X86&#39;, 1)<br>&gt; &gt; +    capstone_files += files(<br>&gt; &gt; +      &#39;capstone/arch/X86/X86Disassembler.c&#39;,<br>&gt; &gt; +      &#39;capstone/arch/X86/X86DisassemblerDecoder.c&#39;,<br>&gt; &gt; +      &#39;capstone/arch/X86/X86ATTInstPrinter.c&#39;,<br>&gt; &gt; +      &#39;capstone/arch/X86/X86IntelInstPrinter.c&#39;,<br>&gt; &gt; +      &#39;capstone/arch/X86/X86Mapping.c&#39;,<br>&gt; &gt; +      &#39;capstone/arch/X86/X86Module.c&#39;<br>&gt; &gt; +    )<br>&gt; &gt; +  endif<br>&gt; &gt; +<br>&gt; &gt; +  configure_file(output: &#39;capstone-defs.h&#39;, configuration: capstone_data)<br>&gt; &gt; +<br>&gt; &gt; +  capstone_cargs = [<br>&gt; &gt; +    # FIXME: There does not seem to be a way to completely replace the c_args<br>&gt; &gt; +    # that come from add_project_arguments() -- we can only add to them.<br>&gt; &gt; +    # So: disable all warnings with a big hammer.<br>&gt; &gt; +    &#39;-Wno-error&#39;, &#39;-w&#39;,<br>&gt; &gt; +<br>&gt; &gt; +    # Include all configuration defines via a header file, which will wind up<br>&gt; &gt; +    # as a dependency on the object file, and thus changes here will result<br>&gt; &gt; +    # in a rebuild.<br>&gt; &gt; +    &#39;-include&#39;, &#39;capstone-defs.h&#39;<br>&gt; &gt; +  ]<br>&gt; &gt; +<br>&gt; &gt; +  libcapstone = static_library(&#39;capstone&#39;,<br>&gt; &gt; +                               sources: capstone_files,<br>&gt; &gt; +                               c_args: capstone_cargs,<br>&gt; &gt; +                               include_directories: &#39;capstone/include&#39;)<br>&gt; &gt; +  capstone = declare_dependency(link_with: libcapstone,<br>&gt; &gt; +                                include_directories: &#39;capstone/include&#39;)<br>&gt; &gt; +endif<br>&gt; &gt; +config_host_data.set(&#39;CONFIG_CAPSTONE&#39;, capstone.found())<br>&gt; &gt; +<br>&gt; &gt; +genh += configure_file(output: &#39;config-host.h&#39;, configuration: config_host_data)<br>&gt; &gt; +<br>&gt; &gt;  # Generators<br>&gt; &gt; <br>&gt; &gt;  hxtool = find_program(&#39;scripts/hxtool&#39;)<br>&gt; &gt; @@ -1512,7 +1609,7 @@ summary_info += {&#39;vvfat support&#39;:     config_host.has_key(&#39;CONFIG_VVFAT&#39;)}<br>&gt; &gt;  summary_info += {&#39;qed support&#39;:       config_host.has_key(&#39;CONFIG_QED&#39;)}<br>&gt; &gt;  summary_info += {&#39;parallels support&#39;: config_host.has_key(&#39;CONFIG_PARALLELS&#39;)}<br>&gt; &gt;  summary_info += {&#39;sheepdog support&#39;:  config_host.has_key(&#39;CONFIG_SHEEPDOG&#39;)}<br>&gt; &gt; -summary_info += {&#39;capstone&#39;:          config_host.has_key(&#39;CONFIG_CAPSTONE&#39;)}<br>&gt; &gt; +summary_info += {&#39;capstone&#39;:          capstone_opt}<br>&gt; &gt;  summary_info += {&#39;libpmem support&#39;:   config_host.has_key(&#39;CONFIG_LIBPMEM&#39;)}<br>&gt; &gt;  summary_info += {&#39;libdaxctl support&#39;: config_host.has_key(&#39;CONFIG_LIBDAXCTL&#39;)}<br>&gt; &gt;  summary_info += {&#39;libudev&#39;:           config_host.has_key(&#39;CONFIG_LIBUDEV&#39;)}<br>&gt; &gt; diff --git a/meson_options.txt b/meson_options.txt<br>&gt; &gt; index 543cf70043..e650a937e7 100644<br>&gt; &gt; --- a/meson_options.txt<br>&gt; &gt; +++ b/meson_options.txt<br>&gt; &gt; @@ -22,3 +22,7 @@ option(&#39;vnc_sasl&#39;, type : &#39;feature&#39;, value : &#39;auto&#39;,<br>&gt; &gt;         description: &#39;SASL authentication for VNC server&#39;)<br>&gt; &gt;  option(&#39;xkbcommon&#39;, type : &#39;feature&#39;, value : &#39;auto&#39;,<br>&gt; &gt;         description: &#39;xkbcommon support&#39;)<br>&gt; &gt; +<br>&gt; &gt; +option(&#39;capstone&#39;, type: &#39;combo&#39;, value: &#39;auto&#39;,<br>&gt; &gt; +       choices: [&#39;no&#39;, &#39;yes&#39;, &#39;auto&#39;, &#39;system&#39;, &#39;internal&#39;],<br>&gt; &gt; +       description: &#39;Whether and how to find the capstone library&#39;)<br>&gt; &gt;<br>&gt;<br>&gt;<div>I also have a question that how about convert</div><div>  --disable-capstone) capstone=&quot;no&quot;<br>  ;;<br>  --enable-capstone) capstone=&quot;yes&quot;<br>  ;;</div><div>to </div><div>    --disable-capstone) capstone=&quot;disabled&quot;<br>  ;;<br>  --enable-capstone) capstone=&quot;enabled&quot;<br>  ;;</div><div><br></div><div>for consistence with meson<br>--<br>         此致<br>礼<br>罗勇刚<br>Yours<br>    sincerely,<br>Yonggang Luo</div></div>
Paolo Bonzini Sept. 18, 2020, 12:58 p.m. UTC | #4
On 18/09/20 10:42, 罗勇刚(Yonggang Luo) wrote:
> I also have a question that how about convert

>   --disable-capstone) capstone="no"

>   ;;

>   --enable-capstone) capstone="yes"

>   ;;

> to 

>     --disable-capstone) capstone="disabled"

>   ;;

>   --enable-capstone) capstone="enabled"

>   ;;

> 

> for consistence with meson


We can do it but it need not hold this series IMHO.

Paolo
罗勇刚(Yonggang Luo) Sept. 18, 2020, 1:02 p.m. UTC | #5
On Fri, Sep 18, 2020 at 8:58 PM Paolo Bonzini <pbonzini@redhat.com> wrote:
>

> On 18/09/20 10:42, 罗勇刚(Yonggang Luo) wrote:

> > I also have a question that how about convert

> >   --disable-capstone) capstone="no"

> >   ;;

> >   --enable-capstone) capstone="yes"

> >   ;;

> > to

> >     --disable-capstone) capstone="disabled"

> >   ;;

> >   --enable-capstone) capstone="enabled"

> >   ;;

> >

> > for consistence with meson

>

> We can do it but it need not hold this series IMHO.

Fine with that, I am trying to convert iconv and curses from configure to
meson
waiting for this series.
>

> Paolo

>



--
         此致
礼
罗勇刚
Yours
    sincerely,
Yonggang Luo
<div dir="ltr"><br><br>On Fri, Sep 18, 2020 at 8:58 PM Paolo Bonzini &lt;<a href="mailto:pbonzini@redhat.com">pbonzini@redhat.com</a>&gt; wrote:<br>&gt;<br>&gt; On 18/09/20 10:42, 罗勇刚(Yonggang Luo) wrote:<br>&gt; &gt; I also have a question that how about convert<br>&gt; &gt;   --disable-capstone) capstone=&quot;no&quot;<br>&gt; &gt;   ;;<br>&gt; &gt;   --enable-capstone) capstone=&quot;yes&quot;<br>&gt; &gt;   ;;<br>&gt; &gt; to <br>&gt; &gt;     --disable-capstone) capstone=&quot;disabled&quot;<br>&gt; &gt;   ;;<br>&gt; &gt;   --enable-capstone) capstone=&quot;enabled&quot;<br>&gt; &gt;   ;;<br>&gt; &gt;<br>&gt; &gt; for consistence with meson<br>&gt;<br>&gt; We can do it but it need not hold this series IMHO.<div>Fine with that, I am trying to convert iconv and curses from configure to meson</div><div>waiting for this series.<br>&gt;<br>&gt; Paolo<br>&gt;<br><br><br>--<br>         此致<br>礼<br>罗勇刚<br>Yours<br>    sincerely,<br>Yonggang Luo</div></div>
Alex Bennée Sept. 21, 2020, 10:54 a.m. UTC | #6
Richard Henderson <richard.henderson@linaro.org> writes:

> There are better ways to do this, e.g. meson cmake subproject,

> but that requires cmake 3.7 and some of our CI environments

> only provide cmake 3.5.

>

> Nor can we add a meson.build file to capstone/, because the git

> submodule would then always report "untracked files".  Fixing that

> would require creating our own branch on the qemu git mirror, at

> which point we could just as easily create a native meson subproject.

>

> Instead, build the library via the main meson.build.

>

> This improves the current state of affairs in that we will re-link

> the qemu executables against a changed libcapstone.a, which we wouldn't

> do before-hand.  In addition, the use of the configuration header file

> instead of command-line -DEFINES means that we will rebuild the

> capstone objects with changes to meson.build.


Something is breaking when switching to a branch with this on from
current master:

  Linking target qemu-hppa
  /usr/bin/ld: libcommon.fa.p/disas_alpha.c.o: in function `print_insn_alpha':
  /home/alex/lsrc/qemu.git/builds/all/../../disas/alpha.c:1818: undefined reference to `bfd_getl32'
  collect2: error: ld returned 1 exit status
  make: *** [Makefile.ninja:5965: qemu-alpha] Error 1
  make: *** Waiting for unfinished jobs....
  /usr/bin/ld: libcommon.fa.p/disas_hppa.c.o: in function `print_insn_hppa':
  /home/alex/lsrc/qemu.git/builds/all/../../disas/hppa.c:1969: undefined reference to `bfd_getb32'
  collect2: error: ld returned 1 exit status
  make: *** [Makefile.ninja:6259: qemu-hppa] Error 1

Aggressively wiping out the submodule and doing a fresh configure in a
empty build directory and I still see a failure:

  ../../disas/capstone.c:25:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘cap_skipdata_s390x_cb’
   cap_skipdata_s390x_cb(const uint8_t *code, size_t code_size,
   ^~~~~~~~~~~~~~~~~~~~~
  ../../disas/capstone.c:49:17: error: ‘cap_skipdata_s390x_cb’ undeclared here (not in a function); did you mean ‘cap_skipdata_s390x’?
       .callback = cap_skipdata_s390x_cb
                   ^~~~~~~~~~~~~~~~~~~~~
                   cap_skipdata_s390x
  Makefile.ninja:1424: recipe for target 'libcommon.fa.p/disas_capstone.c.o' failed
  make: *** [libcommon.fa.p/disas_capstone.c.o] Error 1
  make: *** Waiting for unfinished jobs....

>

> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>

> ---

> Cc: Paolo Bonzini <pbonzini@redhat.com>

> v2: Further reduce probing in configure (paolo),

>     Drop state 'internal' and use 'git' even when it isn't git.

>     Move CONFIG_CAPSTONE to config_host_data.

> v3: Add Submodules separator; fix default in meson_options.txt.

> ---

>  configure         |  61 +++----------------------

>  Makefile          |  16 -------

>  meson.build       | 111 +++++++++++++++++++++++++++++++++++++++++++---

>  meson_options.txt |   4 ++

>  4 files changed, 115 insertions(+), 77 deletions(-)

>

> diff --git a/configure b/configure

> index 7564479008..76636c430d 100755

> --- a/configure

> +++ b/configure

> @@ -478,7 +478,7 @@ opengl=""

>  opengl_dmabuf="no"

>  cpuid_h="no"

>  avx2_opt=""

> -capstone=""

> +capstone="auto"

>  lzo=""

>  snappy=""

>  bzip2=""

> @@ -1580,7 +1580,7 @@ for opt do

>    ;;

>    --enable-capstone) capstone="yes"

>    ;;

> -  --enable-capstone=git) capstone="git"

> +  --enable-capstone=git) capstone="internal"

>    ;;

>    --enable-capstone=system) capstone="system"

>    ;;

> @@ -5128,51 +5128,11 @@ fi

>  # capstone

>  

>  case "$capstone" in

> -  "" | yes)

> -    if $pkg_config capstone; then

> -      capstone=system

> -    elif test -e "${source_path}/.git" && test $git_update = 'yes' ; then

> -      capstone=git

> -    elif test -e "${source_path}/capstone/Makefile" ; then

> -      capstone=internal

> -    elif test -z "$capstone" ; then

> -      capstone=no

> -    else

> -      feature_not_found "capstone" "Install capstone devel or git submodule"

> -    fi

> -    ;;

> -

> -  system)

> -    if ! $pkg_config capstone; then

> -      feature_not_found "capstone" "Install capstone devel"

> -    fi

> -    ;;

> -esac

> -

> -case "$capstone" in

> -  git | internal)

> -    if test "$capstone" = git; then

> +  auto | yes | internal)

> +    # Simpler to always update submodule, even if not needed.

> +    if test -e "${source_path}/.git" && test $git_update = 'yes' ; then

>        git_submodules="${git_submodules} capstone"

>      fi

> -    mkdir -p capstone

> -    if test "$mingw32" = "yes"; then

> -      LIBCAPSTONE=capstone.lib

> -    else

> -      LIBCAPSTONE=libcapstone.a

> -    fi

> -    capstone_libs="-Lcapstone -lcapstone"

> -    capstone_cflags="-I${source_path}/capstone/include"

> -    ;;

> -

> -  system)

> -    capstone_libs="$($pkg_config --libs capstone)"

> -    capstone_cflags="$($pkg_config --cflags capstone)"

> -    ;;

> -

> -  no)

> -    ;;

> -  *)

> -    error_exit "Unknown state for capstone: $capstone"

>      ;;

>  esac

>  

> @@ -7292,11 +7252,6 @@ fi

>  if test "$ivshmem" = "yes" ; then

>    echo "CONFIG_IVSHMEM=y" >> $config_host_mak

>  fi

> -if test "$capstone" != "no" ; then

> -  echo "CONFIG_CAPSTONE=y" >> $config_host_mak

> -  echo "CAPSTONE_CFLAGS=$capstone_cflags" >> $config_host_mak

> -  echo "CAPSTONE_LIBS=$capstone_libs" >> $config_host_mak

> -fi

>  if test "$debug_mutex" = "yes" ; then

>    echo "CONFIG_DEBUG_MUTEX=y" >> $config_host_mak

>  fi

> @@ -7819,9 +7774,6 @@ done # for target in $targets

>  if [ "$fdt" = "git" ]; then

>    subdirs="$subdirs dtc"

>  fi

> -if [ "$capstone" = "git" -o "$capstone" = "internal" ]; then

> -  subdirs="$subdirs capstone"

> -fi

>  echo "SUBDIRS=$subdirs" >> $config_host_mak

>  if test -n "$LIBCAPSTONE"; then

>    echo "LIBCAPSTONE=$LIBCAPSTONE" >> $config_host_mak

> @@ -8008,7 +7960,8 @@ NINJA=${ninja:-$PWD/ninjatool} $meson setup \

>          -Db_coverage=$(if test "$gcov" = yes; then echo true; else echo false; fi) \

>  	-Dsdl=$sdl -Dsdl_image=$sdl_image \

>  	-Dvnc=$vnc -Dvnc_sasl=$vnc_sasl -Dvnc_jpeg=$vnc_jpeg -Dvnc_png=$vnc_png \

> -	-Dgettext=$gettext -Dxkbcommon=$xkbcommon -Du2f=$u2f\

> +	-Dgettext=$gettext -Dxkbcommon=$xkbcommon -Du2f=$u2f \

> +	-Dcapstone=$capstone \

>          $cross_arg \

>          "$PWD" "$source_path"

>  

> diff --git a/Makefile b/Makefile

> index 7c60b9dcb8..f3da1760ad 100644

> --- a/Makefile

> +++ b/Makefile

> @@ -156,22 +156,6 @@ dtc/all: .git-submodule-status dtc/libfdt

>  dtc/%: .git-submodule-status

>  	@mkdir -p $@

>  

> -# Overriding CFLAGS causes us to lose defines added in the sub-makefile.

> -# Not overriding CFLAGS leads to mis-matches between compilation modes.

> -# Therefore we replicate some of the logic in the sub-makefile.

> -# Remove all the extra -Warning flags that QEMU uses that Capstone doesn't;

> -# no need to annoy QEMU developers with such things.

> -CAP_CFLAGS = $(patsubst -W%,,$(CFLAGS) $(QEMU_CFLAGS)) $(CAPSTONE_CFLAGS)

> -CAP_CFLAGS += -DCAPSTONE_USE_SYS_DYN_MEM

> -CAP_CFLAGS += -DCAPSTONE_HAS_ARM

> -CAP_CFLAGS += -DCAPSTONE_HAS_ARM64

> -CAP_CFLAGS += -DCAPSTONE_HAS_POWERPC

> -CAP_CFLAGS += -DCAPSTONE_HAS_X86

> -

> -.PHONY: capstone/all

> -capstone/all: .git-submodule-status

> -	$(call quiet-command,$(MAKE) -C $(SRC_PATH)/capstone CAPSTONE_SHARED=no BUILDDIR="$(BUILD_DIR)/capstone" CC="$(CC)" AR="$(AR)" LD="$(LD)" RANLIB="$(RANLIB)" CFLAGS="$(CAP_CFLAGS)" $(SUBDIR_MAKEFLAGS) $(BUILD_DIR)/capstone/$(LIBCAPSTONE))

> -

>  .PHONY: slirp/all

>  slirp/all: .git-submodule-status

>  	$(call quiet-command,$(MAKE) -C $(SRC_PATH)/slirp		\

> diff --git a/meson.build b/meson.build

> index f4d1ab1096..f23273693d 100644

> --- a/meson.build

> +++ b/meson.build

> @@ -10,6 +10,7 @@ else

>    keyval = import('unstable-keyval')

>  endif

>  ss = import('sourceset')

> +fs = import('fs')

>  

>  sh = find_program('sh')

>  cc = meson.get_compiler('c')

> @@ -409,11 +410,6 @@ if 'CONFIG_USB_LIBUSB' in config_host

>    libusb = declare_dependency(compile_args: config_host['LIBUSB_CFLAGS'].split(),

>                                link_args: config_host['LIBUSB_LIBS'].split())

>  endif

> -capstone = not_found

> -if 'CONFIG_CAPSTONE' in config_host

> -  capstone = declare_dependency(compile_args: config_host['CAPSTONE_CFLAGS'].split(),

> -                                link_args: config_host['CAPSTONE_LIBS'].split())

> -endif

>  libpmem = not_found

>  if 'CONFIG_LIBPMEM' in config_host

>    libpmem = declare_dependency(compile_args: config_host['LIBPMEM_CFLAGS'].split(),

> @@ -470,7 +466,6 @@ foreach k, v: config_host

>      config_host_data.set(k, v == 'y' ? 1 : v)

>    endif

>  endforeach

> -genh += configure_file(output: 'config-host.h', configuration: config_host_data)

>  

>  minikconf = find_program('scripts/minikconf.py')

>  config_all_devices = {}

> @@ -610,6 +605,108 @@ config_all += {

>    'CONFIG_ALL': true,

>  }

>  

> +# Submodules

> +

> +capstone = not_found

> +capstone_opt = get_option('capstone')

> +if capstone_opt == 'no'

> +  capstone_opt = false

> +elif capstone_opt in ['yes', 'auto', 'system']

> +  have_internal = fs.exists('capstone/Makefile')

> +  capstone = dependency('capstone', static: enable_static,

> +                        required: capstone_opt == 'system' or

> +                                  capstone_opt == 'yes' and not have_internal)

> +  if capstone.found()

> +    capstone_opt = 'system'

> +  elif have_internal

> +    capstone_opt = 'internal'

> +  else

> +    capstone_opt = false

> +  endif

> +endif

> +if capstone_opt == 'internal'

> +  capstone_data = configuration_data()

> +  capstone_data.set('CAPSTONE_USE_SYS_DYN_MEM', '1')

> +

> +  capstone_files = files(

> +    'capstone/cs.c',

> +    'capstone/MCInst.c',

> +    'capstone/MCInstrDesc.c',

> +    'capstone/MCRegisterInfo.c',

> +    'capstone/SStream.c',

> +    'capstone/utils.c'

> +  )

> +

> +  if 'CONFIG_ARM_DIS' in config_all_disas

> +    capstone_data.set('CAPSTONE_HAS_ARM', '1')

> +    capstone_files += files(

> +      'capstone/arch/ARM/ARMDisassembler.c',

> +      'capstone/arch/ARM/ARMInstPrinter.c',

> +      'capstone/arch/ARM/ARMMapping.c',

> +      'capstone/arch/ARM/ARMModule.c'

> +    )

> +  endif

> +

> +  # FIXME: This config entry currently depends on a c++ compiler.

> +  # Which is needed for building libvixl, but not for capstone.

> +  if 'CONFIG_ARM_A64_DIS' in config_all_disas

> +    capstone_data.set('CAPSTONE_HAS_ARM64', '1')

> +    capstone_files += files(

> +      'capstone/arch/AArch64/AArch64BaseInfo.c',

> +      'capstone/arch/AArch64/AArch64Disassembler.c',

> +      'capstone/arch/AArch64/AArch64InstPrinter.c',

> +      'capstone/arch/AArch64/AArch64Mapping.c',

> +      'capstone/arch/AArch64/AArch64Module.c'

> +    )

> +  endif

> +

> +  if 'CONFIG_PPC_DIS' in config_all_disas

> +    capstone_data.set('CAPSTONE_HAS_POWERPC', '1')

> +    capstone_files += files(

> +      'capstone/arch/PowerPC/PPCDisassembler.c',

> +      'capstone/arch/PowerPC/PPCInstPrinter.c',

> +      'capstone/arch/PowerPC/PPCMapping.c',

> +      'capstone/arch/PowerPC/PPCModule.c'

> +    )

> +  endif

> +

> +  if 'CONFIG_I386_DIS' in config_all_disas

> +    capstone_data.set('CAPSTONE_HAS_X86', 1)

> +    capstone_files += files(

> +      'capstone/arch/X86/X86Disassembler.c',

> +      'capstone/arch/X86/X86DisassemblerDecoder.c',

> +      'capstone/arch/X86/X86ATTInstPrinter.c',

> +      'capstone/arch/X86/X86IntelInstPrinter.c',

> +      'capstone/arch/X86/X86Mapping.c',

> +      'capstone/arch/X86/X86Module.c'

> +    )

> +  endif

> +

> +  configure_file(output: 'capstone-defs.h', configuration: capstone_data)

> +

> +  capstone_cargs = [

> +    # FIXME: There does not seem to be a way to completely replace the c_args

> +    # that come from add_project_arguments() -- we can only add to them.

> +    # So: disable all warnings with a big hammer.

> +    '-Wno-error', '-w',

> +

> +    # Include all configuration defines via a header file, which will wind up

> +    # as a dependency on the object file, and thus changes here will result

> +    # in a rebuild.

> +    '-include', 'capstone-defs.h'

> +  ]

> +

> +  libcapstone = static_library('capstone',

> +                               sources: capstone_files,

> +                               c_args: capstone_cargs,

> +                               include_directories: 'capstone/include')

> +  capstone = declare_dependency(link_with: libcapstone,

> +                                include_directories: 'capstone/include')

> +endif

> +config_host_data.set('CONFIG_CAPSTONE', capstone.found())

> +

> +genh += configure_file(output: 'config-host.h', configuration: config_host_data)

> +

>  # Generators

>  

>  hxtool = find_program('scripts/hxtool')

> @@ -1512,7 +1609,7 @@ summary_info += {'vvfat support':     config_host.has_key('CONFIG_VVFAT')}

>  summary_info += {'qed support':       config_host.has_key('CONFIG_QED')}

>  summary_info += {'parallels support': config_host.has_key('CONFIG_PARALLELS')}

>  summary_info += {'sheepdog support':  config_host.has_key('CONFIG_SHEEPDOG')}

> -summary_info += {'capstone':          config_host.has_key('CONFIG_CAPSTONE')}

> +summary_info += {'capstone':          capstone_opt}

>  summary_info += {'libpmem support':   config_host.has_key('CONFIG_LIBPMEM')}

>  summary_info += {'libdaxctl support': config_host.has_key('CONFIG_LIBDAXCTL')}

>  summary_info += {'libudev':           config_host.has_key('CONFIG_LIBUDEV')}

> diff --git a/meson_options.txt b/meson_options.txt

> index 543cf70043..e650a937e7 100644

> --- a/meson_options.txt

> +++ b/meson_options.txt

> @@ -22,3 +22,7 @@ option('vnc_sasl', type : 'feature', value : 'auto',

>         description: 'SASL authentication for VNC server')

>  option('xkbcommon', type : 'feature', value : 'auto',

>         description: 'xkbcommon support')

> +

> +option('capstone', type: 'combo', value: 'auto',

> +       choices: ['no', 'yes', 'auto', 'system', 'internal'],

> +       description: 'Whether and how to find the capstone library')



-- 
Alex Bennée
Alex Bennée Sept. 21, 2020, 11:05 a.m. UTC | #7
Alex Bennée <alex.bennee@linaro.org> writes:

> Richard Henderson <richard.henderson@linaro.org> writes:

>

>> There are better ways to do this, e.g. meson cmake subproject,

>> but that requires cmake 3.7 and some of our CI environments

>> only provide cmake 3.5.

>>

>> Nor can we add a meson.build file to capstone/, because the git

>> submodule would then always report "untracked files".  Fixing that

>> would require creating our own branch on the qemu git mirror, at

>> which point we could just as easily create a native meson subproject.

>>

>> Instead, build the library via the main meson.build.

>>

>> This improves the current state of affairs in that we will re-link

>> the qemu executables against a changed libcapstone.a, which we wouldn't

>> do before-hand.  In addition, the use of the configuration header file

>> instead of command-line -DEFINES means that we will rebuild the

>> capstone objects with changes to meson.build.

>

> Something is breaking when switching to a branch with this on from

> current master:

>

>   Linking target qemu-hppa

>   /usr/bin/ld: libcommon.fa.p/disas_alpha.c.o: in function `print_insn_alpha':

>   /home/alex/lsrc/qemu.git/builds/all/../../disas/alpha.c:1818: undefined reference to `bfd_getl32'

>   collect2: error: ld returned 1 exit status

>   make: *** [Makefile.ninja:5965: qemu-alpha] Error 1

>   make: *** Waiting for unfinished jobs....

>   /usr/bin/ld: libcommon.fa.p/disas_hppa.c.o: in function `print_insn_hppa':

>   /home/alex/lsrc/qemu.git/builds/all/../../disas/hppa.c:1969: undefined reference to `bfd_getb32'

>   collect2: error: ld returned 1 exit status

>   make: *** [Makefile.ninja:6259: qemu-hppa] Error 1

>

> Aggressively wiping out the submodule and doing a fresh configure in a

> empty build directory and I still see a failure:

>

>   ../../disas/capstone.c:25:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘cap_skipdata_s390x_cb’

>    cap_skipdata_s390x_cb(const uint8_t *code, size_t code_size,

>    ^~~~~~~~~~~~~~~~~~~~~

>   ../../disas/capstone.c:49:17: error: ‘cap_skipdata_s390x_cb’ undeclared here (not in a function); did you mean ‘cap_skipdata_s390x’?

>        .callback = cap_skipdata_s390x_cb

>                    ^~~~~~~~~~~~~~~~~~~~~

>                    cap_skipdata_s390x

>   Makefile.ninja:1424: recipe for target 'libcommon.fa.p/disas_capstone.c.o' failed

>   make: *** [libcommon.fa.p/disas_capstone.c.o] Error 1

>   make: *** Waiting for unfinished jobs....

>

>>

>> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>

>> ---

>> Cc: Paolo Bonzini <pbonzini@redhat.com>

>> v2: Further reduce probing in configure (paolo),

>>     Drop state 'internal' and use 'git' even when it isn't git.

>>     Move CONFIG_CAPSTONE to config_host_data.

>> v3: Add Submodules separator; fix default in meson_options.txt.

>> ---

>>  configure         |  61 +++----------------------

>>  Makefile          |  16 -------

>>  meson.build       | 111 +++++++++++++++++++++++++++++++++++++++++++---

>>  meson_options.txt |   4 ++

>>  4 files changed, 115 insertions(+), 77 deletions(-)

>>

>> diff --git a/configure b/configure

>> index 7564479008..76636c430d 100755

>> --- a/configure

>> +++ b/configure

>> @@ -478,7 +478,7 @@ opengl=""

>>  opengl_dmabuf="no"

>>  cpuid_h="no"

>>  avx2_opt=""

>> -capstone=""

>> +capstone="auto"

>>  lzo=""

>>  snappy=""

>>  bzip2=""

>> @@ -1580,7 +1580,7 @@ for opt do

>>    ;;

>>    --enable-capstone) capstone="yes"

>>    ;;

>> -  --enable-capstone=git) capstone="git"

>> +  --enable-capstone=git) capstone="internal"

>>    ;;

>>    --enable-capstone=system) capstone="system"

>>    ;;

>> @@ -5128,51 +5128,11 @@ fi

>>  # capstone

>>  

>>  case "$capstone" in

>> -  "" | yes)

>> -    if $pkg_config capstone; then

>> -      capstone=system

>> -    elif test -e "${source_path}/.git" && test $git_update = 'yes' ; then

>> -      capstone=git

>> -    elif test -e "${source_path}/capstone/Makefile" ; then

>> -      capstone=internal

>> -    elif test -z "$capstone" ; then

>> -      capstone=no

>> -    else

>> -      feature_not_found "capstone" "Install capstone devel or git submodule"

>> -    fi

>> -    ;;

>> -

>> -  system)

>> -    if ! $pkg_config capstone; then

>> -      feature_not_found "capstone" "Install capstone devel"

>> -    fi

>> -    ;;

>> -esac

>> -

>> -case "$capstone" in

>> -  git | internal)

>> -    if test "$capstone" = git; then

>> +  auto | yes | internal)

>> +    # Simpler to always update submodule, even if not needed.

>> +    if test -e "${source_path}/.git" && test $git_update = 'yes' ; then

>>        git_submodules="${git_submodules} capstone"

>>      fi

>> -    mkdir -p capstone

>> -    if test "$mingw32" = "yes"; then

>> -      LIBCAPSTONE=capstone.lib

>> -    else

>> -      LIBCAPSTONE=libcapstone.a

>> -    fi

>> -    capstone_libs="-Lcapstone -lcapstone"

>> -    capstone_cflags="-I${source_path}/capstone/include"

>> -    ;;

>> -

>> -  system)

>> -    capstone_libs="$($pkg_config --libs capstone)"

>> -    capstone_cflags="$($pkg_config --cflags capstone)"

>> -    ;;

>> -

>> -  no)

>> -    ;;

>> -  *)

>> -    error_exit "Unknown state for capstone: $capstone"

>>      ;;

>>  esac

>>  

>> @@ -7292,11 +7252,6 @@ fi

>>  if test "$ivshmem" = "yes" ; then

>>    echo "CONFIG_IVSHMEM=y" >> $config_host_mak

>>  fi

>> -if test "$capstone" != "no" ; then

>> -  echo "CONFIG_CAPSTONE=y" >> $config_host_mak

>> -  echo "CAPSTONE_CFLAGS=$capstone_cflags" >> $config_host_mak

>> -  echo "CAPSTONE_LIBS=$capstone_libs" >> $config_host_mak

>> -fi

>>  if test "$debug_mutex" = "yes" ; then

>>    echo "CONFIG_DEBUG_MUTEX=y" >> $config_host_mak

>>  fi

>> @@ -7819,9 +7774,6 @@ done # for target in $targets

>>  if [ "$fdt" = "git" ]; then

>>    subdirs="$subdirs dtc"

>>  fi

>> -if [ "$capstone" = "git" -o "$capstone" = "internal" ]; then

>> -  subdirs="$subdirs capstone"

>> -fi

>>  echo "SUBDIRS=$subdirs" >> $config_host_mak

>>  if test -n "$LIBCAPSTONE"; then

>>    echo "LIBCAPSTONE=$LIBCAPSTONE" >> $config_host_mak

>> @@ -8008,7 +7960,8 @@ NINJA=${ninja:-$PWD/ninjatool} $meson setup \

>>          -Db_coverage=$(if test "$gcov" = yes; then echo true; else echo false; fi) \

>>  	-Dsdl=$sdl -Dsdl_image=$sdl_image \

>>  	-Dvnc=$vnc -Dvnc_sasl=$vnc_sasl -Dvnc_jpeg=$vnc_jpeg -Dvnc_png=$vnc_png \

>> -	-Dgettext=$gettext -Dxkbcommon=$xkbcommon -Du2f=$u2f\

>> +	-Dgettext=$gettext -Dxkbcommon=$xkbcommon -Du2f=$u2f \

>> +	-Dcapstone=$capstone \

>>          $cross_arg \

>>          "$PWD" "$source_path"

>>  

>> diff --git a/Makefile b/Makefile

>> index 7c60b9dcb8..f3da1760ad 100644

>> --- a/Makefile

>> +++ b/Makefile

>> @@ -156,22 +156,6 @@ dtc/all: .git-submodule-status dtc/libfdt

>>  dtc/%: .git-submodule-status

>>  	@mkdir -p $@

>>  

>> -# Overriding CFLAGS causes us to lose defines added in the sub-makefile.

>> -# Not overriding CFLAGS leads to mis-matches between compilation modes.

>> -# Therefore we replicate some of the logic in the sub-makefile.

>> -# Remove all the extra -Warning flags that QEMU uses that Capstone doesn't;

>> -# no need to annoy QEMU developers with such things.

>> -CAP_CFLAGS = $(patsubst -W%,,$(CFLAGS) $(QEMU_CFLAGS)) $(CAPSTONE_CFLAGS)

>> -CAP_CFLAGS += -DCAPSTONE_USE_SYS_DYN_MEM

>> -CAP_CFLAGS += -DCAPSTONE_HAS_ARM

>> -CAP_CFLAGS += -DCAPSTONE_HAS_ARM64

>> -CAP_CFLAGS += -DCAPSTONE_HAS_POWERPC

>> -CAP_CFLAGS += -DCAPSTONE_HAS_X86

>> -

>> -.PHONY: capstone/all

>> -capstone/all: .git-submodule-status

>> -	$(call quiet-command,$(MAKE) -C $(SRC_PATH)/capstone CAPSTONE_SHARED=no BUILDDIR="$(BUILD_DIR)/capstone" CC="$(CC)" AR="$(AR)" LD="$(LD)" RANLIB="$(RANLIB)" CFLAGS="$(CAP_CFLAGS)" $(SUBDIR_MAKEFLAGS) $(BUILD_DIR)/capstone/$(LIBCAPSTONE))

>> -

>>  .PHONY: slirp/all

>>  slirp/all: .git-submodule-status

>>  	$(call quiet-command,$(MAKE) -C $(SRC_PATH)/slirp		\

>> diff --git a/meson.build b/meson.build

>> index f4d1ab1096..f23273693d 100644

>> --- a/meson.build

>> +++ b/meson.build

>> @@ -10,6 +10,7 @@ else

>>    keyval = import('unstable-keyval')

>>  endif

>>  ss = import('sourceset')

>> +fs = import('fs')

>>  

>>  sh = find_program('sh')

>>  cc = meson.get_compiler('c')

>> @@ -409,11 +410,6 @@ if 'CONFIG_USB_LIBUSB' in config_host

>>    libusb = declare_dependency(compile_args: config_host['LIBUSB_CFLAGS'].split(),

>>                                link_args: config_host['LIBUSB_LIBS'].split())

>>  endif

>> -capstone = not_found

>> -if 'CONFIG_CAPSTONE' in config_host

>> -  capstone = declare_dependency(compile_args: config_host['CAPSTONE_CFLAGS'].split(),

>> -                                link_args: config_host['CAPSTONE_LIBS'].split())

>> -endif

>>  libpmem = not_found

>>  if 'CONFIG_LIBPMEM' in config_host

>>    libpmem = declare_dependency(compile_args: config_host['LIBPMEM_CFLAGS'].split(),

>> @@ -470,7 +466,6 @@ foreach k, v: config_host

>>      config_host_data.set(k, v == 'y' ? 1 : v)

>>    endif

>>  endforeach

>> -genh += configure_file(output: 'config-host.h', configuration: config_host_data)

>>  

>>  minikconf = find_program('scripts/minikconf.py')

>>  config_all_devices = {}

>> @@ -610,6 +605,108 @@ config_all += {

>>    'CONFIG_ALL': true,

>>  }

>>  

>> +# Submodules

>> +

>> +capstone = not_found

>> +capstone_opt = get_option('capstone')

>> +if capstone_opt == 'no'

>> +  capstone_opt = false

>> +elif capstone_opt in ['yes', 'auto', 'system']

>> +  have_internal = fs.exists('capstone/Makefile')

>> +  capstone = dependency('capstone', static: enable_static,

>> +                        required: capstone_opt == 'system' or

>> +                                  capstone_opt == 'yes' and not have_internal)

>> +  if capstone.found()

>> +    capstone_opt = 'system'

>> +  elif have_internal

>> +    capstone_opt = 'internal'

>> +  else

>> +    capstone_opt = false

>> +  endif

>> +endif

>> +if capstone_opt == 'internal'

>> +  capstone_data = configuration_data()

>> +  capstone_data.set('CAPSTONE_USE_SYS_DYN_MEM', '1')

>> +

>> +  capstone_files = files(

>> +    'capstone/cs.c',

>> +    'capstone/MCInst.c',

>> +    'capstone/MCInstrDesc.c',

>> +    'capstone/MCRegisterInfo.c',

>> +    'capstone/SStream.c',

>> +    'capstone/utils.c'

>> +  )

>> +

>> +  if 'CONFIG_ARM_DIS' in config_all_disas

>> +    capstone_data.set('CAPSTONE_HAS_ARM', '1')

>> +    capstone_files += files(

>> +      'capstone/arch/ARM/ARMDisassembler.c',

>> +      'capstone/arch/ARM/ARMInstPrinter.c',

>> +      'capstone/arch/ARM/ARMMapping.c',

>> +      'capstone/arch/ARM/ARMModule.c'

>> +    )

>> +  endif

>> +

>> +  # FIXME: This config entry currently depends on a c++ compiler.

>> +  # Which is needed for building libvixl, but not for capstone.

>> +  if 'CONFIG_ARM_A64_DIS' in config_all_disas

>> +    capstone_data.set('CAPSTONE_HAS_ARM64', '1')

>> +    capstone_files += files(

>> +      'capstone/arch/AArch64/AArch64BaseInfo.c',

>> +      'capstone/arch/AArch64/AArch64Disassembler.c',

>> +      'capstone/arch/AArch64/AArch64InstPrinter.c',

>> +      'capstone/arch/AArch64/AArch64Mapping.c',

>> +      'capstone/arch/AArch64/AArch64Module.c'

>> +    )

>> +  endif

>> +

>> +  if 'CONFIG_PPC_DIS' in config_all_disas

>> +    capstone_data.set('CAPSTONE_HAS_POWERPC', '1')

>> +    capstone_files += files(

>> +      'capstone/arch/PowerPC/PPCDisassembler.c',

>> +      'capstone/arch/PowerPC/PPCInstPrinter.c',

>> +      'capstone/arch/PowerPC/PPCMapping.c',

>> +      'capstone/arch/PowerPC/PPCModule.c'

>> +    )

>> +  endif

>> +

>> +  if 'CONFIG_I386_DIS' in config_all_disas

>> +    capstone_data.set('CAPSTONE_HAS_X86', 1)

>> +    capstone_files += files(

>> +      'capstone/arch/X86/X86Disassembler.c',

>> +      'capstone/arch/X86/X86DisassemblerDecoder.c',

>> +      'capstone/arch/X86/X86ATTInstPrinter.c',

>> +      'capstone/arch/X86/X86IntelInstPrinter.c',

>> +      'capstone/arch/X86/X86Mapping.c',

>> +      'capstone/arch/X86/X86Module.c'

>> +    )

>> +  endif

>> +

>> +  configure_file(output: 'capstone-defs.h', configuration: capstone_data)

>> +

>> +  capstone_cargs = [

>> +    # FIXME: There does not seem to be a way to completely replace the c_args

>> +    # that come from add_project_arguments() -- we can only add to them.

>> +    # So: disable all warnings with a big hammer.

>> +    '-Wno-error', '-w',

>> +

>> +    # Include all configuration defines via a header file, which will wind up

>> +    # as a dependency on the object file, and thus changes here will result

>> +    # in a rebuild.

>> +    '-include', 'capstone-defs.h'

>> +  ]

>> +

>> +  libcapstone = static_library('capstone',

>> +                               sources: capstone_files,

>> +                               c_args: capstone_cargs,

>> +                               include_directories: 'capstone/include')

>> +  capstone = declare_dependency(link_with: libcapstone,

>> +                                include_directories: 'capstone/include')

>> +endif

>> +config_host_data.set('CONFIG_CAPSTONE', capstone.found())

>> +

>> +genh += configure_file(output: 'config-host.h', configuration: config_host_data)

>> +

>>  # Generators

>>  

>>  hxtool = find_program('scripts/hxtool')

>> @@ -1512,7 +1609,7 @@ summary_info += {'vvfat support':     config_host.has_key('CONFIG_VVFAT')}

>>  summary_info += {'qed support':       config_host.has_key('CONFIG_QED')}

>>  summary_info += {'parallels support': config_host.has_key('CONFIG_PARALLELS')}

>>  summary_info += {'sheepdog support':  config_host.has_key('CONFIG_SHEEPDOG')}

>> -summary_info += {'capstone':          config_host.has_key('CONFIG_CAPSTONE')}

>> +summary_info += {'capstone':          capstone_opt}

>>  summary_info += {'libpmem support':   config_host.has_key('CONFIG_LIBPMEM')}

>>  summary_info += {'libdaxctl support': config_host.has_key('CONFIG_LIBDAXCTL')}

>>  summary_info += {'libudev':           config_host.has_key('CONFIG_LIBUDEV')}

>> diff --git a/meson_options.txt b/meson_options.txt

>> index 543cf70043..e650a937e7 100644

>> --- a/meson_options.txt

>> +++ b/meson_options.txt

>> @@ -22,3 +22,7 @@ option('vnc_sasl', type : 'feature', value : 'auto',

>>         description: 'SASL authentication for VNC server')

>>  option('xkbcommon', type : 'feature', value : 'auto',

>>         description: 'xkbcommon support')

>> +

>> +option('capstone', type: 'combo', value: 'auto',

>> +       choices: ['no', 'yes', 'auto', 'system', 'internal'],

>> +       description: 'Whether and how to find the capstone library')



Hmm even more confusing is configure does:

  GIT submodules: ui/keycodemapdb tests/fp/berkeley-testfloat-3 tests/fp/berkeley-softfloat-3 meson dtc capstone slirp

but also:

  capstone: system

which I can't quite help but feel is going to be confusing.

-- 
Alex Bennée
罗勇刚(Yonggang Luo) Sept. 21, 2020, 12:50 p.m. UTC | #8
On Mon, Sep 21, 2020 at 7:06 PM Alex Bennée <alex.bennee@linaro.org> wrote:
>

>

> Alex Bennée <alex.bennee@linaro.org> writes:

>

> > Richard Henderson <richard.henderson@linaro.org> writes:

> >

> >> There are better ways to do this, e.g. meson cmake subproject,

> >> but that requires cmake 3.7 and some of our CI environments

> >> only provide cmake 3.5.

> >>

> >> Nor can we add a meson.build file to capstone/, because the git

> >> submodule would then always report "untracked files".  Fixing that

> >> would require creating our own branch on the qemu git mirror, at

> >> which point we could just as easily create a native meson subproject.

> >>

> >> Instead, build the library via the main meson.build.

> >>

> >> This improves the current state of affairs in that we will re-link

> >> the qemu executables against a changed libcapstone.a, which we wouldn't

> >> do before-hand.  In addition, the use of the configuration header file

> >> instead of command-line -DEFINES means that we will rebuild the

> >> capstone objects with changes to meson.build.

> >

> > Something is breaking when switching to a branch with this on from

> > current master:

> >

> >   Linking target qemu-hppa

> >   /usr/bin/ld: libcommon.fa.p/disas_alpha.c.o: in function

`print_insn_alpha':
> >   /home/alex/lsrc/qemu.git/builds/all/../../disas/alpha.c:1818:

undefined reference to `bfd_getl32'
> >   collect2: error: ld returned 1 exit status

> >   make: *** [Makefile.ninja:5965: qemu-alpha] Error 1

> >   make: *** Waiting for unfinished jobs....

> >   /usr/bin/ld: libcommon.fa.p/disas_hppa.c.o: in function

`print_insn_hppa':
> >   /home/alex/lsrc/qemu.git/builds/all/../../disas/hppa.c:1969:

undefined reference to `bfd_getb32'
> >   collect2: error: ld returned 1 exit status

> >   make: *** [Makefile.ninja:6259: qemu-hppa] Error 1

> >

> > Aggressively wiping out the submodule and doing a fresh configure in a

> > empty build directory and I still see a failure:

> >

> >   ../../disas/capstone.c:25:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or

‘__attribute__’ before ‘cap_skipdata_s390x_cb’
> >    cap_skipdata_s390x_cb(const uint8_t *code, size_t code_size,

> >    ^~~~~~~~~~~~~~~~~~~~~

> >   ../../disas/capstone.c:49:17: error: ‘cap_skipdata_s390x_cb’

undeclared here (not in a function); did you mean ‘cap_skipdata_s390x’?
> >        .callback = cap_skipdata_s390x_cb

> >                    ^~~~~~~~~~~~~~~~~~~~~

> >                    cap_skipdata_s390x

> >   Makefile.ninja:1424: recipe for target

'libcommon.fa.p/disas_capstone.c.o' failed
> >   make: *** [libcommon.fa.p/disas_capstone.c.o] Error 1

> >   make: *** Waiting for unfinished jobs....

> >

> >>

> >> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>

> >> ---

> >> Cc: Paolo Bonzini <pbonzini@redhat.com>

> >> v2: Further reduce probing in configure (paolo),

> >>     Drop state 'internal' and use 'git' even when it isn't git.

> >>     Move CONFIG_CAPSTONE to config_host_data.

> >> v3: Add Submodules separator; fix default in meson_options.txt.

> >> ---

> >>  configure         |  61 +++----------------------

> >>  Makefile          |  16 -------

> >>  meson.build       | 111 +++++++++++++++++++++++++++++++++++++++++++---

> >>  meson_options.txt |   4 ++

> >>  4 files changed, 115 insertions(+), 77 deletions(-)

> >>

> >> diff --git a/configure b/configure

> >> index 7564479008..76636c430d 100755

> >> --- a/configure

> >> +++ b/configure

> >> @@ -478,7 +478,7 @@ opengl=""

> >>  opengl_dmabuf="no"

> >>  cpuid_h="no"

> >>  avx2_opt=""

> >> -capstone=""

> >> +capstone="auto"

> >>  lzo=""

> >>  snappy=""

> >>  bzip2=""

> >> @@ -1580,7 +1580,7 @@ for opt do

> >>    ;;

> >>    --enable-capstone) capstone="yes"

> >>    ;;

> >> -  --enable-capstone=git) capstone="git"

> >> +  --enable-capstone=git) capstone="internal"

> >>    ;;

> >>    --enable-capstone=system) capstone="system"

> >>    ;;

> >> @@ -5128,51 +5128,11 @@ fi

> >>  # capstone

> >>

> >>  case "$capstone" in

> >> -  "" | yes)

> >> -    if $pkg_config capstone; then

> >> -      capstone=system

> >> -    elif test -e "${source_path}/.git" && test $git_update = 'yes' ;

then
> >> -      capstone=git

> >> -    elif test -e "${source_path}/capstone/Makefile" ; then

> >> -      capstone=internal

> >> -    elif test -z "$capstone" ; then

> >> -      capstone=no

> >> -    else

> >> -      feature_not_found "capstone" "Install capstone devel or git

submodule"
> >> -    fi

> >> -    ;;

> >> -

> >> -  system)

> >> -    if ! $pkg_config capstone; then

> >> -      feature_not_found "capstone" "Install capstone devel"

> >> -    fi

> >> -    ;;

> >> -esac

> >> -

> >> -case "$capstone" in

> >> -  git | internal)

> >> -    if test "$capstone" = git; then

> >> +  auto | yes | internal)

> >> +    # Simpler to always update submodule, even if not needed.

> >> +    if test -e "${source_path}/.git" && test $git_update = 'yes' ;

then
> >>        git_submodules="${git_submodules} capstone"

> >>      fi

> >> -    mkdir -p capstone

> >> -    if test "$mingw32" = "yes"; then

> >> -      LIBCAPSTONE=capstone.lib

> >> -    else

> >> -      LIBCAPSTONE=libcapstone.a

> >> -    fi

> >> -    capstone_libs="-Lcapstone -lcapstone"

> >> -    capstone_cflags="-I${source_path}/capstone/include"

> >> -    ;;

> >> -

> >> -  system)

> >> -    capstone_libs="$($pkg_config --libs capstone)"

> >> -    capstone_cflags="$($pkg_config --cflags capstone)"

> >> -    ;;

> >> -

> >> -  no)

> >> -    ;;

> >> -  *)

> >> -    error_exit "Unknown state for capstone: $capstone"

> >>      ;;

> >>  esac

> >>

> >> @@ -7292,11 +7252,6 @@ fi

> >>  if test "$ivshmem" = "yes" ; then

> >>    echo "CONFIG_IVSHMEM=y" >> $config_host_mak

> >>  fi

> >> -if test "$capstone" != "no" ; then

> >> -  echo "CONFIG_CAPSTONE=y" >> $config_host_mak

> >> -  echo "CAPSTONE_CFLAGS=$capstone_cflags" >> $config_host_mak

> >> -  echo "CAPSTONE_LIBS=$capstone_libs" >> $config_host_mak

> >> -fi

> >>  if test "$debug_mutex" = "yes" ; then

> >>    echo "CONFIG_DEBUG_MUTEX=y" >> $config_host_mak

> >>  fi

> >> @@ -7819,9 +7774,6 @@ done # for target in $targets

> >>  if [ "$fdt" = "git" ]; then

> >>    subdirs="$subdirs dtc"

> >>  fi

> >> -if [ "$capstone" = "git" -o "$capstone" = "internal" ]; then

> >> -  subdirs="$subdirs capstone"

> >> -fi

> >>  echo "SUBDIRS=$subdirs" >> $config_host_mak

> >>  if test -n "$LIBCAPSTONE"; then

> >>    echo "LIBCAPSTONE=$LIBCAPSTONE" >> $config_host_mak

> >> @@ -8008,7 +7960,8 @@ NINJA=${ninja:-$PWD/ninjatool} $meson setup \

> >>          -Db_coverage=$(if test "$gcov" = yes; then echo true; else

echo false; fi) \
> >>      -Dsdl=$sdl -Dsdl_image=$sdl_image \

> >>      -Dvnc=$vnc -Dvnc_sasl=$vnc_sasl -Dvnc_jpeg=$vnc_jpeg

-Dvnc_png=$vnc_png \
> >> -    -Dgettext=$gettext -Dxkbcommon=$xkbcommon -Du2f=$u2f\

> >> +    -Dgettext=$gettext -Dxkbcommon=$xkbcommon -Du2f=$u2f \

> >> +    -Dcapstone=$capstone \

> >>          $cross_arg \

> >>          "$PWD" "$source_path"

> >>

> >> diff --git a/Makefile b/Makefile

> >> index 7c60b9dcb8..f3da1760ad 100644

> >> --- a/Makefile

> >> +++ b/Makefile

> >> @@ -156,22 +156,6 @@ dtc/all: .git-submodule-status dtc/libfdt

> >>  dtc/%: .git-submodule-status

> >>      @mkdir -p $@

> >>

> >> -# Overriding CFLAGS causes us to lose defines added in the

sub-makefile.
> >> -# Not overriding CFLAGS leads to mis-matches between compilation

modes.
> >> -# Therefore we replicate some of the logic in the sub-makefile.

> >> -# Remove all the extra -Warning flags that QEMU uses that Capstone

doesn't;
> >> -# no need to annoy QEMU developers with such things.

> >> -CAP_CFLAGS = $(patsubst -W%,,$(CFLAGS) $(QEMU_CFLAGS))

$(CAPSTONE_CFLAGS)
> >> -CAP_CFLAGS += -DCAPSTONE_USE_SYS_DYN_MEM

> >> -CAP_CFLAGS += -DCAPSTONE_HAS_ARM

> >> -CAP_CFLAGS += -DCAPSTONE_HAS_ARM64

> >> -CAP_CFLAGS += -DCAPSTONE_HAS_POWERPC

> >> -CAP_CFLAGS += -DCAPSTONE_HAS_X86

> >> -

> >> -.PHONY: capstone/all

> >> -capstone/all: .git-submodule-status

> >> -    $(call quiet-command,$(MAKE) -C $(SRC_PATH)/capstone

CAPSTONE_SHARED=no BUILDDIR="$(BUILD_DIR)/capstone" CC="$(CC)" AR="$(AR)"
LD="$(LD)" RANLIB="$(RANLIB)" CFLAGS="$(CAP_CFLAGS)" $(SUBDIR_MAKEFLAGS)
$(BUILD_DIR)/capstone/$(LIBCAPSTONE))
> >> -

> >>  .PHONY: slirp/all

> >>  slirp/all: .git-submodule-status

> >>      $(call quiet-command,$(MAKE) -C $(SRC_PATH)/slirp               \

> >> diff --git a/meson.build b/meson.build

> >> index f4d1ab1096..f23273693d 100644

> >> --- a/meson.build

> >> +++ b/meson.build

> >> @@ -10,6 +10,7 @@ else

> >>    keyval = import('unstable-keyval')

> >>  endif

> >>  ss = import('sourceset')

> >> +fs = import('fs')

> >>

> >>  sh = find_program('sh')

> >>  cc = meson.get_compiler('c')

> >> @@ -409,11 +410,6 @@ if 'CONFIG_USB_LIBUSB' in config_host

> >>    libusb = declare_dependency(compile_args:

config_host['LIBUSB_CFLAGS'].split(),
> >>                                link_args:

config_host['LIBUSB_LIBS'].split())
> >>  endif

> >> -capstone = not_found

> >> -if 'CONFIG_CAPSTONE' in config_host

> >> -  capstone = declare_dependency(compile_args:

config_host['CAPSTONE_CFLAGS'].split(),
> >> -                                link_args:

config_host['CAPSTONE_LIBS'].split())
> >> -endif

> >>  libpmem = not_found

> >>  if 'CONFIG_LIBPMEM' in config_host

> >>    libpmem = declare_dependency(compile_args:

config_host['LIBPMEM_CFLAGS'].split(),
> >> @@ -470,7 +466,6 @@ foreach k, v: config_host

> >>      config_host_data.set(k, v == 'y' ? 1 : v)

> >>    endif

> >>  endforeach

> >> -genh += configure_file(output: 'config-host.h', configuration:

config_host_data)
> >>

> >>  minikconf = find_program('scripts/minikconf.py')

> >>  config_all_devices = {}

> >> @@ -610,6 +605,108 @@ config_all += {

> >>    'CONFIG_ALL': true,

> >>  }

> >>

> >> +# Submodules

> >> +

> >> +capstone = not_found

> >> +capstone_opt = get_option('capstone')

> >> +if capstone_opt == 'no'

> >> +  capstone_opt = false

> >> +elif capstone_opt in ['yes', 'auto', 'system']

> >> +  have_internal = fs.exists('capstone/Makefile')

> >> +  capstone = dependency('capstone', static: enable_static,

> >> +                        required: capstone_opt == 'system' or

> >> +                                  capstone_opt == 'yes' and not

have_internal)
> >> +  if capstone.found()

> >> +    capstone_opt = 'system'

> >> +  elif have_internal

> >> +    capstone_opt = 'internal'

> >> +  else

> >> +    capstone_opt = false

> >> +  endif

> >> +endif

> >> +if capstone_opt == 'internal'

> >> +  capstone_data = configuration_data()

> >> +  capstone_data.set('CAPSTONE_USE_SYS_DYN_MEM', '1')

> >> +

> >> +  capstone_files = files(

> >> +    'capstone/cs.c',

> >> +    'capstone/MCInst.c',

> >> +    'capstone/MCInstrDesc.c',

> >> +    'capstone/MCRegisterInfo.c',

> >> +    'capstone/SStream.c',

> >> +    'capstone/utils.c'

> >> +  )

> >> +

> >> +  if 'CONFIG_ARM_DIS' in config_all_disas

> >> +    capstone_data.set('CAPSTONE_HAS_ARM', '1')

> >> +    capstone_files += files(

> >> +      'capstone/arch/ARM/ARMDisassembler.c',

> >> +      'capstone/arch/ARM/ARMInstPrinter.c',

> >> +      'capstone/arch/ARM/ARMMapping.c',

> >> +      'capstone/arch/ARM/ARMModule.c'

> >> +    )

> >> +  endif

> >> +

> >> +  # FIXME: This config entry currently depends on a c++ compiler.

> >> +  # Which is needed for building libvixl, but not for capstone.

> >> +  if 'CONFIG_ARM_A64_DIS' in config_all_disas

> >> +    capstone_data.set('CAPSTONE_HAS_ARM64', '1')

> >> +    capstone_files += files(

> >> +      'capstone/arch/AArch64/AArch64BaseInfo.c',

> >> +      'capstone/arch/AArch64/AArch64Disassembler.c',

> >> +      'capstone/arch/AArch64/AArch64InstPrinter.c',

> >> +      'capstone/arch/AArch64/AArch64Mapping.c',

> >> +      'capstone/arch/AArch64/AArch64Module.c'

> >> +    )

> >> +  endif

> >> +

> >> +  if 'CONFIG_PPC_DIS' in config_all_disas

> >> +    capstone_data.set('CAPSTONE_HAS_POWERPC', '1')

> >> +    capstone_files += files(

> >> +      'capstone/arch/PowerPC/PPCDisassembler.c',

> >> +      'capstone/arch/PowerPC/PPCInstPrinter.c',

> >> +      'capstone/arch/PowerPC/PPCMapping.c',

> >> +      'capstone/arch/PowerPC/PPCModule.c'

> >> +    )

> >> +  endif

> >> +

> >> +  if 'CONFIG_I386_DIS' in config_all_disas

> >> +    capstone_data.set('CAPSTONE_HAS_X86', 1)

> >> +    capstone_files += files(

> >> +      'capstone/arch/X86/X86Disassembler.c',

> >> +      'capstone/arch/X86/X86DisassemblerDecoder.c',

> >> +      'capstone/arch/X86/X86ATTInstPrinter.c',

> >> +      'capstone/arch/X86/X86IntelInstPrinter.c',

> >> +      'capstone/arch/X86/X86Mapping.c',

> >> +      'capstone/arch/X86/X86Module.c'

> >> +    )

> >> +  endif

> >> +

> >> +  configure_file(output: 'capstone-defs.h', configuration:

capstone_data)
> >> +

> >> +  capstone_cargs = [

> >> +    # FIXME: There does not seem to be a way to completely replace

the c_args
> >> +    # that come from add_project_arguments() -- we can only add to

them.
> >> +    # So: disable all warnings with a big hammer.

> >> +    '-Wno-error', '-w',

> >> +

> >> +    # Include all configuration defines via a header file, which will

wind up
> >> +    # as a dependency on the object file, and thus changes here will

result
> >> +    # in a rebuild.

> >> +    '-include', 'capstone-defs.h'

> >> +  ]

> >> +

> >> +  libcapstone = static_library('capstone',

> >> +                               sources: capstone_files,

> >> +                               c_args: capstone_cargs,

> >> +                               include_directories:

'capstone/include')
> >> +  capstone = declare_dependency(link_with: libcapstone,

> >> +                                include_directories:

'capstone/include')
> >> +endif

> >> +config_host_data.set('CONFIG_CAPSTONE', capstone.found())

> >> +

> >> +genh += configure_file(output: 'config-host.h', configuration:

config_host_data)
> >> +

> >>  # Generators

> >>

> >>  hxtool = find_program('scripts/hxtool')

> >> @@ -1512,7 +1609,7 @@ summary_info += {'vvfat support':

config_host.has_key('CONFIG_VVFAT')}
> >>  summary_info += {'qed support':

config_host.has_key('CONFIG_QED')}
> >>  summary_info += {'parallels support':

config_host.has_key('CONFIG_PARALLELS')}
> >>  summary_info += {'sheepdog support':

 config_host.has_key('CONFIG_SHEEPDOG')}
> >> -summary_info += {'capstone':

 config_host.has_key('CONFIG_CAPSTONE')}
> >> +summary_info += {'capstone':          capstone_opt}

> >>  summary_info += {'libpmem support':

config_host.has_key('CONFIG_LIBPMEM')}
> >>  summary_info += {'libdaxctl support':

config_host.has_key('CONFIG_LIBDAXCTL')}
> >>  summary_info += {'libudev':

config_host.has_key('CONFIG_LIBUDEV')}
> >> diff --git a/meson_options.txt b/meson_options.txt

> >> index 543cf70043..e650a937e7 100644

> >> --- a/meson_options.txt

> >> +++ b/meson_options.txt

> >> @@ -22,3 +22,7 @@ option('vnc_sasl', type : 'feature', value : 'auto',

> >>         description: 'SASL authentication for VNC server')

> >>  option('xkbcommon', type : 'feature', value : 'auto',

> >>         description: 'xkbcommon support')

> >> +

> >> +option('capstone', type: 'combo', value: 'auto',

> >> +       choices: ['no', 'yes', 'auto', 'system', 'internal'],

> >> +       description: 'Whether and how to find the capstone library')

>

>

> Hmm even more confusing is configure does:

>

>   GIT submodules: ui/keycodemapdb tests/fp/berkeley-testfloat-3

tests/fp/berkeley-softfloat-3 meson dtc capstone slirp
>

> but also:

>

>   capstone: system

>

> which I can't quite help but feel is going to be confusing.

maybe remove the capstone system support is a good idea after-all.
>

> --

> Alex Bennée

>



--
         此致
礼
罗勇刚
Yours
    sincerely,
Yonggang Luo
<div dir="ltr"><br><br>On Mon, Sep 21, 2020 at 7:06 PM Alex Bennée &lt;<a href="mailto:alex.bennee@linaro.org">alex.bennee@linaro.org</a>&gt; wrote:<br>&gt;<br>&gt;<br>&gt; Alex Bennée &lt;<a href="mailto:alex.bennee@linaro.org">alex.bennee@linaro.org</a>&gt; writes:<br>&gt;<br>&gt; &gt; Richard Henderson &lt;<a href="mailto:richard.henderson@linaro.org">richard.henderson@linaro.org</a>&gt; writes:<br>&gt; &gt;<br>&gt; &gt;&gt; There are better ways to do this, e.g. meson cmake subproject,<br>&gt; &gt;&gt; but that requires cmake 3.7 and some of our CI environments<br>&gt; &gt;&gt; only provide cmake 3.5.<br>&gt; &gt;&gt;<br>&gt; &gt;&gt; Nor can we add a meson.build file to capstone/, because the git<br>&gt; &gt;&gt; submodule would then always report &quot;untracked files&quot;.  Fixing that<br>&gt; &gt;&gt; would require creating our own branch on the qemu git mirror, at<br>&gt; &gt;&gt; which point we could just as easily create a native meson subproject.<br>&gt; &gt;&gt;<br>&gt; &gt;&gt; Instead, build the library via the main meson.build.<br>&gt; &gt;&gt;<br>&gt; &gt;&gt; This improves the current state of affairs in that we will re-link<br>&gt; &gt;&gt; the qemu executables against a changed libcapstone.a, which we wouldn&#39;t<br>&gt; &gt;&gt; do before-hand.  In addition, the use of the configuration header file<br>&gt; &gt;&gt; instead of command-line -DEFINES means that we will rebuild the<br>&gt; &gt;&gt; capstone objects with changes to meson.build.<br>&gt; &gt;<br>&gt; &gt; Something is breaking when switching to a branch with this on from<br>&gt; &gt; current master:<br>&gt; &gt;<br>&gt; &gt;   Linking target qemu-hppa<br>&gt; &gt;   /usr/bin/ld: libcommon.fa.p/disas_alpha.c.o: in function `print_insn_alpha&#39;:<br>&gt; &gt;   /home/alex/lsrc/qemu.git/builds/all/../../disas/alpha.c:1818: undefined reference to `bfd_getl32&#39;<br>&gt; &gt;   collect2: error: ld returned 1 exit status<br>&gt; &gt;   make: *** [Makefile.ninja:5965: qemu-alpha] Error 1<br>&gt; &gt;   make: *** Waiting for unfinished jobs....<br>&gt; &gt;   /usr/bin/ld: libcommon.fa.p/disas_hppa.c.o: in function `print_insn_hppa&#39;:<br>&gt; &gt;   /home/alex/lsrc/qemu.git/builds/all/../../disas/hppa.c:1969: undefined reference to `bfd_getb32&#39;<br>&gt; &gt;   collect2: error: ld returned 1 exit status<br>&gt; &gt;   make: *** [Makefile.ninja:6259: qemu-hppa] Error 1<br>&gt; &gt;<br>&gt; &gt; Aggressively wiping out the submodule and doing a fresh configure in a<br>&gt; &gt; empty build directory and I still see a failure:<br>&gt; &gt;<br>&gt; &gt;   ../../disas/capstone.c:25:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘cap_skipdata_s390x_cb’<br>&gt; &gt;    cap_skipdata_s390x_cb(const uint8_t *code, size_t code_size,<br>&gt; &gt;    ^~~~~~~~~~~~~~~~~~~~~<br>&gt; &gt;   ../../disas/capstone.c:49:17: error: ‘cap_skipdata_s390x_cb’ undeclared here (not in a function); did you mean ‘cap_skipdata_s390x’?<br>&gt; &gt;        .callback = cap_skipdata_s390x_cb<br>&gt; &gt;                    ^~~~~~~~~~~~~~~~~~~~~<br>&gt; &gt;                    cap_skipdata_s390x<br>&gt; &gt;   Makefile.ninja:1424: recipe for target &#39;libcommon.fa.p/disas_capstone.c.o&#39; failed<br>&gt; &gt;   make: *** [libcommon.fa.p/disas_capstone.c.o] Error 1<br>&gt; &gt;   make: *** Waiting for unfinished jobs....<br>&gt; &gt;<br>&gt; &gt;&gt;<br>&gt; &gt;&gt; Signed-off-by: Richard Henderson &lt;<a href="mailto:richard.henderson@linaro.org">richard.henderson@linaro.org</a>&gt;<br>&gt; &gt;&gt; ---<br>&gt; &gt;&gt; Cc: Paolo Bonzini &lt;<a href="mailto:pbonzini@redhat.com">pbonzini@redhat.com</a>&gt;<br>&gt; &gt;&gt; v2: Further reduce probing in configure (paolo),<br>&gt; &gt;&gt;     Drop state &#39;internal&#39; and use &#39;git&#39; even when it isn&#39;t git.<br>&gt; &gt;&gt;     Move CONFIG_CAPSTONE to config_host_data.<br>&gt; &gt;&gt; v3: Add Submodules separator; fix default in meson_options.txt.<br>&gt; &gt;&gt; ---<br>&gt; &gt;&gt;  configure         |  61 +++----------------------<br>&gt; &gt;&gt;  Makefile          |  16 -------<br>&gt; &gt;&gt;  meson.build       | 111 +++++++++++++++++++++++++++++++++++++++++++---<br>&gt; &gt;&gt;  meson_options.txt |   4 ++<br>&gt; &gt;&gt;  4 files changed, 115 insertions(+), 77 deletions(-)<br>&gt; &gt;&gt;<br>&gt; &gt;&gt; diff --git a/configure b/configure<br>&gt; &gt;&gt; index 7564479008..76636c430d 100755<br>&gt; &gt;&gt; --- a/configure<br>&gt; &gt;&gt; +++ b/configure<br>&gt; &gt;&gt; @@ -478,7 +478,7 @@ opengl=&quot;&quot;<br>&gt; &gt;&gt;  opengl_dmabuf=&quot;no&quot;<br>&gt; &gt;&gt;  cpuid_h=&quot;no&quot;<br>&gt; &gt;&gt;  avx2_opt=&quot;&quot;<br>&gt; &gt;&gt; -capstone=&quot;&quot;<br>&gt; &gt;&gt; +capstone=&quot;auto&quot;<br>&gt; &gt;&gt;  lzo=&quot;&quot;<br>&gt; &gt;&gt;  snappy=&quot;&quot;<br>&gt; &gt;&gt;  bzip2=&quot;&quot;<br>&gt; &gt;&gt; @@ -1580,7 +1580,7 @@ for opt do<br>&gt; &gt;&gt;    ;;<br>&gt; &gt;&gt;    --enable-capstone) capstone=&quot;yes&quot;<br>&gt; &gt;&gt;    ;;<br>&gt; &gt;&gt; -  --enable-capstone=git) capstone=&quot;git&quot;<br>&gt; &gt;&gt; +  --enable-capstone=git) capstone=&quot;internal&quot;<br>&gt; &gt;&gt;    ;;<br>&gt; &gt;&gt;    --enable-capstone=system) capstone=&quot;system&quot;<br>&gt; &gt;&gt;    ;;<br>&gt; &gt;&gt; @@ -5128,51 +5128,11 @@ fi<br>&gt; &gt;&gt;  # capstone<br>&gt; &gt;&gt; <br>&gt; &gt;&gt;  case &quot;$capstone&quot; in<br>&gt; &gt;&gt; -  &quot;&quot; | yes)<br>&gt; &gt;&gt; -    if $pkg_config capstone; then<br>&gt; &gt;&gt; -      capstone=system<br>&gt; &gt;&gt; -    elif test -e &quot;${source_path}/.git&quot; &amp;&amp; test $git_update = &#39;yes&#39; ; then<br>&gt; &gt;&gt; -      capstone=git<br>&gt; &gt;&gt; -    elif test -e &quot;${source_path}/capstone/Makefile&quot; ; then<br>&gt; &gt;&gt; -      capstone=internal<br>&gt; &gt;&gt; -    elif test -z &quot;$capstone&quot; ; then<br>&gt; &gt;&gt; -      capstone=no<br>&gt; &gt;&gt; -    else<br>&gt; &gt;&gt; -      feature_not_found &quot;capstone&quot; &quot;Install capstone devel or git submodule&quot;<br>&gt; &gt;&gt; -    fi<br>&gt; &gt;&gt; -    ;;<br>&gt; &gt;&gt; -<br>&gt; &gt;&gt; -  system)<br>&gt; &gt;&gt; -    if ! $pkg_config capstone; then<br>&gt; &gt;&gt; -      feature_not_found &quot;capstone&quot; &quot;Install capstone devel&quot;<br>&gt; &gt;&gt; -    fi<br>&gt; &gt;&gt; -    ;;<br>&gt; &gt;&gt; -esac<br>&gt; &gt;&gt; -<br>&gt; &gt;&gt; -case &quot;$capstone&quot; in<br>&gt; &gt;&gt; -  git | internal)<br>&gt; &gt;&gt; -    if test &quot;$capstone&quot; = git; then<br>&gt; &gt;&gt; +  auto | yes | internal)<br>&gt; &gt;&gt; +    # Simpler to always update submodule, even if not needed.<br>&gt; &gt;&gt; +    if test -e &quot;${source_path}/.git&quot; &amp;&amp; test $git_update = &#39;yes&#39; ; then<br>&gt; &gt;&gt;        git_submodules=&quot;${git_submodules} capstone&quot;<br>&gt; &gt;&gt;      fi<br>&gt; &gt;&gt; -    mkdir -p capstone<br>&gt; &gt;&gt; -    if test &quot;$mingw32&quot; = &quot;yes&quot;; then<br>&gt; &gt;&gt; -      LIBCAPSTONE=capstone.lib<br>&gt; &gt;&gt; -    else<br>&gt; &gt;&gt; -      LIBCAPSTONE=libcapstone.a<br>&gt; &gt;&gt; -    fi<br>&gt; &gt;&gt; -    capstone_libs=&quot;-Lcapstone -lcapstone&quot;<br>&gt; &gt;&gt; -    capstone_cflags=&quot;-I${source_path}/capstone/include&quot;<br>&gt; &gt;&gt; -    ;;<br>&gt; &gt;&gt; -<br>&gt; &gt;&gt; -  system)<br>&gt; &gt;&gt; -    capstone_libs=&quot;$($pkg_config --libs capstone)&quot;<br>&gt; &gt;&gt; -    capstone_cflags=&quot;$($pkg_config --cflags capstone)&quot;<br>&gt; &gt;&gt; -    ;;<br>&gt; &gt;&gt; -<br>&gt; &gt;&gt; -  no)<br>&gt; &gt;&gt; -    ;;<br>&gt; &gt;&gt; -  *)<br>&gt; &gt;&gt; -    error_exit &quot;Unknown state for capstone: $capstone&quot;<br>&gt; &gt;&gt;      ;;<br>&gt; &gt;&gt;  esac<br>&gt; &gt;&gt; <br>&gt; &gt;&gt; @@ -7292,11 +7252,6 @@ fi<br>&gt; &gt;&gt;  if test &quot;$ivshmem&quot; = &quot;yes&quot; ; then<br>&gt; &gt;&gt;    echo &quot;CONFIG_IVSHMEM=y&quot; &gt;&gt; $config_host_mak<br>&gt; &gt;&gt;  fi<br>&gt; &gt;&gt; -if test &quot;$capstone&quot; != &quot;no&quot; ; then<br>&gt; &gt;&gt; -  echo &quot;CONFIG_CAPSTONE=y&quot; &gt;&gt; $config_host_mak<br>&gt; &gt;&gt; -  echo &quot;CAPSTONE_CFLAGS=$capstone_cflags&quot; &gt;&gt; $config_host_mak<br>&gt; &gt;&gt; -  echo &quot;CAPSTONE_LIBS=$capstone_libs&quot; &gt;&gt; $config_host_mak<br>&gt; &gt;&gt; -fi<br>&gt; &gt;&gt;  if test &quot;$debug_mutex&quot; = &quot;yes&quot; ; then<br>&gt; &gt;&gt;    echo &quot;CONFIG_DEBUG_MUTEX=y&quot; &gt;&gt; $config_host_mak<br>&gt; &gt;&gt;  fi<br>&gt; &gt;&gt; @@ -7819,9 +7774,6 @@ done # for target in $targets<br>&gt; &gt;&gt;  if [ &quot;$fdt&quot; = &quot;git&quot; ]; then<br>&gt; &gt;&gt;    subdirs=&quot;$subdirs dtc&quot;<br>&gt; &gt;&gt;  fi<br>&gt; &gt;&gt; -if [ &quot;$capstone&quot; = &quot;git&quot; -o &quot;$capstone&quot; = &quot;internal&quot; ]; then<br>&gt; &gt;&gt; -  subdirs=&quot;$subdirs capstone&quot;<br>&gt; &gt;&gt; -fi<br>&gt; &gt;&gt;  echo &quot;SUBDIRS=$subdirs&quot; &gt;&gt; $config_host_mak<br>&gt; &gt;&gt;  if test -n &quot;$LIBCAPSTONE&quot;; then<br>&gt; &gt;&gt;    echo &quot;LIBCAPSTONE=$LIBCAPSTONE&quot; &gt;&gt; $config_host_mak<br>&gt; &gt;&gt; @@ -8008,7 +7960,8 @@ NINJA=${ninja:-$PWD/ninjatool} $meson setup \<br>&gt; &gt;&gt;          -Db_coverage=$(if test &quot;$gcov&quot; = yes; then echo true; else echo false; fi) \<br>&gt; &gt;&gt;      -Dsdl=$sdl -Dsdl_image=$sdl_image \<br>&gt; &gt;&gt;      -Dvnc=$vnc -Dvnc_sasl=$vnc_sasl -Dvnc_jpeg=$vnc_jpeg -Dvnc_png=$vnc_png \<br>&gt; &gt;&gt; -    -Dgettext=$gettext -Dxkbcommon=$xkbcommon -Du2f=$u2f\<br>&gt; &gt;&gt; +    -Dgettext=$gettext -Dxkbcommon=$xkbcommon -Du2f=$u2f \<br>&gt; &gt;&gt; +    -Dcapstone=$capstone \<br>&gt; &gt;&gt;          $cross_arg \<br>&gt; &gt;&gt;          &quot;$PWD&quot; &quot;$source_path&quot;<br>&gt; &gt;&gt; <br>&gt; &gt;&gt; diff --git a/Makefile b/Makefile<br>&gt; &gt;&gt; index 7c60b9dcb8..f3da1760ad 100644<br>&gt; &gt;&gt; --- a/Makefile<br>&gt; &gt;&gt; +++ b/Makefile<br>&gt; &gt;&gt; @@ -156,22 +156,6 @@ dtc/all: .git-submodule-status dtc/libfdt<br>&gt; &gt;&gt;  dtc/%: .git-submodule-status<br>&gt; &gt;&gt;      @mkdir -p $@<br>&gt; &gt;&gt; <br>&gt; &gt;&gt; -# Overriding CFLAGS causes us to lose defines added in the sub-makefile.<br>&gt; &gt;&gt; -# Not overriding CFLAGS leads to mis-matches between compilation modes.<br>&gt; &gt;&gt; -# Therefore we replicate some of the logic in the sub-makefile.<br>&gt; &gt;&gt; -# Remove all the extra -Warning flags that QEMU uses that Capstone doesn&#39;t;<br>&gt; &gt;&gt; -# no need to annoy QEMU developers with such things.<br>&gt; &gt;&gt; -CAP_CFLAGS = $(patsubst -W%,,$(CFLAGS) $(QEMU_CFLAGS)) $(CAPSTONE_CFLAGS)<br>&gt; &gt;&gt; -CAP_CFLAGS += -DCAPSTONE_USE_SYS_DYN_MEM<br>&gt; &gt;&gt; -CAP_CFLAGS += -DCAPSTONE_HAS_ARM<br>&gt; &gt;&gt; -CAP_CFLAGS += -DCAPSTONE_HAS_ARM64<br>&gt; &gt;&gt; -CAP_CFLAGS += -DCAPSTONE_HAS_POWERPC<br>&gt; &gt;&gt; -CAP_CFLAGS += -DCAPSTONE_HAS_X86<br>&gt; &gt;&gt; -<br>&gt; &gt;&gt; -.PHONY: capstone/all<br>&gt; &gt;&gt; -capstone/all: .git-submodule-status<br>&gt; &gt;&gt; -    $(call quiet-command,$(MAKE) -C $(SRC_PATH)/capstone CAPSTONE_SHARED=no BUILDDIR=&quot;$(BUILD_DIR)/capstone&quot; CC=&quot;$(CC)&quot; AR=&quot;$(AR)&quot; LD=&quot;$(LD)&quot; RANLIB=&quot;$(RANLIB)&quot; CFLAGS=&quot;$(CAP_CFLAGS)&quot; $(SUBDIR_MAKEFLAGS) $(BUILD_DIR)/capstone/$(LIBCAPSTONE))<br>&gt; &gt;&gt; -<br>&gt; &gt;&gt;  .PHONY: slirp/all<br>&gt; &gt;&gt;  slirp/all: .git-submodule-status<br>&gt; &gt;&gt;      $(call quiet-command,$(MAKE) -C $(SRC_PATH)/slirp               \<br>&gt; &gt;&gt; diff --git a/meson.build b/meson.build<br>&gt; &gt;&gt; index f4d1ab1096..f23273693d 100644<br>&gt; &gt;&gt; --- a/meson.build<br>&gt; &gt;&gt; +++ b/meson.build<br>&gt; &gt;&gt; @@ -10,6 +10,7 @@ else<br>&gt; &gt;&gt;    keyval = import(&#39;unstable-keyval&#39;)<br>&gt; &gt;&gt;  endif<br>&gt; &gt;&gt;  ss = import(&#39;sourceset&#39;)<br>&gt; &gt;&gt; +fs = import(&#39;fs&#39;)<br>&gt; &gt;&gt; <br>&gt; &gt;&gt;  sh = find_program(&#39;sh&#39;)<br>&gt; &gt;&gt;  cc = meson.get_compiler(&#39;c&#39;)<br>&gt; &gt;&gt; @@ -409,11 +410,6 @@ if &#39;CONFIG_USB_LIBUSB&#39; in config_host<br>&gt; &gt;&gt;    libusb = declare_dependency(compile_args: config_host[&#39;LIBUSB_CFLAGS&#39;].split(),<br>&gt; &gt;&gt;                                link_args: config_host[&#39;LIBUSB_LIBS&#39;].split())<br>&gt; &gt;&gt;  endif<br>&gt; &gt;&gt; -capstone = not_found<br>&gt; &gt;&gt; -if &#39;CONFIG_CAPSTONE&#39; in config_host<br>&gt; &gt;&gt; -  capstone = declare_dependency(compile_args: config_host[&#39;CAPSTONE_CFLAGS&#39;].split(),<br>&gt; &gt;&gt; -                                link_args: config_host[&#39;CAPSTONE_LIBS&#39;].split())<br>&gt; &gt;&gt; -endif<br>&gt; &gt;&gt;  libpmem = not_found<br>&gt; &gt;&gt;  if &#39;CONFIG_LIBPMEM&#39; in config_host<br>&gt; &gt;&gt;    libpmem = declare_dependency(compile_args: config_host[&#39;LIBPMEM_CFLAGS&#39;].split(),<br>&gt; &gt;&gt; @@ -470,7 +466,6 @@ foreach k, v: config_host<br>&gt; &gt;&gt;      config_host_data.set(k, v == &#39;y&#39; ? 1 : v)<br>&gt; &gt;&gt;    endif<br>&gt; &gt;&gt;  endforeach<br>&gt; &gt;&gt; -genh += configure_file(output: &#39;config-host.h&#39;, configuration: config_host_data)<br>&gt; &gt;&gt; <br>&gt; &gt;&gt;  minikconf = find_program(&#39;scripts/minikconf.py&#39;)<br>&gt; &gt;&gt;  config_all_devices = {}<br>&gt; &gt;&gt; @@ -610,6 +605,108 @@ config_all += {<br>&gt; &gt;&gt;    &#39;CONFIG_ALL&#39;: true,<br>&gt; &gt;&gt;  }<br>&gt; &gt;&gt; <br>&gt; &gt;&gt; +# Submodules<br>&gt; &gt;&gt; +<br>&gt; &gt;&gt; +capstone = not_found<br>&gt; &gt;&gt; +capstone_opt = get_option(&#39;capstone&#39;)<br>&gt; &gt;&gt; +if capstone_opt == &#39;no&#39;<br>&gt; &gt;&gt; +  capstone_opt = false<br>&gt; &gt;&gt; +elif capstone_opt in [&#39;yes&#39;, &#39;auto&#39;, &#39;system&#39;]<br>&gt; &gt;&gt; +  have_internal = fs.exists(&#39;capstone/Makefile&#39;)<br>&gt; &gt;&gt; +  capstone = dependency(&#39;capstone&#39;, static: enable_static,<br>&gt; &gt;&gt; +                        required: capstone_opt == &#39;system&#39; or<br>&gt; &gt;&gt; +                                  capstone_opt == &#39;yes&#39; and not have_internal)<br>&gt; &gt;&gt; +  if capstone.found()<br>&gt; &gt;&gt; +    capstone_opt = &#39;system&#39;<br>&gt; &gt;&gt; +  elif have_internal<br>&gt; &gt;&gt; +    capstone_opt = &#39;internal&#39;<br>&gt; &gt;&gt; +  else<br>&gt; &gt;&gt; +    capstone_opt = false<br>&gt; &gt;&gt; +  endif<br>&gt; &gt;&gt; +endif<br>&gt; &gt;&gt; +if capstone_opt == &#39;internal&#39;<br>&gt; &gt;&gt; +  capstone_data = configuration_data()<br>&gt; &gt;&gt; +  capstone_data.set(&#39;CAPSTONE_USE_SYS_DYN_MEM&#39;, &#39;1&#39;)<br>&gt; &gt;&gt; +<br>&gt; &gt;&gt; +  capstone_files = files(<br>&gt; &gt;&gt; +    &#39;capstone/cs.c&#39;,<br>&gt; &gt;&gt; +    &#39;capstone/MCInst.c&#39;,<br>&gt; &gt;&gt; +    &#39;capstone/MCInstrDesc.c&#39;,<br>&gt; &gt;&gt; +    &#39;capstone/MCRegisterInfo.c&#39;,<br>&gt; &gt;&gt; +    &#39;capstone/SStream.c&#39;,<br>&gt; &gt;&gt; +    &#39;capstone/utils.c&#39;<br>&gt; &gt;&gt; +  )<br>&gt; &gt;&gt; +<br>&gt; &gt;&gt; +  if &#39;CONFIG_ARM_DIS&#39; in config_all_disas<br>&gt; &gt;&gt; +    capstone_data.set(&#39;CAPSTONE_HAS_ARM&#39;, &#39;1&#39;)<br>&gt; &gt;&gt; +    capstone_files += files(<br>&gt; &gt;&gt; +      &#39;capstone/arch/ARM/ARMDisassembler.c&#39;,<br>&gt; &gt;&gt; +      &#39;capstone/arch/ARM/ARMInstPrinter.c&#39;,<br>&gt; &gt;&gt; +      &#39;capstone/arch/ARM/ARMMapping.c&#39;,<br>&gt; &gt;&gt; +      &#39;capstone/arch/ARM/ARMModule.c&#39;<br>&gt; &gt;&gt; +    )<br>&gt; &gt;&gt; +  endif<br>&gt; &gt;&gt; +<br>&gt; &gt;&gt; +  # FIXME: This config entry currently depends on a c++ compiler.<br>&gt; &gt;&gt; +  # Which is needed for building libvixl, but not for capstone.<br>&gt; &gt;&gt; +  if &#39;CONFIG_ARM_A64_DIS&#39; in config_all_disas<br>&gt; &gt;&gt; +    capstone_data.set(&#39;CAPSTONE_HAS_ARM64&#39;, &#39;1&#39;)<br>&gt; &gt;&gt; +    capstone_files += files(<br>&gt; &gt;&gt; +      &#39;capstone/arch/AArch64/AArch64BaseInfo.c&#39;,<br>&gt; &gt;&gt; +      &#39;capstone/arch/AArch64/AArch64Disassembler.c&#39;,<br>&gt; &gt;&gt; +      &#39;capstone/arch/AArch64/AArch64InstPrinter.c&#39;,<br>&gt; &gt;&gt; +      &#39;capstone/arch/AArch64/AArch64Mapping.c&#39;,<br>&gt; &gt;&gt; +      &#39;capstone/arch/AArch64/AArch64Module.c&#39;<br>&gt; &gt;&gt; +    )<br>&gt; &gt;&gt; +  endif<br>&gt; &gt;&gt; +<br>&gt; &gt;&gt; +  if &#39;CONFIG_PPC_DIS&#39; in config_all_disas<br>&gt; &gt;&gt; +    capstone_data.set(&#39;CAPSTONE_HAS_POWERPC&#39;, &#39;1&#39;)<br>&gt; &gt;&gt; +    capstone_files += files(<br>&gt; &gt;&gt; +      &#39;capstone/arch/PowerPC/PPCDisassembler.c&#39;,<br>&gt; &gt;&gt; +      &#39;capstone/arch/PowerPC/PPCInstPrinter.c&#39;,<br>&gt; &gt;&gt; +      &#39;capstone/arch/PowerPC/PPCMapping.c&#39;,<br>&gt; &gt;&gt; +      &#39;capstone/arch/PowerPC/PPCModule.c&#39;<br>&gt; &gt;&gt; +    )<br>&gt; &gt;&gt; +  endif<br>&gt; &gt;&gt; +<br>&gt; &gt;&gt; +  if &#39;CONFIG_I386_DIS&#39; in config_all_disas<br>&gt; &gt;&gt; +    capstone_data.set(&#39;CAPSTONE_HAS_X86&#39;, 1)<br>&gt; &gt;&gt; +    capstone_files += files(<br>&gt; &gt;&gt; +      &#39;capstone/arch/X86/X86Disassembler.c&#39;,<br>&gt; &gt;&gt; +      &#39;capstone/arch/X86/X86DisassemblerDecoder.c&#39;,<br>&gt; &gt;&gt; +      &#39;capstone/arch/X86/X86ATTInstPrinter.c&#39;,<br>&gt; &gt;&gt; +      &#39;capstone/arch/X86/X86IntelInstPrinter.c&#39;,<br>&gt; &gt;&gt; +      &#39;capstone/arch/X86/X86Mapping.c&#39;,<br>&gt; &gt;&gt; +      &#39;capstone/arch/X86/X86Module.c&#39;<br>&gt; &gt;&gt; +    )<br>&gt; &gt;&gt; +  endif<br>&gt; &gt;&gt; +<br>&gt; &gt;&gt; +  configure_file(output: &#39;capstone-defs.h&#39;, configuration: capstone_data)<br>&gt; &gt;&gt; +<br>&gt; &gt;&gt; +  capstone_cargs = [<br>&gt; &gt;&gt; +    # FIXME: There does not seem to be a way to completely replace the c_args<br>&gt; &gt;&gt; +    # that come from add_project_arguments() -- we can only add to them.<br>&gt; &gt;&gt; +    # So: disable all warnings with a big hammer.<br>&gt; &gt;&gt; +    &#39;-Wno-error&#39;, &#39;-w&#39;,<br>&gt; &gt;&gt; +<br>&gt; &gt;&gt; +    # Include all configuration defines via a header file, which will wind up<br>&gt; &gt;&gt; +    # as a dependency on the object file, and thus changes here will result<br>&gt; &gt;&gt; +    # in a rebuild.<br>&gt; &gt;&gt; +    &#39;-include&#39;, &#39;capstone-defs.h&#39;<br>&gt; &gt;&gt; +  ]<br>&gt; &gt;&gt; +<br>&gt; &gt;&gt; +  libcapstone = static_library(&#39;capstone&#39;,<br>&gt; &gt;&gt; +                               sources: capstone_files,<br>&gt; &gt;&gt; +                               c_args: capstone_cargs,<br>&gt; &gt;&gt; +                               include_directories: &#39;capstone/include&#39;)<br>&gt; &gt;&gt; +  capstone = declare_dependency(link_with: libcapstone,<br>&gt; &gt;&gt; +                                include_directories: &#39;capstone/include&#39;)<br>&gt; &gt;&gt; +endif<br>&gt; &gt;&gt; +config_host_data.set(&#39;CONFIG_CAPSTONE&#39;, capstone.found())<br>&gt; &gt;&gt; +<br>&gt; &gt;&gt; +genh += configure_file(output: &#39;config-host.h&#39;, configuration: config_host_data)<br>&gt; &gt;&gt; +<br>&gt; &gt;&gt;  # Generators<br>&gt; &gt;&gt; <br>&gt; &gt;&gt;  hxtool = find_program(&#39;scripts/hxtool&#39;)<br>&gt; &gt;&gt; @@ -1512,7 +1609,7 @@ summary_info += {&#39;vvfat support&#39;:     config_host.has_key(&#39;CONFIG_VVFAT&#39;)}<br>&gt; &gt;&gt;  summary_info += {&#39;qed support&#39;:       config_host.has_key(&#39;CONFIG_QED&#39;)}<br>&gt; &gt;&gt;  summary_info += {&#39;parallels support&#39;: config_host.has_key(&#39;CONFIG_PARALLELS&#39;)}<br>&gt; &gt;&gt;  summary_info += {&#39;sheepdog support&#39;:  config_host.has_key(&#39;CONFIG_SHEEPDOG&#39;)}<br>&gt; &gt;&gt; -summary_info += {&#39;capstone&#39;:          config_host.has_key(&#39;CONFIG_CAPSTONE&#39;)}<br>&gt; &gt;&gt; +summary_info += {&#39;capstone&#39;:          capstone_opt}<br>&gt; &gt;&gt;  summary_info += {&#39;libpmem support&#39;:   config_host.has_key(&#39;CONFIG_LIBPMEM&#39;)}<br>&gt; &gt;&gt;  summary_info += {&#39;libdaxctl support&#39;: config_host.has_key(&#39;CONFIG_LIBDAXCTL&#39;)}<br>&gt; &gt;&gt;  summary_info += {&#39;libudev&#39;:           config_host.has_key(&#39;CONFIG_LIBUDEV&#39;)}<br>&gt; &gt;&gt; diff --git a/meson_options.txt b/meson_options.txt<br>&gt; &gt;&gt; index 543cf70043..e650a937e7 100644<br>&gt; &gt;&gt; --- a/meson_options.txt<br>&gt; &gt;&gt; +++ b/meson_options.txt<br>&gt; &gt;&gt; @@ -22,3 +22,7 @@ option(&#39;vnc_sasl&#39;, type : &#39;feature&#39;, value : &#39;auto&#39;,<br>&gt; &gt;&gt;         description: &#39;SASL authentication for VNC server&#39;)<br>&gt; &gt;&gt;  option(&#39;xkbcommon&#39;, type : &#39;feature&#39;, value : &#39;auto&#39;,<br>&gt; &gt;&gt;         description: &#39;xkbcommon support&#39;)<br>&gt; &gt;&gt; +<br>&gt; &gt;&gt; +option(&#39;capstone&#39;, type: &#39;combo&#39;, value: &#39;auto&#39;,<br>&gt; &gt;&gt; +       choices: [&#39;no&#39;, &#39;yes&#39;, &#39;auto&#39;, &#39;system&#39;, &#39;internal&#39;],<br>&gt; &gt;&gt; +       description: &#39;Whether and how to find the capstone library&#39;)<br>&gt;<br>&gt;<br>&gt; Hmm even more confusing is configure does:<br>&gt;<br>&gt;   GIT submodules: ui/keycodemapdb tests/fp/berkeley-testfloat-3 tests/fp/berkeley-softfloat-3 meson dtc capstone slirp<br>&gt;<br>&gt; but also:<br>&gt;<br>&gt;   capstone: system<br>&gt;<br>&gt; which I can&#39;t quite help but feel is going to be confusing.<div>maybe remove the capstone system support is a good idea after-all.<br>&gt;<br>&gt; --<br>&gt; Alex Bennée<br>&gt;<br><br><br>--<br>         此致<br>礼<br>罗勇刚<br>Yours<br>    sincerely,<br>Yonggang Luo</div></div>
Paolo Bonzini Sept. 21, 2020, 1:12 p.m. UTC | #9
On 21/09/20 12:54, Alex Bennée wrote:
> Something is breaking when switching to a branch with this on from

> current master:

> 

>   Linking target qemu-hppa

>   /usr/bin/ld: libcommon.fa.p/disas_alpha.c.o: in function `print_insn_alpha':

>   /home/alex/lsrc/qemu.git/builds/all/../../disas/alpha.c:1818: undefined reference to `bfd_getl32'

>   collect2: error: ld returned 1 exit status

>   make: *** [Makefile.ninja:5965: qemu-alpha] Error 1

>   make: *** Waiting for unfinished jobs....

>   /usr/bin/ld: libcommon.fa.p/disas_hppa.c.o: in function `print_insn_hppa':

>   /home/alex/lsrc/qemu.git/builds/all/../../disas/hppa.c:1969: undefined reference to `bfd_getb32'

>   collect2: error: ld returned 1 exit status

>   make: *** [Makefile.ninja:6259: qemu-hppa] Error 1


From "https://wiki.qemu.org/Features/Meson":

Known issues
============

There is one Make issue that might happen when switching branches: if
the command line changes, the files are not rebuilt. This is always a
problem with Make, but it may become more common now due to the use of
statically-linked libraries.


The simplest fix here would be to use ninja to build QEMU, i.e. do the
main QEMU build recursively just like we do for submodules, keeping Make
purely to orchestrate the build.

Paolo
diff mbox series

Patch

diff --git a/configure b/configure
index 7564479008..76636c430d 100755
--- a/configure
+++ b/configure
@@ -478,7 +478,7 @@  opengl=""
 opengl_dmabuf="no"
 cpuid_h="no"
 avx2_opt=""
-capstone=""
+capstone="auto"
 lzo=""
 snappy=""
 bzip2=""
@@ -1580,7 +1580,7 @@  for opt do
   ;;
   --enable-capstone) capstone="yes"
   ;;
-  --enable-capstone=git) capstone="git"
+  --enable-capstone=git) capstone="internal"
   ;;
   --enable-capstone=system) capstone="system"
   ;;
@@ -5128,51 +5128,11 @@  fi
 # capstone
 
 case "$capstone" in
-  "" | yes)
-    if $pkg_config capstone; then
-      capstone=system
-    elif test -e "${source_path}/.git" && test $git_update = 'yes' ; then
-      capstone=git
-    elif test -e "${source_path}/capstone/Makefile" ; then
-      capstone=internal
-    elif test -z "$capstone" ; then
-      capstone=no
-    else
-      feature_not_found "capstone" "Install capstone devel or git submodule"
-    fi
-    ;;
-
-  system)
-    if ! $pkg_config capstone; then
-      feature_not_found "capstone" "Install capstone devel"
-    fi
-    ;;
-esac
-
-case "$capstone" in
-  git | internal)
-    if test "$capstone" = git; then
+  auto | yes | internal)
+    # Simpler to always update submodule, even if not needed.
+    if test -e "${source_path}/.git" && test $git_update = 'yes' ; then
       git_submodules="${git_submodules} capstone"
     fi
-    mkdir -p capstone
-    if test "$mingw32" = "yes"; then
-      LIBCAPSTONE=capstone.lib
-    else
-      LIBCAPSTONE=libcapstone.a
-    fi
-    capstone_libs="-Lcapstone -lcapstone"
-    capstone_cflags="-I${source_path}/capstone/include"
-    ;;
-
-  system)
-    capstone_libs="$($pkg_config --libs capstone)"
-    capstone_cflags="$($pkg_config --cflags capstone)"
-    ;;
-
-  no)
-    ;;
-  *)
-    error_exit "Unknown state for capstone: $capstone"
     ;;
 esac
 
@@ -7292,11 +7252,6 @@  fi
 if test "$ivshmem" = "yes" ; then
   echo "CONFIG_IVSHMEM=y" >> $config_host_mak
 fi
-if test "$capstone" != "no" ; then
-  echo "CONFIG_CAPSTONE=y" >> $config_host_mak
-  echo "CAPSTONE_CFLAGS=$capstone_cflags" >> $config_host_mak
-  echo "CAPSTONE_LIBS=$capstone_libs" >> $config_host_mak
-fi
 if test "$debug_mutex" = "yes" ; then
   echo "CONFIG_DEBUG_MUTEX=y" >> $config_host_mak
 fi
@@ -7819,9 +7774,6 @@  done # for target in $targets
 if [ "$fdt" = "git" ]; then
   subdirs="$subdirs dtc"
 fi
-if [ "$capstone" = "git" -o "$capstone" = "internal" ]; then
-  subdirs="$subdirs capstone"
-fi
 echo "SUBDIRS=$subdirs" >> $config_host_mak
 if test -n "$LIBCAPSTONE"; then
   echo "LIBCAPSTONE=$LIBCAPSTONE" >> $config_host_mak
@@ -8008,7 +7960,8 @@  NINJA=${ninja:-$PWD/ninjatool} $meson setup \
         -Db_coverage=$(if test "$gcov" = yes; then echo true; else echo false; fi) \
 	-Dsdl=$sdl -Dsdl_image=$sdl_image \
 	-Dvnc=$vnc -Dvnc_sasl=$vnc_sasl -Dvnc_jpeg=$vnc_jpeg -Dvnc_png=$vnc_png \
-	-Dgettext=$gettext -Dxkbcommon=$xkbcommon -Du2f=$u2f\
+	-Dgettext=$gettext -Dxkbcommon=$xkbcommon -Du2f=$u2f \
+	-Dcapstone=$capstone \
         $cross_arg \
         "$PWD" "$source_path"
 
diff --git a/Makefile b/Makefile
index 7c60b9dcb8..f3da1760ad 100644
--- a/Makefile
+++ b/Makefile
@@ -156,22 +156,6 @@  dtc/all: .git-submodule-status dtc/libfdt
 dtc/%: .git-submodule-status
 	@mkdir -p $@
 
-# Overriding CFLAGS causes us to lose defines added in the sub-makefile.
-# Not overriding CFLAGS leads to mis-matches between compilation modes.
-# Therefore we replicate some of the logic in the sub-makefile.
-# Remove all the extra -Warning flags that QEMU uses that Capstone doesn't;
-# no need to annoy QEMU developers with such things.
-CAP_CFLAGS = $(patsubst -W%,,$(CFLAGS) $(QEMU_CFLAGS)) $(CAPSTONE_CFLAGS)
-CAP_CFLAGS += -DCAPSTONE_USE_SYS_DYN_MEM
-CAP_CFLAGS += -DCAPSTONE_HAS_ARM
-CAP_CFLAGS += -DCAPSTONE_HAS_ARM64
-CAP_CFLAGS += -DCAPSTONE_HAS_POWERPC
-CAP_CFLAGS += -DCAPSTONE_HAS_X86
-
-.PHONY: capstone/all
-capstone/all: .git-submodule-status
-	$(call quiet-command,$(MAKE) -C $(SRC_PATH)/capstone CAPSTONE_SHARED=no BUILDDIR="$(BUILD_DIR)/capstone" CC="$(CC)" AR="$(AR)" LD="$(LD)" RANLIB="$(RANLIB)" CFLAGS="$(CAP_CFLAGS)" $(SUBDIR_MAKEFLAGS) $(BUILD_DIR)/capstone/$(LIBCAPSTONE))
-
 .PHONY: slirp/all
 slirp/all: .git-submodule-status
 	$(call quiet-command,$(MAKE) -C $(SRC_PATH)/slirp		\
diff --git a/meson.build b/meson.build
index f4d1ab1096..f23273693d 100644
--- a/meson.build
+++ b/meson.build
@@ -10,6 +10,7 @@  else
   keyval = import('unstable-keyval')
 endif
 ss = import('sourceset')
+fs = import('fs')
 
 sh = find_program('sh')
 cc = meson.get_compiler('c')
@@ -409,11 +410,6 @@  if 'CONFIG_USB_LIBUSB' in config_host
   libusb = declare_dependency(compile_args: config_host['LIBUSB_CFLAGS'].split(),
                               link_args: config_host['LIBUSB_LIBS'].split())
 endif
-capstone = not_found
-if 'CONFIG_CAPSTONE' in config_host
-  capstone = declare_dependency(compile_args: config_host['CAPSTONE_CFLAGS'].split(),
-                                link_args: config_host['CAPSTONE_LIBS'].split())
-endif
 libpmem = not_found
 if 'CONFIG_LIBPMEM' in config_host
   libpmem = declare_dependency(compile_args: config_host['LIBPMEM_CFLAGS'].split(),
@@ -470,7 +466,6 @@  foreach k, v: config_host
     config_host_data.set(k, v == 'y' ? 1 : v)
   endif
 endforeach
-genh += configure_file(output: 'config-host.h', configuration: config_host_data)
 
 minikconf = find_program('scripts/minikconf.py')
 config_all_devices = {}
@@ -610,6 +605,108 @@  config_all += {
   'CONFIG_ALL': true,
 }
 
+# Submodules
+
+capstone = not_found
+capstone_opt = get_option('capstone')
+if capstone_opt == 'no'
+  capstone_opt = false
+elif capstone_opt in ['yes', 'auto', 'system']
+  have_internal = fs.exists('capstone/Makefile')
+  capstone = dependency('capstone', static: enable_static,
+                        required: capstone_opt == 'system' or
+                                  capstone_opt == 'yes' and not have_internal)
+  if capstone.found()
+    capstone_opt = 'system'
+  elif have_internal
+    capstone_opt = 'internal'
+  else
+    capstone_opt = false
+  endif
+endif
+if capstone_opt == 'internal'
+  capstone_data = configuration_data()
+  capstone_data.set('CAPSTONE_USE_SYS_DYN_MEM', '1')
+
+  capstone_files = files(
+    'capstone/cs.c',
+    'capstone/MCInst.c',
+    'capstone/MCInstrDesc.c',
+    'capstone/MCRegisterInfo.c',
+    'capstone/SStream.c',
+    'capstone/utils.c'
+  )
+
+  if 'CONFIG_ARM_DIS' in config_all_disas
+    capstone_data.set('CAPSTONE_HAS_ARM', '1')
+    capstone_files += files(
+      'capstone/arch/ARM/ARMDisassembler.c',
+      'capstone/arch/ARM/ARMInstPrinter.c',
+      'capstone/arch/ARM/ARMMapping.c',
+      'capstone/arch/ARM/ARMModule.c'
+    )
+  endif
+
+  # FIXME: This config entry currently depends on a c++ compiler.
+  # Which is needed for building libvixl, but not for capstone.
+  if 'CONFIG_ARM_A64_DIS' in config_all_disas
+    capstone_data.set('CAPSTONE_HAS_ARM64', '1')
+    capstone_files += files(
+      'capstone/arch/AArch64/AArch64BaseInfo.c',
+      'capstone/arch/AArch64/AArch64Disassembler.c',
+      'capstone/arch/AArch64/AArch64InstPrinter.c',
+      'capstone/arch/AArch64/AArch64Mapping.c',
+      'capstone/arch/AArch64/AArch64Module.c'
+    )
+  endif
+
+  if 'CONFIG_PPC_DIS' in config_all_disas
+    capstone_data.set('CAPSTONE_HAS_POWERPC', '1')
+    capstone_files += files(
+      'capstone/arch/PowerPC/PPCDisassembler.c',
+      'capstone/arch/PowerPC/PPCInstPrinter.c',
+      'capstone/arch/PowerPC/PPCMapping.c',
+      'capstone/arch/PowerPC/PPCModule.c'
+    )
+  endif
+
+  if 'CONFIG_I386_DIS' in config_all_disas
+    capstone_data.set('CAPSTONE_HAS_X86', 1)
+    capstone_files += files(
+      'capstone/arch/X86/X86Disassembler.c',
+      'capstone/arch/X86/X86DisassemblerDecoder.c',
+      'capstone/arch/X86/X86ATTInstPrinter.c',
+      'capstone/arch/X86/X86IntelInstPrinter.c',
+      'capstone/arch/X86/X86Mapping.c',
+      'capstone/arch/X86/X86Module.c'
+    )
+  endif
+
+  configure_file(output: 'capstone-defs.h', configuration: capstone_data)
+
+  capstone_cargs = [
+    # FIXME: There does not seem to be a way to completely replace the c_args
+    # that come from add_project_arguments() -- we can only add to them.
+    # So: disable all warnings with a big hammer.
+    '-Wno-error', '-w',
+
+    # Include all configuration defines via a header file, which will wind up
+    # as a dependency on the object file, and thus changes here will result
+    # in a rebuild.
+    '-include', 'capstone-defs.h'
+  ]
+
+  libcapstone = static_library('capstone',
+                               sources: capstone_files,
+                               c_args: capstone_cargs,
+                               include_directories: 'capstone/include')
+  capstone = declare_dependency(link_with: libcapstone,
+                                include_directories: 'capstone/include')
+endif
+config_host_data.set('CONFIG_CAPSTONE', capstone.found())
+
+genh += configure_file(output: 'config-host.h', configuration: config_host_data)
+
 # Generators
 
 hxtool = find_program('scripts/hxtool')
@@ -1512,7 +1609,7 @@  summary_info += {'vvfat support':     config_host.has_key('CONFIG_VVFAT')}
 summary_info += {'qed support':       config_host.has_key('CONFIG_QED')}
 summary_info += {'parallels support': config_host.has_key('CONFIG_PARALLELS')}
 summary_info += {'sheepdog support':  config_host.has_key('CONFIG_SHEEPDOG')}
-summary_info += {'capstone':          config_host.has_key('CONFIG_CAPSTONE')}
+summary_info += {'capstone':          capstone_opt}
 summary_info += {'libpmem support':   config_host.has_key('CONFIG_LIBPMEM')}
 summary_info += {'libdaxctl support': config_host.has_key('CONFIG_LIBDAXCTL')}
 summary_info += {'libudev':           config_host.has_key('CONFIG_LIBUDEV')}
diff --git a/meson_options.txt b/meson_options.txt
index 543cf70043..e650a937e7 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -22,3 +22,7 @@  option('vnc_sasl', type : 'feature', value : 'auto',
        description: 'SASL authentication for VNC server')
 option('xkbcommon', type : 'feature', value : 'auto',
        description: 'xkbcommon support')
+
+option('capstone', type: 'combo', value: 'auto',
+       choices: ['no', 'yes', 'auto', 'system', 'internal'],
+       description: 'Whether and how to find the capstone library')