lite icon indicating copy to clipboard operation
lite copied to clipboard

Use POSIX shell instead of bash

Open absolutelynothinghere opened this issue 1 year ago • 0 comments

The current build.sh script depends on GNU bash (#!/bin/bash), which is not available on all systems. Consider using the more portable POSIX shell (#!/bin/sh) instead which is available on all POSIX systems... I went ahead and converted the build.sh script for you, the changes I made are:

  • Replaced bash-specific syntax like [[ ... ]] and ${f//...} with the equivalent POSIX syntax
  • Renamed $lflags to $ldflags for clarity, as "lflags" generally refers to lexer flags not linker flags
  • Added pkg-config commands for finding the correct cflags and ldflags for SDL2 on Linux, in case the library is installed in a non-standard location (if pkg-config is not available then the commands will simply become empty strings)

P.S. you might want to look into Makefiles.

#!/bin/sh

cflags="-Wall -O3 -g -std=gnu11 -fno-strict-aliasing -Isrc"
ldflags="-lSDL2 -lm"

case $* in
*windows*)
  platform="windows"
  outfile="lite.exe"
  compiler="x86_64-w64-mingw32-gcc"
  cflags="$cflags -DLUA_USE_POPEN -Iwinlib/SDL2-2.0.10/x86_64-w64-mingw32/include"
  ldflags="$ldflags -Lwinlib/SDL2-2.0.10/x86_64-w64-mingw32/lib"
  ldflags="-lmingw32 -lSDL2main $ldflags -mwindows -o $outfile res.res"
  x86_64-w64-mingw32-windres res.rc -O coff -o res.res
  ;;
*)
  platform="unix"
  outfile="lite"
  compiler="cc"
  cflags="`pkg-config --cflags sdl2` $cflags  -DLUA_USE_POSIX"
  ldflags="`pkg-config --libs  sdl2` $ldflags -o $outfile"
  ;;
esac

if command -v ccache >/dev/null; then
  compiler="ccache $compiler"
fi

echo "compiling ($platform)..."
for f in `find src -name "*.c"`; do
  $compiler $cflags -c $f -o "`echo "$f" | sed -e "s|/|_|g"`.o"
  if [ $? -ne 0 ]; then
    got_error=true
  fi
done

if [ "$got_error" != true ]; then
  echo "linking..."
  $compiler *.o $ldflags
fi

echo "cleaning up..."
rm -f *.o
rm -f res.res
echo "done"

absolutelynothinghere avatar Jan 14 '24 18:01 absolutelynothinghere