Repository navigation
Expand file tree
/
Copy pathlibevent.sh
More file actions
executable file
·82 lines (69 loc) · 3.17 KB
/
Copy pathlibevent.sh
File metadata and controls
executable file
·82 lines (69 loc) · 3.17 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/bin/bash
# We need gettext to build libevent
# This extends the path to look in some common locations (for example, if installed via Homebrew)
PATH=$PATH:/usr/local/bin:/usr/local/opt/gettext/bin
# Generate the configure script (necessary for version control distributions)
if [[ ! -f ./configure ]]; then
./autogen.sh
fi
REBUILD=0
# If the built binaries include a different set of architectures, then rebuild the target
if [[ ${ACTION:-build} = "build" ]]; then
for LIBRARY in "${BUILT_PRODUCTS_DIR}/libevent"*.a
do
for ARCH in $ARCHS
do
if [[ $(lipo -info "${LIBRARY}" 2>&1) != *"${ARCH}"* ]]; then
REBUILD=1;
fi
done
done
fi
# If rebuilding or cleaning then delete the built products
if [[ $ACTION = "clean" ]] || [[ $REBUILD = 1 ]]; then
rm "${BUILT_PRODUCTS_DIR}/libevent"*.a 2>/dev/null
fi
if [[ $REBUILD = 0 ]]; then
exit;
fi
if [[ "${ENABLE_BITCODE}" = "YES" ]]; then
BITCODE_FLAGS="-fembed-bitcode"
fi
# If there is a space in SRCROOT, make a symlink without a space and use that
if [[ "${SRCROOT}" =~ \ ]]; then
SYM_DIR="$(mktemp -d)/Tor"
ln -s "${SRCROOT}" "${SYM_DIR}"
SRCROOT="${SYM_DIR}"
fi
# We need XPC to build libevent, so copy it from the OSX SDK into a temporary directory
XPC_INCLUDE_DIR="${CONFIGURATION_TEMP_DIR}/libevent-xpc"
mkdir -p "${XPC_INCLUDE_DIR}/xpc"
cp -f "$(xcrun --sdk macosx --show-sdk-path)/usr/include/xpc/base.h" "${XPC_INCLUDE_DIR}/xpc"
# Build each architecture one by one using clang
for ARCH in $ARCHS
do
HOST=$(xcrun --sdk ${PLATFORM_NAME} clang -arch ${ARCH} -v 2>&1 | grep Target | sed -e 's/Target: //')
PREFIX="${CONFIGURATION_TEMP_DIR}/libevent-${ARCH}"
mkdir -p $PREFIX
./configure --disable-shared --enable-static --disable-debug-mode --host=${HOST} --prefix=${PREFIX} CFLAGS="-I\"${SRCROOT}/Tor/openssl/include\" ${BITCODE_FLAGS} -I${XPC_INCLUDE_DIR} -arch ${ARCH}" CPPFLAGS="-I\"${SRCROOT}/Tor/openssl/include\" ${BITCODE_FLAGS} -I${XPC_INCLUDE_DIR} -arch ${ARCH}" LDFLAGS="${OTHER_LDFLAGS} ${BITCODE_FLAGS}"
make -j$(sysctl hw.ncpu | awk '{print $2}')
make install
mv include/event2/event-config.h "${PREFIX}/event-config.h"
make distclean
mv "${PREFIX}/event-config.h" include/event2/event-config.h
done
mkdir -p "${BUILT_PRODUCTS_DIR}"
# Copy the build products from the temporary directory to the built products directory
for ARCH in $ARCHS
do
for LIBRARY in "${CONFIGURATION_TEMP_DIR}/libevent-${ARCH}/lib/"*.a;
do
cp $LIBRARY "${BUILT_PRODUCTS_DIR}/$(basename ${LIBRARY} .a).${ARCH}.a"
done
done
# Combine the built products into a fat binary
xcrun --sdk $PLATFORM_NAME lipo -create "${BUILT_PRODUCTS_DIR}/libevent."*.a -output "${BUILT_PRODUCTS_DIR}/libevent.a"
xcrun --sdk $PLATFORM_NAME lipo -create "${BUILT_PRODUCTS_DIR}/libevent_core."*.a -output "${BUILT_PRODUCTS_DIR}/libevent_core.a"
xcrun --sdk $PLATFORM_NAME lipo -create "${BUILT_PRODUCTS_DIR}/libevent_pthreads."*.a -output "${BUILT_PRODUCTS_DIR}/libevent_pthreads.a"
xcrun --sdk $PLATFORM_NAME lipo -create "${BUILT_PRODUCTS_DIR}/libevent_extra."*.a -output "${BUILT_PRODUCTS_DIR}/libevent_extra.a"
rm "${BUILT_PRODUCTS_DIR}/libevent"*.*.a