blob: 4facf17edd26993135c2d472922f62354724c5e3 [file] [log] [blame]
xf.li6c8fc1e2023-08-12 00:11:09 -07001#!/bin/sh
2#***************************************************************************
3# _ _ ____ _
4# Project ___| | | | _ \| |
5# / __| | | | |_) | |
6# | (__| |_| | _ <| |___
7# \___|\___/|_| \_\_____|
8#
9# Copyright (C) 1998 - 2022, 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
26system ()
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 '/^VERSIONINFO=/!d' -e 's/^.* \([0-9]*\):.*$/\1/' -e 'q' \
62 < "${TOPDIR}/lib/Makefile.am"`
63export SONAME
64
65
66################################################################################
67#
68# Tunable configuration parameters.
69#
70################################################################################
71
72setenv TARGETLIB 'CURL' # Target OS/400 program library.
73setenv STATBNDDIR 'CURL_A' # Static binding directory.
74setenv DYNBNDDIR 'CURL' # Dynamic binding directory.
75setenv SRVPGM "CURL.${SONAME}" # Service program.
76setenv TGTCCSID '500' # Target CCSID of objects.
77setenv DEBUG '*ALL' # Debug level.
78setenv OPTIMIZE '10' # Optimization level
79setenv OUTPUT '*NONE' # Compilation output option.
80setenv TGTRLS '*CURRENT' # Target OS release.
81setenv IFSDIR '/curl' # Installation IFS directory.
82
83# Define ZLIB availability and locations.
84
85setenv WITH_ZLIB 0 # Define to 1 to enable.
86setenv ZLIB_INCLUDE '/zlib/include' # ZLIB include IFS directory.
87setenv ZLIB_LIB 'ZLIB' # ZLIB library.
88setenv ZLIB_BNDDIR 'ZLIB_A' # ZLIB binding directory.
89
90# Define LIBSSH2 availability and locations.
91
92setenv WITH_LIBSSH2 0 # Define to 1 to enable.
93setenv LIBSSH2_INCLUDE '/libssh2/include' # LIBSSH2 include IFS directory.
94setenv LIBSSH2_LIB 'LIBSSH2' # LIBSSH2 library.
95setenv LIBSSH2_BNDDIR 'LIBSSH2_A' # LIBSSH2 binding directory.
96
97
98################################################################################
99
100# Need to get the version definitions.
101
102LIBCURL_VERSION=`grep '^#define *LIBCURL_VERSION ' \
103 "${TOPDIR}/include/curl/curlver.h" |
104 sed 's/.*"\(.*\)".*/\1/'`
105LIBCURL_VERSION_MAJOR=`grep '^#define *LIBCURL_VERSION_MAJOR ' \
106 "${TOPDIR}/include/curl/curlver.h" |
107 sed 's/^#define *LIBCURL_VERSION_MAJOR *\([^ ]*\).*/\1/'`
108LIBCURL_VERSION_MINOR=`grep '^#define *LIBCURL_VERSION_MINOR ' \
109 "${TOPDIR}/include/curl/curlver.h" |
110 sed 's/^#define *LIBCURL_VERSION_MINOR *\([^ ]*\).*/\1/'`
111LIBCURL_VERSION_PATCH=`grep '^#define *LIBCURL_VERSION_PATCH ' \
112 "${TOPDIR}/include/curl/curlver.h" |
113 sed 's/^#define *LIBCURL_VERSION_PATCH *\([^ ]*\).*/\1/'`
114LIBCURL_VERSION_NUM=`grep '^#define *LIBCURL_VERSION_NUM ' \
115 "${TOPDIR}/include/curl/curlver.h" |
116 sed 's/^#define *LIBCURL_VERSION_NUM *0x\([^ ]*\).*/\1/'`
117LIBCURL_TIMESTAMP=`grep '^#define *LIBCURL_TIMESTAMP ' \
118 "${TOPDIR}/include/curl/curlver.h" |
119 sed 's/.*"\(.*\)".*/\1/'`
120export LIBCURL_VERSION
121export LIBCURL_VERSION_MAJOR LIBCURL_VERSION_MINOR LIBCURL_VERSION_PATCH
122export LIBCURL_VERSION_NUM LIBCURL_TIMESTAMP
123
124################################################################################
125#
126# OS/400 specific definitions.
127#
128################################################################################
129
130LIBIFSNAME="/QSYS.LIB/${TARGETLIB}.LIB"
131
132
133################################################################################
134#
135# Procedures.
136#
137################################################################################
138
139# action_needed dest [src]
140#
141# dest is an object to build
142# if specified, src is an object on which dest depends.
143#
144# exit 0 (succeeds) if some action has to be taken, else 1.
145
146action_needed()
147
148{
149 [ ! -e "${1}" ] && return 0
150 [ "${2}" ] || return 1
151 [ "${1}" -ot "${2}" ] && return 0
152 return 1
153}
154
155
156# canonicalize_path path
157#
158# Return canonicalized path as:
159# - Absolute
160# - No . or .. component.
161
162canonicalize_path()
163
164{
165 if expr "${1}" : '^/' > /dev/null
166 then P="${1}"
167 else P="`pwd`/${1}"
168 fi
169
170 R=
171 IFSSAVE="${IFS}"
172 IFS="/"
173
174 for C in ${P}
175 do IFS="${IFSSAVE}"
176 case "${C}" in
177 .) ;;
178 ..) R=`expr "${R}" : '^\(.*/\)..*'`
179 ;;
180 ?*) R="${R}${C}/"
181 ;;
182 *) ;;
183 esac
184 done
185
186 IFS="${IFSSAVE}"
187 echo "/`expr "${R}" : '^\(.*\)/'`"
188}
189
190
191# make_module module_name source_name [additional_definitions]
192#
193# Compile source name into ASCII module if needed.
194# As side effect, append the module name to variable MODULES.
195# Set LINK to "YES" if the module has been compiled.
196
197make_module()
198
199{
200 MODULES="${MODULES} ${1}"
201 MODIFSNAME="${LIBIFSNAME}/${1}.MODULE"
202 action_needed "${MODIFSNAME}" "${2}" || return 0;
203 SRCDIR=`dirname \`canonicalize_path "${2}"\``
204
205 # #pragma convert has to be in the source file itself, i.e.
206 # putting it in an include file makes it only active
207 # for that include file.
208 # Thus we build a temporary file with the pragma prepended to
209 # the source file and we compile that themporary file.
210
211 echo "#line 1 \"${2}\"" > __tmpsrcf.c
212 echo "#pragma convert(819)" >> __tmpsrcf.c
213 echo "#line 1" >> __tmpsrcf.c
214 cat "${2}" >> __tmpsrcf.c
215 CMD="CRTCMOD MODULE(${TARGETLIB}/${1}) SRCSTMF('__tmpsrcf.c')"
216# CMD="${CMD} SYSIFCOPT(*IFS64IO) OPTION(*INCDIRFIRST *SHOWINC *SHOWSYS)"
217 CMD="${CMD} SYSIFCOPT(*IFS64IO) OPTION(*INCDIRFIRST)"
218 CMD="${CMD} LOCALETYPE(*LOCALE) FLAG(10)"
219 CMD="${CMD} INCDIR('/qibm/proddata/qadrt/include'"
220 CMD="${CMD} '${TOPDIR}/include/curl' '${TOPDIR}/include' '${SRCDIR}'"
221 CMD="${CMD} '${TOPDIR}/packages/OS400'"
222
223 if [ "${WITH_ZLIB}" != "0" ]
224 then CMD="${CMD} '${ZLIB_INCLUDE}'"
225 fi
226
227 if [ "${WITH_LIBSSH2}" != "0" ]
228 then CMD="${CMD} '${LIBSSH2_INCLUDE}'"
229 fi
230
231 CMD="${CMD} ${INCLUDES})"
232 CMD="${CMD} TGTCCSID(${TGTCCSID}) TGTRLS(${TGTRLS})"
233 CMD="${CMD} OUTPUT(${OUTPUT})"
234 CMD="${CMD} OPTIMIZE(${OPTIMIZE})"
235 CMD="${CMD} DBGVIEW(${DEBUG})"
236
237 DEFINES="${3} BUILDING_LIBCURL"
238
239 if [ "${WITH_ZLIB}" != "0" ]
240 then DEFINES="${DEFINES} HAVE_LIBZ"
241 fi
242
243 if [ "${WITH_LIBSSH2}" != "0" ]
244 then DEFINES="${DEFINES} USE_LIBSSH2"
245 fi
246
247 if [ "${DEFINES}" ]
248 then CMD="${CMD} DEFINE(${DEFINES})"
249 fi
250
251 system "${CMD}"
252 rm -f __tmpsrcf.c
253 LINK=YES
254}
255
256
257# Determine DB2 object name from IFS name.
258
259db2_name()
260
261{
262 if [ "${2}" = 'nomangle' ]
263 then basename "${1}" |
264 tr 'a-z-' 'A-Z_' |
265 sed -e 's/\..*//' \
266 -e 's/^\(.\).*\(.........\)$/\1\2/'
267 else basename "${1}" |
268 tr 'a-z-' 'A-Z_' |
269 sed -e 's/\..*//' \
270 -e 's/^CURL_*/C/' \
271 -e 's/^\(.\).*\(.........\)$/\1\2/'
272 fi
273}
274
275
276# Copy IFS file replacing version info.
277
278versioned_copy()
279
280{
281 sed -e "s/@LIBCURL_VERSION@/${LIBCURL_VERSION}/g" \
282 -e "s/@LIBCURL_VERSION_MAJOR@/${LIBCURL_VERSION_MAJOR}/g" \
283 -e "s/@LIBCURL_VERSION_MINOR@/${LIBCURL_VERSION_MINOR}/g" \
284 -e "s/@LIBCURL_VERSION_PATCH@/${LIBCURL_VERSION_PATCH}/g" \
285 -e "s/@LIBCURL_VERSION_NUM@/${LIBCURL_VERSION_NUM}/g" \
286 -e "s/@LIBCURL_TIMESTAMP@/${LIBCURL_TIMESTAMP}/g" \
287 < "${1}" > "${2}"
288}