From 4524cd32809610ef3ee1fa002fe48b4dfeb9b4c7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Georges=20Dup=C3=A9ron?= <georges.duperon@gmail.com>
Date: Sat, 22 Sep 2018 00:40:07 +0200
Subject: [PATCH] Circumvent the fact that faketime does not work on system
 binaries in macos

---
 .gitignore |  3 +++
 Makefile   | 19 +++++++++++++------
 2 files changed, 16 insertions(+), 6 deletions(-)

diff --git a/.gitignore b/.gitignore
index 4eb63e1..d129e9f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -118,3 +118,6 @@
 /deploy-screenshots/virtualbox-anim.gif
 /deploy-screenshots/virtualbox.png
 /os.bat
+/utils/mcopy
+/utils/mformat
+/utils/mkisofs
diff --git a/Makefile b/Makefile
index 54050f7..6d680e4 100644
--- a/Makefile
+++ b/Makefile
@@ -108,7 +108,8 @@ built_files = ${os_filename} \
               ${tests_noemu:test/%=${bld}/test_pass/noemu_%} \
               ${tests_requiring_sudo:test/%=${bld}/test_pass/sudo_%} \
               ${tests_emu:test/%=${screenshots}/%.png} \
-              ${tests_emu:test/%=${screenshots}/%-anim.gif}
+              ${tests_emu:test/%=${screenshots}/%-anim.gif} \
+              utils/mformat utils/mcopy utils/mkisofs
 
 # Temporary copies used to adjust timestamps for reproducible builds.
 # These are normally created and deleted within a single target, but
@@ -211,12 +212,17 @@ ${more_built_directories}: Makefile
 ${bld}/os.32k: example-os/os.asm ${bld}/check_makefile
 	nasm -w+macro-params -w+macro-selfref -w+orphan-labels -w+gnu-elf-extensions -o $@ $<
 
+# Circumvent the fact that faketime does not work on system binaries in macos
+./utils/mkisofs ./utils/mformat ./utils/mcopy: Makefile	# TODO: depend on the mkisofs binary
+	cp $$(which $$(basename $@)) $@
+	chmod u+x $@
+
 cp_T_option = $$(if test "$$(uname -s)" = Darwin; then echo ''; else echo '-T'; fi)
-${bld}/os.iso: ${bld}/iso_files/os.zip ${bld}/iso_files/boot/iso_boot.sys ${bld}/check_makefile
+${bld}/os.iso: ${bld}/iso_files/os.zip ${bld}/iso_files/boot/iso_boot.sys ./utils/mkisofs ${bld}/check_makefile
 	! test -d ${bld}/iso_files.tmp
 	cp -a ${cp_T_option} -- ${bld}/iso_files ${bld}/iso_files.tmp
 	find ${bld}/iso_files.tmp -depth -exec touch -t ${commit_timestamp} '{}' ';'
-	(cd ./${bld}/iso_files.tmp/ && faketime -f ${commit_faketime} mkisofs \
+	UTILS="$$PWD/utils" (cd ./${bld}/iso_files.tmp/ && faketime -f ${commit_faketime} $$UTILS/mkisofs \
 	 --input-charset utf-8 \
 	 -rock \
 	 -joliet \
@@ -292,14 +298,15 @@ ${eval ${call offset,bytes_gpt_mirror_start, $${bytes_gpt_mirror_end} - $${bytes
 ${eval ${call offset,bytes_zip_end,          $${bytes_os_size},,                                         }}
 
 os_fat12_partition = "$@@@${bytes_fat12_start}"
-${bld}/os.fat12: ${bld}/os.zip ${dep_bytes_fat12_size} ${dep_bytes_fat12_start} ${dep_sectors_os_size} ${bld}/check_makefile
+${bld}/os.fat12: ${bld}/os.zip ${dep_bytes_fat12_size} ${dep_bytes_fat12_start} ${dep_sectors_os_size} \
+                 ./utils/mformat ./utils/mcopy ${bld}/check_makefile
 	set -x; dd if=/dev/zero bs=${sector_size} count=${sectors_os_size} of=$@
-	faketime -f ${commit_faketime} mformat -v "Example OS" \
+	faketime -f ${commit_faketime} ./utils/mformat -v "Example OS" \
 	 -T ${sectors_fat12_size} \
 	 -h ${os_floppy_chs_h} \
 	 -s ${os_floppy_chs_s} \
 	 -i ${os_fat12_partition}
-	faketime -f ${commit_faketime} mcopy -i ${os_fat12_partition} $< "::os.zip"
+	faketime -f ${commit_faketime} ./utils/mcopy -i ${os_fat12_partition} $< "::os.zip"
 
 ${bld}/iso_files/os.zip: ${bld}/os.zip ${bld}/check_makefile
 # TODO: make it so that the various file formats are mutual quines: