1#!/bin/sh 2 3 4setenv() 5 6{ 7 # Define and export. 8 9 eval ${1}="${2}" 10 export ${1} 11} 12 13 14case "${SCRIPTDIR}" in 15/*) ;; 16*) SCRIPTDIR="`pwd`/${SCRIPTDIR}" 17esac 18 19while true 20do case "${SCRIPTDIR}" in 21 */.) SCRIPTDIR="${SCRIPTDIR%/.}";; 22 *) break;; 23 esac 24done 25 26# The script directory is supposed to be in $TOPDIR/os400. 27 28TOPDIR=`dirname "${SCRIPTDIR}"` 29export SCRIPTDIR TOPDIR 30 31# Extract the SONAME from the library makefile. 32 33SONAME=`sed -e '/^VERSION=/!d' -e 's/^.* \([0-9]*\):.*$/\1/' -e 'q' \ 34 < "${TOPDIR}/src/Makefile.am"` 35export SONAME 36 37 38################################################################################ 39# 40# Tunable configuration parameters. 41# 42################################################################################ 43 44setenv TARGETLIB 'LIBSSH2' # Target OS/400 program library. 45setenv STATBNDDIR 'LIBSSH2_A' # Static binding directory. 46setenv DYNBNDDIR 'LIBSSH2' # Dynamic binding directory. 47setenv SRVPGM "LIBSSH2.${SONAME}" # Service program. 48setenv TGTCCSID '500' # Target CCSID of objects. 49setenv DEBUG '*ALL' # Debug level. 50setenv OPTIMIZE '10' # Optimisation level 51setenv OUTPUT '*NONE' # Compilation output option. 52setenv TGTRLS 'V6R1M0' # Target OS release. 53setenv IFSDIR '/libssh2' # Installation IFS directory. 54 55# Define ZLIB availability and locations. 56 57setenv WITH_ZLIB 0 # Define to 1 to enable. 58setenv ZLIB_INCLUDE '/zlib/include' # ZLIB include IFS directory. 59setenv ZLIB_LIB 'ZLIB' # ZLIB library. 60setenv ZLIB_BNDDIR 'ZLIB_A' # ZLIB binding directory. 61 62 63################################################################################ 64 65# Need to get the version definitions. 66 67LIBSSH2_VERSION=`grep '^#define *LIBSSH2_VERSION ' \ 68 "${TOPDIR}/include/libssh2.h" | 69 sed 's/.*"\(.*\)".*/\1/'` 70LIBSSH2_VERSION_MAJOR=`grep '^#define *LIBSSH2_VERSION_MAJOR ' \ 71 "${TOPDIR}/include/libssh2.h" | 72 sed 's/^#define *LIBSSH2_VERSION_MAJOR *\([^ ]*\).*/\1/'` 73LIBSSH2_VERSION_MINOR=`grep '^#define *LIBSSH2_VERSION_MINOR ' \ 74 "${TOPDIR}/include/libssh2.h" | 75 sed 's/^#define *LIBSSH2_VERSION_MINOR *\([^ ]*\).*/\1/'` 76LIBSSH2_VERSION_PATCH=`grep '^#define *LIBSSH2_VERSION_PATCH ' \ 77 "${TOPDIR}/include/libssh2.h" | 78 sed 's/^#define *LIBSSH2_VERSION_PATCH *\([^ ]*\).*/\1/'` 79LIBSSH2_VERSION_NUM=`grep '^#define *LIBSSH2_VERSION_NUM ' \ 80 "${TOPDIR}/include/libssh2.h" | 81 sed 's/^#define *LIBSSH2_VERSION_NUM *0x\([^ ]*\).*/\1/'` 82LIBSSH2_TIMESTAMP=`grep '^#define *LIBSSH2_TIMESTAMP ' \ 83 "${TOPDIR}/include/libssh2.h" | 84 sed 's/.*"\(.*\)".*/\1/'` 85export LIBSSH2_VERSION 86export LIBSSH2_VERSION_MAJOR LIBSSH2_VERSION_MINOR LIBSSH2_VERSION_PATCH 87export LIBSSH2_VERSION_NUM LIBSSH2_TIMESTAMP 88 89################################################################################ 90# 91# OS/400 specific definitions. 92# 93################################################################################ 94 95LIBIFSNAME="/QSYS.LIB/${TARGETLIB}.LIB" 96 97 98################################################################################ 99# 100# Procedures. 101# 102################################################################################ 103 104# action_needed dest [src] 105# 106# dest is an object to build 107# if specified, src is an object on which dest depends. 108# 109# exit 0 (succeeds) if some action has to be taken, else 1. 110 111action_needed() 112 113{ 114 [ ! -e "${1}" ] && return 0 115 [ "${2}" ] || return 1 116 [ "${1}" -ot "${2}" ] && return 0 117 return 1 118} 119 120 121# canonicalize_path path 122# 123# Return canonicalized path as: 124# - Absolute 125# - No . or .. component. 126 127canonicalize_path() 128 129{ 130 if expr "${1}" : '^/' > /dev/null 131 then P="${1}" 132 else P="`pwd`/${1}" 133 fi 134 135 R= 136 IFSSAVE="${IFS}" 137 IFS="/" 138 139 for C in ${P} 140 do IFS="${IFSSAVE}" 141 case "${C}" in 142 .) ;; 143 ..) R=`expr "${R}" : '^\(.*/\)..*'` 144 ;; 145 ?*) R="${R}${C}/" 146 ;; 147 *) ;; 148 esac 149 done 150 151 IFS="${IFSSAVE}" 152 echo "/`expr "${R}" : '^\(.*\)/'`" 153} 154 155 156# make_module module_name source_name [additional_definitions] 157# 158# Compile source name into ASCII module if needed. 159# As side effect, append the module name to variable MODULES. 160# Set LINK to "YES" if the module has been compiled. 161 162make_module() 163 164{ 165 MODULES="${MODULES} ${1}" 166 MODIFSNAME="${LIBIFSNAME}/${1}.MODULE" 167 action_needed "${MODIFSNAME}" "${2}" || return 0; 168 SRCDIR=`dirname \`canonicalize_path "${2}"\`` 169 170 # #pragma convert has to be in the source file itself, i.e. 171 # putting it in an include file makes it only active 172 # for that include file. 173 # Thus we build a temporary file with the pragma prepended to 174 # the source file and we compile that temporary file. 175 176 echo "#line 1 \"${2}\"" > __tmpsrcf.c 177 echo "#pragma convert(819)" >> __tmpsrcf.c 178 echo "#line 1" >> __tmpsrcf.c 179 cat "${2}" >> __tmpsrcf.c 180 CMD="CRTCMOD MODULE(${TARGETLIB}/${1}) SRCSTMF('__tmpsrcf.c')" 181# CMD="${CMD} SYSIFCOPT(*IFS64IO) OPTION(*INCDIRFIRST *SHOWINC *SHOWSYS)" 182 CMD="${CMD} SYSIFCOPT(*IFS64IO) OPTION(*INCDIRFIRST)" 183 CMD="${CMD} LOCALETYPE(*LOCALE) FLAG(10)" 184 CMD="${CMD} INCDIR('${TOPDIR}/os400/include'" 185 CMD="${CMD} '/QIBM/ProdData/qadrt/include' '${TOPDIR}/include'" 186 CMD="${CMD} '${TOPDIR}/os400' '${SRCDIR}'" 187 188 if [ "${WITH_ZLIB}" != "0" ] 189 then CMD="${CMD} '${ZLIB_INCLUDE}'" 190 fi 191 192 CMD="${CMD} ${INCLUDES})" 193 CMD="${CMD} TGTCCSID(${TGTCCSID}) TGTRLS(${TGTRLS})" 194 CMD="${CMD} OUTPUT(${OUTPUT})" 195 CMD="${CMD} OPTIMIZE(${OPTIMIZE})" 196 CMD="${CMD} DBGVIEW(${DEBUG})" 197 198 DEFINES="${3}" 199 200 if [ "${WITH_ZLIB}" != "0" ] 201 then DEFINES="${DEFINES} HAVE_LIBZ LIBSSH2_HAVE_ZLIB" 202 fi 203 204 if [ "${DEFINES}" ] 205 then CMD="${CMD} DEFINE(${DEFINES})" 206 fi 207 208 system "${CMD}" 209 rm -f __tmpsrcf.c 210 LINK=YES 211} 212 213 214# Determine DB2 object name from IFS name. 215 216db2_name() 217 218{ 219 if [ "${2}" = 'nomangle' ] 220 then basename "${1}" | 221 tr 'a-z-' 'A-Z_' | 222 sed -e 's/\..*//;s/^\(.\).*\(.........\)$/\1\2/' 223 else basename "${1}" | 224 tr 'a-z-' 'A-Z_' | 225 sed -e 's/\..*//;s/^LIBSSH2_/SSH2_/' \ 226 -e 's/^\(.\).*\(.........\)$/\1\2/' \ 227 -e 's/^SPUBLICKEY$/SSH2_PKEY/' 228 fi 229} 230 231 232# Copy stream replacing version info. 233 234versioned_copy() 235 236{ 237 sed -e "s/@LIBSSH2_VERSION@/${LIBSSH2_VERSION}/g" \ 238 -e "s/@LIBSSH2_VERSION_MAJOR@/${LIBSSH2_VERSION_MAJOR}/g" \ 239 -e "s/@LIBSSH2_VERSION_MINOR@/${LIBSSH2_VERSION_MINOR}/g" \ 240 -e "s/@LIBSSH2_VERSION_PATCH@/${LIBSSH2_VERSION_PATCH}/g" \ 241 -e "s/@LIBSSH2_VERSION_NUM@/${LIBSSH2_VERSION_NUM}/g" \ 242 -e "s/@LIBSSH2_TIMESTAMP@/${LIBSSH2_TIMESTAMP}/g" 243} 244