Fix generate_compile_commands.sh to work with 64-bit builds 61/320061/2
authorKrzysztof Malysa <k.malysa@samsung.com>
Fri, 21 Feb 2025 10:06:04 +0000 (11:06 +0100)
committerKrzysztof Małysa <k.malysa@samsung.com>
Fri, 21 Feb 2025 10:39:40 +0000 (10:39 +0000)
Change-Id: I5a7a17492d037da3792a7056ad6f2746c2e22221

generate_compile_commands.sh

index f154e948919e7f08459c4f86d2c225c4db2edf78..c653bde2cc72e69eacbf9c9d896e3923bba58a43 100755 (executable)
@@ -1,14 +1,14 @@
 #!/bin/bash
 set -euo pipefail
 
-PROJECT=webauthn-ble
-
 # Change working directory to the directory containing the currently run script
 cd -P -- "$(dirname -- "$0")"
 
+PROJECT="$(basename -- "${PWD}")"
+
 GBS_BUILD_ROOTFS="$(ls -t --directory "$HOME/GBS-ROOT/local/BUILD-ROOTS/"* | head -n 1 || true)"
 if [ -z "$GBS_BUILD_ROOTFS" ]; then
-    echo "Could not find most recent GBS build root, please build the project with GBS first"
+    echo "error: could not find most recent GBS build root, please build the project with GBS first"
     exit 1
 fi
 
@@ -24,8 +24,19 @@ elif [ "${ARCH}" == "i586" ]; then
         sed 's% -msse4.2 % %' |
         sed 's% -mfpmath=sse % %'
     }
+elif [ "${ARCH}" == "aarch64" ]; then
+    target="aarch64-arm-linux"
+    function extra_filters {
+        sed 's% -mtune[^ ]* % %'
+    }
+elif [ "${ARCH}" == "x86_64" ]; then
+    target="x86_64-pc-linux-gnu"
+    function extra_filters {
+        sed 's% -msse4.2 % %' |
+        sed 's% -march=nehalem % %'
+    }
 else
-    echo "Unexpected architecture: ${ARCH}"
+    echo "error: unexpected architecture: ${ARCH}"
     exit 1
 fi
 
@@ -41,7 +52,7 @@ if grep --quiet -- '"file": "/home/abuild/' compile_commands.json 2> /dev/null;
         ORIG_COMPILE_COMMANDS_JSON="$(ls -t "compile_commands.json" "${ORIG_COMPILE_COMMANDS_JSON}" | head -n 1)"
     fi
 elif [ ! -f "${ORIG_COMPILE_COMMANDS_JSON}" ]; then
-    echo "Could not find compile_commands.json generated by CMake, please build the project with GBS first"
+    echo "error: could not find compile_commands.json generated by CMake, please build the project with GBS first"
     exit 1
 elif [ "compile_commands.json" -nt "${ORIG_COMPILE_COMMANDS_JSON}" ] && [ "compile_commands.json" -nt "$(basename "$0")" ]; then # this check fails if compile_commands.json does not exist
     exit 0 # compile_commands.json seem not to need regeneration
@@ -64,10 +75,10 @@ sed "s%\\([\"I ]\\)/%\1${GBS_BUILD_ROOTFS}/%g" <<< "${ORIG_COMPILE_COMMANDS_CONT
     sed 's% -fmax-errors=[^ ]*%%g' |
     sed 's% -Wno-stringop-overflow % %g' |
     # Add system includes from the GBS rootfs
-    sed "s% -std=% -isystem $(echo "${GBS_BUILD_ROOTFS}"/usr/lib/gcc/*-tizen-linux-gnu*/*/include-fixed/) -std=%" |
-    sed "s% -std=% -isystem $(echo "${GBS_BUILD_ROOTFS}"/usr/lib/gcc/*-tizen-linux-gnu*/*/include/) -std=%" |
-    sed "s% -std=% -isystem $(echo "${GBS_BUILD_ROOTFS}"/usr/lib/gcc/*-tizen-linux-gnu*/*/include/c++/) -std=%" |
-    sed "s% -std=% -isystem $(echo "${GBS_BUILD_ROOTFS}"/usr/lib/gcc/*-tizen-linux-gnu*/*/include/c++/*-tizen-linux-gnu*/) -std=%" |
+    sed "s% -std=% -isystem $(echo "${GBS_BUILD_ROOTFS}"/usr/lib*/gcc/*-tizen-linux-gnu*/*/include-fixed/) -std=%" |
+    sed "s% -std=% -isystem $(echo "${GBS_BUILD_ROOTFS}"/usr/lib*/gcc/*-tizen-linux-gnu*/*/include/) -std=%" |
+    sed "s% -std=% -isystem $(echo "${GBS_BUILD_ROOTFS}"/usr/lib*/gcc/*-tizen-linux-gnu*/*/include/c++/) -std=%" |
+    sed "s% -std=% -isystem $(echo "${GBS_BUILD_ROOTFS}"/usr/lib*/gcc/*-tizen-linux-gnu*/*/include/c++/*-tizen-linux-gnu*/) -std=%" |
     sed "s% -std=% -isystem $(echo "${GBS_BUILD_ROOTFS}"/usr/include/) -std=%" |
     extra_filters > compile_commands.json