• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/packages/os400.
27
28TOPDIR=`dirname "${SCRIPTDIR}"`
29TOPDIR=`dirname "${TOPDIR}"`
30export SCRIPTDIR TOPDIR
31
32#  Extract the SONAME from the library makefile.
33
34SONAME=`sed -e '/^VERSIONINFO=/!d' -e 's/^.* \([0-9]*\):.*$/\1/' -e 'q' \
35                                                < "${TOPDIR}/lib/Makefile.am"`
36export SONAME
37
38
39################################################################################
40#
41#                       Tunable configuration parameters.
42#
43################################################################################
44
45setenv TARGETLIB        'CURL'                  # Target OS/400 program library.
46setenv STATBNDDIR       'CURL_A'                # Static binding directory.
47setenv DYNBNDDIR        'CURL'                  # Dynamic binding directory.
48setenv SRVPGM           "CURL.${SONAME}"        # Service program.
49setenv TGTCCSID         '500'                   # Target CCSID of objects.
50setenv DEBUG            '*ALL'                  # Debug level.
51setenv OPTIMIZE         '10'                    # Optimisation level
52setenv OUTPUT           '*NONE'                 # Compilation output option.
53setenv TGTRLS           'V6R1M0'                # Target OS release.
54setenv IFSDIR           '/curl'                 # Installation IFS directory.
55
56#       Define ZLIB availability and locations.
57
58setenv WITH_ZLIB        0                       # Define to 1 to enable.
59setenv ZLIB_INCLUDE     '/zlib/include'         # ZLIB include IFS directory.
60setenv ZLIB_LIB         'ZLIB'                  # ZLIB library.
61setenv ZLIB_BNDDIR      'ZLIB_A'                # ZLIB binding directory.
62
63#       Define LIBSSH2 availability and locations.
64
65setenv WITH_LIBSSH2     0                       # Define to 1 to enable.
66setenv LIBSSH2_INCLUDE  '/libssh2/include'      # LIBSSH2 include IFS directory.
67setenv LIBSSH2_LIB      'LIBSSH2'               # LIBSSH2 library.
68setenv LIBSSH2_BNDDIR   'LIBSSH2_A'             # LIBSSH2 binding directory.
69
70
71################################################################################
72
73#       Need to get the version definitions.
74
75LIBCURL_VERSION=`grep '^#define  *LIBCURL_VERSION '                     \
76                        "${TOPDIR}/include/curl/curlver.h"              |
77                sed 's/.*"\(.*\)".*/\1/'`
78LIBCURL_VERSION_MAJOR=`grep '^#define  *LIBCURL_VERSION_MAJOR '         \
79                        "${TOPDIR}/include/curl/curlver.h"              |
80                sed 's/^#define  *LIBCURL_VERSION_MAJOR  *\([^ ]*\).*/\1/'`
81LIBCURL_VERSION_MINOR=`grep '^#define  *LIBCURL_VERSION_MINOR '         \
82                        "${TOPDIR}/include/curl/curlver.h"              |
83                sed 's/^#define  *LIBCURL_VERSION_MINOR  *\([^ ]*\).*/\1/'`
84LIBCURL_VERSION_PATCH=`grep '^#define  *LIBCURL_VERSION_PATCH '         \
85                        "${TOPDIR}/include/curl/curlver.h"              |
86                sed 's/^#define  *LIBCURL_VERSION_PATCH  *\([^ ]*\).*/\1/'`
87LIBCURL_VERSION_NUM=`grep '^#define  *LIBCURL_VERSION_NUM '             \
88                        "${TOPDIR}/include/curl/curlver.h"              |
89                sed 's/^#define  *LIBCURL_VERSION_NUM  *0x\([^ ]*\).*/\1/'`
90LIBCURL_TIMESTAMP=`grep '^#define  *LIBCURL_TIMESTAMP '                 \
91                        "${TOPDIR}/include/curl/curlver.h"              |
92                sed 's/.*"\(.*\)".*/\1/'`
93export LIBCURL_VERSION
94export LIBCURL_VERSION_MAJOR LIBCURL_VERSION_MINOR LIBCURL_VERSION_PATCH
95export LIBCURL_VERSION_NUM LIBCURL_TIMESTAMP
96
97################################################################################
98#
99#                       OS/400 specific definitions.
100#
101################################################################################
102
103LIBIFSNAME="/QSYS.LIB/${TARGETLIB}.LIB"
104
105
106################################################################################
107#
108#                               Procedures.
109#
110################################################################################
111
112#       action_needed dest [src]
113#
114#       dest is an object to build
115#       if specified, src is an object on which dest depends.
116#
117#       exit 0 (succeeds) if some action has to be taken, else 1.
118
119action_needed()
120
121{
122        [ ! -e "${1}" ] && return 0
123        [ "${2}" ] || return 1
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 themporary file.
183
184        echo "#line 1 \"${2}\"" > __tmpsrcf.c
185        echo "#pragma convert(819)" >> __tmpsrcf.c
186        echo "#line 1" >> __tmpsrcf.c
187        cat "${2}" >> __tmpsrcf.c
188        CMD="CRTCMOD MODULE(${TARGETLIB}/${1}) SRCSTMF('__tmpsrcf.c')"
189#       CMD="${CMD} SYSIFCOPT(*IFS64IO) OPTION(*INCDIRFIRST *SHOWINC *SHOWSYS)"
190        CMD="${CMD} SYSIFCOPT(*IFS64IO) OPTION(*INCDIRFIRST)"
191        CMD="${CMD} LOCALETYPE(*LOCALE) FLAG(10)"
192        CMD="${CMD} INCDIR('/qibm/proddata/qadrt/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} BUILDING_LIBCURL"
211
212        if [ "${WITH_ZLIB}" != "0" ]
213        then    DEFINES="${DEFINES} HAVE_LIBZ HAVE_ZLIB_H"
214        fi
215
216        if [ "${WITH_LIBSSH2}" != "0" ]
217        then    DEFINES="${DEFINES} USE_LIBSSH2 HAVE_LIBSSH2_H"
218        fi
219
220        if [ "${DEFINES}" ]
221        then    CMD="${CMD} DEFINE(${DEFINES})"
222        fi
223
224        system "${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/^\(.\).*\(.........\)$/\1\2/'
245        fi
246}
247
248
249#       Copy IFS file replacing version info.
250
251versioned_copy()
252
253{
254        sed -e "s/@LIBCURL_VERSION@/${LIBCURL_VERSION}/g"               \
255            -e "s/@LIBCURL_VERSION_MAJOR@/${LIBCURL_VERSION_MAJOR}/g"   \
256            -e "s/@LIBCURL_VERSION_MINOR@/${LIBCURL_VERSION_MINOR}/g"   \
257            -e "s/@LIBCURL_VERSION_PATCH@/${LIBCURL_VERSION_PATCH}/g"   \
258            -e "s/@LIBCURL_VERSION_NUM@/${LIBCURL_VERSION_NUM}/g"       \
259            -e "s/@LIBCURL_TIMESTAMP@/${LIBCURL_TIMESTAMP}/g"           \
260                < "${1}" > "${2}"
261}
262