#!/bin/sh -
#
# build script for 1.3
#
# 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.
#

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

JDK13PATH=/opt/jdk1.3

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

    mkdir lcrypto-jdk13-$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-jdk13-$1; tar xf -)

    (
        cd lcrypto-jdk13-$1;

        mkdir classes; mkdir docs;
        rm -rf src/org/bouncycastle/jce

        PATH=$JDK13PATH/bin:$PATH
        export PATH

        echo "compiling"

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

        echo "lightweight regression test"
        java -classpath classes org.bouncycastle.crypto.test.RegressionTest

        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-jdk13-$1 -name CVS -exec rm -rf \{\} \; ) > /dev/null
fi

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

    mkdir jce-jdk13-$1
    tar cf - index.html LICENSE.html CONTRIBUTORS.html releasenotes.html specifications.html src | (cd jce-jdk13-$1; tar xf -)
    (cd jdk1.3; tar cf - * | (cd ../jce-jdk13-$1/src; tar xf -))
    (
    cd jce-jdk13-$1; mkdir classes; mkdir docs;

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

    PATH=$JDK13PATH/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 \
        javax.crypto  \
        javax.crypto.interfaces \
        javax.crypto.spec \
        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.sec \
        org.bouncycastle.asn1.util \
        org.bouncycastle.asn1.test \
        org.bouncycastle.asn1.misc \
        org.bouncycastle.asn1.cms \
        org.bouncycastle.asn1.ocsp \
        org.bouncycastle.asn1.smime \
        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.cert \
        org.bouncycastle.jce.interfaces \
        org.bouncycastle.jce.spec \
        org.bouncycastle.jce.examples \
        org.bouncycastle.jce.provider \
        org.bouncycastle.jce.provider.test \
        org.bouncycastle.openssl \
        org.bouncycastle.ocsp \
        org.bouncycastle.util.encoders \
        org.bouncycastle.util.test > /dev/null \

    echo "compiling"

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

    (cd src/javax/crypto; javac -d ../../../classes -classpath ../../../classes:../../../src *.java */*.java)

    echo "provider regression test"
    java -classpath classes org.bouncycastle.jce.provider.test.RegressionTest
    java -classpath classes org.bouncycastle.ocsp.test.OCSPTest
    java -classpath classes org.bouncycastle.asn1.test.RegressionTest

    #
    # create the test jar
    #
    cat > classes/test.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-jdk13-$1.jar test.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
    rm -rf classes/org/bouncycastle/ocsp/test


    #
    # add the manifest
    #
    cat > classes/provider.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
%

    cat > classes/jce.mf <<%
Manifest-Version: 1.0
Extension-Name: org.bouncycastle.bcjce
Specification-Vendor: BouncyCastle.org
Specification-Version: 1.1
Implementation-Vendor-Id: org.bouncycastle
Implementation-Vendor: BouncyCastle.org
Implementation-Version: 1.19.0
%

    rm -f classes/org/bouncycastle/jce/provider/test/NIST*
    (cd classes; jar cfm ../../bcprov-jdk13-$1.jar provider.mf java org)
    (cd classes; jar cfm ../../jce-jdk13-$1.jar jce.mf javax java org)
    )

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

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

    mkdir bcmail-jdk13-$1
    tar cf - index.html LICENSE.html CONTRIBUTORS.html releasenotes.html specifications.html src/org/bouncycastle/mail src/org/bouncycastle/cms | (cd bcmail-jdk13-$1; tar xf -)
    (cd jdk1.3; tar cf - * | (cd ../bcmail-jdk13-$1/src; tar xf -))
    (
    cd bcmail-jdk13-$1; mkdir classes; mkdir docs;

    PATH=$JDK13PATH/bin:$PATH
    export PATH

    rm -rf src/java
    rm -rf src/org/bouncycastle/jce
    rm -rf src/org/bouncycastle/ocsp

    javadoc -windowtitle "$WINDOWTITLE" -doctitle "$DOCTITLE" \
        -header "$HEADER" -group "Core Packages" "org.bouncycastle*" \
        -group "Example Packages" "example*" -classpath classes:../jce-jdk13-$1/classes \
        -d docs -sourcepath src \
        org.bouncycastle.cms \
        org.bouncycastle.cms.test \
        org.bouncycastle.mail.smime \
        org.bouncycastle.mail.smime.handlers \
        org.bouncycastle.mail.smime.examples \
        org.bouncycastle.mail.smime.test > /dev/null \

    echo "compiling"

    (cd src/org/bouncycastle; javac -d ../../../classes -classpath ../../../classes:../../../src:../../../../jce-jdk13-$1/classes */*.java */*/*.java */*/*/*.java)
    cat > classes/mail.mf <<%
Manifest-Version: 1.0
Extension-Name: org.bouncycastle.bcmail
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 cmf mail.mf ../../bcmail-jdk13-$1.jar org)
    java -classpath ../jce-jdk13-$1/classes:classes org.bouncycastle.mail.smime.test.AllTests
    java -classpath ../jce-jdk13-$1/classes:classes org.bouncycastle.cms.test.AllTests

    )

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