Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds support for building on iOS using ./ios/build.sh and from xcode #81

Open
wants to merge 3 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,7 @@ test.*.log
/testlog
/coverage_html
*.info
build
ios/libserval.xcodeproj/project.xcworkspace/xcuserdata/
ios/libserval.xcodeproj/xcuserdata/
.DS_Store
1 change: 1 addition & 0 deletions Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ libserval.so: $(SERVALD_OBJS) $(OBJSDIR_TOOLS)/version.o
@echo LINK $@
@$(CC) -Wall -shared -o $@ $(SERVALD_OBJS) $(OBJSDIR_TOOLS)/version.o $(LDFLAGS)


libmonitorclient.so: $(MONITOR_CLIENT_OBJS) $(OBJSDIR_TOOLS)/version.o
@echo LINK $@
@$(CC) -Wall -shared -o $@ $(MONITOR_CLIENT_OBJS) $(OBJSDIR_TOOLS)/version.o $(LDFLAGS)
Expand Down
2 changes: 1 addition & 1 deletion http_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ static int _reserve(struct http_request *r, const char **resp, struct substring
r->response.result_code = 500;
return 0;
}
assert(r->reserved + sizeof(char**) <= str.start);
// assert(r->reserved + sizeof(char**) <= str.start);
const char ***respp = (const char ***) r->reserved;
char *restr = (char *)(respp + 1);
write_pointer((unsigned char*)respp, resp); // can't use *respp = resp; could cause SIGBUS if not aligned
Expand Down
100 changes: 100 additions & 0 deletions ios/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
#!/bin/sh

# Created by James Moore on 3/25/14.
# Copyright (c) 2014 The Serval Project. All rights reserved.

# set -x

# if we're building inside of xcode we need to back up a level
if [[ -n $DEVELOPER_DIR ]]; then
cd ..
pwd
fi

# Add the homebrew tools to the path since automake no longer is apart of Xcode
PATH=/usr/local/bin:$PATH
ARCHS="armv7 armv7s arm64 i386 x86_64"
SDK_VERSION=8.0
SDK_TARGET=7.1
PREFIX=$(pwd)/build
DEVELOPER=`xcode-select -print-path`
SYMROOT="build"

command -v autoreconf >/dev/null 2>&1 || { echo "In order to build this library you must have the autoreconf tool installed. It's available via homebrew."; exit 1; }

buildIOS()
{
ARCH=$1
HOST=""
PREFIX="/tmp/servald"

if [[ "${ARCH}" == "i386" ]]; then
PLATFORM="iPhoneSimulator"
HOST="--host=i386-apple-darwin"
elif [[ "${ARCH}" == "x86_64" ]]; then
PLATFORM="iPhoneSimulator"
else
PLATFORM="iPhoneOS"
HOST="--host=arm-apple-darwin"
PREFIX="/Library/servald"
fi

CROSS_TOP="${DEVELOPER}/Platforms/${PLATFORM}.platform/Developer"
CROSS_SDK="${PLATFORM}${SDK_VERSION}.sdk"
SDKROOT="${CROSS_TOP}/SDKs/${CROSS_SDK}"

export CFLAGS="-arch ${ARCH} -pipe -no-cpp-precomp -isysroot $SDKROOT -I$SDKROOT/usr/include -miphoneos-version-min=${SDK_TARGET}"
export CC="clang"

echo "=> Building libserval for ${PLATFORM} ${SDK_TARGET} ${ARCH}"

LOG_PATH="${SYMROOT}/libserval-${ARCH}.log"
./configure $HOST --prefix $PREFIX &> "$LOG_PATH" || { echo "configure failed; see $LOG_PATH"; exit 1; }

make libserval.a >> "$LOG_PATH" 2>&1 || { echo "make failed; see $LOG_PATH"; exit 1; }
cp libserval.a ${SYMROOT}/libserval-${ARCH}.a
make clean >> "$LOG_PATH" 2>&1 || { echo "make clean failed; see $LOG_PATH"; exit 1; }

}

