build.sh 1.2 KB

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