build.sh 750 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. #!/bin/sh
  2. # Variables
  3. SRC="src/lib.c"
  4. LIB_NAME="libhpff.so"
  5. INSTALL_DIR="/usr/local/lib"
  6. # Function to build the shared library
  7. build() {
  8. echo "Building shared library..."
  9. gcc -march=native -O3 -fPIC -shared -o "$LIB_NAME" "$SRC"
  10. if [ $? -ne 0 ]; then
  11. echo "Build failed!"
  12. exit 1
  13. fi
  14. echo "Build successful: $LIB_NAME"
  15. }
  16. # Function to install the library
  17. install() {
  18. if [ -d /usr/local/lib ]; then
  19. echo "Installing to /usr/local/lib"
  20. cp "$LIB_NAME" /usr/local/lib
  21. else
  22. echo "Installing to /usr/lib"
  23. cp "$LIB_NAME" /usr/lib
  24. fi
  25. ldconfig
  26. echo "Installation successful."
  27. }
  28. # Main script logic
  29. if [ "$1" = "install" ]; then
  30. build
  31. install
  32. else
  33. build
  34. fi