compile 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #!/usr/bin/env sh
  2. if [ ! -f "./.gfcp_root" ] || [ ! -f "./.gfcptun_root" ]; then
  3. printf '%s\n' 'Error: You must execute "build" from the project root.'
  4. exit 1
  5. fi
  6. export BUILD_DIR="./build" || {
  7. printf '%s\n' "Error: export failure."
  8. exit 1
  9. }
  10. if [ ! -d "${BUILD_DIR:?Error: BUILD_DIR undefined.}" ]; then
  11. mkdir -p "${BUILD_DIR:?Error: BUILD_DIR undefined.}" ||
  12. {
  13. printf '%s\n' "Error: mkdir failed."
  14. exit 1
  15. }
  16. fi
  17. cd "${BUILD_DIR:?Error: BUILD_DIR undefined.}" || {
  18. printf '%s\n' "Error: unable to set cwd to BUILD_DIR."
  19. exit 1
  20. }
  21. export GO111MODULE="on" ||
  22. {
  23. printf '%s\n' "Error: export failure."
  24. exit 1
  25. }
  26. VERSION=$(date -u +%Y%m%d-gridfinity ||
  27. { printf '%s\n' "Error: failed to set VERSION."; }) ||
  28. {
  29. printf '%s\n' "Error: export failure."
  30. exit 1
  31. }
  32. export VERSION ||
  33. {
  34. printf '%s\n' "Error: export failure."
  35. exit 1
  36. }
  37. export LDFLAGS='-X main.VERSION='${VERSION:?Error: VERSION undefined.}' -s -w -linkmode "internal" -buildid=' ||
  38. {
  39. printf '%s\n' "Error: export failure."
  40. exit 1
  41. }
  42. CGO_ENABLED=0 go build -tags="osnetgo,osusergo" -v -a -ldflags "${LDFLAGS:?Error: LDFLAGS undefined.}" -o "client_gfcp_${VERSION:?Error: VERSION undefined.}" ../client ||
  43. {
  44. printf '%s\n' "Error: Client build failed."
  45. exit 1
  46. }
  47. CGO_ENABLED=0 go build -tags="osnetgo,osusergo" -v -a -ldflags "${LDFLAGS:?Error: LDFLAGS undefined.}" -o "server_gfcp_${VERSION:?Error: VERSION undefined.}" ../server ||
  48. {
  49. printf '%s\n' "Error: Server build failed."
  50. exit 1
  51. }
  52. UPXC=$(env command -v upx 2>/dev/null || printf '%s' "true") || true :
  53. # shellcheck disable=SC2236,SC2154
  54. if [ ! -z "${UPXC:-}" ] || [ -n "${UPXC:-}" ]; then
  55. printf '%s\n' "Compressing output with UPX, please wait ..."
  56. # shellcheck disable=SC2015
  57. strip --strip-all ./*_gfcp_*-gridfinity &&
  58. "${UPXC:-}" "--ultra-brute" "-qq" ./*_gfcp_*-gridfinity &&
  59. printf '%s\n' "UPX compression completed successfully." ||
  60. { printf '%s\n' "Error: UPX compression failure."; }
  61. else
  62. printf '%s\n' "UPX not available, skipping binary compression."
  63. fi
  64. printf '%s\n' "Build completed."