a1e75b7
#!/bin/bash
a1e75b7
# Generates the 'source tarball' for JDK projects.
a1e75b7
#
a1e75b7
# Example:
a1e75b7
# When used from local repo set REPO_ROOT pointing to file:// with your repo
2fc9989
# If your local repo follows upstream forests conventions, it may be enough to set OPENJDK_URL
a773423
# If you want to use a local copy of patch PR3782, set the path to it in the PR3782 variable
a1e75b7
#
a1e75b7
# In any case you have to set PROJECT_NAME REPO_NAME and VERSION. eg:
a1e75b7
# PROJECT_NAME=jdk
a1e75b7
# REPO_NAME=jdk
a1e75b7
# VERSION=tip
a1e75b7
# or to eg prepare systemtap:
a1e75b7
# icedtea7's jstack and other tapsets
a1e75b7
# VERSION=6327cf1cea9e
a1e75b7
# REPO_NAME=icedtea7-2.6
a1e75b7
# PROJECT_NAME=release
a1e75b7
# OPENJDK_URL=http://icedtea.classpath.org/hg/
a1e75b7
# TO_COMPRESS="*/tapset"
a1e75b7
# 
a1e75b7
# They are used to create correct name and are used in construction of sources url (unless REPO_ROOT is set)
a1e75b7
a1e75b7
# This script creates a single source tarball out of the repository
a1e75b7
# based on the given tag and removes code not allowed in fedora/rhel. For
a1e75b7
# consistency, the source tarball will always contain 'openjdk' as the top
a1e75b7
# level folder, name is created, based on parameter
a1e75b7
#
a1e75b7
a773423
if [ ! "x$PR3782" = "x" ] ; then
a773423
  if [ ! -f "$PR3782" ] ; then
a773423
    echo "You have specified PR3782 as $PR3782 but it does not exist. Exiting"
a1e75b7
    exit 1
a1e75b7
  fi
a1e75b7
fi
a1e75b7
a1e75b7
set -e
a1e75b7
a1e75b7
OPENJDK_URL_DEFAULT=http://hg.openjdk.java.net
a1e75b7
COMPRESSION_DEFAULT=xz
a1e75b7
a1e75b7
if [ "x$1" = "xhelp" ] ; then
a1e75b7
    echo -e "Behaviour may be specified by setting the following variables:\n"
a1e75b7
    echo "VERSION - the version of the specified OpenJDK project"
a1e75b7
    echo "PROJECT_NAME -- the name of the OpenJDK project being archived (optional; only needed by defaults)"
a1e75b7
    echo "REPO_NAME - the name of the OpenJDK repository (optional; only needed by defaults)"
a1e75b7
    echo "OPENJDK_URL - the URL to retrieve code from (optional; defaults to ${OPENJDK_URL_DEFAULT})"
a1e75b7
    echo "COMPRESSION - the compression type to use (optional; defaults to ${COMPRESSION_DEFAULT})"
a1e75b7
    echo "FILE_NAME_ROOT - name of the archive, minus extensions (optional; defaults to PROJECT_NAME-REPO_NAME-VERSION)"
a1e75b7
    echo "TO_COMPRESS - what part of clone to pack (default is openjdk)"
a773423
    echo "PR3782 - the path to the PR3782 patch to apply (optional; downloaded if unavailable)"
a1e75b7
    exit 1;
a1e75b7
fi
a1e75b7
a1e75b7
a1e75b7
if [ "x$VERSION" = "x" ] ; then
a1e75b7
    echo "No VERSION specified"
a1e75b7
    exit -2
a1e75b7
fi
a1e75b7
echo "Version: ${VERSION}"
a1e75b7
    
a1e75b7
# REPO_NAME is only needed when we default on REPO_ROOT and FILE_NAME_ROOT
a1e75b7
if [ "x$FILE_NAME_ROOT" = "x" -o "x$REPO_ROOT" = "x" ] ; then
a1e75b7
  if [ "x$PROJECT_NAME" = "x" ] ; then
a1e75b7
    echo "No PROJECT_NAME specified"
a1e75b7
    exit -1
a1e75b7
  fi
a1e75b7
  echo "Project name: ${PROJECT_NAME}"
a1e75b7
  if [ "x$REPO_NAME" = "x" ] ; then
a1e75b7
    echo "No REPO_NAME specified"
a1e75b7
    exit -3
a1e75b7
  fi
a1e75b7
  echo "Repository name: ${REPO_NAME}"
a1e75b7
fi
a1e75b7
a1e75b7
if [ "x$OPENJDK_URL" = "x" ] ; then
a1e75b7
    OPENJDK_URL=${OPENJDK_URL_DEFAULT}
a1e75b7
    echo "No OpenJDK URL specified; defaulting to ${OPENJDK_URL}"
a1e75b7
else
a1e75b7
    echo "OpenJDK URL: ${OPENJDK_URL}"
