#!/bin/sh -
#
# build script for 1.4
#
# If it's given a buildname it creates a subdirectory and places a build in it,
# otherwise it just creates the docs and class files.
#

JDK14PATH=/opt/j2sdk1.4.0   # JDK 1.4 location

WINDOWTITLE='Bouncy Castle Cryptography 1.19 API Specification'
HEADER='<b>Bouncy Castle Cryptography 1.19</b>'
DOCTITLE='Bouncy Castle 1.19 API Specification'

if test "$1" != ""
then
    echo "making lightweight release"

    mkdir lcrypto-jdk14-$1
    tar cf - index.html LICENSE.html CONTRIBUTORS.html releasenotes.html specifications.html src/org/bouncycastle/LICENSE.java src/org/bouncycastle/math src/org/bouncycastle/crypto src/org/bouncycastle/util src/org/bouncycastle/asn1 | (cd lcrypto-jdk14-$1; tar xf -)

    (
        cd lcrypto-jdk14-$1;

        mkdir classes; mkdir docs;

        PATH=$JDK14PATH/bin:$PATH
        export PATH

        echo "compiling"

        (cd src/org/bouncycastle; javac -d ../../../classes -classpath ../../../classes:../../../src *.java */*.java */*/*.java )

        javadoc -windowtitle "$WINDOWTITLE" -doctitle "$DOCTITLE" \
            -header "$HEADER" -group "Core Packages" "org.bouncycastle*" \
            -group "Example Packages" "example*" -classpath classes \
            -d docs -sourcepath src \
            org.bouncycastle.asn1 \
            org.bouncycastle.asn1.pkcs \
            org.bouncycastle.asn1.x509 \
            org.bouncycastle.asn1.x9 \
            org.bouncycastle.asn1.oiw \
            org.bouncycastle.asn1.sec \
            org.bouncycastle.asn1.util \
            org.bouncycastle.asn1.misc \
            org.bouncycastle.asn1.cms \
            org.bouncycastle.asn1.smime \
            org.bouncycastle.asn1.ocsp \
            org.bouncycastle.asn1.test \
            org.bouncycastle.math.ec \
            org.bouncycastle.crypto \
            org.bouncycastle.crypto.agreement \
            org.bouncycastle.crypto.digests \
            org.bouncycastle.crypto.encodings \
            org.bouncycastle.crypto.engines \
            org.bouncycastle.crypto.generators \
            org.bouncycastle.crypto.io \
            org.bouncycastle.crypto.macs \
            org.bouncycastle.crypto.modes \
            org.bouncycastle.crypto.paddings \
            org.bouncycastle.crypto.params \
            org.bouncycastle.crypto.signers \
            org.bouncycastle.crypto.test \
            org.bouncycastle.crypto.examples \
            org.bouncycastle.util.encoders \
            org.bouncycastle.util.test > /dev/null \

    )
    (2>&1 find lcrypto-jdk14-$1 -name CVS -exec rm -rf \{\} \; ) > /dev/null
fi

if test "$1" != ""
then
    echo "making JCE provider"

    mkdir bcprov-jdk14-$1
    tar cf - index.html LICENSE.html CONTRIBUTORS.html releasenotes.html specifications.html src | (cd bcprov-jdk14-$1; tar xf -)
    (
    cd bcprov-jdk14-$1; mkdir classes; mkdir docs;

    rm -rf src/org/bouncycastle/mail
    rm -rf src/org/bouncycastle/cms

    PATH=$JDK14PATH/bin:$PATH
    export PATH

    javadoc -windowtitle "$WINDOWTITLE" -doctitle "$DOCTITLE" \
        -header "$HEADER" -group "Core Packages" "org.bouncycastle*" \
        -group "Example Packages" "example*" -classpath classes \
        -d docs -sourcepath src \
        org.bouncycastle.jce \
        org.bouncycastle.asn1 \
        org.bouncycastle.asn1.pkcs \
        org.bouncycastle.asn1.x509 \
        org.bouncycastle.asn1.x9 \
        org.bouncycastle.asn1.oiw \
        org.bouncycastle.asn1.ocsp \
        org.bouncycastle.asn1.sec \
        org.bouncycastle.asn1.util \
        org.bouncycastle.asn1.misc \
        org.bouncycastle.asn1.cms \
        org.bouncycastle.asn1.smime \
        org.bouncycastle.asn1.test \
        org.bouncycastle.math.ec \
        org.bouncycastle.crypto \
        org.bouncycastle.crypto.agreement \
        org.bouncycastle.crypto.digests \
        org.bouncycastle.crypto.encodings \
        org.bouncycastle.crypto.engines \
        org.bouncycastle.crypto.generators \
        org.bouncycastle.crypto.io \
        org.bouncycastle.crypto.macs \
        org.bouncycastle.crypto.modes \
        org.bouncycastle.crypto.paddings \
        org.bouncycastle.crypto.params \
        org.bouncycastle.crypto.signers \
        org.bouncycastle.crypto.test \
        org.bouncycastle.crypto.examples \
        org.bouncycastle.jce.interfaces \
        org.bouncycastle.jce.spec \
        org.bouncycastle.jce.examples \
        org.bouncycastle.jce.provider \
        org.bouncycastle.jce.provider.test \
        org.bouncycastle.ocsp \
        org.bouncycastle.util.encoders \
        org.bouncycastle.util.test > /dev/null \

    echo "compiling"

    rm -rf src/org/bouncycastle/mail;

    (cd src/org/bouncycastle; javac -d ../../../classes -classpath ../../../classes:../../../src *.java */*.java */*/*.java */*/*/*.java)

    #
    # create test jar
    #
    cat > classes/details.mf <<%
Manifest-Version: 1.0
Extension-Name: org.bouncycastle.bctest
Specification-Vendor: BouncyCastle.org
Specification-Version: 1.1
Implementation-Vendor-Id: org.bouncycastle
Implementation-Vendor: BouncyCastle.org
Implementation-Version: 1.19.0
%

    (cd classes; jar cfm ../../bctest-jdk14-$1.jar details.mf org/bouncycastle/asn1/test org/bouncycastle/crypto/test org/bouncycastle/jce/provider/test)

    rm -rf classes/org/bouncycastle/asn1/test
    rm -rf classes/org/bouncycastle/crypto/test
    rm -rf classes/org/bouncycastle/jce/provider/test

    #
    # add the manifest
    #
    cat > classes/details.mf <<%
Manifest-Version: 1.0
Extension-Name: org.bouncycastle.bcprovider
Specification-Vendor: BouncyCastle.org
Specification-Version: 1.1
Implementation-Vendor-Id: org.bouncycastle
Implementation-Vendor: BouncyCastle.org
Implementation-Version: 1.19.0
%

    (cd classes; jar cfm ../../bcprov-jdk14-$1.jar details.mf org)

    rm -rf classes
    )

    (2>&1 find bcprov-jdk14-$1 -name CVS -exec rm -rf \{\} \;) > /dev/null
fi
