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