1#!/bin/sh 2#*************************************************************************** 3# _ _ ____ _ 4# Project ___| | | | _ \| | 5# / __| | | | |_) | | 6# | (__| |_| | _ <| |___ 7# \___|\___/|_| \_\_____| 8# 9# Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al. 10# 11# This software is licensed as described in the file COPYING, which 12# you should have received as part of this distribution. The terms 13# are also available at https://curl.se/docs/copyright.html. 14# 15# You may opt to use, copy, modify, merge, publish, distribute and/or sell 16# copies of the Software, and permit persons to whom the Software is 17# furnished to do so, under the terms of the COPYING file. 18# 19# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 20# KIND, either express or implied. 21# 22# SPDX-License-Identifier: curl 23# 24########################################################################### 25 26CLcommand() 27{ 28 /usr/bin/system "${@}" || exit 1 29} 30 31setenv() 32 33{ 34 # Define and export. 35 36 eval ${1}="${2}" 37 export ${1} 38} 39 40 41case "${SCRIPTDIR}" in 42/*) ;; 43*) SCRIPTDIR="`pwd`/${SCRIPTDIR}" 44esac 45 46while true 47do case "${SCRIPTDIR}" in 48 */.) SCRIPTDIR="${SCRIPTDIR%/.}";; 49 *) break;; 50 esac 51done 52 53# The script directory is supposed to be in $TOPDIR/packages/os400. 54 55TOPDIR=`dirname "${SCRIPTDIR}"` 56TOPDIR=`dirname "${TOPDIR}"` 57export SCRIPTDIR TOPDIR 58 59# Extract the SONAME from the library makefile. 60 61SONAME=`sed -e '/^VERSIONCHANGE=/!d;s/^.*=\([0-9]*\).*/\1/' \ 62 < "${TOPDIR}/lib/Makefile.soname"` 63export SONAME 64 65# Get OS/400 configuration parameters. 66 67. "${SCRIPTDIR}/config400.default" 68if [ -f "${SCRIPTDIR}/config400.override" ] 69then . "${SCRIPTDIR}/config400.override" 70fi 71 72# Need to get the version definitions. 73 74LIBCURL_VERSION=`grep '^#define *LIBCURL_VERSION ' \ 75 "${TOPDIR}/include/curl/curlver.h" | 76 sed 's/.*"\(.*\)".*/\1/'` 77LIBCURL_VERSION_MAJOR=`grep '^#define *LIBCURL_VERSION_MAJOR ' \ 78 "${TOPDIR}/include/curl/curlver.h" | 79 sed 's/^#define *LIBCURL_VERSION_MAJOR *\([^ ]*\).*/\1/'` 80LIBCURL_VERSION_MINOR=`grep '^#define *LIBCURL_VERSION_MINOR ' \ 81 "${TOPDIR}/include/curl/curlver.h" | 82 sed 's/^#define *LIBCURL_VERSION_MINOR *\([^ ]*\).*/\1/'` 83LIBCURL_VERSION_PATCH=`grep '^#define *LIBCURL_VERSION_PATCH ' \ 84 "${TOPDIR}/include/curl/curlver.h" | 85 sed 's/^#define *LIBCURL_VERSION_PATCH *\([^ ]*\).*/\1/'` 86LIBCURL_VERSION_NUM=`grep '^#define *LIBCURL_VERSION_NUM ' \ 87 "${TOPDIR}/include/curl/curlver.h" | 88 sed 's/^#define *LIBCURL_VERSION_NUM *0x\([^ ]*\).*/\1/'` 89LIBCURL_TIMESTAMP=`grep '^#define *LIBCURL_TIMESTAMP ' \ 90 "${TOPDIR}/include/curl/curlver.h" | 91 sed 's/.*"\(.*\)".*/\1/'` 92export LIBCURL_VERSION 93export LIBCURL_VERSION_MAJOR LIBCURL_VERSION_MINOR LIBCURL_VERSION_PATCH 94export LIBCURL_VERSION_NUM LIBCURL_TIMESTAMP 95 96################################################################################ 97# 98# OS/400 specific definitions. 99# 100################################################################################ 101 102LIBIFSNAME="/QSYS.LIB/${TARGETLIB}.LIB" 103 104 105################################################################################ 106# 107# Procedures. 108# 109################################################################################ 110 111# action_needed dest [src] 112# 113# dest is an object to build 114# if specified, src is an object on which dest depends. 115# 116# exit 0 (succeeds) if some action has to be taken, else 1. 117 118action_needed() 119 120{ 121 [ ! -e "${1}" ] && return 0 122 [ "${2}" ] || return 1 123 [ "${1}" -ot "${2}" ] && return 0 124 return 1 125} 126 127 128# canonicalize_path path 129# 130# Return canonicalized path as: 131# - Absolute 132# - No . or .. component. 133 134canonicalize_path() 135 136{ 137 if expr "${1}" : '^/' > /dev/null 138 then P="${1}" 139 else P="`pwd`/${1}" 140 fi 141 142 R= 143 IFSSAVE="${IFS}" 144 IFS="/" 145 146 for C in ${P} 147 do IFS="${IFSSAVE}" 148 case "${C}" in 149 .) ;; 150 ..) R=`expr "${R}" : '^\(.*/\)..*'` 151 ;; 152 ?*) R="${R}${C}/" 153 ;; 154 *) ;; 155 esac 156 done 157 158 IFS="${IFSSAVE}" 159 echo "/`expr "${R}" : '^\(.*\)/'`" 160} 161 162 163# make_module module_name source_name [additional_definitions] 164# 165# Compile source name into ASCII module if needed. 166# As side effect, append the module name to variable MODULES. 167# Set LINK to "YES" if the module has been compiled. 168 169make_module() 170 171{ 172 MODULES="${MODULES} ${1}" 173 MODIFSNAME="${LIBIFSNAME}/${1}.MODULE" 174 action_needed "${MODIFSNAME}" "${2}" || return 0; 175 SRCDIR=`dirname \`canonicalize_path "${2}"\`` 176 177 # #pragma convert has to be in the source file itself, i.e. 178 # putting it in an include file makes it only active 179 # for that include file. 180 # Thus we build a temporary file with the pragma prepended to 181 # the source file and we compile that temporary file. 182 183 echo "#line 1 \"${2}\"" > __tmpsrcf.c 184 echo "#pragma convert(819)" >> __tmpsrcf.c 185 echo "#line 1" >> __tmpsrcf.c 186 cat "${2}" >> __tmpsrcf.c 187 CMD="CRTCMOD MODULE(${TARGETLIB}/${1}) SRCSTMF('__tmpsrcf.c')" 188 CMD="${CMD} SYSIFCOPT(*IFS64IO *ASYNCSIGNAL)" 189# CMD="${CMD} OPTION(*INCDIRFIRST *SHOWINC *SHOWSYS)" 190 CMD="${CMD} OPTION(*INCDIRFIRST)" 191 CMD="${CMD} LOCALETYPE(*LOCALE) FLAG(10)" 192 CMD="${CMD} INCDIR('${QADRTDIR}/include'" 193 CMD="${CMD} '${TOPDIR}/include/curl' '${TOPDIR}/include' '${SRCDIR}'" 194 CMD="${CMD} '${TOPDIR}/packages/OS400'" 195 196 if [ "${WITH_ZLIB}" != "0" ] 197 then CMD="${CMD} '${ZLIB_INCLUDE}'" 198 fi 199 200 if [ "${WITH_LIBSSH2}" != "0" ] 201 then CMD="${CMD} '${LIBSSH2_INCLUDE}'" 202 fi 203 204 CMD="${CMD} ${INCLUDES})" 205 CMD="${CMD} TGTCCSID(${TGTCCSID}) TGTRLS(${TGTRLS})" 206 CMD="${CMD} OUTPUT(${OUTPUT})" 207 CMD="${CMD} OPTIMIZE(${OPTIMIZE})" 208 CMD="${CMD} DBGVIEW(${DEBUG})" 209 210 DEFINES="${3} 'qadrt_use_inline'" 211 212 if [ "${WITH_ZLIB}" != "0" ] 213 then DEFINES="${DEFINES} HAVE_LIBZ" 214 fi 215 216 if [ "${WITH_LIBSSH2}" != "0" ] 217 then DEFINES="${DEFINES} USE_LIBSSH2" 218 fi 219 220 if [ "${DEFINES}" ] 221 then CMD="${CMD} DEFINE(${DEFINES})" 222 fi 223 224 CLcommand "${CMD}" 225 rm -f __tmpsrcf.c 226 LINK=YES 227} 228 229 230# Determine DB2 object name from IFS name. 231 232db2_name() 233 234{ 235 if [ "${2}" = 'nomangle' ] 236 then basename "${1}" | 237 tr 'a-z-' 'A-Z_' | 238 sed -e 's/\..*//' \ 239 -e 's/^\(.\).*\(.........\)$/\1\2/' 240 else basename "${1}" | 241 tr 'a-z-' 'A-Z_' | 242 sed -e 's/\..*//' \ 243 -e 's/^CURL_*/C/' \ 244 -e 's/^TOOL_*/T/' \ 245 -e 's/^\(.\).*\(.........\)$/\1\2/' 246 fi 247} 248 249 250# Copy IFS file replacing version info. 251 252versioned_copy() 253 254{ 255 sed -e "s/@LIBCURL_VERSION@/${LIBCURL_VERSION}/g" \ 256 -e "s/@LIBCURL_VERSION_MAJOR@/${LIBCURL_VERSION_MAJOR}/g" \ 257 -e "s/@LIBCURL_VERSION_MINOR@/${LIBCURL_VERSION_MINOR}/g" \ 258 -e "s/@LIBCURL_VERSION_PATCH@/${LIBCURL_VERSION_PATCH}/g" \ 259 -e "s/@LIBCURL_VERSION_NUM@/${LIBCURL_VERSION_NUM}/g" \ 260 -e "s/@LIBCURL_TIMESTAMP@/${LIBCURL_TIMESTAMP}/g" \ 261 < "${1}" > "${2}" 262} 263 264 265# Get definitions from a make file. 266# The `sed' statement works as follows: 267# - Join \nl-separated lines. 268# - Retain only lines that begins with "identifier =". 269# - Replace @...@ substitutions by shell variable references. 270# - Turn these lines into shell variable assignments. 271 272get_make_vars() 273 274{ 275 eval "`sed -e ': begin' \ 276 -e '/\\\\$/{' \ 277 -e 'N' \ 278 -e 's/\\\\\\n/ /' \ 279 -e 'b begin' \ 280 -e '}' \ 281 -e '/^[A-Za-z_][A-Za-z0-9_]*[[:space:]]*=/!d' \ 282 -e 's/@\\([A-Za-z0-9_]*\\)@/${\\1}/g' \ 283 -e 's/[[:space:]]*=[[:space:]]*/=/' \ 284 -e 's/=\\(.*[^[:space:]]\\)[[:space:]]*$/=\\"\\1\\"/' \ 285 -e 's/\\\$(\\([^)]*\\))/\${\\1}/g' \ 286 < \"${1}\"`" 287} 288