Fix missing cleanup of toplevel Makefile

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
diff --git a/scripts/all-core.sh b/scripts/all-core.sh
index 903d09c..e2fe2e1 100644
--- a/scripts/all-core.sh
+++ b/scripts/all-core.sh
@@ -396,9 +396,9 @@
     # subdirectories.
     # Remove **/Makefile only if it looks like it was created by an in-tree
     # CMake build.
-    local cmake_dirs=($(list_git_files 'CMakeLists.txt' '**/CMakeLists.txt' |
-                        sed -e 's![^/]*$!!'))
-    for d in "${cmake_dirs[@]}"; do
+    local cmakelists=($(list_git_files 'CMakeLists.txt' '**/CMakeLists.txt'))
+    for f in "${cmakelists[@]}"; do
+        local d="$(dirname -- "$f")"
         if [ -d "$d/CMakeFiles" ]; then
             rm -rf "$d/CMakeFiles" \
                "$d/cmake_install.cmake" \