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