build.sh 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. SRC=$(find src/ -name "*.cpp")
  20. echo "> Compiling and linking source files... "
  21. FLAGS="-std=c++17 -O1 -stdlib=libc++ -Wfatal-errors -Iinclude"
  22. if [[ "$OSTYPE" == "darwin"* ]]; then
  23. LIB_EXTENSION=".dylib"
  24. FLAGS="$FLAGS -undefined dynamic_lookup"
  25. LINK_FLAGS=""
  26. else
  27. LIB_EXTENSION=".so"
  28. LINK_FLAGS="-Wl,-rpath=."
  29. fi
  30. clang++ $FLAGS -o libpocketpy$LIB_EXTENSION $SRC -fPIC -shared -ldl
  31. # compile main.cpp and link to libpocketpy.so
  32. echo "> Compiling main.cpp and linking to libpocketpy$LIB_EXTENSION..."
  33. clang++ $FLAGS -o main -O1 src2/main.cpp -L. -lpocketpy $LINK_FLAGS
  34. if [ $? -eq 0 ]; then
  35. echo "Build completed. Type \"./main\" to enter REPL."
  36. else
  37. echo "Build failed."
  38. exit 1
  39. fi