Advertisement
Guest User

Untitled

a guest
Jan 9th, 2025
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 45.48 KB | None | 0 0
  1. # Maintainer: Toolybird <toolybird at tuta dot io>
  2. #
  3. # WORK IN PROGRESS
  4. #
  5. # <rant>This thing is a packaging nightmare!! The upstream build system is
  6. # *especially* distro unfriendly (build on Centos 7...WTF?). Building from
  7. # source to proper Arch standards is "interesting" to say the least.</rant>
  8. #
  9. # NOTE: upstream uses losetup (root) for disk image preparation and GRUB
  10. # installation. Solved by utilizing libguestfs/QEMU.
  11. #
  12. # NOT INCLUDED (compared to upstream): ARM64, MIPS64, LiveCD.
  13. #
  14. # PROBLEMS: FIXME
  15. #
  16. # - ancient pkg versions used in the build
  17. # - includes bundled / vendored sources
  18. # - some third party / pre-compiled / downloaded binaries are used
  19. #
  20. # This PKGBUILD is based on "INSTALL/all_in_one.sh". The upstream build
  21. # environment is Centos 7 (as root!). See "DOC/BuildVentoyFromSource.txt" and
  22. # GitHub CI/docker files. The Ventoy code is unfortunately built upon very old
  23. # and outdated pkgs. In order to achieve an initial working build, I've simply
  24. # tried to replicate upstream procedures as much as possible. Some patches are
  25. # required to successfully build on a modern Arch system. The main components of
  26. # Ventoy are heavily modified versions of:
  27. #
  28. # - grub (Jul 2019) (2.04)
  29. # - ipxe (Sep 2019) (3fe683e)
  30. # - edk2 (Dec 2019) (201911)
  31. #
  32. # Please see the "License" folder for full details of various other bits that
  33. # have been modified.
  34.  
  35. pkgname=ventoy
  36. pkgver=1.0.99
  37. _grub_ver=2.04 # (Jul 2019)
  38. #_unifont_ver=15.0.01 # FIXME see NOTE below
  39. _ipxe_ver=3fe683e # (Sep 29 2019)
  40. _edk2_ver=stable201911 # (Dec 2019)
  41. _diet_ver=0.34 # FIXME AUR pkg needs a patch, see below, build our own (64/32)
  42. _musl_ver=1.2.5 # upstream uses 1.2.1, use repo for 64-bit, build our own 32-bit
  43. _kern_hdrs_musl_ver=4.19.88 # for busybox 32-bit
  44. _fuse_ver=2.9.9 # need a static lib built against musl, build our own (64/32)
  45. _exfat_ver=1.3.0 # (Sep 2018) old! FIXME see comments below for why we build our own
  46. _lz4_ver=1.8.1.2 # (Jan 2018) old! FIXME statically linked into unsquashfs
  47. _xz_ver=5.0.4 # (Jun 2012) old! FIXME statically linked into unsquashfs
  48. _lzo_ver=2.08 # (Jun 2014) old! FIXME statically linked into unsquashfs
  49. _zstd_ver=1.4.4 # (Nov 2019) old! FIXME statically linked into unsquashfs
  50. _zlib_ver=1.3.1 # need a static 32-bit lib for unsquashfs, build our own
  51. _squash_ver=4.4 # (Aug 2019) old! FIXME for unsquashfs
  52. _dm_ver=1.02.28 # (Sep 2008) old! FIXME for dmsetup
  53. _zstd1_ver=1.0.0 # (Sep 2016) old! FIXME for standalone zstdcat
  54. _xz_embed_ver=20130513 # (May 2013) old! FIXME for xzminidec
  55. _busybox_ver=1.32.0 # (Jun 2020) old! FIXME
  56. _crypt_ver=1.7.5 # (Apr 2017) old! FIXME for veritysetup
  57. _lunzip_ver=1.11 # (Jan 2019) old! FIXME
  58. _wimboot_ver=2.7.3 # (Apr 2021) old! FIXME
  59. pkgrel=3
  60. pkgdesc="A new bootable USB solution"
  61. arch=(x86_64)
  62. url="https://www.ventoy.net/"
  63. license=(GPL-3.0-or-later)
  64. depends=(bash dosfstools)
  65. makedepends=(
  66. acpica # edk2
  67. cdrtools # EfiISO
  68. cpio # IMG/USB prep
  69. device-mapper # grub2
  70. freetype2 # grub2
  71. fuse2 # grub2 exfat
  72. git # ipxe
  73. gtk3 # GUI
  74. kernel-headers-musl # busybox
  75. lib32-gcc-libs # 32-bit squashfs-tools lz4 xz lzo zstd vblade
  76. lib32-glibc # 32-bit dietlibc vtoytool dmsetup zstdcat xzminidec busybox lunzip
  77. libguestfs # IMG/USB prep
  78. linux # libguestfs
  79. musl # vtoycli fuse fuseiso xzminidec busybox
  80. nasm # edk2
  81. python # grub2 edk2
  82. python-setuptools # edk2 (python-3.12+)
  83. qt5-base # GUI
  84. ttf-dejavu # grub2
  85. )
  86. optdepends=(
  87. 'gtk3: for GTK GUI'
  88. 'parted: for preferred CLI partitioner'
  89. 'polkit: for GUI privilege escalation'
  90. 'qt5-base: for Qt GUI'
  91. )
  92. conflicts=(ventoy-bin)
  93. # A regression in latest pacman unsets MAKEFLAGS when using !buildflags.
  94. # https://gitlab.archlinux.org/archlinux/packaging/packages/pacman/-/issues/25
  95. # Workaround it for now by manually unsetting VARS. See (way down) below in build() function.
  96. #options=(!buildflags)
  97. source=(
  98. "$pkgname-$pkgver.tar.gz::https://github.com/ventoy/Ventoy/archive/refs/tags/v$pkgver.tar.gz"
  99. https://ftp.gnu.org/gnu/grub/grub-"$_grub_ver".tar.xz
  100. ventoy-grub-fix-build-with-binutils-2.36.patch::https://git.savannah.gnu.org/cgit/grub.git/patch/configure.ac?id=b9827513
  101. # https://ftp.gnu.org/gnu/unifont/unifont-"$_unifont_ver/unifont-$_unifont_ver".bdf.gz
  102. git+https://github.com/ipxe/ipxe.git#commit="$_ipxe_ver"
  103. https://github.com/tianocore/edk2/archive/refs/tags/edk2-"$_edk2_ver".zip
  104. ventoy-fix-ucs-2-lookup-on-python-3.9.patch::https://github.com/tianocore/edk2/commit/5d864834.patch
  105. ventoy-fix-array.array.tostring-removal-in-python-3.9.patch::https://github.com/tianocore/edk2/commit/43bec9ea.patch
  106. https://www.fefe.de/dietlibc/dietlibc-"$_diet_ver".tar.xz
  107. dietlibc-headers-fix.patch::https://salsa.debian.org/debian/dietlibc/-/raw/master/debian/patches/bugfixes/newer-linux-headers.diff
  108. https://musl.libc.org/releases/musl-"$_musl_ver".tar.gz
  109. kernel-headers-musl-"$_kern_hdrs_musl_ver".tar.gz::https://github.com/sabotage-linux/kernel-headers/archive/v"$_kern_hdrs_musl_ver".tar.gz
  110. https://github.com/libfuse/libfuse/releases/download/fuse-"$_fuse_ver/fuse-$_fuse_ver".tar.gz
  111. exfat-"$_exfat_ver".tar.gz::https://github.com/relan/exfat/archive/refs/tags/v"$_exfat_ver".tar.gz
  112. https://github.com/madler/zlib/releases/download/v"$_zlib_ver/zlib-$_zlib_ver".tar.xz
  113. squashfs-tools-"$_squash_ver".tar.gz::https://github.com/plougher/squashfs-tools/archive/refs/tags/"$_squash_ver".tar.gz
  114. http://vault.centos.org/5.3/os/SRPMS/device-mapper-"$_dm_ver"-2.el5.src.rpm
  115. zstd-"$_zstd1_ver".tar.gz::https://github.com/facebook/zstd/archive/refs/tags/v"$_zstd1_ver".tar.gz
  116. https://tukaani.org/xz/xz-embedded-"$_xz_embed_ver".tar.gz
  117. https://busybox.net/downloads/busybox-"$_busybox_ver".tar.bz2
  118. https://mirrors.edge.kernel.org/pub/linux/utils/cryptsetup/v"${_crypt_ver%.*}"/cryptsetup-"$_crypt_ver".tar.xz
  119. wimboot-"$_wimboot_ver".tar.gz::https://github.com/ipxe/wimboot/archive/v"$_wimboot_ver".tar.gz
  120. wimboot-binutils-2.42-fix.patch
  121. )
  122. noextract=(
  123. grub-"$_grub_ver".tar.xz
  124. edk2-"$_edk2_ver".zip
  125. fuse-"$_fuse_ver".tar.gz
  126. exfat-"$_exfat_ver".tar.gz
  127. zlib-"$_zlib_ver".tar.xz
  128. squashfs-tools-"$_squash_ver".tar.gz
  129. device-mapper-"$_dm_ver"-2.el5.src.rpm
  130. zstd-"$_zstd1_ver".tar.gz
  131. xz-embedded-"$_xz_embed_ver".tar.gz
  132. busybox-"$_busybox_ver".tar.bz2
  133. cryptsetup-"$_crypt_ver".tar.xz
  134. wimboot-"$_wimboot_ver".tar.gz
  135. )
  136. sha256sums=('2557ccdeaf8b0e517087afb63f65c4e2a32ef3f15bd196b7f828d93d586ca7b9'
  137. 'e5292496995ad42dabe843a0192cf2a2c502e7ffcc7479398232b10a472df77d'
  138. 'db2a9018392a3984d1e1e649bde0ffc19c90fa4d96b9fd2d4caaf9c1ca2af68b'
  139. '5ee49d23d376aeea24269f7605fcaa7fbd326c04cda4e31b8eb7fa15a540ef44'
  140. 'c6f691aa91afbaab811a369fe729f61d8e5b58bb5ad79a45446c9ee849c1a60b'
  141. '0e6f338f78d26ff30a921078a31fd294143ee603166a476dd38d2b2277e4b049'
  142. '03171f233e7d7472a7fc212ea5cca0ab5b6dace7976bb2ffb1379a3f83960dd9'
  143. '7994ad5a63d00446da2e95da1f3f03355b272f096d7eb9830417ab14393b3ace'
  144. '313aa962c7f80a02f41758d90d6f67687c77c74a6126b060337f248bc1b637f6'
  145. 'a9a118bbe84d8764da0ea0d28b3ab3fae8477fc7e4085d90102b8596fc7c75e4'
  146. 'd104397fc657ffb0f0bda46f54fd182b76a9ebc324149c183a4ff8c86a8db53d'
  147. 'd0e69d5d608cc22ff4843791ad097f554dd32540ddc9bed7638cc6fea7c1b4b5'
  148. '689bcb4a639acd2d45e6fa0ff455f7f18edb2421d4f4f42909943775adc0e375'
  149. '38ef96b8dfe510d42707d9c781877914792541133e1870841463bfa73f883e32'
  150. 'a7fa4845e9908523c38d4acf92f8a41fdfcd19def41bd5090d7ad767a6dc75c3'
  151. '599a630fdf020282e27c66aa2b4f3d624d731bd150749a8d7b74f544be03b2bb'
  152. '197e6ef74da878cbf72844f38461bb18129d144fd5221b3598e973ecda6f5963'
  153. '19577e9f68a2d4e08bb5564e3946e35c6323276cb6749c101c86e26505e3bf0e'
  154. 'c35d87f1d04b2b153d33c275c2632e40d388a88f19a9e71727e0bbbff51fe689'
  155. '2b30cd1d0dd606a53ac77b406e1d37798d4b0762fa89de6ea546201906a251bd'
  156. '3cf04ca4a5b4466e624570d980638f8ab72feaed9b94106dd6ed2bed674a4cdf'
  157. '8121a64145ff317693de80148fbdca6cb73d3f2ed92f66b946949750ab71afe9')
  158.  
  159. # Some components below are notated as follows:
  160. #
  161. # 'HOST' -> a tool that runs on Arch itself. e.g. it might be part of the
  162. # install routine to set up (install) a Ventoy USB drive. Usually a "normal"
  163. # x86_64 binary.
  164. #
  165. # 'IMG/USB' -> a tool that is "embedded" into a Ventoy USB drive. The tool is
  166. # stored inside a cpio archive on the ESP and is typically involved in the
  167. # process of booting ISO's. There will usually be an additional 32-bit binary.
  168. # These tools are meant to be small and self-contained and are often statically
  169. # linked against dietlibc or musl.
  170.  
  171. prepare() {
  172. cd Ventoy-$pkgver
  173. : "${_DIFF:=0}" # "1" to generate diffs for easier inspection of Ventoy mod's.
  174.  
  175. # Create our own INSTALL trees
  176. mv -v INSTALL{,.upstream}
  177. mv -v IMG/cpio_x86{,.upstream}
  178.  
  179. (
  180. # Refer "GRUB2/buildgrub.sh"
  181. cd GRUB2
  182. mkdir -v SRC NBP PXE
  183. tar -xf "$srcdir"/grub-$_grub_ver.tar.xz -C SRC
  184. cp -av MOD_SRC/grub-$_grub_ver SRC
  185.  
  186. if ((_DIFF)); then
  187. tar -xf "$srcdir"/grub-$_grub_ver.tar.xz -C SRC --xform "s|\(grub-$_grub_ver\)|\1.orig|"
  188. diff -urN SRC/grub-$_grub_ver{.orig,} > ventoy-$pkgver-grub-$_grub_ver.patch || :
  189. fi
  190.  
  191. # Fix build for newer toolchain.
  192. patch -d SRC/grub-$_grub_ver -Np1 -i "$srcdir"/ventoy-grub-fix-build-with-binutils-2.36.patch
  193.  
  194. # Tweak font path.
  195. sed -i 's|\(/usr/share/fonts/dejavu\)|\1 /usr/share/fonts/TTF|g' SRC/grub-$_grub_ver/configure.ac
  196.  
  197. # NOTE: Upstream builds don't include this. Yet they ship their own
  198. # {ascii,unicode}.pf2 font files...how are they derived? FIXME
  199. # gzip -cd "$srcdir"/unifont-$_unifont_ver.bdf.gz > SRC/grub-$_grub_ver/unifont.bdf
  200. )
  201.  
  202. (
  203. # Refer "IPXE/buildipxe.sh"
  204. cd IPXE
  205. tar -xf ipxe_org_code/ipxe-$_ipxe_ver.tar.bz2
  206. cp -av ipxe_mod_code/ipxe-$_ipxe_ver .
  207.  
  208. if ((_DIFF)); then
  209. # The bundled tarball has been independently verified as being identical
  210. # to a git checkout. But might as well use the git version for comparison.
  211. diff -urN -x .git "$srcdir"/ipxe ipxe-$_ipxe_ver > ventoy-$pkgver-ipxe-$_ipxe_ver.patch || :
  212. fi
  213.  
  214. rm -rfv ipxe-$_ipxe_ver/src/{bin,drivers}
  215. )
  216.  
  217. (
  218. # Refer "EDK2/buildedk.sh"
  219. cd EDK2
  220. bsdtar -xf "$srcdir"/edk2-$_edk2_ver.zip
  221. cp -av edk2_mod/edk2-edk2-$_edk2_ver .
  222.  
  223. if ((_DIFF)); then
  224. bsdtar -xf "$srcdir"/edk2-$_edk2_ver.zip -s "|edk2-edk2-$_edk2_ver|~.orig|"
  225. diff -urN edk2-edk2-$_edk2_ver{.orig,} > ventoy-$pkgver-edk2-$_edk2_ver.patch || :
  226. fi
  227.  
  228. cd edk2-edk2-$_edk2_ver
  229.  
  230. # Remove -Werror for successful build (as per main Arch repo).
  231. sed -i 's/ -Werror//g' BaseTools/Conf/*.template BaseTools/Source/C/Makefiles/*.makefile
  232.  
  233. # Fix build with newer toolchain.
  234. sed -i 's/GCC48/GCC5/' ../build.sh
  235.  
  236. # Fix build against recent python.
  237. patch -Np1 -i "$srcdir"/ventoy-fix-ucs-2-lookup-on-python-3.9.patch
  238. patch -Np1 -i "$srcdir"/ventoy-fix-array.array.tostring-removal-in-python-3.9.patch
  239. )
  240.  
  241. (
  242. cd "$srcdir"/dietlibc-$_diet_ver
  243.  
  244. # Fix from Debian. Avoid errors when compiling apps against recent kernel headers. FIXME
  245. patch -Np1 -i "$srcdir"/dietlibc-headers-fix.patch
  246.  
  247. # <cpuid.h> compile fix
  248. sed -i 's/__leaf/__LEAF/' include/sys/cdefs.h
  249. )
  250.  
  251. (
  252. cd SQUASHFS
  253. if ((_DIFF)); then
  254. tar -xf "$srcdir"/squashfs-tools-$_squash_ver.tar.gz --xform "s|\(squashfs-tools-$_squash_ver\)|\1.orig|"
  255. diff -urN squashfs-tools-$_squash_ver{.orig,} > ventoy-$pkgver-squashfs-tools-$_squash_ver.patch || :
  256. fi
  257. )
  258.  
  259. (
  260. cd Ventoy2Disk
  261. if ((_DIFF)); then
  262. tar -xf "$srcdir"/xz-embedded-$_xz_embed_ver.tar.gz -C Ventoy2Disk --xform "s|\(xz-embedded-$_xz_embed_ver\)|\1.orig|"
  263. diff -urN Ventoy2Disk/xz-embedded-$_xz_embed_ver{.orig,} > ventoy-$pkgver-xz-embedded-$_xz_embed_ver.patch || :
  264. fi
  265. )
  266.  
  267. (
  268. cd wimboot
  269. # Some *.S files are missing from the bundled source. We will grab them from the tarball.
  270. tar -xf "$srcdir"/wimboot-$_wimboot_ver.tar.gz --xform "s|\(wimboot-$_wimboot_ver\)|\1.orig|"
  271.  
  272. if ((_DIFF)); then
  273. diff -ur wimboot-$_wimboot_ver{.orig,}/src > ventoy-$pkgver-wimboot-$_wimboot_ver.patch || :
  274. fi
  275.  
  276. # Fix build with recent binutils.
  277. cd wimboot-$_wimboot_ver.orig
  278. patch -Np1 -i "$srcdir"/wimboot-binutils-2.42-fix.patch
  279. )
  280. }
  281.  
  282. _build_grub() (
  283. echo ":: grub"
  284. # Refer "GRUB2/buildgrub.sh"
  285. cd Ventoy-$pkgver/GRUB2
  286. local _VT_GRUB_DIR=$PWD
  287.  
  288. (
  289. cd SRC/grub-$_grub_ver
  290. ./autogen.sh
  291. )
  292.  
  293. cp -a SRC/grub-$_grub_ver SRC/grub-x86_64-efi
  294. cp -a SRC/grub-$_grub_ver SRC/grub-i386-efi
  295. cp -a SRC/grub-$_grub_ver SRC/grub-i386-pc
  296.  
  297. mkdir -pv ../INSTALL/{EFI/BOOT,grub/i386-pc}
  298. local _conf_args=(--prefix="$_VT_GRUB_DIR"/INSTALL --disable-werror)
  299.  
  300. _build_grub-x86_64-efi() (
  301. cd SRC/grub-x86_64-efi
  302. ./configure --with-platform=efi "${_conf_args[@]}"
  303. make
  304. sh install.sh uefi
  305. )
  306.  
  307. _build_grub-i386-efi() (
  308. cd SRC/grub-i386-efi
  309. ./configure --target=i386 --with-platform=efi "${_conf_args[@]}"
  310. make
  311. sh install.sh i386efi
  312. )
  313.  
  314. _build_grub-i386-pc() (
  315. cd SRC/grub-i386-pc
  316. ./configure --target=i386 --with-platform=pc "${_conf_args[@]}"
  317. make
  318. sh install.sh
  319. )
  320.  
  321. _build_grub-x86_64-efi
  322. _build_grub-i386-efi
  323. _build_grub-i386-pc
  324.  
  325. # Copy over the ancillary stuff.
  326. local _d
  327. for _d in distro fonts help menu themes; do
  328. cp -av ../INSTALL.upstream/grub/$_d ../INSTALL/grub
  329. done
  330. cp -av ../INSTALL.upstream/grub/*.cfg ../INSTALL/grub
  331. )
  332.  
  333. _build_ipxe() (
  334. echo ":: ipxe"
  335. # Refer "IPXE/buildipxe.sh"
  336. cd Ventoy-$pkgver/IPXE/ipxe-$_ipxe_ver/src
  337.  
  338. make bin/ipxe.lkrn NO_WERROR=1 V=1
  339. install -Dv bin/ipxe.lkrn "$srcdir"/Ventoy-$pkgver/INSTALL/ventoy/ipxe.krn
  340. )
  341.  
  342. _build_edk2() (
  343. echo ":: edk2"
  344. # Refer "EDK2/buildedk.sh"
  345. cd Ventoy-$pkgver/EDK2
  346.  
  347. (
  348. cd edk2-edk2-$_edk2_ver
  349. make -C BaseTools
  350. )
  351.  
  352. mkdir -pv ../INSTALL/ventoy
  353. sh ./build.sh ia32
  354. sh ./build.sh
  355. )
  356.  
  357. _build_dietlibc() (
  358. echo ":: dietlibc"
  359. # Refer "DOC/installdietlibc.sh"
  360. cd dietlibc-$_diet_ver
  361. make
  362. make i386
  363. )
  364.  
  365. _build_musl32() (
  366. echo ":: musl32"
  367. # Refer "DOC/BuildVentoyFromSource.txt" Section 2.3
  368. (
  369. cd musl-$_musl_ver
  370.  
  371. CFLAGS=-m32 \
  372. ./configure --prefix="$srcdir"/musl32 --syslibdir="$srcdir"/musl32/lib \
  373. --target=i386 --build=i386
  374. make
  375. make install
  376. )
  377.  
  378. cd kernel-headers-$_kern_hdrs_musl_ver
  379. make ARCH=x86 prefix="$srcdir"/musl32 install
  380. )
  381.  
  382. # IMG/USB
  383. _build_vtoytool() (
  384. echo ":: vtoytool"
  385. # Refer "VtoyTool/build.sh"
  386. cd Ventoy-$pkgver/VtoyTool
  387.  
  388. "$srcdir"/dietlibc-$_diet_ver/bin-x86_64/diet -Os gcc -DVTOY_X86_64 -D_FILE_OFFSET_BITS=64 ./*.c BabyISO/*.c \
  389. -IBabyISO -Wall -DBUILD_VTOY_TOOL -DUSE_DIET_C -o vtoytool_64
  390.  
  391. "$srcdir"/dietlibc-$_diet_ver/bin-i386/diet -Os gcc -DVTOY_I386 -D_FILE_OFFSET_BITS=64 -m32 ./*.c BabyISO/*.c \
  392. -IBabyISO -Wall -DBUILD_VTOY_TOOL -DUSE_DIET_C -o vtoytool_32
  393.  
  394. strip --strip-all vtoytool_{64,32}
  395. rm -rfv vtoytool
  396. install -Dvt vtoytool/00 vtoytool_{64,32}
  397. )
  398.  
  399. # HOST
  400. _build_vtoycli() (
  401. echo ":: vtoycli"
  402. # Refer "vtoycli/fat_io_lib/buildlib.sh" and "vtoycli/build.sh"
  403. #
  404. # Upstream builds small and static here, but this is a "host" binary so we
  405. # don't really need that, nor do we need a 32-bit binary. A "normal" GCC
  406. # binary would do. FIXME
  407.  
  408. cd Ventoy-$pkgver/vtoycli
  409.  
  410. (
  411. cd fat_io_lib/release
  412. rm -rfv ../{include,lib}
  413.  
  414. # GCC-14 build fix
  415. sed -i '/fat_cache.h/a #include "fat_format.h"' fat_filelib.c
  416.  
  417. musl-gcc -O2 -D_FILE_OFFSET_BITS=64 fat*.c -c
  418. ar -rc libfat_io_64.a ./*.o
  419. rm -fv ./*.o
  420.  
  421. # gcc -m32 -O2 -D_FILE_OFFSET_BITS=64 fat*.c -c
  422. # ar -rc libfat_io_32.a ./*.o
  423. # rm -fv ./*.o
  424.  
  425. mkdir -v ../{include,lib}
  426. mv -v ./*.a ../lib/
  427. cp -av ./*.h ../include/
  428. )
  429.  
  430. local _SRCS=(vtoycli.c vtoyfat.c vtoygpt.c crc32.c partresize.c)
  431.  
  432. musl-gcc -Os -static -D_FILE_OFFSET_BITS=64 \
  433. "${_SRCS[@]}" -Ifat_io_lib/include fat_io_lib/lib/libfat_io_64.a -o vtoycli_64
  434.  
  435. # "$srcdir"/dietlibc-$_diet_ver/bin-i386/diet -Os gcc -D_FILE_OFFSET_BITS=64 -m32 \
  436. # "${_SRCS[@]}" -Ifat_io_lib/include fat_io_lib/lib/libfat_io_32.a -o vtoycli_32
  437.  
  438. strip --strip-all vtoycli_64
  439. # strip --strip-all vtoycli_32
  440. install -Dv vtoycli_64 ../INSTALL/tool/x86_64/vtoycli
  441. # install -Dv vtoycli_32 ../INSTALL/tool/i386/vtoycli
  442. )
  443.  
  444. # IMG/USB
  445. _build_fuseiso() (
  446. echo ":: fuseiso"
  447. # Refer "FUSEISO/build.sh"
  448. cd Ventoy-$pkgver/FUSEISO
  449.  
  450. __build_libfuse_static() (
  451. # Refer "FUSEISO/build_libfuse.sh"
  452. tar -xf "$srcdir"/fuse-$_fuse_ver.tar.gz
  453. cd fuse-$_fuse_ver
  454. mkdir -v build{64,32}
  455.  
  456. local _conf_args=(
  457. --disable-shared
  458. --disable-util
  459. --disable-example
  460. CFLAGS=-Os
  461. )
  462.  
  463. (
  464. cd build64
  465. CC=musl-gcc \
  466. ../configure "${_conf_args[@]}"
  467. make V=1
  468. )
  469.  
  470. (
  471. cd build32
  472. CC="$srcdir/musl32/bin/musl-gcc -m32" \
  473. LDFLAGS="-Wl,-melf_i386" \
  474. ../configure "${_conf_args[@]}"
  475. make V=1
  476. )
  477. )
  478.  
  479. __build_libfuse_static
  480.  
  481. rm -fv vtoy_fuse_iso_*
  482.  
  483. musl-gcc -static -O2 -D_FILE_OFFSET_BITS=64 vtoy_fuse_iso.c -Ifuse-$_fuse_ver/include \
  484. fuse-$_fuse_ver/build64/lib/.libs/libfuse.a -o vtoy_fuse_iso_64
  485.  
  486. "$srcdir"/musl32/bin/musl-gcc -m32 -static -O2 -D_FILE_OFFSET_BITS=64 \
  487. vtoy_fuse_iso.c -Ifuse-$_fuse_ver/include -Wl,-melf_i386 \
  488. fuse-$_fuse_ver/build32/lib/.libs/libfuse.a -o vtoy_fuse_iso_32
  489.  
  490. strip --strip-all vtoy_fuse_iso_{64,32}
  491. )
  492.  
  493. # HOST
  494. _build_exfat() (
  495. echo ":: exfat"
  496. # Refer "ExFAT/buidexfat.sh"
  497. #
  498. # This is the FUSE based pkg. The version in the repo "exfat-utils" is going
  499. # away in favor of the kernel based "exfatprogs" [1]. Ventoy is apparently not
  500. # yet ready for the newer "exfatprogs" tools. Upstream builds want to link
  501. # "libfuse.a" statically, however this is a "host" binary so there's no need.
  502. # Additionally, Ventoy modifies it slightly with the sed below. Although, it
  503. # appears the mod is only applicable to "mount.exfat-fuse" which we don't need
  504. # (see below). FIXME
  505. #
  506. # [1] https://bugs.archlinux.org/task/72629
  507.  
  508. cd Ventoy-$pkgver/ExFAT
  509.  
  510. tar -xf "$srcdir"/exfat-$_exfat_ver.tar.gz
  511. cd exfat-$_exfat_ver
  512.  
  513. sed "/printf.*VERSION/a\\\tif (access(\"/etc/initrd-release\", F_OK) >= 0) argv[0][0] = '@';" \
  514. -i fuse/main.c
  515. autoreconf -i
  516. ./configure
  517. make
  518.  
  519. # NOTE: AFAICT "mount.exfat-fuse" is used only in the LiveCD which is of no use to us.
  520. # If it turns out that it is required, a runtime dep on "fuse2" will be needed.
  521.  
  522. # strip --strip-all fuse/mount.exfat-fuse
  523. strip --strip-all mkfs/mkexfatfs
  524.  
  525. # install -Dvt ../../INSTALL/tool/x86_64 fuse/mount.exfat-fuse
  526. install -Dvt ../../INSTALL/tool/x86_64 mkfs/mkexfatfs
  527. )
  528.  
  529. # IMG/USB
  530. _build_unsquashfs() (
  531. echo ":: unsquashfs"
  532. # Refer "SQUASHFS/build.txt"
  533. cd Ventoy-$pkgver/SQUASHFS/SRC
  534. CFLAGS=-Os
  535. local _libdir="$srcdir"/Ventoy-$pkgver/SQUASHFS/LIB
  536.  
  537. __build_lz4_static() (
  538. # Refer "SQUASHFS/SRC/build_lz4.sh"
  539. # The bundled lz4 tarball (ver 1.8.1.2 Jan 2018) has been independently
  540. # verified as being identical to the one available on GitHub.
  541.  
  542. tar -xf lz4-$_lz4_ver.tar.gz
  543. sed -i "s/@\$(CC)/\$(CC)/" lz4-$_lz4_ver/lib/Makefile
  544. cp -a lz4-$_lz4_ver{,-32}
  545.  
  546. (
  547. cd lz4-$_lz4_ver
  548. make -C lib
  549. make -C lib install PREFIX="$_libdir"/LZ4
  550. )
  551.  
  552. (
  553. cd lz4-$_lz4_ver-32
  554. CC="gcc -m32" \
  555. make -C lib
  556. make -C lib install PREFIX="$_libdir"32/LZ4
  557. )
  558. )
  559.  
  560. __build_xz_static() (
  561. # Refer "SQUASHFS/SRC/build_lzma.sh"
  562. # The bundled liblzma/xz zip file contents have been independently verified
  563. # as being identical to (ver 5.0.4 Jun 2012) available on [1], apart from
  564. # the addition of a single file "liblzma-builder.sh".
  565. #
  566. # [1] https://tukaani.org/xz/old.html
  567.  
  568. bsdtar -xf liblzma-master.zip
  569. cp -a liblzma-master{,-32}
  570.  
  571. local _conf_args=(
  572. --disable-shared
  573. --disable-xz
  574. --disable-xzdec
  575. --disable-lzmadec
  576. --disable-lzmainfo
  577. --enable-small
  578. )
  579.  
  580. (
  581. cd liblzma-master
  582. ./configure --prefix="$_libdir"/LZMA "${_conf_args[@]}"
  583. make
  584. make install
  585. )
  586.  
  587. (
  588. cd liblzma-master-32
  589. CC="gcc -m32" \
  590. ./configure --prefix="$_libdir"32/LZMA "${_conf_args[@]}"
  591. make
  592. make install
  593. )
  594. )
  595.  
  596. __build_lzo_static() (
  597. # Refer "SQUASHFS/SRC/build_lzo.sh"
  598. # The bundled lzo tarball (ver 2.08 Jun 2014) contents have been
  599. # independently verified as being identical to the 2.08 tarball available
  600. # on [1], apart from a 1 line change in "configure{,.ac}" and a minor change
  601. # in "include/lzo/lzodefs.h" but these appear to be tweaks by lzo upstream.
  602. #
  603. # [1] https://www.oberhumer.com/opensource/lzo/download/lzo-2.08.tar.gz
  604.  
  605. tar -xf lzo-$_lzo_ver.tar.gz
  606. cp -a lzo-$_lzo_ver{,-32}
  607.  
  608. (
  609. cd lzo-$_lzo_ver
  610. ./configure --prefix="$_libdir"/LZO
  611. make V=1
  612. make install
  613. )
  614.  
  615. (
  616. cd lzo-$_lzo_ver-32
  617. CC="gcc -m32" \
  618. ./configure --prefix="$_libdir"32/LZO
  619. make V=1
  620. make install
  621. )
  622. )
  623.  
  624. __build_zstd_static() (
  625. # Refer "SQUASHFS/SRC/build_zstd.sh"
  626. # The bundled zstd tarball (ver 1.4.4 Nov 2019) has been independently
  627. # verified as being identical to the one available on GitHub.
  628.  
  629. tar -xf zstd-$_zstd_ver.tar.gz
  630. cp -a zstd-$_zstd_ver{,-32}
  631.  
  632. (
  633. cd zstd-$_zstd_ver
  634. ZSTD_LIB_COMPRESSION=0 make -C lib
  635. make -C lib install PREFIX="$_libdir"/ZSTD
  636. )
  637.  
  638. (
  639. cd zstd-$_zstd_ver-32
  640. export CC="gcc -m32"
  641. ZSTD_LIB_COMPRESSION=0 make -C lib
  642. make -C lib install PREFIX="$_libdir"32/ZSTD
  643. )
  644. )
  645.  
  646. __build_zlib_static-32() (
  647. tar -xf "$srcdir"/zlib-$_zlib_ver.tar.xz
  648. cd zlib-$_zlib_ver
  649.  
  650. CC="gcc -m32" \
  651. ./configure --static
  652. make
  653. )
  654.  
  655. __build_lz4_static
  656. __build_xz_static
  657. __build_lzo_static
  658. __build_zstd_static
  659. __build_zlib_static-32
  660.  
  661. cd "$srcdir"/Ventoy-$pkgver/SQUASHFS
  662. unset CFLAGS
  663. cp -a squashfs-tools-4.4/squashfs-tools{,-32}
  664. rm -fv unsquashfs_*
  665.  
  666. (
  667. cd squashfs-tools-4.4/squashfs-tools
  668. sed -i 's|LIBS) -o|LIBS) /usr/lib/libz.a -o|' Makefile
  669. make unsquashfs LZ4_LIBDIR="$_libdir"/LZ4 LZMA_LIBDIR="$_libdir"/LZMA \
  670. LZO_LIBDIR="$_libdir"/LZO ZSTD_LIBDIR="$_libdir"/ZSTD
  671.  
  672. strip --strip-all unsquashfs
  673. cp -av unsquashfs ../../unsquashfs_64
  674. )
  675.  
  676. (
  677. cd squashfs-tools-4.4/squashfs-tools-32
  678. sed -i "s|LIBS) -o|LIBS) ../../SRC/zlib-$_zlib_ver/libz.a -o|" Makefile
  679. CC="gcc -m32" \
  680. make unsquashfs LZ4_LIBDIR="$_libdir"32/LZ4 LZMA_LIBDIR="$_libdir"32/LZMA \
  681. LZO_LIBDIR="$_libdir"32/LZO ZSTD_LIBDIR="$_libdir"32/ZSTD
  682.  
  683. strip --strip-all unsquashfs
  684. cp -av unsquashfs ../../unsquashfs_32
  685. )
  686. )
  687.  
  688. # IMG/USB
  689. _build_vblade() (
  690. echo ":: vblade"
  691. # Refer "VBLADE/vblade-master/build.sh"
  692. cd Ventoy-$pkgver/VBLADE/vblade-master
  693. rm -fv vblade_*
  694.  
  695. # Need -fcommon for build to succeed FIXME
  696. gcc linux.c aoe.c ata.c bpf.c -Os -o vblade_64 -fcommon
  697. gcc linux.c aoe.c ata.c bpf.c -Os -m32 -o vblade_32 -fcommon
  698.  
  699. strip --strip-all vblade_{64,32}
  700. )
  701.  
  702. # IMG/USB
  703. _build_dmsetup() (
  704. echo ":: dmsetup"
  705. # Refer "DMSETUP/build.txt"
  706. cd Ventoy-$pkgver/DMSETUP
  707. rm -fv dmsetup*
  708. bsdtar -O -xvf "$srcdir"/device-mapper*.rpm device-mapper*.tgz | tar -xzf -
  709.  
  710. tee -a device-mapper.$_dm_ver/include/configure.h.in > /dev/null << _EOF_
  711. #ifndef UINT32_MAX
  712. #define UINT32_MAX (4294967295U)
  713. #endif
  714.  
  715. #ifndef UINT64_C
  716. #define UINT64_C(c) c ## ULL
  717. #endif
  718. _EOF_
  719.  
  720. # GCC-14 build fixes
  721. sed -i '/ctype.h/a #include <strings.h>' device-mapper.$_dm_ver/lib/libdm-report.c
  722. sed -i '/langinfo.h/a #include <strings.h>' device-mapper.$_dm_ver/dmsetup/dmsetup.c
  723.  
  724. cp -a device-mapper.$_dm_ver{,-32}
  725.  
  726. (
  727. cd device-mapper.$_dm_ver
  728. CC="$srcdir/dietlibc-$_diet_ver/bin-x86_64/diet gcc" \
  729. ./configure
  730. sed -i '/rpl_malloc/d' include/configure.h
  731. make
  732. strip --strip-all dmsetup/dmsetup
  733. cp -av dmsetup/dmsetup ../dmsetup64
  734. )
  735.  
  736. (
  737. cd device-mapper.$_dm_ver-32
  738. CC="$srcdir/dietlibc-$_diet_ver/bin-i386/diet gcc -m32" \
  739. ./configure
  740. sed -i '/rpl_malloc/d' include/configure.h
  741. make
  742. strip --strip-all dmsetup/dmsetup
  743. cp -av dmsetup/dmsetup ../dmsetup32
  744. )
  745. )
  746.  
  747. # IMG/USB
  748. _build_zstdcat() (
  749. echo ":: zstdcat"
  750. # Refer "ZSTD/build.txt"
  751. cd Ventoy-$pkgver/ZSTD
  752. rm -fv zstdcat*
  753. tar -xf "$srcdir"/zstd-$_zstd1_ver.tar.gz
  754. cp -a zstd-$_zstd1_ver{,-32}
  755.  
  756. local _compile_opts1=(
  757. -I../lib -I../lib/common -I../lib/dictBuilder -I../lib/legacy -Wall -DZSTD_LEGACY_SUPPORT=1
  758. ../lib/decompress/zstd_decompress.c -c -o ../lib/decompress/zstd_decompress.o
  759. )
  760.  
  761. local _compile_opts2=(
  762. -I../lib -I../lib/common -I../lib/dictBuilder -I../lib/legacy -Wall -DZSTD_LEGACY_SUPPORT=1
  763. ../lib/decompress/zstd_decompress.o ../lib/decompress/huf_decompress.c ../lib/common/entropy_common.c
  764. ../lib/common/fse_decompress.c ../lib/common/xxhash.c ../lib/common/zstd_common.c
  765. ../lib/compress/zstd_compress.c ../lib/compress/fse_compress.c ../lib/compress/huf_compress.c
  766. ../lib/legacy/zstd_v01.c ../lib/legacy/zstd_v02.c ../lib/legacy/zstd_v03.c ../lib/legacy/zstd_v04.c
  767. ../lib/legacy/zstd_v05.c ../lib/legacy/zstd_v06.c ../lib/legacy/zstd_v07.c ../lib/dictBuilder/divsufsort.c
  768. ../lib/dictBuilder/zdict.c zstdcli.c fileio.c bench.c datagen.c dibio.c -o zstd
  769. )
  770.  
  771. (
  772. cd zstd-$_zstd1_ver/programs
  773. "$srcdir"/dietlibc-$_diet_ver/bin-x86_64/diet -Os gcc -pipe -nostdinc -falign-loops=32 "${_compile_opts1[@]}"
  774. "$srcdir"/dietlibc-$_diet_ver/bin-x86_64/diet -Os gcc -pipe -nostdinc "${_compile_opts2[@]}"
  775. strip --strip-all zstd
  776. cp -av zstd ../../zstdcat64
  777. )
  778.  
  779. (
  780. cd zstd-$_zstd1_ver-32/programs
  781. "$srcdir"/dietlibc-$_diet_ver/bin-i386/diet -Os gcc -m32 -pipe -nostdinc -falign-loops=32 "${_compile_opts1[@]}"
  782. "$srcdir"/dietlibc-$_diet_ver/bin-i386/diet -Os gcc -m32 -pipe -nostdinc "${_compile_opts2[@]}"
  783. strip --strip-all zstd
  784. cp -av zstd ../../zstdcat
  785. )
  786.  
  787. install -Dvt ../IMG/cpio_x86/ventoy/tool zstdcat{,64}
  788. )
  789.  
  790. # IMG/USB
  791. _build_xzminidec() (
  792. echo ":: xzminidec"
  793. # Refer "DOC/BuildVentoyFromSource.txt" Section(s) 4.15 and 4.16
  794. cd Ventoy-$pkgver/Ventoy2Disk/Ventoy2Disk/xz-embedded-20130513/userspace
  795.  
  796. make -f ventoy_makefile CC="$srcdir/dietlibc-$_diet_ver/bin-i386/diet gcc -Os -m32 -std=gnu89"
  797. mv -v xzminidec{,32}
  798. make clean
  799. rm -v bytetest.o
  800.  
  801. make -f ventoy_makefile CC="$srcdir/dietlibc-$_diet_ver/bin-x86_64/diet gcc -Os -std=gnu89"
  802. mv -v xzminidec{,64}
  803. make clean
  804. rm -v bytetest.o
  805.  
  806. make -f ventoy_makefile CC="musl-gcc -Os -static -std=gnu89"
  807. mv -v xzminidec{,64_musl}
  808. make clean
  809. rm -v bytetest.o
  810.  
  811. strip --strip-all xzminidec{32,64}*
  812. install -Dvt ../../../../IMG/cpio_x86/ventoy/busybox xzminidec{32,64}*
  813. )
  814.  
  815. # IMG/USB
  816. _build_busybox() (
  817. echo ":: busybox"
  818. # Refer "BUSYBOX/build.txt"
  819. cd Ventoy-$pkgver/BUSYBOX
  820. mkdir -pv ../IMG/cpio_x86/ventoy/busybox
  821.  
  822. (
  823. # Refer "BUSYBOX/chmod/build.sh"
  824. cd chmod
  825. rm -vf vtchmod*{32,64}*
  826.  
  827. "$srcdir"/dietlibc-$_diet_ver/bin-x86_64/diet gcc -Os vtchmod.c -o vtchmod64
  828. "$srcdir"/dietlibc-$_diet_ver/bin-i386/diet gcc -Os -m32 vtchmod.c -o vtchmod32
  829. musl-gcc -Os -static vtchmod.c -o vtchmod64_musl
  830. strip --strip-all vtchmod{64,32} vtchmod64_musl
  831. cp -avt ../../IMG/cpio_x86/ventoy/busybox vtchmod{64,32} vtchmod64_musl
  832. )
  833.  
  834. tar -xf "$srcdir"/busybox-$_busybox_ver.tar.bz2
  835.  
  836. cp -a busybox-$_busybox_ver{,-xzcat64}
  837. cp -a busybox-$_busybox_ver{,-xzcat32}
  838. cp -a busybox-$_busybox_ver{,-32}
  839.  
  840. (
  841. cd busybox-$_busybox_ver-xzcat64
  842. cp -av ../x86_64_xzcat.config .config
  843. make CC=musl-gcc V=1
  844. mv -v busybox xzcat64_musl
  845. xz xzcat64_musl
  846. cp -avt ../../IMG/cpio_x86/ventoy/busybox xzcat64_musl.xz
  847. )
  848.  
  849. (
  850. cd busybox-$_busybox_ver-xzcat32
  851. sed 's/# CONFIG_LFS is not set/CONFIG_LFS=y/' ../x86_64_xzcat.config > .config
  852. make CC="$srcdir/musl32/bin/musl-gcc -m32 -Wl,-melf_i386" V=1
  853. mv -v busybox xzcat32_musl
  854. xz xzcat32_musl
  855. cp -avt ../../IMG/cpio_x86/ventoy/busybox xzcat32_musl.xz
  856. )
  857.  
  858. (
  859. cd busybox-$_busybox_ver
  860. make defconfig
  861. sed -i 's/# CONFIG_STATIC is not set/CONFIG_STATIC=y/' .config
  862. make CC=musl-gcc V=1
  863. mv -v busybox busybox64
  864. xz busybox64
  865. cp -avt ../../IMG/cpio_x86/ventoy/busybox busybox64.xz
  866. )
  867.  
  868. (
  869. cd busybox-$_busybox_ver-32
  870. make defconfig
  871. sed -i 's/# CONFIG_STATIC is not set/CONFIG_STATIC=y/' .config
  872. make CC="$srcdir/musl32/bin/musl-gcc -m32 -Wl,-melf_i386" V=1
  873. mv -v busybox busybox32
  874. xz busybox32
  875. cp -avt ../../IMG/cpio_x86/ventoy/busybox busybox32.xz
  876. )
  877. )
  878.  
  879. # IMG/USB
  880. _build_lunzip() (
  881. echo ":: lunzip"
  882. # Refer "DOC/BuildVentoyFromSource.txt" Section 4.19
  883. # The bundled lunzip tarball (ver 1.11 Jan 2019) has been independently
  884. # verified as being identical to the one available on [1].
  885. #
  886. # [1] http://download.savannah.gnu.org/releases/lzip/lunzip/
  887.  
  888. cd Ventoy-$pkgver/LZIP
  889. rm -fv lunzip*{32,64}
  890. tar -xf lunzip-$_lunzip_ver.tar.gz
  891. cp -a lunzip-$_lunzip_ver{,-32}
  892.  
  893. (
  894. cd lunzip-$_lunzip_ver
  895. ./configure CC="$srcdir/dietlibc-$_diet_ver/bin-x86_64/diet gcc" CFLAGS=-Os
  896. make
  897. strip --strip-all lunzip
  898. cp -av lunzip ../lunzip64
  899. )
  900.  
  901. (
  902. cd lunzip-$_lunzip_ver-32
  903. ./configure CC="$srcdir/dietlibc-$_diet_ver/bin-i386/diet gcc -m32" CFLAGS=-Os
  904. make
  905. strip --strip-all lunzip
  906. cp -av lunzip ../lunzip32
  907. )
  908.  
  909. # Undocumented!
  910. rm -fv lz4cat*
  911. "$srcdir"/dietlibc-$_diet_ver/bin-x86_64/diet -Os gcc -D_FILE_OFFSET_BITS=64 smallz4cat.c -o lz4cat64
  912. strip --strip-all lz4cat64
  913. install -Dvt ../IMG/cpio_x86/ventoy/tool lz4cat64
  914. )
  915.  
  916. # IMG/USB
  917. _build_verity() (
  918. echo ":: verity"
  919. # Refer "cryptsetup/cryptsetup-build.txt"
  920. # Needed for *experimental* FydeOS/CloudReady (ChromeOS) support.
  921.  
  922. cd Ventoy-$pkgver/cryptsetup
  923. tar -xf "$srcdir"/cryptsetup-$_crypt_ver.tar.xz
  924. cp -a cryptsetup-$_crypt_ver{,-32}
  925.  
  926. # 30 Jun 2024. Ugh, this now fails to build because latest libgcrypt-1.11.0
  927. # has removed libgcrypt-config. Just use the upstream provided 64-bit binary
  928. # for now. The ChromeOS support is experimental anyway. FIXME
  929.  
  930. # (
  931. # rm -v veritysetup64
  932. # cd cryptsetup-$_crypt_ver
  933. # ./configure --enable-static --host=x86_64-pc-linux-gnu
  934. # make
  935. # cd src
  936. # gcc -Wall -O2 -o veritysetup veritysetup-utils_crypt.o veritysetup-utils_loop.o veritysetup-utils_tools.o \
  937. # veritysetup-veritysetup.o -lpopt -ldevmapper -lgcrypt -luuid .././lib/.libs/libcryptsetup.a
  938. # strip --strip-all veritysetup
  939. # cp -av veritysetup ../../veritysetup64
  940. # )
  941.  
  942. # Ugh, this needs multilib (lib32-e2fsprogs lib32-popt lib32-libgcrypt) and
  943. # a 32-bit libdevmapper which doesn't actually exist in the repo. Just use the
  944. # upstream provided 32-bit binary for now. FIXME
  945.  
  946. # rm -v veritysetup32
  947. # cd cryptsetup-$_crypt_ver-32
  948. # CC="gcc -m32" \
  949. # ./configure --enable-static --host=x86_64-pc-linux-gnu
  950. # make
  951. # cd src
  952. # gcc -m32 -Wall -O2 -o veritysetup veritysetup-utils_crypt.o veritysetup-utils_loop.o veritysetup-utils_tools.o \
  953. # veritysetup-veritysetup.o -lpopt -ldevmapper -lgcrypt -luuid .././lib/.libs/libcryptsetup.a
  954. # strip --strip-all veritysetup
  955. # cp -av veritysetup ../../veritysetup32
  956. )
  957.  
  958. # IMG/USB
  959. _build_wimboot() (
  960. echo ":: wimboot"
  961. # Refer "wimboot/build.sh"
  962. cd Ventoy-$pkgver/wimboot/wimboot-$_wimboot_ver/src
  963.  
  964. # Grab the missing *.S files
  965. cp -av ../../wimboot-$_wimboot_ver.orig/src/*.S .
  966. sed -i '/^CFLAGS/s/ -Werror//' Makefile
  967.  
  968. # pesign (if installed) appears to make no difference, ignore.
  969. make wimboot.x86_64 wimboot.i386.efi
  970. xz wimboot.{x86_64,i386.efi}
  971. install -Dvt "$srcdir"/Ventoy-$pkgver/INSTALL/ventoy wimboot.{x86_64,i386.efi}.xz
  972. )
  973.  
  974. _pack_ventoy() (
  975. echo ":: pack"
  976. # Refer "INSTALL/ventoy_pack.sh"
  977. # 3RD PARTY BINARIES ALERT! FIXME
  978.  
  979. cd Ventoy-$pkgver
  980. local _LDFLAGS="-Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now,-z,pack-relative-relocs"
  981.  
  982. (
  983. cd IMG
  984. sed -i '/arm64 #/i exit 0' mkcpio.sh
  985. install -dv cpio_x86/ventoy/{busybox,tool}
  986. cp -avt cpio_x86/ventoy/tool cpio_x86.upstream/ventoy/tool/*.sh
  987.  
  988. # 32-bit tiny lz4cat binary FIXME
  989. # Refer "DOC/BuildVentoyFromSource.txt" Section 5.1
  990. cp -avt cpio_x86/ventoy/tool cpio_x86.upstream/ventoy/tool/lz4cat
  991.  
  992. # 32-bit busybox ar binary FIXME
  993. # Refer "DOC/BuildVentoyFromSource.txt" Section 5.2
  994. cp -avt cpio_x86/ventoy/tool cpio_x86.upstream/ventoy/tool/ar
  995.  
  996. # 32-bit busybox inotifyd binary FIXME
  997. # Refer "DOC/BuildVentoyFromSource.txt" Section 5.3
  998. cp -avt cpio_x86/ventoy/tool cpio_x86.upstream/ventoy/tool/inotifyd
  999.  
  1000. # 32-bit busybox ash binary FIXME
  1001. # Refer "DOC/BuildVentoyFromSource.txt" Section 5.4
  1002. cp -avt cpio_x86/ventoy/busybox cpio_x86.upstream/ventoy/busybox/ash
  1003.  
  1004. # 64-bit busybox ash binary FIXME
  1005. # Refer "DOC/BuildVentoyFromSource.txt" Section 4.18
  1006. # For some unknown reason this is the only binary built with uclibc.
  1007. # Please see: https://github.com/ventoy/Ventoy/issues/2183
  1008. cp -avt cpio_x86/ventoy/busybox cpio_x86.upstream/ventoy/busybox/64h
  1009.  
  1010. # patch for device-mapper kernel modules FIXME
  1011. # Refer "DMPATCH/readme.txt"
  1012. cp -avt cpio_x86/ventoy/tool cpio_x86.upstream/ventoy/tool/dm_patch_*
  1013.  
  1014. sh mkcpio.sh
  1015. install -Dvm 644 -t ../INSTALL/ventoy ventoy.cpio ventoy_x86.cpio
  1016.  
  1017. # "IMG/vtloopex" contains pre-compiled binary kernel modules (dm-mod) for
  1018. # stuff like LibreELEC, openwrt, etc. FIXME
  1019. sh mkloopex.sh
  1020. )
  1021.  
  1022. (
  1023. # "IMG/Unix" contains pre-compiled binary kernel modules (geom_ventoy) for
  1024. # various BSD's, FreeBSD, etc. FIXME
  1025. cd Unix
  1026. sh pack_unix.sh
  1027. )
  1028.  
  1029. (
  1030. # HOST
  1031. cd LinuxGUI
  1032. sed -i '/dos2unix/d' language.sh
  1033. sh language.sh
  1034.  
  1035. mkdir -pv ../INSTALL/tool/x86_64
  1036.  
  1037. sed -e '/^build.*i386/d;/^build.*aarch64/d;/^build.*mips/d;/^build.*gtk2/d;/^export/d' \
  1038. -e "/\$XXLIB/a \ $_LDFLAGS \\\\" \
  1039. -e "/VTOY_GUI/s/$/ $_LDFLAGS/" -i.bak build.sh build_gtk.sh
  1040. sh build.sh
  1041. sh build_gtk.sh
  1042.  
  1043. sed -e '/^if.*CentOS8/,+6d;/^build.*aarch64$/d;/^build.*mips64el$/d' \
  1044. -e '/QT_INC.*gcc_64/a \ QT_INC_PATH="/usr/include/qt"' \
  1045. -e '/QT_LIB.*gcc_64/a \ QT_LIB_PATH="/usr/lib"' \
  1046. -e "/LFLAGS.*PATH\"/a \ LFLAGS+=\" $_LDFLAGS\"" -i.bak build_qt.sh
  1047. sh build_qt.sh
  1048. )
  1049.  
  1050. (
  1051. # HOST
  1052. cd Plugson
  1053. sed -e '/^build.*i386/d;/^build.*aarch64/d;/^build.*mips/d' \
  1054. -e "/\$XXLIB/a \ $_LDFLAGS \\\\" -i.bak build.sh
  1055. sh build.sh
  1056. sh pack.sh
  1057. )
  1058.  
  1059. (
  1060. # HOST
  1061. # Upstream builds small and static here, but this is a "host" binary so we
  1062. # don't really need that. A "normal" GCC binary would do. FIXME
  1063. cd Vlnk
  1064. local _SRCS=(src/crc32.c src/main_linux.c src/vlnk.c)
  1065.  
  1066. musl-gcc -Os -static -D_FILE_OFFSET_BITS=64 "${_SRCS[@]}" -Isrc -o vlnk
  1067. strip --strip-all vlnk
  1068. install -Dvt ../INSTALL/tool/x86_64 vlnk
  1069.  
  1070. sh pack.sh
  1071. )
  1072.  
  1073. (
  1074. cd EfiISO
  1075. sed -i 's/-P/-publisher/' mkefiiso.sh
  1076. sh mkefiiso.sh
  1077. )
  1078.  
  1079. # Binary EFI Secure Boot stuff FIXME
  1080. # These files are taken from various projects. "?" denotes unverified/unknown origin
  1081.  
  1082. local _efi_files=(
  1083. BOOTIA32.EFI # shim 32-bit ver 15.6 # SUISBD [1] based on Fedora
  1084. BOOTX64.EFI # shim 64-bit ver 15.7 # ? SUSE Linux Enterprise ?
  1085. grub.efi # preloader 64-bit # SUISBD [1]
  1086. grubia32.efi # preloader 32-bit # SUISBD [2]
  1087. mmia32.efi # MokManager 32-bit ver 15.6 # same length as SUISBD [1] (but 261 bytes differ) based on Fedora
  1088. MokManager.efi # MokManager 64-bit ver 15.7 # ? SUSE Linux Enterprise ?
  1089. )
  1090.  
  1091. # This file is also from SUISBD
  1092. install -vm 644 INSTALL.upstream/tool/ENROLL_THIS_KEY_IN_MOKMANAGER.cer INSTALL/tool
  1093. (
  1094. cd INSTALL.upstream/EFI/BOOT
  1095. install -Dvt "$srcdir"/Ventoy-$pkgver/INSTALL/EFI/BOOT "${_efi_files[@]}"
  1096. )
  1097. # [1] https://github.com/ValdikSS/Super-UEFIinSecureBoot-Disk/releases/download/3-4/Super-UEFIinSecureBoot-Disk_minimal_v3-4.zip
  1098. # [2] https://github.com/ValdikSS/Super-UEFIinSecureBoot-Disk/releases/download/3-3/Super-UEFIinSecureBoot-Disk_minimal_v3-3.zip
  1099.  
  1100. # More EFI stuff. Should be buildable with EDK2 FIXME
  1101. # Refer "DOC/BuildVentoyFromSource.txt" Section 4.17
  1102. cp -avt INSTALL/ventoy INSTALL.upstream/ventoy/iso9660_{x64,ia32}.efi
  1103. cp -avt INSTALL/ventoy INSTALL.upstream/ventoy/udf_{x64,ia32}.efi
  1104.  
  1105. # Windows stuff. Apparently buildable with Microsoft Visual Studio FIXME
  1106. # Refer "DOC/BuildVentoyFromSource.txt" Section 4.4
  1107. cp -avt INSTALL/ventoy INSTALL.upstream/ventoy/vtoyjump{64,32}.exe
  1108.  
  1109. # 3rd party Windows stuff FIXME
  1110. # Refer "DOC/BuildVentoyFromSource.txt" Section(s) 5.12 and 5.8
  1111. cp -avt INSTALL/ventoy INSTALL.upstream/ventoy/7z
  1112. cp -avt INSTALL/ventoy INSTALL.upstream/ventoy/imdisk
  1113.  
  1114. # Unknown Windows crap. Config data for Windows Boot Manager? Where from? FIXME
  1115. cp -avt INSTALL/ventoy INSTALL.upstream/ventoy/common_{bcd,bootmgr}.xz
  1116.  
  1117. # From syslinux. Could we use our own repo version? FIXME
  1118. # Refer "DOC/BuildVentoyFromSource.txt" Section 5.9
  1119. cp -avt INSTALL/ventoy INSTALL.upstream/ventoy/memdisk
  1120.  
  1121. # DragonFly BSD stuff FIXME
  1122. # Refer "Unix/ventoy_unix/DragonFly/mkinitrd.sh"
  1123. cp -avt INSTALL/ventoy INSTALL.upstream/ventoy/dragonfly.mfs.xz
  1124. )
  1125.  
  1126. _create_img() (
  1127. echo ":: image"
  1128. # Refer "INSTALL/ventoy_pack.sh"
  1129. mkdir -pv Ventoy-$pkgver/INSTALL
  1130. cd Ventoy-$pkgver/INSTALL
  1131.  
  1132. # Create a 256M Ventoy disk image, partition/format a 32M ESP
  1133. dd if=/dev/zero of=img.bin bs=1M count=256 status=none
  1134. echo -e 'size=223M, type=7, bootable\n size=32M, type=U\n' | sfdisk img.bin
  1135. guestfish add img.bin : run : mkfs vfat /dev/sda2 label:VTOYEFI
  1136.  
  1137. # Create a 64M "scratch" disk image / ext4 partition
  1138. dd if=/dev/zero of=scratch.bin bs=1M count=64 status=none
  1139. echo -e 'size=+\n' | sfdisk scratch.bin
  1140. guestfish add scratch.bin : run : mkfs ext4 /dev/sda1 label:SCRATCH
  1141.  
  1142. # Copy our GRUB stuff into the scratch disk
  1143. tar -czvf - -C "$srcdir"/Ventoy-$pkgver/INSTALL grub/i386-pc |
  1144. guestfish add scratch.bin : run : mount /dev/sda1 / : tar-in - / compress:gzip
  1145. tar -czvf - -C "$srcdir"/Ventoy-$pkgver/GRUB2 INSTALL |
  1146. guestfish add scratch.bin : run : mount /dev/sda1 / : tar-in - / compress:gzip
  1147.  
  1148. # Do the GRUB install business
  1149. #
  1150. # XXX (ab)using `guestfish debug sh "args ..."' like this is a dirty hack. FIXME. Pls see:
  1151. # https://www.libguestfs.org/guestfs-faq.1.html#whats-the-difference-between-guestfish-and-virt-rescue
  1152. #
  1153. # We should be using `guestfish sh command' or maybe `guestfish command "args ..."' but we
  1154. # cannot do so because we don't have a proper guest filesystem.
  1155. # https://www.libguestfs.org/guestfish.1.html#sh
  1156. # https://www.libguestfs.org/guestfish.1.html#command
  1157. #
  1158. # Possible alternative for a guest image -> Arch Boxes basic qcow2...or maybe we just don't
  1159. # use guestfish here at all and instead use something like [1] with an Arch ISO.
  1160. #
  1161. # [1] https://gitlab.archlinux.org/archlinux/ci-scripts/-/blob/master/scripts/build_in_archiso_vm.sh
  1162.  
  1163. guestfish add img.bin : add scratch.bin : run : mount /dev/sdb1 / : debug sh \
  1164. "/sysroot/INSTALL/sbin/grub-bios-setup --skip-fs-probe --directory=/sysroot/grub/i386-pc /dev/sda"
  1165.  
  1166. (
  1167. cd grub
  1168. tar -czf help.tar.gz help
  1169. rm -rf help
  1170.  
  1171. vtlangtitle=$(grep VTLANG_LANGUAGE_NAME menu/zh_CN.json | awk -F\" '{print $4}')
  1172. {
  1173. echo "menuentry \"zh_CN - $vtlangtitle\" --class=menu_lang_item --class=debug_menu_lang --class=F5tool {"
  1174. echo " vt_load_menu_lang zh_CN"
  1175. echo "}"
  1176. } >> menulang.cfg
  1177.  
  1178. # shellcheck disable=SC2010 # FIXME
  1179. ls -1 menu | grep -v 'zh_CN' | sort | while read -r vtlang; do
  1180. vtlangname=${vtlang%.*}
  1181. vtlangtitle=$(grep VTLANG_LANGUAGE_NAME menu/"$vtlang" | awk -F\" '{print $4}')
  1182. {
  1183. echo "menuentry \"$vtlangname - $vtlangtitle\" --class=menu_lang_item --class=debug_menu_lang --class=F5tool {"
  1184. echo " vt_load_menu_lang $vtlangname"
  1185. echo "}"
  1186. } >> menulang.cfg
  1187. done
  1188.  
  1189. {
  1190. echo "menuentry \"\$VTLANG_RETURN_PREVIOUS\" --class=vtoyret VTOY_RET {"
  1191. echo " echo \"Return ...\""
  1192. echo "}"
  1193. } >> menulang.cfg
  1194.  
  1195. tar -czf menu.tar.gz menu
  1196. rm -rf menu
  1197.  
  1198. rm -fv i386-pc/*.img
  1199. )
  1200.  
  1201. # Apparently grub.cfg needs to be located at the front of the partition, copy it first..
  1202. guestfish add img.bin : run : mount /dev/sda2 / : mkdir /grub : copy-in grub/grub.cfg /grub
  1203.  
  1204. # ..and now the rest
  1205. tar -czvf - --exclude=grub.cfg -C grub . |
  1206. guestfish add img.bin : run : mount /dev/sda2 / : tar-in - /grub compress:gzip
  1207. tar -czvf - ventoy EFI |
  1208. guestfish add img.bin : run : mount /dev/sda2 / : tar-in - / compress:gzip
  1209. guestfish add img.bin : run : mount /dev/sda2 / : copy-in tool/ENROLL_THIS_KEY_IN_MOKMANAGER.cer /
  1210.  
  1211. # Just *WTF* is going on here? FIXME
  1212. dd status=none bs=1024 count=16 if=/dev/zero of=/tmp/mount.exfat-fuse_aarch64
  1213. guestfish add img.bin : run : mount /dev/sda2 / : mkdir /tool : copy-in /tmp/mount.exfat-fuse_aarch64 /tool
  1214.  
  1215. # Prepare the final "payload" dir
  1216. curver=$(grep 'set.*VENTOY_VERSION=' ./grub/grub.cfg | awk -F'"' '{print $2}')
  1217. tmpdir=ventoy-$curver
  1218.  
  1219. mkdir -pv "$tmpdir"/{boot,ventoy}
  1220. echo "$curver" > "$tmpdir"/ventoy/version
  1221. dd if=img.bin of="$tmpdir"/boot/boot.img bs=1 count=512 status=none
  1222. dd if=img.bin of="$tmpdir"/boot/core.img bs=512 count=2047 skip=1 status=none
  1223. xz --check=crc32 "$tmpdir"/boot/core.img
  1224.  
  1225. cp -avt "$tmpdir" tool ../INSTALL.upstream/plugin ../LinuxGUI/WebUI
  1226. sed -i 's/.*SCRIPT_DEL_THIS \(.*\)/\1/g' "$tmpdir"/WebUI/index.html
  1227.  
  1228. cp -avt "$tmpdir"/tool \
  1229. ../INSTALL.upstream/tool/{distro_gui_type.json,VentoyGTK.glade,ventoy_lib.sh,VentoyWorker.sh}
  1230.  
  1231. cp -avt "$tmpdir" VentoyGUI.x86_64 VentoyVlnk.sh \
  1232. ../INSTALL.upstream/{Ventoy2Disk,VentoyWeb,VentoyPlugson,CreatePersistentImg,ExtendPersistentImg}.sh
  1233.  
  1234. # 32MB ESP image
  1235. dd status=none if=img.bin of="$tmpdir"/ventoy/ventoy.disk.img bs=512 count=65536 skip=458752
  1236. xz --check=crc32 "$tmpdir"/ventoy/ventoy.disk.img
  1237.  
  1238. chmod -v +x "$tmpdir"{,/tool}/*.sh
  1239. cp -avt "$tmpdir"/tool ../LANGUAGES/languages.json
  1240.  
  1241. # Fix ups
  1242. sed -e 's|./log.txt|/var/log/ventoy.log|' \
  1243. -e "/^vtdebug()/a \ test -w /var/log && \\\\" -i "$tmpdir"/{Ventoy2Disk,tool/ventoy_lib}.sh
  1244.  
  1245. sed -i 's|log.txt|/var/log/ventoy.log|' "$tmpdir/"WebUI/static/js/languages.js \
  1246. "$tmpdir"/tool/{languages.json,VentoyWorker.sh} "$tmpdir"/VentoyWeb.sh
  1247.  
  1248. sed -e '/^chmod/d' -e '/^echo.*decompress/d' \
  1249. -e '/^echo.*2D/s|^|test -w /var/log \&\& |' \
  1250. -e '/^date/s|^|test -w /var/log \&\& |' -i "$tmpdir"/Ventoy2Disk.sh
  1251.  
  1252. sed -e 's|#!/bin/sh|#!/usr/bin/env bash|' -i "$tmpdir"/tool/{VentoyWorker.sh,ventoy_lib.sh}
  1253. )
  1254.  
  1255. build() {
  1256. # Workaround for abovementioned pacman regression.
  1257. unset CPPFLAGS CFLAGS DEBUG_CFLAGS CXXFLAGS DEBUG_CXXFLAGS LDFLAGS LTOFLAGS RUSTFLAGS DEBUG_RUSTFLAGS
  1258.  
  1259. _build_grub
  1260. _build_ipxe
  1261. _build_edk2
  1262. _build_dietlibc
  1263. _build_musl32
  1264. _build_vtoytool
  1265. _build_vtoycli
  1266. _build_fuseiso
  1267. _build_exfat
  1268. _build_unsquashfs
  1269. _build_vblade
  1270. _build_dmsetup
  1271. _build_zstdcat
  1272. _build_xzminidec
  1273. _build_busybox
  1274. _build_lunzip
  1275. _build_verity
  1276. _build_wimboot
  1277. _pack_ventoy
  1278. _create_img
  1279. }
  1280.  
  1281. package() {
  1282. mkdir -pv "$pkgdir"/{opt,usr/{bin,share/{applications,pixmaps}}}
  1283.  
  1284. cp -arv Ventoy-$pkgver/INSTALL/ventoy-$pkgver "$pkgdir"/opt/ventoy
  1285.  
  1286. # Everything below this line -> Credits: https://aur.archlinux.org/packages/ventoy-bin
  1287. tee "$pkgdir"/usr/bin/ventoy > /dev/null << _EOF_
  1288. #!/bin/sh
  1289.  
  1290. cd /opt/ventoy || exit 1
  1291. exec ./Ventoy2Disk.sh "\$@"
  1292. _EOF_
  1293.  
  1294. tee "$pkgdir"/usr/bin/ventoygui > /dev/null << _EOF_
  1295. #!/bin/sh
  1296.  
  1297. cd /opt/ventoy || exit 1
  1298. ./VentoyGUI.x86_64 "\$@"
  1299. _EOF_
  1300.  
  1301. tee "$pkgdir"/usr/bin/ventoyplugson > /dev/null << _EOF_
  1302. #!/bin/sh
  1303.  
  1304. cd /opt/ventoy || exit 1
  1305. exec ./VentoyPlugson.sh "\$@"
  1306. _EOF_
  1307.  
  1308. tee "$pkgdir"/usr/bin/ventoyweb > /dev/null << _EOF_
  1309. #!/bin/sh
  1310.  
  1311. cd /opt/ventoy || exit 1
  1312. exec ./VentoyWeb.sh "\$@"
  1313. _EOF_
  1314.  
  1315. tee "$pkgdir"/usr/bin/ventoy-persistent > /dev/null << _EOF_
  1316. #!/bin/sh
  1317.  
  1318. exec /opt/ventoy/CreatePersistentImg.sh "\$@"
  1319. _EOF_
  1320.  
  1321. tee "$pkgdir"/usr/bin/ventoy-extend-persistent > /dev/null << _EOF_
  1322. #!/bin/sh
  1323.  
  1324. exec /opt/ventoy/ExtendPersistentImg.sh "\$@"
  1325. _EOF_
  1326.  
  1327. tee "$pkgdir"/usr/share/applications/ventoy.desktop > /dev/null << _EOF_
  1328. [Desktop Entry]
  1329. Type=Application
  1330. Icon=ventoy
  1331. Name=Ventoy
  1332. Exec=ventoygui --xdg
  1333. Terminal=false
  1334. Hidden=false
  1335. Categories=Utility
  1336. Comment=Ventoy2Disk GUI
  1337. _EOF_
  1338.  
  1339. chmod -v 755 "$pkgdir"/usr/bin/*
  1340. cp -av Ventoy-$pkgver/LinuxGUI/WebUI/static/img/VentoyLogo.png "$pkgdir"/usr/share/pixmaps/ventoy.png
  1341. }
  1342.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement