]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
[gdb/syscalls] Improve update-linux-from-src.sh
authorTom de Vries <tdevries@suse.de>
Tue, 26 Nov 2024 08:49:29 +0000 (09:49 +0100)
committerTom de Vries <tdevries@suse.de>
Tue, 26 Nov 2024 08:49:29 +0000 (09:49 +0100)
Some improvements in gdb/syscalls/update-linux-from-src.sh:
- use bash instead of sh
- use local to distinguish between local and global vars
  (which brings to light that pre uses the global rather than the local
  start_date)
- factor out main and parse_args
- factor out regen
- iterate over *.xml.in instead of *.in

Tested on aarch64-linux.  Verified with shellcheck.

gdb/syscalls/update-linux-from-src.sh

index 21c921af1265573dca154a10748844dbd42145cb..b6985bae88c587907898040641504e03b1f23ae3 100755 (executable)
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/bin/bash
 
 # Copyright (C) 2022-2024 Free Software Foundation, Inc.
 #
 # Used to generate .xml.in files, like so:
 # $ ./update-linux-from-src.sh ~/linux-stable.git
 
-if [ $# -lt 1 ]; then
-    echo "dir argument needed"
-    exit 1
-fi
-
-d="$1"
-shift
-
-if [ ! -d "$d" ]; then
-    echo "cannot find $d"
-    exit 1
-fi
+parse_args ()
+{
+    if [ $# -lt 1 ]; then
+       echo "dir argument needed"
+       exit 1
+    fi
+
+    d="$1"
+    shift
+
+    if [ ! -d "$d" ]; then
+       echo "cannot find $d"
+       exit 1
+    fi
+}
 
 pre ()
 {
+    local f
     f="$1"
+    local start_date
+    start_date="$2"
 
+    local year
     year=$(date +%Y)
 
     cat <<EOF
@@ -69,9 +76,13 @@ post ()
 
 one ()
 {
+    local f
     f="$1"
+    local abi
     abi="$2"
+    local start_date
     start_date="$3"
+    local offset
     offset="$4"
 
     pre "$f" "$start_date"
@@ -85,10 +96,18 @@ one ()
     post
 }
 
-for f in *.in; do
+regen ()
+{
+    local f
+    f="$1"
+
+    local start_date
     start_date=2009
+    local offset
     offset=0
 
+    local t
+    local abi
     case $f in
        amd64-linux.xml.in)
            t="arch/x86/entry/syscalls/syscall_64.tbl"
@@ -144,30 +163,42 @@ for f in *.in; do
            ;;
        bfin-linux.xml.in)
            echo "Skipping $f, no longer supported"
-           continue
+           return
            ;;
        aarch64-linux.xml.in)
            echo "Skipping $f, no syscall.tbl"
-           continue
+           return
            ;;
        arm-linux.xml.in)
            echo "Skipping $f, use arm-linux.py instead"
-           continue
+           return
            ;;
        loongarch-linux.xml.in)
            echo "Skipping $f, no syscall.tbl"
-           continue
+           return
            ;;
        linux-defaults.xml.in)
-           continue
+           return
            ;;
        *)
            echo "Don't know how to generate $f"
-           continue
+           return
            ;;
     esac
 
     echo "Generating $f"
     one "$t" "$abi" "$start_date" "$offset" > "$f"
+}
+
+main ()
+{
+    # Set global d.
+    parse_args "$@"
+
+    local f
+    for f in *.xml.in; do
+       regen "$f"
+    done
+}
 
-done
+main "$@"