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#       make_module module_name source_name [additional_definitions]
123#
124#       Compile source name into ASCII module if needed.
125#       As side effect, append the module name to variable MODULES.
126#       Set LINK to "YES" if the module has been compiled.
127
128make_module()
129
130{
131        MODULES="${MODULES} ${1}"
132        MODIFSNAME="${LIBIFSNAME}/${1}.MODULE"
133        action_needed "${MODIFSNAME}" "${2}" || return 0;
134
135        #       #pragma convert has to be in the source file itself, i.e.
136        #               putting it in an include file makes it only active
137        #               for that include file.
138        #       Thus we build a temporary file with the pragma prepended to
139        #               the source file and we compile that themporary file.
140
141        echo "#line 1 \"${2}\"" > __tmpsrcf.c
142        echo "#pragma convert(819)" >> __tmpsrcf.c
143        echo "#line 1" >> __tmpsrcf.c
144        cat "${2}" >> __tmpsrcf.c
145        CMD="CRTCMOD MODULE(${TARGETLIB}/${1}) SRCSTMF('__tmpsrcf.c')"
146#       CMD="${CMD} SYSIFCOPT(*IFS64IO) OPTION(*INCDIRFIRST *SHOWINC *SHOWSYS)"
147        CMD="${CMD} SYSIFCOPT(*IFS64IO) OPTION(*INCDIRFIRST)"
148        CMD="${CMD} LOCALETYPE(*LOCALE)"
149        CMD="${CMD} INCDIR('/qibm/proddata/qadrt/include'"
150        CMD="${CMD} '${TOPDIR}/include/curl' '${TOPDIR}/include'"
151        CMD="${CMD} '${TOPDIR}/packages/OS400'"
152
153        if [ "${WITH_ZLIB}" != "0" ]
154        then    CMD="${CMD} '${ZLIB_INCLUDE}'"
155        fi
156
157        CMD="${CMD} ${INCLUDES})"
158        CMD="${CMD} TGTCCSID(${TGTCCSID}) TGTRLS(${TGTRLS})"
159        CMD="${CMD} OUTPUT(${OUTPUT})"
160        CMD="${CMD} OPTIMIZE(${OPTIMIZE})"
161        CMD="${CMD} DBGVIEW(${DEBUG})"
162
163        DEFINES="${3}"
164
165        if [ "${WITH_ZLIB}" != "0" ]
166        then    DEFINES="${DEFINES} HAVE_LIBZ HAVE_ZLIB_H"
167        fi
168
169        if [ "${DEFINES}" ]
170        then    CMD="${CMD} DEFINE(${DEFINES})"
171        fi
172
173        system "${CMD}"
174        rm -f __tmpsrcf.c
175        LINK=YES
176}
177
178
179#       Determine DB2 object name from IFS name.
180
181db2_name()
182
183{
184        if [ "${2}" = 'nomangle' ]
185        then    basename "${1}"                                         |
186                tr 'a-z-' 'A-Z_'                                        |
187                sed -e 's/\..*//'                                       \
188                    -e 's/^\(.\).*\(.........\)$/\1\2/'
189        else    basename "${1}"                                         |
190                tr 'a-z-' 'A-Z_'                                        |
191                sed -e 's/\..*//'                                       \
192                    -e 's/^CURL_*/C/'                                   \
193                    -e 's/^\(.\).*\(.........\)$/\1\2/'
194        fi
195}
196
197
198#       Copy IFS file replacing version info.
199
200versioned_copy()
201
202{
203        sed -e "s/@LIBCURL_VERSION@/${LIBCURL_VERSION}/g"               \
204            -e "s/@LIBCURL_VERSION_MAJOR@/${LIBCURL_VERSION_MAJOR}/g"   \
205            -e "s/@LIBCURL_VERSION_MINOR@/${LIBCURL_VERSION_MINOR}/g"   \
206            -e "s/@LIBCURL_VERSION_PATCH@/${LIBCURL_VERSION_PATCH}/g"   \
207            -e "s/@LIBCURL_VERSION_NUM@/${LIBCURL_VERSION_NUM}/g"       \
208            -e "s/@LIBCURL_TIMESTAMP@/${LIBCURL_TIMESTAMP}/g"           \
209                < "${1}" > "${2}"
210}
211