dist-copynativelibs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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. --isallib=*)
  79. ISALLIB=${i#*=}
  80. ;;
  81. --isalbundle=*)
  82. ISALBUNDLE=${i#*=}
  83. ;;
  84. --pmdklib=*)
  85. PMDKLIB=${i#*=}
  86. ;;
  87. --pmdkbundle=*)
  88. PMDKBUNDLE=${i#*=}
  89. ;;
  90. --opensslbinbundle=*)
  91. OPENSSLBINBUNDLE=${i#*=}
  92. ;;
  93. --openssllib=*)
  94. OPENSSLLIB=${i#*=}
  95. ;;
  96. --openssllibbundle=*)
  97. OPENSSLLIBBUNDLE=${i#*=}
  98. ;;
  99. --snappybinbundle=*)
  100. SNAPPYBINBUNDLE=${i#*=}
  101. ;;
  102. --snappylib=*)
  103. SNAPPYLIB=${i#*=}
  104. ;;
  105. --snappylibbundle=*)
  106. SNAPPYLIBBUNDLE=${i#*=}
  107. ;;
  108. --zstdbinbundle=*)
  109. ZSTDBINBUNDLE=${i#*=}
  110. ;;
  111. --zstdlib=*)
  112. ZSTDLIB=${i#*=}
  113. ;;
  114. --zstdlibbundle=*)
  115. ZSTDLIBBUNDLE=${i#*=}
  116. ;;
  117. esac
  118. done
  119. TAR='tar cf -'
  120. UNTAR='tar xfBp -'
  121. LIB_DIR="${BUILD_DIR}/native/target/usr/local/lib"
  122. BIN_DIR="${BUILD_DIR}/bin"
  123. TARGET_DIR="${BUILD_DIR}/${ARTIFACTID}-${VERSION}/lib/native"
  124. TARGET_BIN_DIR="${BUILD_DIR}/${ARTIFACTID}-${VERSION}/bin"
  125. # Most systems
  126. if [[ -d "${LIB_DIR}" ]]; then
  127. mkdir -p "${TARGET_DIR}"
  128. cd "${LIB_DIR}" || exit 1
  129. ${TAR} lib* | (cd "${TARGET_DIR}"/ || exit 1; ${UNTAR})
  130. if [[ $? -ne 0 ]]; then
  131. echo "Bundling lib files failed"
  132. exit 1
  133. fi
  134. bundle_native_lib "${SNAPPYLIBBUNDLE}" "snappy.lib" "snappy" "${SNAPPYLIB}"
  135. bundle_native_lib "${ZSTDLIBBUNDLE}" "zstd.lib" "zstd" "${ZSTDLIB}"
  136. bundle_native_lib "${OPENSSLLIBBUNDLE}" "openssl.lib" "crypto" "${OPENSSLLIB}"
  137. bundle_native_lib "${ISALBUNDLE}" "isal.lib" "isa" "${ISALLIB}"
  138. bundle_native_lib "${PMDKBUNDLE}" "pmdk.lib" "pmdk" "${PMDKLIB}"
  139. fi
  140. # Windows
  141. # Windows doesn't have a LIB_DIR, everything goes into bin
  142. if [[ -d "${BIN_DIR}" ]] ; then
  143. mkdir -p "${TARGET_BIN_DIR}"
  144. cd "${BIN_DIR}" || exit 1
  145. ${TAR} ./* | (cd "${TARGET_BIN_DIR}"/ || exit 1; ${UNTAR})
  146. if [[ $? -ne 0 ]]; then
  147. echo "Bundling bin files failed"
  148. exit 1
  149. fi
  150. bundle_native_bin "${SNAPPYBINBUNDLE}" "${SNAPPYLIBBUNDLE}" "snappy.lib" "snappy" "${SNAPPYLIB}"
  151. bundle_native_bin "${ZSTDBINBUNDLE}" "${ZSTDLIBBUNDLE}" "zstd.lib" "zstd" "${ZSTDLIB}"
  152. bundle_native_bin "${OPENSSLBINBUNDLE}" "${OPENSSLLIBBUNDLE}" "openssl.lib" "crypto" "${OPENSSLLIB}"
  153. fi