a1e75b7
fi
a1e75b7
a1e75b7
if [ "x$COMPRESSION" = "x" ] ; then
a1e75b7
    # rhel 5 needs tar.gz
a1e75b7
    COMPRESSION=${COMPRESSION_DEFAULT}
a1e75b7
fi
a1e75b7
echo "Creating a tar.${COMPRESSION} archive"
a1e75b7
a1e75b7
if [ "x$FILE_NAME_ROOT" = "x" ] ; then
a1e75b7
    FILE_NAME_ROOT=${PROJECT_NAME}-${REPO_NAME}-${VERSION}
a1e75b7
    echo "No file name root specified; default to ${FILE_NAME_ROOT}"
a1e75b7
fi
a1e75b7
if [ "x$REPO_ROOT" = "x" ] ; then
a1e75b7
    REPO_ROOT="${OPENJDK_URL}/${PROJECT_NAME}/${REPO_NAME}"
a1e75b7
    echo "No repository root specified; default to ${REPO_ROOT}"
a1e75b7
fi;
a1e75b7
a1e75b7
if [ "x$TO_COMPRESS" = "x" ] ; then
a1e75b7
    TO_COMPRESS="openjdk"
a1e75b7
    echo "No to be compressed targets specified, ; default to ${TO_COMPRESS}"
a1e75b7
fi;
a1e75b7
a1e75b7
if [ -d ${FILE_NAME_ROOT} ] ; then
a1e75b7
  echo "exists exists exists exists exists exists exists "
a1e75b7
  echo "reusing reusing reusing reusing reusing reusing "
a1e75b7
  echo ${FILE_NAME_ROOT}
a1e75b7
else
a1e75b7
  mkdir "${FILE_NAME_ROOT}"
a1e75b7
  pushd "${FILE_NAME_ROOT}"
a1e75b7
    echo "Cloning ${VERSION} root repository from ${REPO_ROOT}"
a1e75b7
    hg clone ${REPO_ROOT} openjdk -r ${VERSION}
a1e75b7
  popd
a1e75b7
fi
a1e75b7
pushd "${FILE_NAME_ROOT}"
a1e75b7
    if [ -d openjdk/src ]; then 
a1e75b7
        pushd openjdk
a1e75b7
            echo "Removing EC source code we don't build"
a1e75b7
            CRYPTO_PATH=src/jdk.crypto.ec/share/native/libsunec/impl
2fc9989
	    rm -vf ${CRYPTO_PATH}/ec2.h
2fc9989
	    rm -vf ${CRYPTO_PATH}/ec2_163.c
2fc9989
	    rm -vf ${CRYPTO_PATH}/ec2_193.c
2fc9989
	    rm -vf ${CRYPTO_PATH}/ec2_233.c
2fc9989
	    rm -vf ${CRYPTO_PATH}/ec2_aff.c
2fc9989
	    rm -vf ${CRYPTO_PATH}/ec2_mont.c
2fc9989
	    rm -vf ${CRYPTO_PATH}/ecp_192.c
2fc9989
	    rm -vf ${CRYPTO_PATH}/ecp_224.c
2fc9989
a1e75b7
            echo "Syncing EC list with NSS"
a773423
            if [ "x$PR3782" = "x" ] ; then
2fc9989
                # originally for 8:
a773423
                # get pr3782.patch (from http://icedtea.classpath.org/hg/icedtea14) from most correct tag
a773423
                # Do not push it or publish it (see http://icedtea.classpath.org/bugzilla/show_bug.cgi?id=3782)
a773423
		echo "PR3782 not found. Downloading..."
a773423
		wget https://icedtea.classpath.org/hg/icedtea14/raw-file/tip/patches/pr3782.patch
a773423
	        echo "Applying ${PWD}/pr3782.patch"
a773423
		patch -Np1 < pr3782.patch
a773423
		rm pr3782.patch
2fc9989
	    else
a773423
		echo "Applying ${PR3782}"
a773423
		patch -Np1 < $PR3782
a1e75b7
            fi;
a1e75b7
            find . -name '*.orig' -exec rm -vf '{}' ';'
a1e75b7
        popd
a1e75b7
    fi
a1e75b7
a1e75b7
    echo "Compressing remaining forest"
a1e75b7
    if [ "X$COMPRESSION" = "Xxz" ] ; then
a1e75b7
        SWITCH=cJf
a1e75b7
    else
a1e75b7
        SWITCH=czf
a1e75b7
    fi
a1e75b7
    tar --exclude-vcs -$SWITCH ${FILE_NAME_ROOT}.tar.${COMPRESSION} $TO_COMPRESS
a1e75b7
    mv ${FILE_NAME_ROOT}.tar.${COMPRESSION}  ..
a1e75b7
popd
a1e75b7
echo "Done. You may want to remove the uncompressed version - $FILE_NAME_ROOT."
a1e75b7
a1e75b7