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 [ -n "${2}" ] || return 1 123 # shellcheck disable=SC3013 124 [ "${1}" -ot "${2}" ] && return 0 125 return 1 126} 127 128 129# canonicalize_path path 130# 131# Return canonicalized path as: 132# - Absolute 133# - No . or .. component. 134 135canonicalize_path() 136 137{ 138 if expr "${1}" : '^/' > /dev/null 139 then P="${1}" 140 else P="$(pwd)/${1}" 141 fi 142 143 R= 144 IFSSAVE="${IFS}" 145 IFS="/" 146 147 for C in ${P} 148 do IFS="${IFSSAVE}" 149 case "${C}" in 150 .) ;; 151 ..) R="$(expr "${R}" : '^\(.*/\)..*')" 152 ;; 153 ?*) R="${R}${C}/" 154 ;; 155 *) ;; 156 esac 157 done 158 159 IFS="${IFSSAVE}" 160 echo "/$(expr "${R}" : '^\(.*\)/')" 161} 162 163 164# make_module module_name source_name [additional_definitions] 165# 166# Compile source name into ASCII module if needed. 167# As side effect, append the module name to variable MODULES. 168# Set LINK to "YES" if the module has been compiled. 169 170make_module() 171 172{ 173 MODULES="${MODULES} ${1}" 174 MODIFSNAME="${LIBIFSNAME}/${1}.MODULE" 175 action_needed "${MODIFSNAME}" "${2}" || return 0; 176 SRCDIR="$(dirname "$(canonicalize_path "${2}")")" 177 178 # #pragma convert has to be in the source file itself, i.e. 179 # putting it in an include file makes it only active 180 # for that include file. 181 # Thus we build a temporary file with the pragma prepended to 182 # the source file and we compile that temporary file. 183 184 { 185 echo "#line 1 \"${2}\"" 186 echo "#pragma convert(819)" 187 echo "#line 1" 188 cat "${2}" 189 } > __tmpsrcf.c 190 CMD="CRTCMOD MODULE(${TARGETLIB}/${1}) SRCSTMF('__tmpsrcf.c')" 191 CMD="${CMD} SYSIFCOPT(*IFS64IO *ASYNCSIGNAL)" 192# CMD="${CMD} OPTION(*INCDIRFIRST *SHOWINC *SHOWSYS)" 193 CMD="${CMD} OPTION(*INCDIRFIRST)" 194 CMD="${CMD} LOCALETYPE(*LOCALE) FLAG(10)" 195 CMD="${CMD} INCDIR('${QADRTDIR}/include'" 196 CMD="${CMD} '${TOPDIR}/include/curl' '${TOPDIR}/include' '${SRCDIR}'" 197 CMD="${CMD} '${TOPDIR}/packages/OS400'" 198 199 if [ "${WITH_ZLIB}" != "0" ] 200 then CMD="${CMD} '${ZLIB_INCLUDE}'" 201 fi 202 203 if [ "${WITH_LIBSSH2}" != "0" ] 204 then CMD="${CMD} '${LIBSSH2_INCLUDE}'" 205 fi 206 207 CMD="${CMD} ${INCLUDES})" 208 CMD="${CMD} TGTCCSID(${TGTCCSID}) TGTRLS(${TGTRLS})" 209 CMD="${CMD} OUTPUT(${OUTPUT})" 210 CMD="${CMD} OPTIMIZE(${OPTIMIZE})" 211 CMD="${CMD} DBGVIEW(${DEBUG})" 212 213 DEFINES="${3} 'qadrt_use_inline'" 214 215 if [ "${WITH_ZLIB}" != "0" ] 216 then DEFINES="${DEFINES} HAVE_LIBZ" 217 fi 218 219 if [ "${WITH_LIBSSH2}" != "0" ] 220 then DEFINES="${DEFINES} USE_LIBSSH2" 221 fi 222 223 if [ -n "${DEFINES}" ] 224 then CMD="${CMD} DEFINE(${DEFINES})" 225 fi 226 227 CLcommand "${CMD}" 228 rm -f __tmpsrcf.c 229 # shellcheck disable=SC2034 230 LINK=YES 231} 232 233 234# Determine DB2 object name from IFS name. 235 236db2_name() 237 238{ 239 if [ "${2}" = 'nomangle' ] 240 then basename "${1}" | 241 tr 'a-z-' 'A-Z_' | 242 sed -e 's/\..*//' \ 243 -e 's/^\(.\).*\(.........\)$/\1\2/' 244 else basename "${1}" | 245 tr 'a-z-' 'A-Z_' | 246 sed -e 's/\..*//' \ 247 -e 's/^CURL_*/C/' \ 248 -e 's/^TOOL_*/T/' \ 249 -e 's/^\(.\).*\(.........\)$/\1\2/' 250 fi 251} 252 253 254# Copy IFS file replacing version info. 255 256versioned_copy() 257 258{ 259 sed -e "s/@LIBCURL_VERSION@/${LIBCURL_VERSION}/g" \ 260 -e "s/@LIBCURL_VERSION_MAJOR@/${LIBCURL_VERSION_MAJOR}/g" \ 261 -e "s/@LIBCURL_VERSION_MINOR@/${LIBCURL_VERSION_MINOR}/g" \ 262 -e "s/@LIBCURL_VERSION_PATCH@/${LIBCURL_VERSION_PATCH}/g" \ 263 -e "s/@LIBCURL_VERSION_NUM@/${LIBCURL_VERSION_NUM}/g" \ 264 -e "s/@LIBCURL_TIMESTAMP@/${LIBCURL_TIMESTAMP}/g" \ 265 < "${1}" > "${2}" 266} 267 268 269# Get definitions from a make file. 270# The `sed' statement works as follows: 271# - Join \nl-separated lines. 272# - Retain only lines that begins with "identifier =". 273# - Replace @...@ substitutions by shell variable references. 274# - Turn these lines into shell variable assignments. 275 276get_make_vars() 277 278{ 279 eval "$(sed -e ': begin' \ 280 -e '/\\$/{' \ 281 -e 'N' \ 282 -e 's/\\\n/ /' \ 283 -e 'b begin' \ 284 -e '}' \ 285 -e 's/[[:space:]][[:space:]]*/ /g' \ 286 -e '/^[A-Za-z_][A-Za-z0-9_]* *=/!d' \ 287 -e 's/@\([A-Za-z0-9_]*\)@/${\1}/g' \ 288 -e 's/ *= */=/' \ 289 -e 's/=\(.*[^ ]\) *$/="\1"/' \ 290 -e 's/\$(\([^)]*\))/${\1}/g' \ 291 < "${1}")" 292} 293