#!/bin/sh
rm -rf gr
tar xf ../gr-latest-Darwin-x86_64.tar.gz && mv gr x86_64
tar xf ../gr-latest-Darwin-aarch64.tar.gz && mv gr arm64
rsync -a x86_64/ gr/
for lib in arm64/lib/*.dylib arm64/lib/*.so
do
        name=`basename ${lib}`
        lipo -create -output gr/lib/${name} x86_64/lib/${name} arm64/lib/${name}
        echo ${name}: `lipo -archs gr/lib/${name}`
done
for app in GKSTerm gksqt grplot
do
        dir="Applications/${app}.app/Contents/MacOS"
        lipo -create -output gr/${dir}/${app} x86_64/${dir}/${app} arm64/${dir}/${app}
        echo ${app}: `lipo -archs gr/${dir}/${app}`
done
tar cfz ../gr-latest-Darwin-universal.tar.gz gr
rm -rf gr x86_64 arm64
