build.sh 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #!/bin/bash
  2. # Check if clang is installed
  3. if ! type -P clang >/dev/null 2>&1; then
  4. echo "clang is required and not installed. Kindly install it."
  5. echo "Run: sudo apt-get install clang"
  6. exit 1
  7. fi
  8. echo "It takes a moment to finish building."
  9. echo ""
  10. echo "> Running prebuild.py... "
  11. python prebuild.py
  12. if [ $? -ne 0 ]; then
  13. echo "prebuild.py failed."
  14. exit 1
  15. fi
  16. SRC=$(find src/ -name "*.c")
  17. echo "> Compiling and linking source files... "
  18. FLAGS="-std=c11 -O1 -Wfatal-errors -Iinclude"
  19. if [[ "$OSTYPE" == "darwin"* ]]; then
  20. LIB_EXTENSION=".dylib"
  21. FLAGS="$FLAGS -undefined dynamic_lookup"
  22. LINK_FLAGS=""
  23. else
  24. LIB_EXTENSION=".so"
  25. LINK_FLAGS="-Wl,-rpath=."
  26. fi
  27. clang $FLAGS -o libpocketpy$LIB_EXTENSION $SRC -fPIC -shared
  28. # compile main.cpp and link to libpocketpy.so
  29. echo "> Compiling main.c and linking to libpocketpy$LIB_EXTENSION..."
  30. clang $FLAGS -o main -O1 src2/main.c -L. -lpocketpy $LINK_FLAGS
  31. if [ $? -eq 0 ]; then
  32. echo "Build completed. Type \"./main\" to enter REPL."
  33. else
  34. echo "Build failed."
  35. exit 1
  36. fi