Skip to contentSkip to conversation

target/hexagon: Fix macOS build

PATCH In review Anton Johansson via 2 participants 6 messages Apr 2, 2025 – Apr 4, 2025 Arm/Amlogic Meson SoC support

lore
Share & tools
lore
#0 lore raw

v2 cover target/hexagon: Fix macOS build

A default macOS build with xcode cli tools installed lacks the indent program needed by the idef-parser postprocess step. If indent is installed through homebrew it doesn't support the -linux flag. Conditionally run indent only on linux hosts.

Additionally cpp used by the idef-parser preprocess step expands into clang ... -traditional-cpp and doesn't support macro concatenation among other things, replace it with a meson custom_target running ${compiler} -E.

Note: default bison on macOS is still too old (v2.3 vs v3.0) and a newer version needs to be installed via homebrew. I'll take a look at supporting v2.3.

Changes in v2:
* Don't remove the indent step but only run on linux hosts.

Anton Johansson (2):
target/hexagon: Replace prepare script with meson target target/hexagon: Only indent on linux

 target/hexagon/idef-parser/prepare | 24 ------------------------
 target/hexagon/meson.build         |  5 +++--
 2 files changed, 3 insertions(+), 26 deletions(-)
 delete mode 100755 target/hexagon/idef-parser/prepare
Signature · 1 line
2.47.1
#1 lore raw

PATCH v2 1/2 target/hexagon: Replace `prepare` script with meson target

The purpose of the prepare script is to invoke cpp to preprocess input to idef-parser by expanding a few select macros. On macOS cpp expands into clang ... -traditional-cpp which breaks macro concatenation. Replace cpp with ${compiler} -E
and replace the script with a meson custom_target.

---
 target/hexagon/idef-parser/prepare | 24 ------------------------
 target/hexagon/meson.build         |  3 ++-
 2 files changed, 2 insertions(+), 25 deletions(-)
 delete mode 100755 target/hexagon/idef-parser/prepare
target/hexagon/idef-parser/prepare deleted +0 -24
deleted file mode 100755
index cb3622d4f8..0000000000
@@ -1,24 +0,0 @@
-#!/usr/bin/env bash
-
-#
-#  Copyright(c) 2019-2021 rev.ng Labs Srl. All Rights Reserved.
-#
-#  This program is free software; you can redistribute it and/or modify
-#  it under the terms of the GNU General Public License as published by
-#  the Free Software Foundation; either version 2 of the License, or
-#  (at your option) any later version.
-#
-#  This program is distributed in the hope that it will be useful,
-#  but WITHOUT ANY WARRANTY; without even the implied warranty of
-#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#  GNU General Public License for more details.
-#
-#  You should have received a copy of the GNU General Public License
-#  along with this program; if not, see <http://www.gnu.org/licenses/>.
-#
-
-set -e
-set -o pipefail
-
-# Run the preprocessor and drop comments
-cpp "$@"
target/hexagon/meson.build +2 -1
index bb4ebaae81..abcf00ca1f 100644
@@ -280,12 +280,13 @@ if idef_parser_enabled and 'hexagon-linux-user' in target_dirs
         command: [python, files('gen_idef_parser_funcs.py'), semantics_generated, '@OUTPUT@'],
     )
 
+    compiler = meson.get_compiler('c').get_id()
     preprocessed_idef_parser_input_generated = custom_target(
         'idef_parser_input.preprocessed.h.inc',
         output: 'idef_parser_input.preprocessed.h.inc',
         input: idef_parser_input_generated,
         depend_files: [idef_parser_dir / 'macros.h.inc'],
-        command: [idef_parser_dir / 'prepare', '@INPUT@', '-I' + idef_parser_dir, '-o', '@OUTPUT@'],
+        command: [compiler, '-x', 'c', '-E', '-I', idef_parser_dir, '-o', '@OUTPUT@', '@INPUT@'],
     )
 
     flex = generator(
Signature · 1 line
2.47.1
Reviewed-by on v2 1/2
#2 lore raw

Re: [PATCH v2 1/2] target/hexagon: Replace `prepare` script with meson target

Quoted 8 lines · Anton Johansson

The purpose of the prepare script is to invoke cpp to preprocess input to idef-parser by expanding a few select macros. On macOS cpp expands into clang ... -traditional-cpp which breaks macro concatenation. Replace cpp with ${compiler} -E
and replace the script with a meson custom_target.

---

Quoted 54 lines
  target/hexagon/idef-parser/prepare | 24 ------------------------
  target/hexagon/meson.build         |  3 ++-
  2 files changed, 2 insertions(+), 25 deletions(-)

delete mode 100755 target/hexagon/idef-parser/prepare

target/hexagon/idef-parser/prepare deleted +0 -24
deleted file mode 100755
index cb3622d4f8..0000000000
@@ -1,24 +0,0 @@
-#!/usr/bin/env bash
-
-#
-#  Copyright(c) 2019-2021 rev.ng Labs Srl. All Rights Reserved.
-#
-#  This program is free software; you can redistribute it and/or modify
-#  it under the terms of the GNU General Public License as published by
-#  the Free Software Foundation; either version 2 of the License, or
-#  (at your option) any later version.
-#
-#  This program is distributed in the hope that it will be useful,
-#  but WITHOUT ANY WARRANTY; without even the implied warranty of
-#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#  GNU General Public License for more details.
-#
-#  You should have received a copy of the GNU General Public License
-#  along with this program; if not, see <http://www.gnu.org/licenses/>.
-#
-
-set -e
-set -o pipefail
-
-# Run the preprocessor and drop comments
-cpp "$@"
target/hexagon/meson.build +2 -1
index bb4ebaae81..abcf00ca1f 100644
@@ -280,12 +280,13 @@ if idef_parser_enabled and 'hexagon-linux-user' in target_dirs
          command: [python, files('gen_idef_parser_funcs.py'), semantics_generated, '@OUTPUT@'],
      )
 
