]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
Rewrote the scripts to sh instead of bash 1750/head
authorCarl Woffenden <cwoffenden@gmail.com>
Wed, 28 Aug 2019 17:20:42 +0000 (19:20 +0200)
committerCarl Woffenden <cwoffenden@gmail.com>
Wed, 28 Aug 2019 17:20:42 +0000 (19:20 +0200)
contrib/declib/build.sh
contrib/declib/combine.sh

index 9b85c551e01272586cdc5433ecd6a5307cb9cb68..e0a6274567740bd0a1c94a60a55134676f7abc8e 100755 (executable)
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
 
 # Where to find the sources
 ZSTD_SRC_ROOT="../../lib"
@@ -10,6 +10,7 @@ OUT_FILE="tempbin"
 OUT_WASM="temp.wasm"
 
 # Amalgamate the sources
+echo "Amalgamating files... this may take a few minutes"
 ./combine.sh -r "$ZSTD_SRC_ROOT" -r "$ZSTD_SRC_ROOT/common" -r "$ZSTD_SRC_ROOT/decompress" -o zstddeclib.c zstddeclib-in.c
 # Did combining work?
 if [ $? -ne 0 ]; then
index b798a8a3ecb745497a08b841b699735b9ecd6c30..d30e371d60d07c7d491c6ac9f3bcff4bdbc8ad61 100755 (executable)
@@ -1,7 +1,10 @@
-#!/bin/bash
+#!/bin/sh -e
 
 # Tool to bundle multiple C/C++ source files, inlining any includes.
 # 
+# Note: this POSIX-compliant script is many times slower than the original bash
+# implementation (due to the grep calls) but it runs and works everywhere.
+# 
 # TODO: ROOTS and FOUND as arrays (since they fail on paths with spaces)
 
 # Common file roots
@@ -14,7 +17,7 @@ FOUND=""
 DESTN=""
 
 # Prints the script usage then exits
-function usage {
+usage() {
   echo "Usage: $0 [-r <path>] [-o <outfile>] infile"
   echo "  -r file root search paths"
   echo "  -o output file (otherwise stdout)"
@@ -22,27 +25,26 @@ function usage {
   exit 1
 }
 
-# Tests if list $1 has item $2
-function list_has_item {
-  local list="$1"
-  local item="$2"
-  if [[ $list =~ (^|[[:space:]]*)"$item"($|[[:space:]]*) ]]; then
+# Tests if list $1 has item $2 (returning zero on a match)
+list_has_item() {
+  if echo "$1" | grep -Eq "(^|\s*)$2(\$|\s*)"; then
     return 0
+  else
+    return 1
   fi
-  return 1
 }
 
 # Adds a new line with the supplied arguments to $DESTN (or stdout)
-function write_line {
+write_line() {
   if [ -n "$DESTN" ]; then
-    printf "%s\n" "$@" >> "$DESTN"
+    printf '%s\n' "$@" >> "$DESTN"
   else
-    printf "%s\n" "$@"
+    printf '%s\n' "$@"
   fi
 }
 
 # Adds the contents of $1 with any of its includes inlined
-function add_file {
+add_file() {
   # Match the path
   local file=
   if [ -f "$1" ]; then
@@ -56,12 +58,12 @@ function add_file {
   fi
   if [ -n "$file" ]; then
     # Read the file
-    local line
+    local line=
     while IFS= read -r line; do
-      if [[ $line =~ ^[[:space:]]*\#[[:space:]]*include[[:space:]]*\"(.*)\".* ]]; then
-        # We have an include directive
-        local inc=${BASH_REMATCH[1]}
-        if ! `list_has_item "$FOUND" "$inc"`; then
+      if echo "$line" | grep -Eq '^\s*#\s*include\s*".+"'; then
+        # We have an include directive so strip the (first) file
+        local inc=$(echo "$line" | grep -Eo '".*"' | grep -Eo '\w*(\.?\w+)+' | head -1)
+        if ! list_has_item "$FOUND" "$inc"; then
           # And we've not previously encountered it
           FOUND="$FOUND $inc"
           write_line "/**** start inlining $inc ****/"
@@ -102,7 +104,7 @@ if [ -n "$1" ]; then
     fi
     add_file $1
   else
-    echo "Input file not found: '$1'"
+    echo "Input file not found: \"$1\""
     exit 1
   fi
 else