Skip to content

Commit

Permalink
Add osx build script
Browse files Browse the repository at this point in the history
  • Loading branch information
kayahr committed Apr 27, 2015
1 parent 0024ba9 commit e7ea266
Showing 1 changed file with 67 additions and 0 deletions.
67 changes: 67 additions & 0 deletions build/osx.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# ============================================================================
# Build script for Mac OS X.
#
# The script automatically compiles the multi-binary for x86 and x86_64 and
# creates the corresponding JAR file in the target folder.
#
# Requirements: cmake, make, curl, jar
# ============================================================================

if [ $# -ne 1 ]
then
echo "Syntax: $0 <ARCH>"
exit 1
fi

# Fail on all errors
set -e

# Software versions
LIBUSB_VERSION=1.0.19

# Determine directories
cd "$(dirname $0)/.."
PROJECT_DIR="$(pwd)"
TARGET_DIR="$PROJECT_DIR/target"
ROOT_DIR="$TARGET_DIR/root"

# Clean up target directory
rm -rf "$TARGET_DIR"

# Determine OS and architecture
OS=osx
ARCH="$1"
case "$ARCH" in
x86)
OSX_ARCH=i386
;;
*)
OSX_ARCH="$ARCH"
esac
echo "Building for platform $OS-$ARCH"

# Download and build libusb
mkdir -p "$TARGET_DIR/libusb"
cd "$TARGET_DIR/libusb"
curl -L "http://downloads.sf.net/project/libusb/libusb-1.0/libusb-$LIBUSB_VERSION/libusb-$LIBUSB_VERSION.tar.bz2" \
| tar xvj --strip-components=1
CFLAGS="-I$ROOT_DIR/include -arch $OSX_ARCH" \
LDFLAGS="-L$ROOT_DIR/lib" \
./configure --disable-shared --enable-static --with-pic --prefix="$ROOT_DIR"
make install-strip

# Build libusb4java
mkdir -p "$TARGET_DIR/libusb4java"
cd "$TARGET_DIR/libusb4java"
PKG_CONFIG_PATH="$ROOT_DIR/lib/pkgconfig" cmake "$PROJECT_DIR" \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX="" \
-DCMAKE_OSX_ARCHITECTURES=$OSX_ARCH \
-DLibUsb_USE_STATIC_LIBS=true
make install/strip DESTDIR="$ROOT_DIR"

# Create the JAR file
OS=osx
mkdir -p "$TARGET_DIR/classes/org/usb4java/$OS-$ARCH"
cp "$ROOT_DIR/lib/libusb4java.dylib" "$TARGET_DIR/classes/org/usb4java/$OS-$ARCH"
jar cf "$TARGET_DIR/libusb4java-$OS-$ARCH.jar" -C "$TARGET_DIR/classes" org

0 comments on commit e7ea266

Please sign in to comment.