#!/bin/zsh


export COPYFILE_DISABLE=true

if [[ -f universal-darwin.tar.xz ]]; then
	rm  universal-darwin.tar.xz
fi

if [[ -d universal-darwin ]]; then
	rm -R universal-darwin
fi

if [[ -f RawCode/universal-darwin.tar.xz ]]; then
	rm  RawCode/universal-darwin.tar.xz
fi

if [[ -d RawCode/universal-darwin ]]; then
	rm -R RawCode/universal-darwin
fi

mkdir universal-darwin

cd RawCode/x86_64-apple-darwin18.7.0
files=`ls`
for f in $files; do
	if  ! [[ -L $f ]] &&  [[ "$(file $f)" = "$f: Mach-O 64-bit executable x86_64" ]] && [[ -e ../aarch64-apple-darwin20.6.0/$f ]]; then		
	lipo $f ../aarch64-apple-darwin20.6.0/$f -create -output ../../universal-darwin/$f
	fi
done

for f in $files; do
	if  ! [[ -L $f ]] && [[ "$(file $f)" = "$f: Mach-O 64-bit executable x86_64" ]]  && ! [[ -e ../aarch64-apple-darwin20.6.0/$f ]]; then
	# echo $f$		
	cp $f ../../universal-darwin/$f
	fi
done

for f in $files; do
	if  ! [[ -L $f ]] && ! [[ "$(file $f)" = "$f: Mach-O 64-bit executable x86_64" ]]  ; then
	# echo $f$		
	cp $f ../../universal-darwin/$f
	fi
done

for f in $files; do
	if  [[ -L $f ]] ; then
	# echo $f$		
	cp -R $f ../../universal-darwin/$f
	fi
done

cd ../
lipo asy-Intel asy-Arm -create -output ../universal-darwin/asy
# cp asy ../../universal-darwin/asy
cd ../universal-darwin
ln -s ../../texmf-dist/asymptote/GUI/xasy.py xasy
mv xindy.mem xindy-x86_64.mem
cp ../RawCode/aarch64-apple-darwin20.6.0/xindy.mem xindy-arm64.mem






cd ..



