-
Notifications
You must be signed in to change notification settings - Fork 47
/
fatify
executable file
·61 lines (59 loc) · 2.29 KB
/
fatify
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#! /bin/sh
#
# This script is a part of Cgreen and creates fat versions of
# cgreen-runner and libcgreen.dylib which is necessary if you are
# using e.g. Homebrew/MacPorts gcc which don't have suppport for fat
# binaries built in.
#
# NOTE: This does not work completely automatic for x86_64/M1 since
# Homebrew GCC can only compile for the current architecture.
#
# Since automatically ensuring that both architectures are built is
# currently impossible from a single environment, you have to run this
# script once on each architecture. The script will save the built
# binaries under descriptive names and if it discovers that binaries
# for the other architecture already exists it uses lipo to merge them
# into fat binaries.
#
# At this point there is no way to run this as part of the CMake build
# and install, and since the install target of CMake always rebuilds
# you can't install them except with manual copying.
#
# /thoni56
#
function buildfor() {
rm -rf build
make
cp build/tools/cgreen-runner cgreen-runner.$1
cp build/src/libcgreen.dylib libcgreen.$1.dylib
}
arch=`arch`
if [ $arch == "arm64" ] ; then
buildfor arm64
if [ ! -f libcgreen.x86_64.dylib ] ; then
echo "You need to run this aldo in an x86_64 environment to create fat binaries."
exit
fi
else
buildfor x86_64
if [ ! -f libcgreen.arm64.dylib ] ; then
echo "You need to run this in an arm64 environment to create fat binaries."
exit
fi
fi
lipo -create -o cgreen-runner -arch arm64 cgreen-runner.arm64 -arch x86_64 cgreen-runner.x86_64
lipo -create -o libcgreen.dylib -arch arm64 libcgreen.arm64.dylib -arch x86_64 libcgreen.x86_64.dylib
if [ -z "$1" ] ; then
echo "Fat binaries of cgreen-runner and libcgreen.dylib built:"
file cgreen-runner libcgreen.dylib
echo "Install with:"
echo " sudo cp cgreen-runner <installpath>/bin/cgreen-runner"
echo " sudo cp libcgreen.dylib <installpath>/lib/libcgreen.dylib"
echo
echo "If <installpath> is the same for bin and lib, such as '/usr/local',"
echo "you can give that as an argument and the script will do that for you."
else
echo "Installing fat 'cgreen-runner' in $1/bin and 'libcgreen.dylib' in $1/lib..."
sudo cp cgreen-runner $1/bin/cgreen-runner
sudo cp libcgreen.dylib $1/lib/libcgreen.dylib
fi