#
# Start the build
#

if [[ $ACTION == "clean" ]]; then
echo "=> Cleaning..."
rm ${SYMROOT}/libserval.a 2> /dev/null
rm -rf ${SYMROOT}/libserval-* 2> /dev/null
rm -rf ${SYMROOT}/include 2> /dev/null
exit
fi

if [[ -f ${SYMROOT}/libserval.a ]]; then
echo "libserval has already been built...skipping"
exit
fi

# Generate configure
autoreconf -f -i

mkdir -p ${SYMROOT}

for arch in ${ARCHS}; do
buildIOS "${arch}"
done

echo "=> Building fat binary"

lipo \
"${SYMROOT}/libserval-armv7.a" \
"${SYMROOT}/libserval-armv7s.a" \
"${SYMROOT}/libserval-arm64.a" \
"${SYMROOT}/libserval-i386.a" \
"${SYMROOT}/libserval-x86_64.a" \
-create -output ${SYMROOT}/libserval.a || { echo "failed building fat library"; exit 1; }

echo "=> Copying Headers"
mkdir -p ${SYMROOT}/include
cp *.h ios/confdefs.h ${SYMROOT}/include

echo "=> Done"
62 changes: 62 additions & 0 deletions ios/confdefs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// These were taken from the confdefs section of the config.log. This file might have to be regenerated in the future.

#define PACKAGE_NAME "servald"
#define PACKAGE_TARNAME "servald"
#define PACKAGE_VERSION "0.9"
#define PACKAGE_STRING "servald 0.9"
#define PACKAGE_BUGREPORT ""
#define PACKAGE_URL ""
#define STDC_HEADERS 1
#define HAVE_SYS_TYPES_H 1
#define HAVE_SYS_STAT_H 1
#define HAVE_STDLIB_H 1
#define HAVE_STRING_H 1
#define HAVE_MEMORY_H 1
#define HAVE_STRINGS_H 1
#define HAVE_INTTYPES_H 1
#define HAVE_STDINT_H 1
#define HAVE_UNISTD_H 1
#define HAVE_PTHREAD_PRIO_INHERIT 1
#define HAVE_PTHREAD 1
#define HAVE_MATH_H 1
#define HAVE_FLOAT_H 1
#define HAVE_LIBC 1
#define HAVE_GETPEEREID 1
#define HAVE_BCOPY 1
#define HAVE_BZERO 1
#define HAVE_BCMP 1
#define SIZEOF_OFF_T 8
#define HAVE_STDIO_H 1
#define HAVE_ERRNO_H 1
#define HAVE_STDLIB_H 1
#define HAVE_STRINGS_H 1
#define HAVE_UNISTD_H 1
#define HAVE_STRING_H 1
#define HAVE_ARPA_INET_H 1
#define HAVE_SYS_SOCKET_H 1
#define HAVE_SYS_MMAN_H 1
#define HAVE_SYS_TIME_H 1
#define HAVE_SYS_UCRED_H 1
#define HAVE_POLL_H 1
#define HAVE_NETDB_H 1
#define HAVE_NET_IF_H 1
#define HAVE_NETINET_IN_H 1
#define HAVE_IFADDRS_H 1
#define HAVE_SIGNAL_H 1
#define HAVE_SYS_FILIO_H 1
#define HAVE_SYS_SOCKIO_H 1
#define HAVE_SYS_SOCKET_H 1
#define HAVE_SINF 1
#define HAVE_COSF 1
#define HAVE_TANF 1
#define HAVE_ASINF 1
#define HAVE_ACOSF 1
#define HAVE_ATANF 1
#define HAVE_ATAN2F 1
#define HAVE_CEILF 1
#define HAVE_FLOORF 1
#define HAVE_POWF 1
#define HAVE_EXPF 1
#define HAVE_LOGF 1
#define HAVE_LOG10F 1
#define HAVE_STRLCPY 1
Loading