build.sh 1.4 KB

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