+    compiler = meson.get_compiler('c').get_id()
      preprocessed_idef_parser_input_generated = custom_target(
          'idef_parser_input.preprocessed.h.inc',
          output: 'idef_parser_input.preprocessed.h.inc',
          input: idef_parser_input_generated,
          depend_files: [idef_parser_dir / 'macros.h.inc'],
-        command: [idef_parser_dir / 'prepare', '@INPUT@', '-I' + idef_parser_dir, '-o', '@OUTPUT@'],
+        command: [compiler, '-x', 'c', '-E', '-I', idef_parser_dir, '-o', '@OUTPUT@', '@INPUT@'],
      )
 
      flex = generator(
#3 lore raw

PATCH v2 2/2 target/hexagon: Only indent on linux

In reply to Anton Johansson via

indent on macOS, installed via homebrew, doesn't support -linux. Only run indent on linux hosts.

---
 target/hexagon/meson.build | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target/hexagon/meson.build +1 -1
index abcf00ca1f..d26787a9b9 100644
@@ -324,7 +324,7 @@ if idef_parser_enabled and 'hexagon-linux-user' in target_dirs
     )
 
     indent = find_program('indent', required: false)
-    if indent.found()
+    if indent.found() and host_os == 'linux'
         idef_generated_tcg_c = custom_target(
             'indent',
             input: idef_generated_tcg[0],
Signature · 1 line
2.47.1
Reviewed-by on v2 2/2
#4 lore raw

Re: [PATCH v2 2/2] target/hexagon: Only indent on linux

Quoted 5 lines · Anton Johansson

indent on macOS, installed via homebrew, doesn't support -linux. Only run indent on linux hosts.

---

Quoted 16 lines
  target/hexagon/meson.build | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
target/hexagon/meson.build +1 -1
index abcf00ca1f..d26787a9b9 100644
@@ -324,7 +324,7 @@ if idef_parser_enabled and 'hexagon-linux-user' in target_dirs
      )
 
      indent = find_program('indent', required: false)
-    if indent.found()
+    if indent.found() and host_os == 'linux'
          idef_generated_tcg_c = custom_target(
              'indent',
              input: idef_generated_tcg[0],
#5 lore raw
In reply to Anton Johansson via
Quoted 10 lines · Anton Johansson

A default macOS build with xcode cli tools installed lacks the indent program needed by the idef-parser postprocess step. If indent is installed through homebrew it doesn't support the -linux flag. Conditionally run indent only on linux hosts.

Additionally cpp used by the idef-parser preprocess step expands into clang ... -traditional-cpp and doesn't support macro concatenation among other things, replace it with a meson custom_target running ${compiler} -E.

Quoted 8 lines

Note: default bison on macOS is still too old (v2.3 vs v3.0) and a newer version needs to be installed via homebrew. I'll take a look at supporting v2.3.

Changes in v2:
* Don't remove the indent step but only run on linux hosts.

Thanks: this series is queued on the "hex-next-express" branch at https://github.com/quic/qemu/

Quoted 9 lines

Anton Johansson (2):
target/hexagon: Replace prepare script with meson target target/hexagon: Only indent on linux

  target/hexagon/idef-parser/prepare | 24 ------------------------
  target/hexagon/meson.build         |  5 +++--
  2 files changed, 3 insertions(+), 26 deletions(-)

delete mode 100755 target/hexagon/idef-parser/prepare