Welcome to little lamb

Code » comain » commit d03ba86

Better POSIX sh compatibility

author Olivier Brunel
2023-01-26 09:33:37 UTC
committer Olivier Brunel
2023-01-26 12:40:29 UTC
parent a2d962c97982ba60d8eef64a39e57a2e613a7bb3

Better POSIX sh compatibility

configure +15 -13
libcomain +12 -2

diff --git a/configure b/configure
index ae09cbf..e904d1e 100755
--- a/configure
+++ b/configure
@@ -93,10 +93,10 @@ for arg ; do
         --prefer-static) prefer=static ;;
         --set-shared=*) eval "link${arg#*=}=1" ;;
         --set-static=*) eval "link${arg#*=}=2" ;;
-        --with-*) eval optdisabled${arg:7}=0 ;;
-        --without-*) eval optdisabled${arg:10}=1 ;;
-        --enable-*) eval optdisabled${arg:9}=0 ;;
-        --disable-*) eval optdisabled${arg:10}=1 ;;
+        --with-*) eval optdisabled$(expr substr "$arg" 8 ${#arg})=0 ;;
+        --without-*) eval optdisabled$(expr substr "$arg" 11 ${#arg})=1 ;;
+        --enable-*) eval optdisabled$(expr substr "$arg" 10 ${#arg})=0 ;;
+        --disable-*) eval optdisabled$(expr substr "$arg" 11 ${#arg})=1 ;;
 
         -h|--help) usage 0  ;;
         -*) error 1 "invalid option '$arg'" ;;
@@ -459,15 +459,16 @@ if test -d meta/libs; then
         depsA=
         depsSO=
         while IFS= read -r line <&4; do
-            if test "${line:0:1}" == "#"; then continue; fi
+            if test "$(expr substr "$line" 1 1)" = "#"; then continue; fi
             foreach "dep" $nbdeps setdep
-            if test "${line:${#line}-2}" == ".o"; then
-                lineso="${line:0:${#line}-2}.lo"
+            offset=$((${#line}-1))
+            if test "$(expr substr "$line" $offset 2)" = ".o"; then
+                lineso="$(expr substr "$line" 1 $(($offset-1))).lo"
             else
                 lineso=
             fi
-            if test "${line:${#line}-2}" == ".O"; then
-                line="${line:0:${#line}-2}.o"
+            if test "$(expr substr "$line" $offset 2)" = ".O"; then
+                line="$(expr substr "$line" 1 $(($offset-1))).o"
             fi
             if test -z "$lineso"; then
                 lineso="$line"
@@ -486,10 +487,11 @@ if test -d meta/bins; then
         exec 4<"$file"
         deps=
         while IFS= read -r line <&4; do
-            if test "${line:0:1}" == "#"; then continue; fi
+            if test "$(expr substr "$line" 1 1)" = "#"; then continue; fi
             foreach "dep" $nbdeps setdep
-            if test "${line:${#line}-2}" == ".O"; then
-                line="${line:0:${#line}-2}.o"
+            offset=$((${#line}-1))
+            if test "$(expr substr "$line" $offset 2)" = ".O"; then
+                line="$(expr substr "$line" 1 $(($offset-1))).o"
             fi
             deps="$deps $line"
         done
@@ -526,7 +528,7 @@ mv -f config.mk.tmp config.mk
 
 
 echo "  -> Generating config.h..."
-prefix=$(printf "%s" "$name" | tr [:lower:] [:upper:] | tr -c [:alnum:] _)
+prefix=$(sanitize "$name")
 
 url="$(cat meta/site 2>/dev/null)"
 if test -z "$url"; then url="https://lila.oss"; fi
diff --git a/libcomain b/libcomain
index 1989da5..1c22c79 100644
--- a/libcomain
+++ b/libcomain
@@ -31,6 +31,16 @@ warn()
     echo "$0: $@" >&2
 }
 
+upper()
+{
+    printf "%s" "$@" | tr [:lower:] [:upper:]
+}
+
+sanitize()
+{
+    printf "%s" "$@" | tr [:lower:] [:upper:] | tr -c [:alnum:] _
+}
+
 quote()
 {
     printf %s\\n "$1" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/'/" ;
@@ -135,7 +145,7 @@ loadoptions()
         desc="$(cat meta/options/$name/desc 2>/dev/null)"
         if test -z "$desc"; then return 0; fi
         cvar="$(cat meta/options/$name/cvar 2>/dev/null)"
-        if test -z "$cvar"; then cvar="WITH_${name^^}"; fi
+        if test -z "$cvar"; then cvar="WITH_$(sanitize $name)"; fi
         cflags="$(cat meta/options/$name/cflags 2>/dev/null)"
         ldflags="$(cat meta/options/$name/ldflags 2>/dev/null)"
         disabled=0
@@ -153,7 +163,7 @@ loadoptions()
         eval tmp=\"\$need$dep\"
         if test -z "$tmp"; then
             eval need$dep=$name
-        elif test "$tmp" == "1"; then
+        elif test "$tmp" = "1"; then
             eval need$dep=$name
         else
             eval need$dep=\"$\need$dep $name\"