1#!/bin/sh 2# 3# libssh2 compilation script for the OS/400. 4# 5 6SCRIPTDIR=`dirname "${0}"` 7. "${SCRIPTDIR}/initscript.sh" 8cd "${TOPDIR}/src" 9 10 11# Function to extract external prototypes from header files. 12# Input: concatenated header files. 13# Output: external prototypes, one per (long) line. 14 15extproto() 16{ 17 sed -e 'x;G;s/^\n//;s/\n/ /g' \ 18 -e 's#[[:space:]]*/\*[^*]*\(\*\([^/*][^*]*\)\{0,1\}\)*\*/[[:space:]]*##g' \ 19 -e 'h' \ 20 -e '/\/\*/!{' \ 21 -e '/^#/{s/^.*[^\\]$//;h;d' \ 22 -e '}' \ 23 -e 's/[{}]/;/g;s/\\$//' \ 24 -e ':loop1' \ 25 -e '/;/{' \ 26 -e 's/^[^;]*;//;x;s/;.*//' \ 27 -e '/^[[:space:]]*LIBSSH2_API[[:space:]].*(/{' \ 28 -e 's/^[[:space:]]*LIBSSH2_API[[:space:]]*//' \ 29 -e 's/[[:space:]]*$//' \ 30 -e 's/[[:space:]][[:space:]]*/ /g' \ 31 -e 'p' \ 32 -e '}' \ 33 -e 'g;bloop1' \ 34 -e '}' \ 35 -e '}' \ 36 -n 37} 38 39# Need to have IFS access to the mih/modasa header file. 40 41if action_needed modasa.mih '/QSYS.LIB/QSYSINC.LIB/MIH.FILE/MODASA.MBR' 42then rm -f modasa.mih 43 ln -s '/QSYS.LIB/QSYSINC.LIB/MIH.FILE/MODASA.MBR' modasa.mih 44fi 45 46 47# Create and compile the identification source file. 48 49echo '#pragma comment(user, "libssh2 version '"${LIBSSH2_VERSION}"'")' > os400.c 50echo '#pragma comment(user, __DATE__)' >> os400.c 51echo '#pragma comment(user, __TIME__)' >> os400.c 52echo '#pragma comment(copyright, "See COPYING file. OS/400 version by P. Monnerat")' >> os400.c 53make_module OS400 os400.c 54LINK= # No need to rebuild service program yet. 55MODULES= 56 57 58# Generate the procedures implementing macros. 59 60if action_needed macros.c "${TOPDIR}/os400/macros.h" 61then ( 62 echo '#include "libssh2_publickey.h"' 63 echo '#include "libssh2_sftp.h"' 64 extproto < "${TOPDIR}/os400/macros.h" | 65 sed -e 'h;s/^[^(]*[ *]\([^ (]*\) *(.*/\1/' \ 66 -e 's/.*/#pragma map(_&, "&")/;p' \ 67 -e 'g;s/^\([^(]*[ *]\)\([^ (]*\)\( *(.*\)/\1_\2\3 {/;p' \ 68 -e 'g;s/^[^(]*(\(.*\))$/,\1,/;s/[^A-Za-z0-9_,]/ /g' \ 69 -e 's/ *,/,/g;s/,[^,]* \([^ ,]*\)/,\1/g' \ 70 -e 's/ //g;s/^,void,$/,,/' \ 71 -e 's/^,\(.*\),$/(\1); }/;s/,/, /g' \ 72 -e 'x;s/(.*//;s/ *$//;G;s/\n//g' \ 73 -e 's/^void\([ *]\)/\1/;s/^ *//' \ 74 -e 's/^[^(]*[ *]\([A-Za-z][A-Za-z0-9_]* *(\)/return \1/' \ 75 -e 's/.*/ &/' 76 ) > macros.c 77fi 78 79# Get source list. 80 81cat ../Makefile.inc ../Makefile.os400qc3.inc | 82 sed -e ':begin' \ 83 -e '/\\$/{' \ 84 -e 's/\\$/ /' \ 85 -e 'N' \ 86 -e 'bbegin' \ 87 -e '}' \ 88 -e 's/\n//g' \ 89 -e 's/[[:space:]]*$//' \ 90 -e 's/^\([A-Za-z][A-Za-z0-9_]*\)[[:space:]]*=[[:space:]]*\(.*\)/\1="\2"/' \ 91 -e 's/\$(\([A-Za-z][A-Za-z0-9_]*\))/${\1}/g' \ 92 > tmpscript.sh 93. ./tmpscript.sh 94 95 96# Compile the sources into modules. 97 98INCLUDES="'`pwd`'" 99 100for SRC in "${TOPDIR}/os400/os400sys.c" "${TOPDIR}/os400/ccsid.c" \ 101 ${CSOURCES} ${CRYPTO_CSOURCES} macros.c 102do MODULE=`db2_name "${SRC}"` 103 make_module "${MODULE}" "${SRC}" 104done 105 106 107# If needed, (re)create the static binding directory. 108 109if action_needed "${LIBIFSNAME}/${STATBNDDIR}.BNDDIR" 110then LINK=YES 111fi 112 113if [ "${LINK}" ] 114then rm -rf "${LIBIFSNAME}/${STATBNDDIR}.BNDDIR" 115 CMD="CRTBNDDIR BNDDIR(${TARGETLIB}/${STATBNDDIR})" 116 CMD="${CMD} TEXT('libssh2 API static binding directory')" 117 system "${CMD}" 118 119 for MODULE in ${MODULES} 120 do CMD="ADDBNDDIRE BNDDIR(${TARGETLIB}/${STATBNDDIR})" 121 CMD="${CMD} OBJ((${TARGETLIB}/${MODULE} *MODULE))" 122 system "${CMD}" 123 done 124 125# V6R1M0 does not list system service program QC3PBEXT in the 126# implicit binding directory: thus we add it here in ours. 127 128 CMD="ADDBNDDIRE BNDDIR(${TARGETLIB}/${STATBNDDIR})" 129 CMD="${CMD} OBJ((QSYS/QC3PBEXT *SRVPGM))" 130 system "${CMD}" 131fi 132 133 134# The exportation file for service program creation must be in a DB2 135# source file, so make sure it exists. 136 137if action_needed "${LIBIFSNAME}/TOOLS.FILE" 138then CMD="CRTSRCPF FILE(${TARGETLIB}/TOOLS) RCDLEN(112)" 139 CMD="${CMD} TEXT('libssh2: build tools')" 140 system "${CMD}" 141fi 142 143 144# Gather the list of symbols to export. 145 146EXPORTS=`cat "${TOPDIR}"/include/*.h "${TOPDIR}/os400/macros.h" \ 147 "${TOPDIR}/os400/libssh2_ccsid.h" | 148 extproto | 149 sed -e 's/(.*//;s/[^A-Za-z0-9_]/ /g;s/ *$//;s/^.* //'` 150 151# Create the service program exportation file in DB2 member if needed. 152 153BSF="${LIBIFSNAME}/TOOLS.FILE/BNDSRC.MBR" 154 155if action_needed "${BSF}" Makefile.am 156then LINK=YES 157fi 158 159if [ "${LINK}" ] 160then echo " STRPGMEXP PGMLVL(*CURRENT) SIGNATURE('LIBSSH2_${SONAME}')" \ 161 > "${BSF}" 162 for EXPORT in ${EXPORTS} 163 do echo ' EXPORT SYMBOL("'"${EXPORT}"'")' >> "${BSF}" 164 done 165 166 echo ' ENDPGMEXP' >> "${BSF}" 167fi 168 169 170# Build the service program if needed. 171 172if action_needed "${LIBIFSNAME}/${SRVPGM}.SRVPGM" 173then LINK=YES 174fi 175 176if [ "${LINK}" ] 177then CMD="CRTSRVPGM SRVPGM(${TARGETLIB}/${SRVPGM})" 178 CMD="${CMD} SRCFILE(${TARGETLIB}/TOOLS) SRCMBR(BNDSRC)" 179 CMD="${CMD} MODULE(${TARGETLIB}/OS400)" 180 CMD="${CMD} BNDDIR(${TARGETLIB}/${STATBNDDIR}" 181 if [ "${WITH_ZLIB}" != 0 ] 182 then CMD="${CMD} ${ZLIB_LIB}/${ZLIB_BNDDIR}" 183 liblist -a "${ZLIB_LIB}" 184 fi 185 CMD="${CMD})" 186 CMD="${CMD} BNDSRVPGM(QADRTTS)" 187 CMD="${CMD} TEXT('libssh2 API library')" 188 CMD="${CMD} TGTRLS(${TGTRLS})" 189 system "${CMD}" 190 LINK=YES 191fi 192 193 194# If needed, (re)create the dynamic binding directory. 195 196if action_needed "${LIBIFSNAME}/${DYNBNDDIR}.BNDDIR" 197then LINK=YES 198fi 199 200if [ "${LINK}" ] 201then rm -rf "${LIBIFSNAME}/${DYNBNDDIR}.BNDDIR" 202 CMD="CRTBNDDIR BNDDIR(${TARGETLIB}/${DYNBNDDIR})" 203 CMD="${CMD} TEXT('libssh2 API dynamic binding directory')" 204 system "${CMD}" 205 CMD="ADDBNDDIRE BNDDIR(${TARGETLIB}/${DYNBNDDIR})" 206 CMD="${CMD} OBJ((*LIBL/${SRVPGM} *SRVPGM))" 207 system "${CMD}" 208fi 209