dist-copynativelibs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. #!/usr/bin/env bash
  2. # Licensed to the Apache Software Foundation (ASF) under one or more
  3. # contributor license agreements. See the NOTICE file distributed with
  4. # this work for additional information regarding copyright ownership.
  5. # The ASF licenses this file to You under the Apache License, Version 2.0
  6. # (the "License"); you may not use this file except in compliance with
  7. # the License. You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing, software
  12. # distributed under the License is distributed on an "AS IS" BASIS,
  13. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. # See the License for the specific language governing permissions and
  15. # limitations under the License.
  16. set -o pipefail
  17. # Bundle a native library if requested. Exit 1 in case error happens.
  18. # Usage: bundle_native_lib bundleoption liboption libpattern libdir
  19. function bundle_native_lib()
  20. {
  21. declare bundleoption="$1"
  22. declare liboption="$2"
  23. declare libpattern="$3"
  24. declare libdir="$4"
  25. echo "Checking to bundle with:"
  26. echo "bundleoption=${bundleoption}, liboption=${liboption}, pattern=${libpattern} libdir=${libdir}"
  27. if [[ "${bundleoption}" != "true" ]]; then
  28. return
  29. fi
  30. if [[ -z "${libdir}" ]] || [[ ! -d "${libdir}" ]]; then
  31. echo "The required option ${liboption} isn't given or invalid. Bundling the lib failed"
  32. exit 1
  33. fi
  34. cd "${libdir}" || exit 1
  35. ${TAR} ./*"${libpattern}"* | (cd "${TARGET_DIR}"/ || exit 1; ${UNTAR})
  36. if [[ $? -ne 0 ]]; then
  37. echo "Bundling library with ${liboption} failed "
  38. exit 1
  39. fi
  40. }
  41. function bundle_native_bin
  42. {
  43. declare bundleoption="$1"
  44. declare libbundle="$2"
  45. declare binoption="$3"
  46. declare binpattern="$4"
  47. declare libdir="$5"
  48. echo "Checking to bundle with:"
  49. echo "bundleoption=${bundleoption}, libbundle=${libbundle}, binoption=${binoption}, libdir=${libdir}, binpattern=${binpattern}"
  50. if [[ "${bundleoption}" != "true" ]]; then
  51. return
  52. fi
  53. if [[ "${libbundle}" != "true" ]]; then
  54. return
  55. fi
  56. if [[ -z "${libdir}" ]] || [[ ! -d "${libdir}" ]]; then
  57. echo "The required option ${liboption} isn't given or invalid. Bundling the lib failed"
  58. exit 1
  59. fi
  60. cd "${libdir}" || exit 1
  61. ${TAR} ./*"${libpattern}"* | (cd "${TARGET_BIN_DIR}"/ || exit 1 ; ${UNTAR})
  62. if [[ $? -ne 0 ]]; then
  63. echo "Bundling bin files for ${binoption} failed"
  64. exit 1
  65. fi
  66. }
  67. for i in "$@"; do
  68. case "${i}" in
  69. --version=*)
  70. VERSION=${i#*=}
  71. ;;
  72. --artifactid=*)
  73. ARTIFACTID=${i#*=}
  74. ;;
  75. --builddir=*)
  76. BUILD_DIR=${i#*=}
  77. ;;
  78. --opensslbinbundle=*)
  79. OPENSSLBINBUNDLE=${i#*=}
  80. ;;
  81. --openssllib=*)
  82. OPENSSLLIB=${i#*=}
  83. ;;
  84. --openssllibbundle=*)
  85. OPENSSLLIBBUNDLE=${i#*=}
  86. ;;
  87. --snappybinbundle=*)
  88. SNAPPYBINBUNDLE=${i#*=}
  89. ;;
  90. --snappylib=*)
  91. SNAPPYLIB=${i#*=}
  92. ;;
  93. --snappylibbundle=*)
  94. SNAPPYLIBBUNDLE=${i#*=}
  95. ;;
  96. --zstdbinbundle=*)
  97. ZSTDBINBUNDLE=${i#*=}
  98. ;;
  99. --zstdlib=*)
  100. ZSTDLIB=${i#*=}
  101. ;;
  102. --zstdlibbundle=*)
  103. ZSTDLIBBUNDLE=${i#*=}
  104. esac
  105. done
  106. TAR='tar cf -'
  107. UNTAR='tar xfBp -'
  108. LIB_DIR="${BUILD_DIR}/native/target/usr/local/lib"
  109. BIN_DIR="${BUILD_DIR}/bin"
  110. TARGET_DIR="${BUILD_DIR}/${ARTIFACTID}-${VERSION}/lib/native"
  111. TARGET_BIN_DIR="${BUILD_DIR}/${ARTIFACTID}-${VERSION}/bin"
  112. # Most systems
  113. if [[ -d "${LIB_DIR}" ]]; then
  114. mkdir -p "${TARGET_DIR}"
  115. cd "${LIB_DIR}" || exit 1
  116. ${TAR} lib* | (cd "${TARGET_DIR}"/ || exit 1; ${UNTAR})
  117. if [[ $? -ne 0 ]]; then
  118. echo "Bundling lib files failed"
  119. exit 1
  120. fi
  121. bundle_native_lib "${SNAPPYLIBBUNDLE}" "snappy.lib" "snappy" "${SNAPPYLIB}"
  122. bundle_native_lib "${ZSTDLIBBUNDLE}" "zstd.lib" "zstd" "${ZSTDLIB}"
  123. bundle_native_lib "${OPENSSLLIBBUNDLE}" "openssl.lib" "crypto" "${OPENSSLLIB}"
  124. fi
  125. # Windows
  126. # Windows doesn't have a LIB_DIR, everything goes into bin
  127. if [[ -d "${BIN_DIR}" ]] ; then
  128. mkdir -p "${TARGET_BIN_DIR}"
  129. cd "${BIN_DIR}" || exit 1
  130. ${TAR} ./* | (cd "${TARGET_BIN_DIR}"/ || exit 1; ${UNTAR})
  131. if [[ $? -ne 0 ]]; then
  132. echo "Bundling bin files failed"
  133. exit 1
  134. fi
  135. bundle_native_bin "${SNAPPYBINBUNDLE}" "${SNAPPYLIBBUNDLE}" "snappy.lib" "snappy" "${SNAPPYLIB}"
  136. bundle_native_bin "${ZSTDBINBUNDLE}" "${ZSTDLIBBUNDLE}" "zstd.lib" "zstd" "${ZSTDLIB}"
  137. bundle_native_bin "${OPENSSLBINBUNDLE}" "${OPENSSLLIBBUNDLE}" "openssl.lib" "crypto" "${OPENSSLLIB}"
  138. fi