Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use POSIX shell instead of bash #317

Open
absolutelynothinghere opened this issue Jan 14, 2024 · 0 comments
Open

Use POSIX shell instead of bash #317

absolutelynothinghere opened this issue Jan 14, 2024 · 0 comments

Comments

@absolutelynothinghere
Copy link

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"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant