#!/bin/sh
#
#       Compilation scripts initialization for the OS/400 implementation.
#
#       See Copyright for the status of this software.
#
#       Author: Patrick Monnerat <pm@datasphere.ch>, DATASPHERE S.A.
#

case "${SCRIPTDIR}" in
/*)     ;;
*)      SCRIPTDIR="`pwd`/${SCRIPTDIR}"
esac

while true
do      case "${SCRIPTDIR}" in
        */.)    SCRIPTDIR="${SCRIPTDIR%/.}";;
        *)      break;;
        esac
done

#  The script directory is supposed to be in $TOPDIR/os400.

TOPDIR=`dirname "${SCRIPTDIR}"`
export SCRIPTDIR TOPDIR

setenv()

{
        #       Define and export.

        eval ${1}="${2}"
        export ${1}
}

################################################################################
#
#                       Tunable configuration parameters.
#
################################################################################

setenv TARGETLIB        'LIBXML2'       # Target OS/400 program library.
setenv STATBNDDIR       'LIBXML2_A'     # Static binding directory.
setenv DYNBNDDIR        'LIBXML2'       # Dynamic binding directory.
setenv SRVPGM           "LIBXML2"       # Service program.
setenv TGTCCSID         '500'           # Target CCSID of objects.
setenv DEBUG            '*ALL'          # Debug level.
setenv OPTIMIZE         '10'            # Optimisation level.
setenv OUTPUT           '*NONE'         # Compilation output option.
setenv TGTRLS           'V6R1M0'        # Target OS release.
setenv IFSDIR           '/libxml2'      # Installation IFS directory.

################################################################################
#
#                       Conditional compilation parameters.
#
################################################################################

setenv WITH_TRIO                1    # Configure trio support.
setenv WITH_THREADS             1    # Configure thread support.
setenv WITH_THREAD_ALLOC        1    # Whether allocation hooks are per-thread.
setenv WITH_TREE                1    # Compile DOM tree API.
setenv WITH_OUTPUT              1    # Compile serialization/saving support.
setenv WITH_PUSH                1    # Compile push parser.
setenv WITH_READER              1    # Compile parsing interface.
setenv WITH_PATTERN             1    # Compile pattern node selection interface.
setenv WITH_WRITER              1    # Compile saving interface.
setenv WITH_SAX1                1    # Compile SAX version 1 interface.
setenv WITH_FTP                 1    # Compile FTP support.
setenv WITH_HTTP                1    # Compile HTTP support.
setenv WITH_VALID               1    # Compile DTD validation support.
setenv WITH_HTML                1    # Compile HTML support.
setenv WITH_LEGACY              1    # Compile deprecated API.
setenv WITH_C14N                1    # Compile canonicalization support.
setenv WITH_CATALOG             1    # Compile catalog support.
setenv WITH_DOCB                1    # Compile SGML Docbook support.
setenv WITH_XPATH               1    # Compile XPath support.
setenv WITH_XPTR                1    # Compile XPointer support.
setenv WITH_XINCLUDE            1    # Compile XInclude support.
setenv WITH_ICONV               1    # Whether iconv support is available.
setenv WITH_ICU                 0    # Whether icu support is available.
setenv WITH_ISO8859X            1    # Compile ISO-8859-* support if no iconv.
setenv WITH_DEBUG               1    # Compile debugging module.
setenv WITH_MEM_DEBUG           1    # Compile memory debugging module.
setenv WITH_RUN_DEBUG           1    # Compile runtime debugging.
setenv WITH_REGEXPS             1    # Compile regular expression interfaces.
setenv WITH_SCHEMAS             1    # Compile schema validation interface.
setenv WITH_SCHEMATRON          1    # Compile schematron validation interface.
setenv WITH_MODULES             1    # Compile module interfaces.
setenv WITH_ZLIB                0    # Whether zlib is available.
setenv WITH_LZMA                0    # Whether LZMA is available.

#       Define ZLIB locations. This is ignored if WITH_ZLIB is 0.

setenv ZLIB_INCLUDE             '/zlib/include' # ZLIB include IFS directory.
setenv ZLIB_LIB                 'ZLIB'          # ZLIB library.
setenv ZLIB_BNDDIR              'ZLIB_A'        # ZLIB binding directory.

################################################################################
#
#                       OS/400 specific definitions.
#
################################################################################

setenv LIBIFSNAME               "/QSYS.LIB/${TARGETLIB}.LIB"
setenv MODULE_EXTENSION         '.SRVPGM'

################################################################################
#
#                       Extract version information.
#
################################################################################

#       Transitional: get file name of configure script.

AUTOCONFSCRIPT="${TOPDIR}/configure.ac"

if [ ! -f "${AUTOCONFSCRIPT}" ]
then    AUTOCONFSCRIPT="${TOPDIR}/configure.in"
fi

#       Need to get the version definitions.

eval "`grep '^LIBXML_[A-Z]*_VERSION=' \"${AUTOCONFSCRIPT}\"`"
eval "`grep '^LIBXML_MICRO_VERSION_SUFFIX=' \"${AUTOCONFSCRIPT}\"`"
LIBXML_VERSION="${LIBXML_MAJOR_VERSION}.${LIBXML_MINOR_VERSION}"
LIBXML_VERSION="${LIBXML_VERSION}.${LIBXML_MICRO_VERSION}"
LIBXML_VERSION="${LIBXML_VERSION}${LIBXML_MICRO_VERSION_SUFFIX}"
LIBXML_VERSION_NUMBER=`expr "${LIBXML_MAJOR_VERSION}" \* 10000 +        \
                            "${LIBXML_MINOR_VERSION}" \* 100 +          \
                            "${LIBXML_MICRO_VERSION}"`
export LIBXML_MAJOR_VERSION LIBXML_MINOR_VERSION
export LIBXML_MICRO_VERSION LIBXML_MICROVERSION_SUFFIX
export LIBXML_VERSION LIBXML_VERSION_NUMBER
setenv LIBXML_VERSION_EXTRA ''
setenv VERSION  "${LIBXML_VERSION}"

################################################################################
#
#                               Procedures.
#
################################################################################

#       action_needed dest [src]
#
#       dest is an object to build
#       if specified, src is an object on which dest depends.
#
#       exit 0 (succeeds) if some action has to be taken, else 1.

action_needed()

{
        [ ! -e "${1}" ] && return 0
        [ "${2}" ] || return 1
        [ "${1}" -ot "${2}" ] && return 0
        return 1
}

#       make_module [option] module_name source_name
#
#       Compile source name into ASCII module if needed.
#       As side effect, append the module name to variable MODULES.
#       Set LINK to "YES" if the module has been compiled.
#       Options are:
#         --define <additional definitions>
#         --ebcdic
#         --sysiconv

make_module()

{
        DEFN=
        EBCDIC=
        SYSICONV=
        while true
        do      case "${1}" in
                --define)
                        DEFN="${2}"
                        shift
                        ;;
                --ebcdic)
                        EBCDIC=yes
                        ;;
                --sysiconv)
                        SYSICONV=yes
                        ;;
                *)      break
                esac
                shift
        done
        MODULES="${MODULES} ${1}"
        MODIFSNAME="${LIBIFSNAME}/${1}.MODULE"
        action_needed "${MODIFSNAME}" "${2}" || return 0;

        #       #pragma convert has to be in the source file itself, i.e.
        #               putting it in an include file makes it only active
        #               for that include file.
        #       Thus we build a temporary file with the pragma prepended to
        #               the source file and we compile that temporary file.

        rm -f __tmpsrcf.c
        if [ -z "${EBCDIC}" ]
        then    echo "#line 1 \"${2}\"" >> __tmpsrcf.c
                echo "#pragma convert(819)" >> __tmpsrcf.c
                echo '#include "wrappers.h"' >> __tmpsrcf.c
        fi
        echo "#line 1 \"${2}\"" >> __tmpsrcf.c
        cat "${2}" >> __tmpsrcf.c
        CMD="CRTCMOD MODULE(${TARGETLIB}/${1}) SRCSTMF('__tmpsrcf.c')"
#       CMD="${CMD} OPTION(*INCDIRFIRST *SHOWINC *SHOWSYS)"
        CMD="${CMD} OPTION(*INCDIRFIRST) FLAG(10)"
        CMD="${CMD} SYSIFCOPT(*IFS64IO) LANGLVL(*EXTENDED) LOCALETYPE(*LOCALE)"
        CMD="${CMD} INCDIR("
        if [  -z "${SYSICONV}" ]
        then    CMD="${CMD} '${TOPDIR}/os400/iconv'"
        fi
        if [ -z "${EBCDIC}" ]
        then    CMD="${CMD} '/qibm/proddata/qadrt/include'"
        fi
        CMD="${CMD} '${TOPDIR}/os400' '${TOPDIR}/os400/dlfcn'"
        CMD="${CMD} '${IFSDIR}/include/libxml' '${IFSDIR}/include'"
        if [ "${ZLIB_INCLUDE}" ]
        then    CMD="${CMD} '${ZLIB_INCLUDE}'"
        fi
        CMD="${CMD} '${TOPDIR}' ${INCLUDES})"
        CMD="${CMD} TGTCCSID(${TGTCCSID}) TGTRLS(${TGTRLS})"
        CMD="${CMD} OUTPUT(${OUTPUT})"
        CMD="${CMD} OPTIMIZE(${OPTIMIZE})"
        CMD="${CMD} DBGVIEW(${DEBUG})"
        CMD="${CMD} DEFINE('_REENTRANT' 'TRIO_HAVE_CONFIG_H' 'NDEBUG' ${DEFN})"

        system "${CMD}"
        rm -f __tmpsrcf.c
        LINK=YES
}

#       Determine DB2 object name from IFS name.

db2_name()

{
        if [ "${2}" = 'nomangle' ]
        then    basename "${1}"                                         |
                tr 'a-z-' 'A-Z_'                                        |
                sed -e 's/\..*//'                                       \
                    -e 's/^\(..........\).*$/\1/'
        else    basename "${1}"                                         |
                tr 'a-z-' 'A-Z_'                                        |
                sed -e 's/\..*//'                                       \
                    -e 's/^TEST/T/'                                     \
                    -e 's/^XML/X/'                                      \
                    -e 's/^\(.\).*\(.........\)$/\1\2/'
        fi
}

#       Copy IFS file replacing version & configuration info.

versioned_copy()

{
    sed -e "s/@LIBXML_VERSION@/${LIBXML_VERSION}/g"                     \
                                                                        \
        -e "s#@LIBXML_MAJOR_VERSION@#${LIBXML_MAJOR_VERSION}#g"         \
        -e "s#@LIBXML_MINOR_VERSION@#${LIBXML_MINOR_VERSION}#g"         \
        -e "s#@LIBXML_MICRO_VERSION@#${LIBXML_MICRO_VERSION}#g"         \
        -e "s#@LIBXML_MICRO_VERSION_SUFFIX@#${LIBXML_MICRO_VERSION_SUFFIX}#g" \
        -e "s#@LIBXML_VERSION@#${LIBXML_VERSION}#g"                     \
        -e "s#@LIBXML_VERSION_NUMBER@#${LIBXML_VERSION_NUMBER}#g"       \
        -e "s#@LIBXML_VERSION_EXTRA@#${LIBXML_VERSION_EXTRA}#g"         \
        -e "s#@VERSION@#${VERSION}#g"                                   \
        -e "s#@WITH_TRIO@#${WITH_TRIO}#g"                               \
        -e "s#@WITH_THREADS@#${WITH_THREADS}#g"                         \
        -e "s#@WITH_THREAD_ALLOC@#${WITH_THREAD_ALLOC}#g"               \
        -e "s#@WITH_TREE@#${WITH_TREE}#g"                               \
        -e "s#@WITH_OUTPUT@#${WITH_OUTPUT}#g"                           \
        -e "s#@WITH_PUSH@#${WITH_PUSH}#g"                               \
        -e "s#@WITH_READER@#${WITH_READER}#g"                           \
        -e "s#@WITH_PATTERN@#${WITH_PATTERN}#g"                         \
        -e "s#@WITH_WRITER@#${WITH_WRITER}#g"                           \
        -e "s#@WITH_SAX1@#${WITH_SAX1}#g"                               \
        -e "s#@WITH_FTP@#${WITH_FTP}#g"                                 \
        -e "s#@WITH_HTTP@#${WITH_HTTP}#g"                               \
        -e "s#@WITH_VALID@#${WITH_VALID}#g"                             \
        -e "s#@WITH_HTML@#${WITH_HTML}#g"                               \
        -e "s#@WITH_LEGACY@#${WITH_LEGACY}#g"                           \
        -e "s#@WITH_C14N@#${WITH_C14N}#g"                               \
        -e "s#@WITH_CATALOG@#${WITH_CATALOG}#g"                         \
        -e "s#@WITH_DOCB@#${WITH_DOCB}#g"                               \
        -e "s#@WITH_XPATH@#${WITH_XPATH}#g"                             \
        -e "s#@WITH_XPTR@#${WITH_XPTR}#g"                               \
        -e "s#@WITH_XINCLUDE@#${WITH_XINCLUDE}#g"                       \
        -e "s#@WITH_ICONV@#${WITH_ICONV}#g"                             \
        -e "s#@WITH_ICU@#${WITH_ICU}#g"                                 \
        -e "s#@WITH_ISO8859X@#${WITH_ISO8859X}#g"                       \
        -e "s#@WITH_DEBUG@#${WITH_DEBUG}#g"                             \
        -e "s#@WITH_MEM_DEBUG@#${WITH_MEM_DEBUG}#g"                     \
        -e "s#@WITH_RUN_DEBUG@#${WITH_RUN_DEBUG}#g"                     \
        -e "s#@WITH_REGEXPS@#${WITH_REGEXPS}#g"                         \
        -e "s#@WITH_SCHEMAS@#${WITH_SCHEMAS}#g"                         \
        -e "s#@WITH_SCHEMATRON@#${WITH_SCHEMATRON}#g"                   \
        -e "s#@WITH_MODULES@#${WITH_MODULES}#g"                         \
        -e "s#@WITH_ZLIB@#${WITH_ZLIB}#g"                               \
        -e "s#@WITH_LZMA@#${WITH_LZMA}#g"
}


#!/bin/sh
#
#       Compilation script for the iconv names DFA builer.
#
#       See Copyright for the status of this software.
#
#       Author: Patrick Monnerat <pm@datasphere.ch>, DATASPHERE S.A.
#

SCRIPTDIR=`dirname "${0}"`
. "${SCRIPTDIR}/initscript.sh"
cd "${TOPDIR}/os400/iconv/bldcsndfa"

# This is for old XML library (bootstrapping).
#rm -rf xml.h xml
#ln -s /QSYS.LIB/XML.LIB/H.FILE/XML.MBR xml.h
#mkdir xml
#mkdir xml/h
#ln -s /QSYS.LIB/XML.LIB/H.FILE/UTF8.MBR xml/h/utf8

#       Compile.

CMD="CRTCMOD MODULE(${TARGETLIB}/BLDCSNDFA) SRCSTMF('bldcsndfa.c')"
CMD="${CMD} SYSIFCOPT(*IFS64IO) LANGLVL(*EXTENDED) LOCALETYPE(*LOCALE)"
CMD="${CMD} INCDIR("
CMD="${CMD} '${IFSDIR}/include' ${INCLUDES})"
CMD="${CMD} TGTCCSID(${TGTCCSID}) TGTRLS(${TGTRLS})"
CMD="${CMD} OUTPUT(${OUTPUT})"
CMD="${CMD} OPTIMIZE(10)"
CMD="${CMD} DBGVIEW(${DEBUG})"
#CMD="${CMD} DEFINE('OLDXML' 'xmlXPathSetContextNode=xmlXPathSetCurrentNode')"

system "${CMD}"

#       Link

CMD="CRTPGM PGM(${TARGETLIB}/BLDCSNDFA) MODULE(${TARGETLIB}/BLDCSNDFA)"
CMD="${CMD} BNDDIR(${TARGETLIB}/${DYNBNDDIR})"
#CMD="${CMD} BNDDIR(XML/XML)"
CMD="${CMD} TGTRLS(${TGTRLS})"
system "${CMD}"


#!/bin/sh
#
#       Installation of the C header files in the OS/400 library.
#
#       See Copyright for the status of this software.
#
#       Author: Patrick Monnerat <pm@datasphere.ch>, DATASPHERE S.A.
#

SCRIPTDIR=`dirname "${0}"`
. "${SCRIPTDIR}/initscript.sh"
cd "${TOPDIR}/include"

#       Create the OS/400 source program file for the C header files.

SRCPF="${LIBIFSNAME}/LIBXML.FILE"

if action_needed "${SRCPF}"
then    CMD="CRTSRCPF FILE(${TARGETLIB}/LIBXML) RCDLEN(112)"
        CMD="${CMD} CCSID(${TGTCCSID}) TEXT('libxml2: C/C++ header files')"
        system "${CMD}"
fi

#       Create the IFS directory for the C header files.

if action_needed "${IFSDIR}/include/libxml"
then    mkdir -p "${IFSDIR}/include/libxml"
fi

#       Enumeration values may be used as va_arg tagfields, so they MUST be
#               integers.

copy_hfile()

{
        sed -e '1i\
#pragma enum(int)\
' "${@}" -e '$a\
#pragma enum(pop)\
'
}

#       Copy the header files to DB2 library. Link from IFS include directory.

for HFILE in "${TOPDIR}/os400/transcode.h" libxml/*.h libxml/*.h.in
do      CMD="cat \"${HFILE}\""
        DEST="${SRCPF}/`db2_name \"${HFILE}\" nomangle`.MBR"

        case "`basename \"${HFILE}\"`" in

        *.in)   CMD="${CMD} | versioned_copy";;

        xmlschemastypes.h)      #       Special case: rename colliding file.
                DEST="${SRCPF}/SCHMTYPES.MBR";;

        esac

        if action_needed "${DEST}" "${HFILE}"
        then    eval "${CMD}" | copy_hfile > tmphdrfile

                #       Need to translate to target CCSID.

                CMD="CPY OBJ('`pwd`/tmphdrfile') TOOBJ('${DEST}')"
                CMD="${CMD} TOCCSID(${TGTCCSID}) DTAFMT(*TEXT) REPLACE(*YES)"
                system "${CMD}"
        fi

        IFSFILE="${IFSDIR}/include/libxml/`basename \"${HFILE}\" .in`"

        if action_needed "${IFSFILE}" "${DEST}"
        then    rm -f "${IFSFILE}"
                ln -s "${DEST}" "${IFSFILE}"
        fi
done


#!/bin/sh
#
#       Installation of the ILE/RPG header files in the OS/400 library.
#
#       See Copyright for the status of this software.
#
#       Author: Patrick Monnerat <pm@datasphere.ch>, DATASPHERE S.A.
#

SCRIPTDIR=`dirname "${0}"`
. "${SCRIPTDIR}/initscript.sh"
cd "${TOPDIR}/os400/libxmlrpg"

#       Create the OS/400 source program file for the ILE/RPG header files.

SRCPF="${LIBIFSNAME}/LIBXMLRPG.FILE"

if action_needed "${SRCPF}"
then    CMD="CRTSRCPF FILE(${TARGETLIB}/LIBXMLRPG) RCDLEN(112)"
        CMD="${CMD} CCSID(${TGTCCSID}) TEXT('libxml2: ILE/RPG header files')"
        system "${CMD}"
fi

#       Map file names to DB2 name syntax.

for HFILE in *.rpgle *.rpgle.in
do      NAME="`basename \"${HFILE}\" .in`"
        VAR="`basename \"${NAME}\" .rpgle`"
        VAL="`db2_name \"${NAME}\" nomangle`"

        if [ "${VAR}" = 'xmlschemastypes' ]
        then    VAL=SCHMTYPES
        fi

        eval "VAR_${VAR}=\"${VAL}\""
        echo "${VAR} s/${VAR}/${VAL}/g"
done > tmpsubstfile1

#       Order substitution commands so that a prefix appears after all
#               file names beginning with the prefix.

sort -r tmpsubstfile1 | sed 's/^[^ ]*[ ]*//' > tmpsubstfile2

change_include()

{
        sed -e '\#^....../include  *"libxmlrpg/#{'                      \
            -e 's///'                                                   \
            -e 's/".*//'                                                \
            -f tmpsubstfile2                                            \
            -e 's#.*#      /include libxmlrpg,&#'                       \
            -e '}'
}

#       Create the IFS directory for the ILE/RPG header files.

RPGIFSDIR="${IFSDIR}/include/libxmlrpg"

if action_needed "${RPGIFSDIR}"
then    mkdir -p "${RPGIFSDIR}"
fi

#       Copy the header files to IFS ILE/RPG include directory.
#       Copy them with include path editing to the DB2 library.

for HFILE in *.rpgle *.rpgle.in
do      IFSCMD="cat \"${HFILE}\""
        DB2CMD="change_include < \"${HFILE}\""
        IFSFILE="`basename \"${HFILE}\" .in`"

        case "${HFILE}" in

        *.in)   IFSCMD="${IFSCMD} | versioned_copy"
                DB2CMD="${DB2CMD} | versioned_copy"
                ;;
        esac

        IFSDEST="${RPGIFSDIR}/${IFSFILE}"

        if action_needed "${IFSDEST}" "${HFILE}"
        then    eval "${IFSCMD}" > "${IFSDEST}"
        fi

        eval DB2MBR="\"\${VAR_`basename \"${IFSDEST}\" .rpgle`}\""
        DB2DEST="${SRCPF}/${DB2MBR}.MBR"

        if action_needed "${DB2DEST}" "${HFILE}"
        then    eval "${DB2CMD}" | change_include > tmphdrfile

                #       Need to translate to target CCSID.

                CMD="CPY OBJ('`pwd`/tmphdrfile') TOOBJ('${DB2DEST}')"
                CMD="${CMD} TOCCSID(${TGTCCSID}) DTAFMT(*TEXT) REPLACE(*YES)"
                system "${CMD}"
        fi
done


#!/bin/sh
#
#       libxml compilation script for the OS/400.
#
#       See Copyright for the status of this software.
#
#       Author: Patrick Monnerat <pm@datasphere.ch>, DATASPHERE S.A.
#

SCRIPTDIR=`dirname "${0}"`
. "${SCRIPTDIR}/initscript.sh"
cd "${TOPDIR}"

#      Create and compile the identification source file.

echo '#pragma comment(user, "libxml2 version '"${LIBXML_VERSION}"'")' > os400.c
echo '#pragma comment(user, __DATE__)' >> os400.c
echo '#pragma comment(user, __TIME__)' >> os400.c
echo '#pragma comment(copyright, "Copyright (C) 1998-2017 Daniel Veillard. OS/400 version by P. Monnerat.")' >> os400.c
make_module     OS400           os400.c
LINK=                           # No need to rebuild service program yet.
MODULES=

#       Get source list.

foldlines()

{
        sed -e ':begin'                                                 \
            -e '/\\$/{'                                                 \
            -e 's/\\$/ /'                                               \
            -e 'N'                                                      \
            -e 'bbegin'                                                 \
            -e '}'                                                      \
            -e 's/\n//g'                                                \
            -e 's/[[:space:]]*$//'
}

get_make_var()

{
        foldlines < Makefile.am                                         |
        sed -e "/^${1}[[:space:]]*=[[:space:]]*/{"                      \
            -e 's///'                                                   \
            -e 'q'                                                      \
            -e '}'                                                      \
            -e 'd'
}

docb_sources=`get_make_var docb_sources`
trio_sources=`get_make_var trio_sources`
CSOURCES=`eval echo "\`get_make_var libxml2_la_SOURCES | tr '()' '{}'\`"`

#       Compile the sources into modules.

INCLUDES="'`pwd`'"

#       OS/400 specific modules first.

make_module     --ebcdic        DLFCN           "${SCRIPTDIR}/dlfcn/dlfcn.c"
make_module     --ebcdic        ICONV           "${SCRIPTDIR}/iconv/iconv.c"
make_module     --ebcdic        WRAPPERS        "${SCRIPTDIR}/wrappers.c"
make_module                     TRANSCODE       "${SCRIPTDIR}/transcode.c"
make_module                     RPGSUPPORT      "${SCRIPTDIR}/rpgsupport.c"

#       Regular libxml2 modules.

for SRC in ${CSOURCES}
do      MODULE=`db2_name "${SRC}"`
        make_module "${MODULE}" "${SRC}"
done

#       If needed, (re)create the static binding directory.

if action_needed "${LIBIFSNAME}/${STATBNDDIR}.BNDDIR"
then    LINK=YES
fi

if [ "${LINK}" ]
then    rm -rf "${LIBIFSNAME}/${STATBNDDIR}.BNDDIR"
        CMD="CRTBNDDIR BNDDIR(${TARGETLIB}/${STATBNDDIR})"
        CMD="${CMD} TEXT('libxml2 static binding directory')"
        system "${CMD}"

        for MODULE in ${MODULES}
        do      CMD="ADDBNDDIRE BNDDIR(${TARGETLIB}/${STATBNDDIR})"
                CMD="${CMD} OBJ((${TARGETLIB}/${MODULE} *MODULE))"
                system "${CMD}"
        done
fi

#       The exportation file for service program creation must be in a DB2
#               source file, so make sure it exists.

if action_needed "${LIBIFSNAME}/TOOLS.FILE"
then    CMD="CRTSRCPF FILE(${TARGETLIB}/TOOLS) RCDLEN(112)"
        CMD="${CMD} CCSID(${TGTCCSID}) TEXT('libxml2: build tools')"
        system "${CMD}"
fi

#       Generate all exported symbol table versions in a binding source file.

BSF="${LIBIFSNAME}/TOOLS.FILE/BNDSRC.MBR"
PGMEXPS=

OS400SYMS=`cat os400/transcode.h os400/rpgsupport.h                     |
           sed -e 'H'                                                   \
               -e 'g'                                                   \
               -e 's/\n/ /'                                             \
               -e 's/\\$/ /'                                            \
               -e 's/.*/& /'                                            \
               -e 's/\/\*.*\*\// /g'                                    \
               -e 'h'                                                   \
               -e ':loop'                                               \
               -e 'g'                                                   \
               -e '/\/\*/d'                                             \
               -e '/;/!d'                                               \
               -e 's/[^;]*;//'                                          \
               -e 'x'                                                   \
               -e 's/[[:space:]]*;.*$//'                                \
               -e '/XMLPUBFUN/{'                                        \
               -e 's/[[:space:]]*(.*$//'                                \
               -e 's/.*[[:space:]*]//'                                  \
               -e 'p'                                                   \
               -e 'bloop'                                               \
               -e '}'                                                   \
               -e '/XMLPUBVAR/!bloop'                                   \
               -e ':loop2'                                              \
               -e '/\[[^][]*\]/{'                                       \
               -e 's///'                                                \
               -e 'bloop2'                                              \
               -e '}'                                                   \
               -e 's/[[:space:]]*,[[:space:]]*/,/g'                     \
               -e 's/[^,]*[[:space:]*]//'                               \
               -e 's/[^[:alnum:]_,]//g'                                 \
               -e 's/,/\n/g'                                            \
               -e 'p'                                                   \
               -e 'bloop'`

sed -e 's/#.*//'                                                        \
    -e 's/[[:space:]]*$//'                                              \
    -e 's/^[[:space:]]*//'                                              \
    -e '/^*global:$/d'                                                  \
    -e '/^$/d'                                                          \
    -e '/[[:space:]]*{$/{'                                              \
    -e   's///'                                                         \
    -e   'h'                                                            \
    -e   's/[^A-Za-z0-9]/_/g'                                           \
    -e   's/^[0-9]/_&/'                                                 \
    -e   'x'                                                            \
    -e   'G'                                                            \
    -e   's/\(.*\)\n\(.*\)/\2_SIGNATURE="\1"/'                          \
    -e   'p'                                                            \
    -e   's/.*//'                                                       \
    -e   'x'                                                            \
    -e   "s/.*/SONAME='&'/"                                             \
    -e   'b'                                                            \
    -e '}'                                                              \
    -e '/[[:space:]]*;$/!d'                                             \
    -e 's///'                                                           \
    -e '/^xmlDllMain$/d'                                                \
    -e '/^}[[:space:]]*/!{'                                             \
    -e   'H'                                                            \
    -e   'd'                                                            \
    -e '}'                                                              \
    -e 's///'                                                           \
    -e '/^$/!{'                                                         \
    -e   's/[^A-Za-z0-9]/_/g'                                           \
    -e   's/^[0-9]/_&/'                                                 \
    -e   's/.*/${&}/'                                                   \
    -e   'x'                                                            \
    -e   'H'                                                            \
    -e   's/.*//'                                                       \
    -e '}'                                                              \
    -e 'x'                                                              \
    -e 's/\n/ /g'                                                       \
    -e 's/^[[:space:]]*//'                                              \
    -e 's/.*/declare ${SONAME}="&"/'                                    \
    -e 's/.*/&; PGMEXPS="${SONAME} ${PGMEXPS}"/'                        \
        < "${TOPDIR}/libxml2.syms"    > bndvars
. ./bndvars

PGMLVL=CURRENT
for PGMEXP in ${PGMEXPS}
do      SIGNATURE=`echo "${PGMEXP}" | sed 's/^LIBXML2_//'`
        eval ENTRIES=\"\${${PGMEXP}}\"
        echo " STRPGMEXP PGMLVL(*${PGMLVL}) SIGNATURE('${SIGNATURE}')"
        for ENTRY in ${ENTRIES} ${OS400SYMS}
        do      echo " EXPORT    SYMBOL('${ENTRY}')"
        done
        echo ' ENDPGMEXP'
        PGMLVL=PRV
done            > "${BSF}"

#       Build the service program if needed.

if action_needed "${LIBIFSNAME}/${SRVPGM}.SRVPGM"
then    LINK=YES
fi

if [ "${LINK}" ]
then    CMD="CRTSRVPGM SRVPGM(${TARGETLIB}/${SRVPGM})"
        CMD="${CMD} SRCFILE(${TARGETLIB}/TOOLS) SRCMBR(BNDSRC)"
        CMD="${CMD} MODULE(${TARGETLIB}/OS400)"
        CMD="${CMD} BNDDIR((${TARGETLIB}/${STATBNDDIR})"
        if [ "${WITH_ZLIB}" -ne 0 ]
        then    CMD="${CMD} (${ZLIB_LIB}/${ZLIB_BNDDIR})"
        fi
        CMD="${CMD})"
        CMD="${CMD} BNDSRVPGM(QADRTTS)"
        CMD="${CMD} TEXT('libxml2 dynamic library')"
        CMD="${CMD} TGTRLS(${TGTRLS})"
        system "${CMD}"
        LINK=YES
fi

#       If needed, (re)create the dynamic binding directory.

if action_needed "${LIBIFSNAME}/${DYNBNDDIR}.BNDDIR"
then    LINK=YES
fi

if [ "${LINK}" ]
then    rm -rf "${LIBIFSNAME}/${DYNBNDDIR}.BNDDIR"
        CMD="CRTBNDDIR BNDDIR(${TARGETLIB}/${DYNBNDDIR})"
        CMD="${CMD} TEXT('libxml2 dynamic binding directory')"
        system "${CMD}"
        CMD="ADDBNDDIRE BNDDIR(${TARGETLIB}/${DYNBNDDIR})"
        CMD="${CMD} OBJ((*LIBL/${SRVPGM} *SRVPGM))"
        system "${CMD}"
fi

#       Compile the ASCII main() stub.

make_module     --ebcdic --sysiconv     LIBXMLMAIN  "${SCRIPTDIR}/libxmlmain.c"

#       Compile and link program xmllint.

if action_needed "${LIBIFSNAME}/XMLLINT.PGM" "xmllint.c" ||
   action_needed "${LIBIFSNAME}/XMLLINT.PGM" "${LIBIFSNAME}/${SRVPGM}.SRVPGM" ||
   action_needed "${LIBIFSNAME}/XMLLINT.PGM" "${LIBIFSNAME}/LIBXMLMAIN.MODULE"
then    make_module XMLLINT xmllint.c
        CMD="CRTPGM PGM(${TARGETLIB}/XMLLINT) MODULE(${TARGETLIB}/XMLLINT)"
        CMD="${CMD} ENTMOD(${TARGETLIB}/LIBXMLMAIN)"
        CMD="${CMD} BNDSRVPGM(QADRTTS) BNDDIR((${TARGETLIB}/${STATBNDDIR})"
        if [ "${WITH_ZLIB}" -ne 0 ]
        then    CMD="${CMD} (${ZLIB_LIB}/${ZLIB_BNDDIR})"
        fi
        CMD="${CMD}) ACTGRP(*NEW) TEXT('XML tool')"
        CMD="${CMD} TGTRLS(${TGTRLS})"
        system "${CMD}"
        rm -f "${LIBIFSNAME}/XMLLINT.MODULE"
fi

#       Install xmllint in IFS.

if [ ! -d "${IFSDIR}/bin" ]
then    mkdir -p "${IFSDIR}/bin"
fi
rm -f "${IFSDIR}/bin/xmllint"
ln -s "${LIBIFSNAME}/XMLLINT.PGM" "${IFSDIR}/bin/xmllint"

#       Prepare the XMLLINT command and its response program.

if action_needed "${LIBIFSNAME}/XMLLINTCL.PGM" "${SCRIPTDIR}/xmllintcl.c"
then    make_module --ebcdic XMLLINTCL "${SCRIPTDIR}/xmllintcl.c"
        CMD="CRTPGM PGM(${TARGETLIB}/XMLLINTCL) MODULE(${TARGETLIB}/XMLLINTCL)"
        CMD="${CMD} ACTGRP(*NEW) TEXT('XMLLINT command response')"
        CMD="${CMD} TGTRLS(${TGTRLS})"
        system "${CMD}"
        rm -f "${LIBIFSNAME}/XMLLINTCL.MODULE"
fi

if action_needed "${LIBIFSNAME}/TOOLS.FILE/XMLLINT.MBR"                 \
                 "${SCRIPTDIR}/xmllint.cmd"
then    CMD="CPY OBJ('${SCRIPTDIR}/xmllint.cmd')"
        CMD="${CMD} TOOBJ('${LIBIFSNAME}/TOOLS.FILE/XMLLINT.MBR')"
        CMD="${CMD} TOCCSID(${TGTCCSID}) DTAFMT(*TEXT) REPLACE(*YES)"
        system "${CMD}"
fi

if action_needed "${LIBIFSNAME}/XMLLINT.CMD"                            \
                 "${LIBIFSNAME}/TOOLS.FILE/XMLLINT.MBR"
then    CMD="CRTCMD CMD(${TARGETLIB}/XMLLINT) PGM(${TARGETLIB}/XMLLINTCL)"
        CMD="${CMD} SRCFILE(${TARGETLIB}/TOOLS) SRCMBR(XMLLINT) THDSAFE(*YES)"
        CMD="${CMD} TEXT('XML tool') REPLACE(*YES)"
        system "${CMD}"
fi

#       Compile and link program xmlcatalog.

if action_needed "${LIBIFSNAME}/XMLCATALOG.PGM" "xmlcatalog.c" ||
   action_needed "${LIBIFSNAME}/XMLCATALOG.PGM"                         \
                 "${LIBIFSNAME}/${SRVPGM}.SRVPGM" ||
   action_needed "${LIBIFSNAME}/XMLCATALOG.PGM"                         \
                 "${LIBIFSNAME}/LIBXMLMAIN.MODULE"
then    make_module XMLCATALOG xmlcatalog.c
        CMD="CRTPGM PGM(${TARGETLIB}/XMLCATALOG)"
        CMD="${CMD}  MODULE(${TARGETLIB}/XMLCATALOG)"
        CMD="${CMD} ENTMOD(${TARGETLIB}/LIBXMLMAIN)"
        CMD="${CMD} BNDSRVPGM(QADRTTS) BNDDIR((${TARGETLIB}/${STATBNDDIR})"
        if [ "${WITH_ZLIB}" -ne 0 ]
        then    CMD="${CMD} (${ZLIB_LIB}/${ZLIB_BNDDIR})"
        fi
        CMD="${CMD}) ACTGRP(*NEW) TEXT('XML/SGML catalog tool')"
        CMD="${CMD} TGTRLS(${TGTRLS})"
        system "${CMD}"
        rm -f "${LIBIFSNAME}/XMLCATALOG.MODULE"
fi

#       Install xmlcatalog in IFS.

rm -f "${IFSDIR}/bin/xmlcatalog"
ln -s "${LIBIFSNAME}/XMLCATALOG.PGM" "${IFSDIR}/bin/xmlcatalog"

#       Prepare the XMLCATALOG command and its response program.

if action_needed "${LIBIFSNAME}/XMLCATLGCL.PGM" "${SCRIPTDIR}/xmlcatlgcl.c"
then    make_module --ebcdic XMLCATLGCL "${SCRIPTDIR}/xmlcatlgcl.c"
        CMD="CRTPGM PGM(${TARGETLIB}/XMLCATLGCL)"
        CMD="${CMD} MODULE(${TARGETLIB}/XMLCATLGCL)"
        CMD="${CMD} ACTGRP(*NEW) TEXT('XMLCATALOG command response')"
        CMD="${CMD} TGTRLS(${TGTRLS})"
        system "${CMD}"
        rm -f "${LIBIFSNAME}/XMLCATLGCL.MODULE"
fi

if action_needed "${LIBIFSNAME}/TOOLS.FILE/XMLCATALOG.MBR"              \
                 "${SCRIPTDIR}/xmlcatalog.cmd"
then    CMD="CPY OBJ('${SCRIPTDIR}/xmlcatalog.cmd')"
        CMD="${CMD} TOOBJ('${LIBIFSNAME}/TOOLS.FILE/XMLCATALOG.MBR')"
        CMD="${CMD} TOCCSID(${TGTCCSID}) DTAFMT(*TEXT) REPLACE(*YES)"
        system "${CMD}"
fi

if action_needed "${LIBIFSNAME}/XMLCATALOG.CMD"                         \
                 "${LIBIFSNAME}/TOOLS.FILE/XMLCATALOG.MBR"
then    CMD="CRTCMD CMD(${TARGETLIB}/XMLCATALOG) PGM(${TARGETLIB}/XMLCATLGCL)"
        CMD="${CMD} SRCFILE(${TARGETLIB}/TOOLS) SRCMBR(XMLCATALOG)"
        CMD="${CMD} THDSAFE(*YES) TEXT('XML/SGML catalog tool') REPLACE(*YES)"
        system "${CMD}"
fi


#!/bin/sh
#
#       libxml2 compilation script for the OS/400.
#       This is a shell script since make is not a standard component of OS/400.
#
#       See Copyright for the status of this software.
#
#       Author: Patrick Monnerat <pm@datasphere.ch>, DATASPHERE S.A.
#

SCRIPTDIR=`dirname "${0}"`
. "${SCRIPTDIR}/initscript.sh"
cd "${TOPDIR}"

#       Create the OS/400 library if it does not exist.

if action_needed "${LIBIFSNAME}"
then    CMD="CRTLIB LIB(${TARGETLIB})"
        CMD="${CMD} TEXT('libxml2: XML parser and toolkit API')"
        system "${CMD}"
fi

#       Create the DOCS source file if it does not exist.

if action_needed "${LIBIFSNAME}/DOCS.FILE"
then    CMD="CRTSRCPF FILE(${TARGETLIB}/DOCS) RCDLEN(112)"
        CMD="${CMD} CCSID(${TGTCCSID}) TEXT('Documentation texts')"
        system "${CMD}"
fi

#       Copy some documentation files if needed.

for TEXT in "${TOPDIR}/AUTHORS" "${TOPDIR}/ChangeLog"                   \
    "${TOPDIR}/Copyright" "${TOPDIR}/CONTRIBUTING" "${TOPDIR}/README"        \
    "${TOPDIR}/MAINTAINERS" "${TOPDIR}/NEWS" "${TOPDIR}/TODO"           \
    "${TOPDIR}/TODO_SCHEMAS" "${TOPDIR}/os400/README400"
do      if [ -f "${TEXT}" ]
        then    MEMBER="`basename \"${TEXT}\" .OS400`"
                MEMBER="${LIBIFSNAME}/DOCS.FILE/`db2_name \"${MEMBER}\"`.MBR"

                if action_needed "${MEMBER}" "${TEXT}"
                then    # Sources are in UTF-8.
                        rm -f "${TOPDIR}/tmpfile"[12]
                        CMD="CPY OBJ('${TEXT}') TOOBJ('${TOPDIR}/tmpfile1')"
                        CMD="${CMD} FROMCCSID(1208) TOCCSID(${TGTCCSID})"
                        CMD="${CMD} DTAFMT(*TEXT) REPLACE(*YES)"
                        system "${CMD}"
                        # Make sure all lines are < 100 characters.
                        sed -e 's/.\{99\}/&\
/g' -e 's/\n$//' "${TOPDIR}/tmpfile1" > "${TOPDIR}/tmpfile2"
                        CMD="CPY OBJ('${TOPDIR}/tmpfile2') TOOBJ('${MEMBER}')"
                        CMD="${CMD} TOCCSID(${TGTCCSID})"
                        CMD="${CMD} DTAFMT(*TEXT) REPLACE(*YES)"
                        system "${CMD}"
                fi
        fi
done

#       Build files from template.

configFile()

{
        args=`set | sed -e '/^[A-Za-z_][A-Za-z0-9_]*=/!d'               \
                        -e 's/[\/\\\\&]/\\\\&/g'                        \
                        -e "s/'/'\\\\\\''/g"                            \
                        -e 's/^\([^=]*\)=\(.*\)$/-e '\''s\/@\1@\/\2\/g'\'/`
        eval sed ${args} < "${1}".in > "${1}"
}

configFile include/libxml/xmlversion.h
configFile os400/os400config.h
mv os400/os400config.h config.h

#       Build in each directory.

for SUBDIR in include rpg src
do      "${SCRIPTDIR}/make-${SUBDIR}.sh"
done


LIBXML2=$1
TARGETCPU=$2
TARGETTYPE=$3

if [ -z "$2" ]; then
	TARGETCPU=SIMPENTIUMgnu
fi

if [ -z "$3" ]; then
	TARGETTYPE=RTP
fi

echo "LIBXML2 Version:     ${LIBXML2}"
echo "LIBXML2 Target CPU:  ${TARGETCPU}"
echo "LIBXML2 Target Type: ${TARGETTYPE}"

rm -fR src
tar xvzf ${LIBXML2}.tar.gz
mv ${LIBXML2} src
cd src

./configure --with-minimum --with-reader --with-writer --with-regexps --with-threads --with-thread-alloc

find . -name '*.in' -exec rm -fR {} +
find . -name '*.am' -exec rm -fR {} +
rm -fR *.m4
rm -fR *.pc
rm -fR *.pl
rm -fR *.py
rm -fR *.spec
rm -fR .deps
rm -fR AUTHORS
rm -fR bakefile
rm -fR ChangeLog
rm -fR config.guess
rm -fR config.log
rm -fR config.status
rm -fR config.stub
rm -fR config.sub
rm -fR configure
rm -fR COPYING
rm -fR Copyright
rm -fR depcomp
rm -fR doc
rm -fR example
rm -fR INSTALL
rm -fR install-sh
rm -fR libxml.3
rm -fR ltmain.sh
rm -fR Makefile
rm -fR Makefile.tests
rm -fR macos
rm -fR mkinstalldirs
rm -fR missing
rm -fR nanoftp.c
rm -fR nanohttp.c
rm -fR NEWS
rm -fR python
rm -fR README
rm -fR README.tests
rm -fR regressions.xml
rm -fR result
rm -fR runsuite.c
rm -fR runtest.c
rm -fR test
rm -fR test*.c
rm -fR TODO*
rm -fR trio*
rm -fR vms
rm -fR win32
rm -fR xml2*
rm -fR xmllint.c
rm -fR xstc

cd ..

make clean all VXCPU=${TARGETCPU} VXTYPE=${TARGETTYPE}

if [ "${TARGETTYPE}" = "RTP" ]; then
	cp libxml2.so ../../lib/.
else
	cp xml2.out ../../bin/.
fi

cp -R src/include/libxml ../../include/.


#!/bin/sh
# Run this to generate all the initial makefiles, etc.

srcdir=`dirname $0`
test -z "$srcdir" && srcdir=.

THEDIR=`pwd`
cd $srcdir
DIE=0

(autoconf --version) < /dev/null > /dev/null 2>&1 || {
	echo
	echo "You must have autoconf installed to compile libxml."
	echo "Download the appropriate package for your distribution,"
	echo "or see http://www.gnu.org/software/autoconf"
	DIE=1
}

(libtoolize --version) < /dev/null > /dev/null 2>&1 ||
(glibtoolize --version) < /dev/null > /dev/null 2>&1 || {
	echo
	echo "You must have libtool installed to compile libxml."
	echo "Download the appropriate package for your distribution,"
	echo "or see http://www.gnu.org/software/libtool"
	DIE=1
}

(automake --version) < /dev/null > /dev/null 2>&1 || {
	echo
	DIE=1
	echo "You must have automake installed to compile libxml."
	echo "Download the appropriate package for your distribution,"
	echo "or see http://www.gnu.org/software/automake"
}

if test "$DIE" -eq 1; then
	exit 1
fi

test -f entities.c || {
	echo "You must run this script in the top-level libxml directory"
	exit 1
}

EXTRA_ARGS=
if test "x$1" = "x--system"; then
    shift
    prefix=/usr
    libdir=$prefix/lib
    sysconfdir=/etc
    localstatedir=/var
    if [ -d /usr/lib64 ]; then
      libdir=$prefix/lib64
    fi
    EXTRA_ARGS="--prefix=$prefix --sysconfdir=$sysconfdir --localstatedir=$localstatedir --libdir=$libdir"
    echo "Running ./configure with $EXTRA_ARGS $@"
else
    if test -z "$NOCONFIGURE" && test -z "$*"; then
        echo "I am going to run ./configure with no arguments - if you wish "
        echo "to pass any to it, please specify them on the $0 command line."
    fi
fi

if [ ! -d $srcdir/m4 ]; then
        mkdir $srcdir/m4
fi

# Replaced by autoreconf below
autoreconf -if -Wall

if ! grep -q pkg.m4 aclocal.m4; then
    cat <<EOF

Couldn't find pkg.m4 from pkg-config. Install the appropriate package for
your distribution or set ACLOCAL_PATH to the directory containing pkg.m4.
EOF
    exit 1
fi

cd $THEDIR

if test x$OBJ_DIR != x; then
    mkdir -p "$OBJ_DIR"
    cd "$OBJ_DIR"
fi

if test -z "$NOCONFIGURE"; then
    $srcdir/configure $EXTRA_ARGS "$@"
    if test "$?" -ne 0; then
        echo
        echo "Configure script failed, check config.log for more info."
    else
        echo
        echo "Now type 'make' to compile libxml2."
    fi
fi


#!/bin/sh

OPENSSL=../../apps/openssl
OPENSSL_CONF=../../apps/openssl.cnf
export OPENSSL_CONF

# Root CA: create certificate directly
CN="Test Root CA" $OPENSSL req -config ca.cnf -x509 -nodes \
	-keyout root.pem -out root.pem -newkey rsa:2048 -days 3650
# Intermediate CA: request first
CN="Test Intermediate CA" $OPENSSL req -config ca.cnf -nodes \
	-keyout intkey.pem -out intreq.pem -newkey rsa:2048
# Sign request: CA extensions
$OPENSSL x509 -req -in intreq.pem -CA root.pem -days 3600 \
	-extfile ca.cnf -extensions v3_ca -CAcreateserial -out intca.pem

# Server certificate: create request first
CN="Test Server Cert" $OPENSSL req -config ca.cnf -nodes \
	-keyout skey.pem -out req.pem -newkey rsa:1024
# Sign request: end entity extensions
$OPENSSL x509 -req -in req.pem -CA intca.pem -CAkey intkey.pem -days 3600 \
	-extfile ca.cnf -extensions usr_cert -CAcreateserial -out server.pem

# Client certificate: request first
CN="Test Client Cert" $OPENSSL req -config ca.cnf -nodes \
	-keyout ckey.pem -out creq.pem -newkey rsa:1024
# Sign using intermediate CA
$OPENSSL x509 -req -in creq.pem -CA intca.pem -CAkey intkey.pem -days 3600 \
	-extfile ca.cnf -extensions usr_cert -CAcreateserial -out client.pem

# Revoked certificate: request first
CN="Test Revoked Cert" $OPENSSL req -config ca.cnf -nodes \
	-keyout revkey.pem -out rreq.pem -newkey rsa:1024
# Sign using intermediate CA
$OPENSSL x509 -req -in rreq.pem -CA intca.pem -CAkey intkey.pem -days 3600 \
	-extfile ca.cnf -extensions usr_cert -CAcreateserial -out rev.pem

# OCSP responder certificate: request first
CN="Test OCSP Responder Cert" $OPENSSL req -config ca.cnf -nodes \
	-keyout respkey.pem -out respreq.pem -newkey rsa:1024
# Sign using intermediate CA and responder extensions
$OPENSSL x509 -req -in respreq.pem -CA intca.pem -CAkey intkey.pem -days 3600 \
	-extfile ca.cnf -extensions ocsp_cert -CAcreateserial -out resp.pem

# Example creating a PKCS#3 DH certificate.

# First DH parameters

[ -f dhp.pem ] || $OPENSSL genpkey -genparam -algorithm DH -pkeyopt dh_paramgen_prime_len:1024 -out dhp.pem

# Now a DH private key
$OPENSSL genpkey -paramfile dhp.pem -out dhskey.pem
# Create DH public key file
$OPENSSL pkey -in dhskey.pem -pubout -out dhspub.pem
# Certificate request, key just reuses old one as it is ignored when the
# request is signed.
CN="Test Server DH Cert" $OPENSSL req -config ca.cnf -new \
	-key skey.pem -out dhsreq.pem
# Sign request: end entity DH extensions
$OPENSSL x509 -req -in dhsreq.pem -CA root.pem -days 3600 \
	-force_pubkey dhspub.pem \
	-extfile ca.cnf -extensions dh_cert -CAcreateserial -out dhserver.pem

# DH client certificate

$OPENSSL genpkey -paramfile dhp.pem -out dhckey.pem
$OPENSSL pkey -in dhckey.pem -pubout -out dhcpub.pem
CN="Test Client DH Cert" $OPENSSL req -config ca.cnf -new \
	-key skey.pem -out dhcreq.pem
$OPENSSL x509 -req -in dhcreq.pem -CA root.pem -days 3600 \
	-force_pubkey dhcpub.pem \
	-extfile ca.cnf -extensions dh_cert -CAcreateserial -out dhclient.pem

# Examples of CRL generation without the need to use 'ca' to issue
# certificates.
# Create zero length index file
>index.txt
# Create initial crl number file
echo 01 >crlnum.txt
# Add entries for server and client certs
$OPENSSL ca -valid server.pem -keyfile root.pem -cert root.pem \
		-config ca.cnf -md sha1
$OPENSSL ca -valid client.pem -keyfile root.pem -cert root.pem \
		-config ca.cnf -md sha1
$OPENSSL ca -valid rev.pem -keyfile root.pem -cert root.pem \
		-config ca.cnf -md sha1
# Generate a CRL.
$OPENSSL ca -gencrl -keyfile root.pem -cert root.pem -config ca.cnf \
		-md sha1 -crldays 1 -out crl1.pem
# Revoke a certificate
openssl ca -revoke rev.pem -crl_reason superseded \
		-keyfile root.pem -cert root.pem -config ca.cnf -md sha1
# Generate another CRL
$OPENSSL ca -gencrl -keyfile root.pem -cert root.pem -config ca.cnf \
		-md sha1 -crldays 1 -out crl2.pem


# Example querying OpenSSL test responder. Assumes ocsprun.sh has been
# called.

OPENSSL=../../apps/openssl
OPENSSL_CONF=../../apps/openssl.cnf
export OPENSSL_CONF

# Send responder queries for each certificate.

echo "Requesting OCSP status for each certificate"
$OPENSSL ocsp -issuer intca.pem -cert client.pem -CAfile root.pem \
			-url http://127.0.0.1:8888/
$OPENSSL ocsp -issuer intca.pem -cert server.pem -CAfile root.pem \
			-url http://127.0.0.1:8888/
$OPENSSL ocsp -issuer intca.pem -cert rev.pem -CAfile root.pem \
			-url http://127.0.0.1:8888/
# One query for all three certificates.
echo "Requesting OCSP status for three certificates in one request"
$OPENSSL ocsp -issuer intca.pem \
	-cert client.pem -cert server.pem -cert rev.pem \
	-CAfile root.pem -url http://127.0.0.1:8888/


# Example of running an querying OpenSSL test OCSP responder.
# This assumes "mkcerts.sh" or similar has been run to set up the
# necessary file structure.

OPENSSL=../../apps/openssl
OPENSSL_CONF=../../apps/openssl.cnf
export OPENSSL_CONF

# Run OCSP responder.

PORT=8888

$OPENSSL ocsp -port $PORT -index index.txt -CA intca.pem \
	-rsigner resp.pem -rkey respkey.pem -rother intca.pem $*


#!/bin/sh

# Recreate the demo certificates in the apps directory.

OPENSSL=openssl

# Root CA: create certificate directly
CN="OpenSSL Test Root CA" $OPENSSL req -config apps.cnf -x509 -nodes \
	-keyout root.pem -out root.pem -key rootkey.pem -new -days 3650
# Intermediate CA: request first
CN="OpenSSL Test Intermediate CA" $OPENSSL req -config apps.cnf -nodes \
	-key intkey.pem -out intreq.pem -new
# Sign request: CA extensions
$OPENSSL x509 -req -in intreq.pem -CA root.pem -CAkey rootkey.pem -days 3630 \
	-extfile apps.cnf -extensions v3_ca -CAcreateserial -out intca.pem
# Client certificate: request first
CN="Test Client Cert" $OPENSSL req -config apps.cnf -nodes \
	-key ckey.pem -out creq.pem -new
# Sign using intermediate CA
$OPENSSL x509 -req -in creq.pem -CA intca.pem -CAkey intkey.pem -days 3600 \
	-extfile apps.cnf -extensions usr_cert -CAcreateserial | \
	$OPENSSL x509 -nameopt oneline -subject -issuer >client.pem
# Server certificate: request first
CN="Test Server Cert" $OPENSSL req -config apps.cnf -nodes \
	-key skey.pem -out sreq.pem -new
# Sign using intermediate CA
$OPENSSL x509 -req -in sreq.pem -CA intca.pem -CAkey intkey.pem -days 3600 \
	-extfile apps.cnf -extensions usr_cert -CAcreateserial | \
	$OPENSSL x509 -nameopt oneline -subject -issuer >server.pem
# Server certificate #2: request first
CN="Test Server Cert #2" $OPENSSL req -config apps.cnf -nodes \
	-key skey2.pem -out sreq2.pem -new
# Sign using intermediate CA
$OPENSSL x509 -req -in sreq2.pem -CA intca.pem -CAkey intkey.pem -days 3600 \
	-extfile apps.cnf -extensions usr_cert -CAcreateserial | \
	$OPENSSL x509 -nameopt oneline -subject -issuer >server2.pem

# Append keys to file.

cat skey.pem >>server.pem
cat skey2.pem >>server2.pem
cat ckey.pem >>client.pem

$OPENSSL verify -CAfile root.pem -untrusted intca.pem \
				server2.pem server.pem client.pem


# Create certificates using various algorithms to test multi-certificate
# functionality.

OPENSSL=../../../apps/openssl
CN="OpenSSL Test RSA SHA-1 cert" $OPENSSL req \
	-config apps.cnf -extensions usr_cert -x509 -nodes \
	-keyout tsha1.pem -out tsha1.pem -new -days 3650 -sha1
CN="OpenSSL Test RSA SHA-256 cert" $OPENSSL req \
	-config apps.cnf -extensions usr_cert -x509 -nodes \
	-keyout tsha256.pem -out tsha256.pem -new -days 3650 -sha256
CN="OpenSSL Test RSA SHA-512 cert" $OPENSSL req \
	-config apps.cnf -extensions usr_cert -x509 -nodes \
	-keyout tsha512.pem -out tsha512.pem -new -days 3650 -sha512

# Create EC parameters

$OPENSSL ecparam -name P-256 -out ecp256.pem
$OPENSSL ecparam -name P-384 -out ecp384.pem

CN="OpenSSL Test P-256 SHA-256 cert" $OPENSSL req \
	-config apps.cnf -extensions ec_cert -x509 -nodes \
	-nodes -keyout tecp256.pem -out tecp256.pem -newkey ec:ecp256.pem \
	-days 3650 -sha256

CN="OpenSSL Test P-384 SHA-384 cert" $OPENSSL req \
	-config apps.cnf -extensions ec_cert -x509 -nodes \
	-nodes -keyout tecp384.pem -out tecp384.pem -newkey ec:ecp384.pem \
	-days 3650 -sha384


#!/bin/sh -ex
#
# Copyright 2017 The OpenSSL Project Authors. All Rights Reserved.
#
# Licensed under the OpenSSL license (the "License").  You may not use
# this file except in compliance with the License.  You can obtain a copy
# in the file LICENSE in the source distribution or at
# https://www.openssl.org/source/license.html

# krb5's test suite clears LD_LIBRARY_PATH
LDFLAGS="-L`pwd`/$BLDTOP -Wl,-rpath,`pwd`/$BLDTOP"
CFLAGS="-I`pwd`/$BLDTOP/include -I`pwd`/$SRCTOP/include"

cd $SRCTOP/krb5/src
autoreconf
./configure --with-ldap --with-prng-alg=os --enable-pkinit \
            --with-crypto-impl=openssl --with-tls-impl=openssl \
            CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS"

# quiet make so that Travis doesn't overflow
make -s

make check


#!/bin/sh
#
# Copyright 2017 The OpenSSL Project Authors. All Rights Reserved.
# Copyright (c) 2017, Oracle and/or its affiliates.  All rights reserved.
#
# Licensed under the OpenSSL license (the "License").  You may not use
# this file except in compliance with the License.  You can obtain a copy
# in the file LICENSE in the source distribution or at
# https://www.openssl.org/source/license.html

#
# OpenSSL external testing using the Python Cryptography module
#
set -e

O_EXE=`pwd`/$BLDTOP/apps
O_BINC=`pwd`/$BLDTOP/include
O_SINC=`pwd`/$SRCTOP/include
O_LIB=`pwd`/$BLDTOP

export PATH=$O_EXE:$PATH
export LD_LIBRARY_PATH=$O_LIB:$LD_LIBRARY_PATH

# Check/Set openssl version
OPENSSL_VERSION=`openssl version | cut -f 2 -d ' '`

echo "------------------------------------------------------------------"
echo "Testing OpenSSL using Python Cryptography:"
echo "   CWD:                $PWD"
echo "   SRCTOP:             $SRCTOP"
echo "   BLDTOP:             $BLDTOP"
echo "   OpenSSL version:    $OPENSSL_VERSION"
echo "------------------------------------------------------------------"

cd $SRCTOP

# Create a python virtual env and activate
rm -rf venv-pycrypto
virtualenv venv-pycrypto
. ./venv-pycrypto/bin/activate

cd pyca-cryptography

pip install .[test]

echo "------------------------------------------------------------------"
echo "Building cryptography"
echo "------------------------------------------------------------------"
python ./setup.py clean

CFLAGS="-I$O_BINC -I$O_SINC -L$O_LIB" python ./setup.py build

echo "------------------------------------------------------------------"
echo "Running tests"
echo "------------------------------------------------------------------"

CFLAGS="-I$O_BINC -I$O_SINC -L$O_LIB" python ./setup.py test

cd ../
deactivate
rm -rf venv-pycrypto

exit 0


#!/bin/sh
# Copyright 2013-2016 The OpenSSL Project Authors. All Rights Reserved.
#
# Licensed under the OpenSSL license (the "License").  You may not use
# this file except in compliance with the License.  You can obtain a copy
# in the file LICENSE in the source distribution or at
# https://www.openssl.org/source/license.html

# Utility to recreate S/MIME certificates

OPENSSL=../../apps/openssl
OPENSSL_CONF=./ca.cnf
export OPENSSL_CONF

# Root CA: create certificate directly
CN="Test S/MIME RSA Root" $OPENSSL req -config ca.cnf -x509 -nodes \
	-keyout smroot.pem -out smroot.pem -newkey rsa:2048 -days 3650

# EE RSA certificates: create request first
CN="Test S/MIME EE RSA #1" $OPENSSL req -config ca.cnf -nodes \
	-keyout smrsa1.pem -out req.pem -newkey rsa:2048
# Sign request: end entity extensions
$OPENSSL x509 -req -in req.pem -CA smroot.pem -days 3600 \
	-extfile ca.cnf -extensions usr_cert -CAcreateserial >>smrsa1.pem

CN="Test S/MIME EE RSA #2" $OPENSSL req -config ca.cnf -nodes \
	-keyout smrsa2.pem -out req.pem -newkey rsa:2048
$OPENSSL x509 -req -in req.pem -CA smroot.pem -days 3600 \
	-extfile ca.cnf -extensions usr_cert -CAcreateserial >>smrsa2.pem

CN="Test S/MIME EE RSA #3" $OPENSSL req -config ca.cnf -nodes \
	-keyout smrsa3.pem -out req.pem -newkey rsa:2048
$OPENSSL x509 -req -in req.pem -CA smroot.pem -days 3600 \
	-extfile ca.cnf -extensions usr_cert -CAcreateserial >>smrsa3.pem

# Create DSA parameters

$OPENSSL dsaparam -out dsap.pem 2048

CN="Test S/MIME EE DSA #1" $OPENSSL req -config ca.cnf -nodes \
	-keyout smdsa1.pem -out req.pem -newkey dsa:dsap.pem
$OPENSSL x509 -req -in req.pem -CA smroot.pem -days 3600 \
	-extfile ca.cnf -extensions usr_cert -CAcreateserial >>smdsa1.pem
CN="Test S/MIME EE DSA #2" $OPENSSL req -config ca.cnf -nodes \
	-keyout smdsa2.pem -out req.pem -newkey dsa:dsap.pem
$OPENSSL x509 -req -in req.pem -CA smroot.pem -days 3600 \
	-extfile ca.cnf -extensions usr_cert -CAcreateserial >>smdsa2.pem
CN="Test S/MIME EE DSA #3" $OPENSSL req -config ca.cnf -nodes \
	-keyout smdsa3.pem -out req.pem -newkey dsa:dsap.pem
$OPENSSL x509 -req -in req.pem -CA smroot.pem -days 3600 \
	-extfile ca.cnf -extensions usr_cert -CAcreateserial >>smdsa3.pem

# Create EC parameters

$OPENSSL ecparam -out ecp.pem -name P-256
$OPENSSL ecparam -out ecp2.pem -name K-283

CN="Test S/MIME EE EC #1" $OPENSSL req -config ca.cnf -nodes \
	-keyout smec1.pem -out req.pem -newkey ec:ecp.pem
$OPENSSL x509 -req -in req.pem -CA smroot.pem -days 3600 \
	-extfile ca.cnf -extensions usr_cert -CAcreateserial >>smec1.pem
CN="Test S/MIME EE EC #2" $OPENSSL req -config ca.cnf -nodes \
	-keyout smec2.pem -out req.pem -newkey ec:ecp2.pem
$OPENSSL x509 -req -in req.pem -CA smroot.pem -days 3600 \
	-extfile ca.cnf -extensions usr_cert -CAcreateserial >>smec2.pem
CN="Test S/MIME EE EC #3" $OPENSSL req -config ca.cnf -nodes \
	-keyout smec3.pem -out req.pem -newkey ec:ecp.pem
$OPENSSL x509 -req -in req.pem -CA smroot.pem -days 3600 \
	-extfile ca.cnf -extensions usr_cert -CAcreateserial >>smec3.pem
# Create X9.42 DH parameters.
$OPENSSL genpkey -genparam -algorithm DH -pkeyopt dh_paramgen_type:2 \
	-out dhp.pem
# Generate X9.42 DH key.
$OPENSSL genpkey -paramfile dhp.pem -out smdh.pem
$OPENSSL pkey -pubout -in smdh.pem -out dhpub.pem
# Generate dummy request.
CN="Test S/MIME EE DH #1" $OPENSSL req -config ca.cnf -nodes \
	-keyout smtmp.pem -out req.pem -newkey rsa:2048
# Sign request but force public key to DH
$OPENSSL x509 -req -in req.pem -CA smroot.pem -days 3600 \
	-force_pubkey dhpub.pem \
	-extfile ca.cnf -extensions usr_cert -CAcreateserial >>smdh.pem
# Remove temp files.
rm -f req.pem ecp.pem ecp2.pem dsap.pem dhp.pem dhpub.pem smtmp.pem smroot.srl


#!/bin/sh

HERE="`echo $0 | sed -e 's|[^/]*$||'`"
OPENSSL="${HERE}../apps/openssl"

if [ -d "${HERE}../engines" -a "x$OPENSSL_ENGINES" = "x" ]; then
	OPENSSL_ENGINES="${HERE}../engines"; export OPENSSL_ENGINES
fi

if [ -x "${OPENSSL}.exe" ]; then
	# The original reason for this script existence is to work around
	# certain caveats in run-time linker behaviour. On Windows platforms
	# adjusting $PATH used to be sufficient, but with introduction of
	# SafeDllSearchMode in XP/2003 the only way to get it right in
	# *all* possible situations is to copy newly built .DLLs to apps/
	# and test/, which is now done elsewhere... The $PATH is adjusted
	# for backward compatibility (and nostagical reasons:-).
	if [ "$OSTYPE" != msdosdjgpp ]; then
		PATH="${HERE}..:$PATH"; export PATH
	fi
	exec "${OPENSSL}.exe" "$@"
elif [ -x "${OPENSSL}" -a -x "${HERE}shlib_wrap.sh" ]; then
	exec "${HERE}shlib_wrap.sh" "${OPENSSL}" "$@"
else
	exec "${OPENSSL}" "$@"	# hope for the best...
fi