download-jdks.sh 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. #!/bin/bash
  2. #(c) jmonkeyengine.org
  3. #Author MeFisto94
  4. # This script is build up like a gradle build script. It contains many functions, each for it's distinctive task and every function is calling it's dependency functions.
  5. # This means in order for "unpack" to work, it will first launch "download" etc. While each task is self-explanatory, here's the process in short:
  6. # 1. Download JDK, 2. Unpack JDK (this used to be more work, with SFX Installers from Oracle etc), 3. Compile (this zips the unpacked and processed jdk and
  7. # creates a SFX Installer again from the zip), 4. Build (Build is the more general code to call compile (which calls unpack which calls download) and links the currently
  8. # most up to date JDK version into the main directory (because several old jdk versions are stored as well).
  9. set -e # Quit on Error
  10. jdk_major_version="21"
  11. jvm_impl="hotspot"
  12. jdk_vendor="eclipse"
  13. function download_jdk {
  14. echo ">>> Downloading the JDK for $1_$2$3"
  15. if [ -f downloads/jdk-$1_$2$3 ];
  16. then
  17. echo "<<< Already existing, SKIPPING."
  18. else
  19. curl -# -o downloads/jdk-$1_$2$3 -L https://api.adoptium.net/v3/binary/latest/$jdk_major_version/ga/$2/$1/jdk/$jvm_impl/normal/$jdk_vendor?project=jdk
  20. echo "<<< OK!"
  21. fi
  22. }
  23. function unpack_mac_jdk {
  24. echo ">> Extracting the Mac JDK..."
  25. #cd local/$jdk_version-$jdk_build_version/
  26. if [ -f "compiled/jdk-macosx.zip" ];
  27. then
  28. echo "< Already existing, SKIPPING."
  29. #cd ../../
  30. return 0
  31. fi
  32. download_jdk x64 mac .tar.gz
  33. tar xf downloads/jdk-x64_mac.tar.gz
  34. cd jdk-$jdk_major_version*/Contents/
  35. # FROM HERE: build-osx-zip.sh by normen (with changes)
  36. mv Home jdk # rename folder
  37. rm -rf jdk/man jdk/legal # ANT got stuck at the symlinks (https://bz.apache.org/bugzilla/show_bug.cgi?id=64053)
  38. zip -9 -r -y -q ../../compiled/jdk-macosx.zip jdk
  39. cd ../../
  40. rm -rf jdk-$jdk_major_version*
  41. if [ "$TRAVIS" == "true" ]; then
  42. rm -rf downloads/jdk-x64_mac.tar.gz
  43. fi
  44. #cd ../../
  45. echo "<< OK!"
  46. }
  47. function build_mac_jdk {
  48. echo "> Building the Mac JDK"
  49. if ! [ -f "compiled/jdk-macosx.zip" ];
  50. then
  51. unpack_mac_jdk # Depends on "unpack" which depends on "download" (Unpack includes what compile is to other archs)
  52. fi
  53. rm -rf ../../jdk-macosx.zip
  54. ln -rs compiled/jdk-macosx.zip ../../
  55. echo "< OK!"
  56. }
  57. # PARAMS arch
  58. function unpack_windows {
  59. echo ">> Extracting the JDK for windows-$1"
  60. #cd local/$jdk_version-$jdk_build_version/
  61. if [ -d windows-$1 ];
  62. then
  63. echo "<< Already existing, SKIPPING."
  64. # cd ../../
  65. return 0
  66. fi
  67. download_jdk "$1" windows .zip
  68. mkdir -p windows-$1
  69. unzip -qq downloads/jdk-$1_windows.zip -d windows-$1
  70. cd windows-$1/
  71. mv jdk-$jdk_major_version*/* .
  72. rm -rf jdk-$jdk_major_version*
  73. # This seems to be replaced by lib/tools.jar in openJDK
  74. #unzip -qq tools.zip -d .
  75. #rm tools.zip
  76. find . -exec chmod u+w {} \; # Make all file writable to allow uninstaller's cleaner to remove file
  77. find . -type f \( -name "*.exe" -o -name "*.dll" \) -exec chmod u+rwx {} \; # Make them executable
  78. # Insert fake unpack200.exe
  79. # See https://github.com/jMonkeyEngine/sdk/issues/491
  80. touch bin/unpack200.exe
  81. cd ../
  82. if [ "$TRAVIS" == "true" ]; then
  83. rm -rf downloads/jdk-$1_windows.zip
  84. fi
  85. echo "<< OK!"
  86. }
  87. function unpack_linux {
  88. echo ">> Extracting the JDK for linux-$1"
  89. #cd local/$jdk_version-$jdk_build_version/
  90. if [ -d linux-$1 ];
  91. then
  92. echo "<< Already existing, SKIPPING."
  93. #cd ../../
  94. return 0
  95. fi
  96. download_jdk "$1" linux .tar.gz
  97. mkdir -p linux-$1
  98. cd linux-$1
  99. tar -xf "../downloads/jdk-$1_linux.tar.gz"
  100. mv jdk-$jdk_major_version*/* .
  101. rm -rf jdk-$jdk_major_version*
  102. cd ../
  103. if [ "$TRAVIS" == "true" ]; then
  104. rm -rf downloads/jdk-$1.tar.gz
  105. fi
  106. echo "<< OK!"
  107. }
  108. # PARAMS: os arch arch_unzipsfx
  109. function compile_other {
  110. echo "> Compiling JDK for $1-$2"
  111. if [ $1 == "windows" ]; then
  112. name="jdk-$1-$3.exe"
  113. elif [ $1 == "linux" ]; then
  114. name="jdk-$1-$3.bin"
  115. else
  116. echo "Unknown Platform $1. ERROR!!!"
  117. exit 1
  118. fi
  119. if [ -f "compiled/$name" ]; then
  120. echo "< Already existing, SKIPPING."
  121. return 0
  122. fi
  123. # Depends on UNPACK and thus DOWNLOAD
  124. if [ $1 == "windows" ]; then
  125. unpack_windows $2
  126. elif [ $1 == "linux" ]; then
  127. unpack_linux $2
  128. fi
  129. unzipsfxname="../../unzipsfx/unzipsfx-$1-$3"
  130. if [ ! -f "$unzipsfxname" ]; then
  131. echo "No unzipsfx for platform $1-$3 found at $unzipsfxname, cannot continue"
  132. exit 1
  133. fi
  134. echo "> Zipping JDK"
  135. cd $1-$2 # zip behaves differently between 7zip and Info-Zip, so simply change wd
  136. zip -9 -qry ../jdk_tmp_sfx.zip *
  137. cd ../
  138. echo "> Building SFX"
  139. cat $unzipsfxname jdk_tmp_sfx.zip > compiled/$name
  140. chmod +x compiled/$name
  141. rm -rf jdk_tmp_sfx.zip
  142. if [ "$TRAVIS" == "true" ]; then
  143. rm -rf $1-$2
  144. fi
  145. echo "< OK!"
  146. }
  147. # PARAMS: os arch arch_unzipsfx
  148. function build_other_jdk {
  149. echo "> Building Package for $1-$2"
  150. compile_other $1 $2 $3 # Depend on Compile
  151. if [ $1 == "windows" ]; then
  152. name="jdk-$1-$3.exe"
  153. elif [ $1 == "linux" ]; then
  154. name="jdk-$1-$3.bin"
  155. fi
  156. rm -rf ../../$name
  157. ln -rs compiled/$name ../../
  158. echo "< OK!"
  159. }
  160. mkdir -p local/$jdk_major_version/downloads
  161. mkdir -p local/$jdk_major_version/compiled
  162. cd local/$jdk_major_version
  163. if [ "x$TRAVIS" != "x" ]; then
  164. if [ "x$BUILD_X64" != "x" ]; then
  165. build_other_jdk windows x64 x64
  166. build_other_jdk linux x64 x64
  167. else
  168. # We have to save space at all cost, so force-delete x64 jdks, which might come from the build cache.
  169. # that's bad because they won't be cached anymore, but we have to trade time for space.
  170. rm -rf compiled/jdk-windows-x64.exe compiled/jdk-linux-x64.bin
  171. fi
  172. if [ "x$BUILD_X86" != "x" ]; then
  173. build_other_jdk windows x86-32 x86
  174. #build_other_jdk linux x86 i586
  175. else
  176. rm -rf compiled/jdk-windows-x86.exe compiled/jdk-linux-x86.bin
  177. fi
  178. if [ "x$BUILD_OTHER" != "x" ]; then
  179. build_mac_jdk
  180. else
  181. rm -rf compiled/jdk-macosx.zip
  182. fi
  183. else
  184. if [ "x$PARALLEL" != "x" ];
  185. then
  186. build_mac_jdk &
  187. build_other_jdk linux x64 x64 &
  188. # Windows 32bit not by default build_other_jdk windows x86-32 x86 &
  189. build_other_jdk windows x64 x64 &
  190. else
  191. build_mac_jdk
  192. build_other_jdk linux x64 x64
  193. ## Windows 32bit not by default build_other_jdk windows x86-32 x86
  194. build_other_jdk windows x64 x64
  195. # Linux 32bit not supported... build_other_jdk linux x86-32
  196. fi
  197. fi
  198. if [ "x$PARALLEL" != "x" ];
  199. then
  200. wait
  201. fi
  202. cd ../../