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           'V5R3M0'                # 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
64################################################################################
65
66#       Need to get the version definitions.
67
68LIBCURL_VERSION=`grep '^#define  *LIBCURL_VERSION '                     \
69                        "${TOPDIR}/include/curl/curlver.h"              |
70                sed 's/.*"\(.*\)".*/\1/'`
71LIBCURL_VERSION_MAJOR=`grep '^#define  *LIBCURL_VERSION_MAJOR '         \
72                        "${TOPDIR}/include/curl/curlver.h"              |
73                sed 's/^#define  *LIBCURL_VERSION_MAJOR  *\([^ ]*\).*/\1/'`
74LIBCURL_VERSION_MINOR=`grep '^#define  *LIBCURL_VERSION_MINOR '         \
75                        "${TOPDIR}/include/curl/curlver.h"              |
76                sed 's/^#define  *LIBCURL_VERSION_MINOR  *\([^ ]*\).*/\1/'`
77LIBCURL_VERSION_PATCH=`grep '^#define  *LIBCURL_VERSION_PATCH '         \
78                        "${TOPDIR}/include/curl/curlver.h"              |
79                sed 's/^#define  *LIBCURL_VERSION_PATCH  *\([^ ]*\).*/\1/'`
80LIBCURL_VERSION_NUM=`grep '^#define  *LIBCURL_VERSION_NUM '             \
81                        "${TOPDIR}/include/curl/curlver.h"              |
82                sed 's/^#define  *LIBCURL_VERSION_NUM  *0x\([^ ]*\).*/\1/'`
83LIBCURL_TIMESTAMP=`grep '^#define  *LIBCURL_TIMESTAMP '                 \
84                        "${TOPDIR}/include/curl/curlver.h"              |
85                sed 's/.*"\(.*\)".*/\1/'`
86export LIBCURL_VERSION
87export LIBCURL_VERSION_MAJOR LIBCURL_VERSION_MINOR LIBCURL_VERSION_PATCH
88export LIBCURL_VERSION_NUM LIBCURL_TIMESTAMP
89
90################################################################################
91#
92#                       OS/400 specific definitions.
93#
94################################################################################
95
96LIBIFSNAME="/QSYS.LIB/${TARGETLIB}.LIB"
97
98
99################################################################################
100#
101#                               Procedures.
102#
103################################################################################
104
105#       action_needed dest [src]
106#
107#       dest is an object to build
108#       if specified, src is an object on which dest depends.
109#
110#       exit 0 (succeeds) if some action has to be taken, else 1.
111
112action_needed()
113
114{
115        [ ! -e "${1}" ] && return 0
116        [ "${2}" ] || return 1
117        [ "${1}" -ot "${2}" ] && return 0
118        return 1
119}
120
121
122#       canonicalize_path path
123#
124#       Return canonicalized path as:
125#       - Absolute
126#       - No . or .. component.
127
128canonicalize_path()
129
130{
131        if expr "${1}" : '^/' > /dev/null
132        then    P="${1}"
133        else    P="`pwd`/${1}"
134        fi
135
136        R=
137        IFSSAVE="${IFS}"
138        IFS="/"
139
140        for C in ${P}
141        do      IFS="${IFSSAVE}"
142                case "${C}" in
143                .)      ;;
144                ..)     R=`expr "${R}" : '^\(.*/\)..*'`
145                        ;;
146                ?*)     R="${R}${C}/"
147                        ;;
148                *)      ;;
149                esac
150        done
151
152        IFS="${IFSSAVE}"
153        echo "/`expr "${R}" : '^\(.*\)/'`"
154}
155
156
157#       make_module module_name source_name [additional_definitions]
158#
159#       Compile source name into ASCII module if needed.
160#       As side effect, append the module name to variable MODULES.
161#       Set LINK to "YES" if the module has been compiled.
162
163make_module()
164
165{
166        MODULES="${MODULES} ${1}"
167        MODIFSNAME="${LIBIFSNAME}/${1}.MODULE"
168        action_needed "${MODIFSNAME}" "${2}" || return 0;
169        SRCDIR=`dirname \`canonicalize_path "${2}"\``
170
171        #       #pragma convert has to be in the source file itself, i.e.
172        #               putting it in an include file makes it only active
173        #               for that include file.
174        #       Thus we build a temporary file with the pragma prepended to
175        #               the source file and we compile that themporary file.
176
177        echo "#line 1 \"${2}\"" > __tmpsrcf.c
178        echo "#pragma convert(819)" >> __tmpsrcf.c
179        echo "#line 1" >> __tmpsrcf.c
180        cat "${2}" >> __tmpsrcf.c
181        CMD="CRTCMOD MODULE(${TARGETLIB}/${1}) SRCSTMF('__tmpsrcf.c')"
182#       CMD="${CMD} SYSIFCOPT(*IFS64IO) OPTION(*INCDIRFIRST *SHOWINC *SHOWSYS)"
183        CMD="${CMD} SYSIFCOPT(*IFS64IO) OPTION(*INCDIRFIRST)"
184        CMD="${CMD} LOCALETYPE(*LOCALE)"
185        CMD="${CMD} INCDIR('/qibm/proddata/qadrt/include'"
186        CMD="${CMD} '${TOPDIR}/include/curl' '${TOPDIR}/include' '${SRCDIR}'"
187        CMD="${CMD} '${TOPDIR}/packages/OS400'"
188
189        if [ "${WITH_ZLIB}" != "0" ]
190        then    CMD="${CMD} '${ZLIB_INCLUDE}'"
191        fi
192
193        CMD="${CMD} ${INCLUDES})"
194        CMD="${CMD} TGTCCSID(${TGTCCSID}) TGTRLS(${TGTRLS})"
195        CMD="${CMD} OUTPUT(${OUTPUT})"
196        CMD="${CMD} OPTIMIZE(${OPTIMIZE})"
197        CMD="${CMD} DBGVIEW(${DEBUG})"
198
199        DEFINES="${3}"
200
201        if [ "${WITH_ZLIB}" != "0" ]
202        then    DEFINES="${DEFINES} HAVE_LIBZ HAVE_ZLIB_H"
203        fi
204
205        if [ "${DEFINES}" ]
206        then    CMD="${CMD} DEFINE(${DEFINES})"
207        fi
208
209        system "${CMD}"
210        rm -f __tmpsrcf.c
211        LINK=YES
212}
213
214
215#       Determine DB2 object name from IFS name.
216
217db2_name()
218
219{
220        if [ "${2}" = 'nomangle' ]
221        then    basename "${1}"                                         |
222                tr 'a-z-' 'A-Z_'                                        |
223                sed -e 's/\..*//'                                       \
224                    -e 's/^\(.\).*\(.........\)$/\1\2/'
225        else    basename "${1}"                                         |
226                tr 'a-z-' 'A-Z_'                                        |
227                sed -e 's/\..*//'                                       \
228                    -e 's/^CURL_*/C/'                                   \
229                    -e 's/^\(.\).*\(.........\)$/\1\2/'
230        fi
231}
232
233
234#       Copy IFS file replacing version info.
235
236versioned_copy()
237
238{
239        sed -e "s/@LIBCURL_VERSION@/${LIBCURL_VERSION}/g"               \
240            -e "s/@LIBCURL_VERSION_MAJOR@/${LIBCURL_VERSION_MAJOR}/g"   \
241            -e "s/@LIBCURL_VERSION_MINOR@/${LIBCURL_VERSION_MINOR}/g"   \
242            -e "s/@LIBCURL_VERSION_PATCH@/${LIBCURL_VERSION_PATCH}/g"   \
243            -e "s/@LIBCURL_VERSION_NUM@/${LIBCURL_VERSION_NUM}/g"       \
244            -e "s/@LIBCURL_TIMESTAMP@/${LIBCURL_TIMESTAMP}/g"           \
245                < "${1}" > "${2}"
246}
247