|
| 1 | +#!/bin/bash |
| 2 | +# |
| 3 | +# Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved. |
| 4 | +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 5 | +# |
| 6 | +# This code is free software; you can redistribute it and/or modify it |
| 7 | +# under the terms of the GNU General Public License version 2 only, as |
| 8 | +# published by the Free Software Foundation. Oracle designates this |
| 9 | +# particular file as subject to the "Classpath" exception as provided |
| 10 | +# by Oracle in the LICENSE file that accompanied this code. |
| 11 | +# |
| 12 | +# This code is distributed in the hope that it will be useful, but WITHOUT |
| 13 | +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 14 | +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 15 | +# version 2 for more details (a copy is included in the LICENSE file that |
| 16 | +# accompanied this code). |
| 17 | +# |
| 18 | +# You should have received a copy of the GNU General Public License version |
| 19 | +# 2 along with this work; if not, write to the Free Software Foundation, |
| 20 | +# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 21 | +# |
| 22 | +# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
| 23 | +# or visit www.oracle.com if you need additional information or have any |
| 24 | +# questions. |
| 25 | +# |
| 26 | + |
| 27 | +# This script generates a libffi bundle. On linux by building it from source |
| 28 | +# using a devkit, which should match the devkit used to build the JDK. |
| 29 | +# |
| 30 | +# Set MAKE_ARGS to add parameters to make. Ex: |
| 31 | +# |
| 32 | +# $ MAKE_ARGS=-j32 bash createLibffiBundle.sh |
| 33 | +# |
| 34 | +# The script tries to behave well on multiple invocations, only performing steps |
| 35 | +# not already done. To redo a step, manually delete the target files from that |
| 36 | +# step. |
| 37 | +# |
| 38 | +# Note that the libtool and texinfo packages are needed to build libffi |
| 39 | +# $ sudo apt install libtool texinfo |
| 40 | + |
| 41 | +LIBFFI_VERSION=3.4.2 |
| 42 | + |
| 43 | +BUNDLE_NAME=libffi-$LIBFFI_VERSION.tar.gz |
| 44 | + |
| 45 | +SCRIPT_FILE="$(basename $0)" |
| 46 | +SCRIPT_DIR="$(cd "$(dirname $0)" > /dev/null && pwd)" |
| 47 | +OUTPUT_DIR="${SCRIPT_DIR}/../../build/libffi" |
| 48 | +SRC_DIR="$OUTPUT_DIR/src" |
| 49 | +DOWNLOAD_DIR="$OUTPUT_DIR/download" |
| 50 | +INSTALL_DIR="$OUTPUT_DIR/install" |
| 51 | +IMAGE_DIR="$OUTPUT_DIR/image" |
| 52 | + |
| 53 | +USAGE="$0 <devkit dir>" |
| 54 | + |
| 55 | +if [ "$1" = "" ]; then |
| 56 | + echo $USAGE |
| 57 | + exit 1 |
| 58 | +fi |
| 59 | +DEVKIT_DIR="$1" |
| 60 | + |
| 61 | +# Download source distros |
| 62 | +mkdir -p $DOWNLOAD_DIR |
| 63 | +cd $DOWNLOAD_DIR |
| 64 | +SOURCE_TAR=v$LIBFFI_VERSION.tar.gz |
| 65 | +if [ ! -f $SOURCE_TAR ]; then |
| 66 | + wget https://github.com/libffi/libffi/archive/refs/tags/v$LIBFFI_VERSION.tar.gz |
| 67 | +fi |
| 68 | + |
| 69 | +# Unpack src |
| 70 | +mkdir -p $SRC_DIR |
| 71 | +cd $SRC_DIR |
| 72 | +LIBFFI_DIRNAME=libffi-$LIBFFI_VERSION |
| 73 | +LIBFFI_DIR=$SRC_DIR/$LIBFFI_DIRNAME |
| 74 | +if [ ! -d $LIBFFI_DIRNAME ]; then |
| 75 | + echo "Unpacking $SOURCE_TAR" |
| 76 | + tar xf $DOWNLOAD_DIR/$SOURCE_TAR |
| 77 | +fi |
| 78 | + |
| 79 | +# Build |
| 80 | +cd $LIBFFI_DIR |
| 81 | +if [ ! -e $LIBFFI_DIR/configure ]; then |
| 82 | + bash ./autogen.sh |
| 83 | +fi |
| 84 | +# For Linux/x86, add --build=i686-pc-linux-gnu CFLAGS=-m32 CXXFLAGS=-m32 LDFLAGS=-m32 |
| 85 | +bash ./configure --prefix=$INSTALL_DIR CC=$DEVKIT_DIR/bin/gcc CXX=$DEVKIT_DIR/bin/g++ |
| 86 | + |
| 87 | +# Run with nice to keep system usable during build. |
| 88 | +nice make $MAKE_ARGS install |
| 89 | + |
| 90 | +mkdir -p $IMAGE_DIR |
| 91 | +# Extract what we need into an image |
| 92 | +if [ ! -e $IMAGE_DIR/lib/libffi.so ]; then |
| 93 | + echo "Copying libffi.so* to image" |
| 94 | + mkdir -p $IMAGE_DIR/lib |
| 95 | + # For Linux/x86 it's under /lib/ instead of /lib64/ |
| 96 | + cp -a $INSTALL_DIR/lib64/libffi.so* $IMAGE_DIR/lib/ |
| 97 | +fi |
| 98 | +if [ ! -e $IMAGE_DIR/include/ ]; then |
| 99 | + echo "Copying include to image" |
| 100 | + mkdir -p $IMAGE_DIR/include |
| 101 | + cp -a $INSTALL_DIR/include/. $IMAGE_DIR/include/ |
| 102 | +fi |
| 103 | +if [ ! -e $IMAGE_DIR/$SCRIPT_FILE ]; then |
| 104 | + echo "Copying this script to image" |
| 105 | + cp -a $SCRIPT_DIR/$SCRIPT_FILE $IMAGE_DIR/ |
| 106 | +fi |
| 107 | + |
| 108 | +# Create bundle |
| 109 | +if [ ! -e $OUTPUT_DIR/$BUNDLE_NAME ]; then |
| 110 | + echo "Creating $OUTPUT_DIR/$BUNDLE_NAME" |
| 111 | + cd $IMAGE_DIR |
| 112 | + tar zcf $OUTPUT_DIR/$BUNDLE_NAME * |
| 113 | +fi |
0 commit comments