1#!/bin/sh
2#
3#       libcurl compilation script for the OS/400.
4#
5
6SCRIPTDIR=`dirname "${0}"`
7. "${SCRIPTDIR}/initscript.sh"
8cd "${TOPDIR}/lib"
9
10#       Need to have IFS access to the mih/cipher header file.
11
12if action_needed cipher.mih '/QSYS.LIB/QSYSINC.LIB/MIH.FILE/CIPHER.MBR'
13then    rm -f cipher.mih
14        ln -s '/QSYS.LIB/QSYSINC.LIB/MIH.FILE/CIPHER.MBR' cipher.mih
15fi
16
17
18#      Create and compile the identification source file.
19
20echo '#pragma comment(user, "libcurl version '"${LIBCURL_VERSION}"'")' > os400.c
21echo '#pragma comment(user, __DATE__)' >> os400.c
22echo '#pragma comment(user, __TIME__)' >> os400.c
23echo '#pragma comment(copyright, "Copyright (C) 1998-2014 Daniel Stenberg et al. OS/400 version by P. Monnerat")' >> os400.c
24make_module     OS400           os400.c
25LINK=                           # No need to rebuild service program yet.
26MODULES=
27
28
29#       Get source list.
30
31sed -e ':begin'                                                         \
32    -e '/\\$/{'                                                         \
33    -e 's/\\$/ /'                                                       \
34    -e 'N'                                                              \
35    -e 'bbegin'                                                         \
36    -e '}'                                                              \
37    -e 's/\n//g'                                                        \
38    -e 's/[[:space:]]*$//'                                              \
39    -e 's/^\([A-Za-z][A-Za-z0-9_]*\)[[:space:]]*=[[:space:]]*\(.*\)/\1="\2"/' \
40    -e 's/\$(\([A-Za-z][A-Za-z0-9_]*\))/${\1}/g'                        \
41        < Makefile.inc > tmpscript.sh
42. ./tmpscript.sh
43
44
45#       Compile the sources into modules.
46
47INCLUDES="'`pwd`'"
48
49make_module     OS400SYS        "${SCRIPTDIR}/os400sys.c"
50make_module     CCSIDCURL       "${SCRIPTDIR}/ccsidcurl.c"
51
52for SRC in ${CSOURCES}
53do      MODULE=`db2_name "${SRC}"`
54        make_module "${MODULE}" "${SRC}"
55done
56
57
58#       If needed, (re)create the static binding directory.
59
60if action_needed "${LIBIFSNAME}/${STATBNDDIR}.BNDDIR"
61then    LINK=YES
62fi
63
64if [ "${LINK}" ]
65then    rm -rf "${LIBIFSNAME}/${STATBNDDIR}.BNDDIR"
66        CMD="CRTBNDDIR BNDDIR(${TARGETLIB}/${STATBNDDIR})"
67        CMD="${CMD} TEXT('LibCurl API static binding directory')"
68        system "${CMD}"
69
70        for MODULE in ${MODULES}
71        do      CMD="ADDBNDDIRE BNDDIR(${TARGETLIB}/${STATBNDDIR})"
72                CMD="${CMD} OBJ((${TARGETLIB}/${MODULE} *MODULE))"
73                system "${CMD}"
74        done
75fi
76
77
78#       The exportation file for service program creation must be in a DB2
79#               source file, so make sure it exists.
80
81if action_needed "${LIBIFSNAME}/TOOLS.FILE"
82then    CMD="CRTSRCPF FILE(${TARGETLIB}/TOOLS) RCDLEN(112)"
83        CMD="${CMD} TEXT('curl: build tools')"
84        system "${CMD}"
85fi
86
87
88#       Gather the list of symbols to export.
89
90EXPORTS=`grep '^CURL_EXTERN[[:space:]]'                                 \
91              "${TOPDIR}"/include/curl/*.h                              \
92              "${SCRIPTDIR}/ccsidcurl.h"                                |
93         sed -e 's/^.*CURL_EXTERN[[:space:]]\(.*\)(.*$/\1/'             \
94             -e 's/[[:space:]]*$//'                                     \
95             -e 's/^.*[[:space:]][[:space:]]*//'                        \
96             -e 's/^\*//'                                               \
97             -e 's/(\(.*\))/\1/'`
98
99#       Create the service program exportation file in DB2 member if needed.
100
101BSF="${LIBIFSNAME}/TOOLS.FILE/BNDSRC.MBR"
102
103if action_needed "${BSF}" Makefile.am
104then    LINK=YES
105fi
106
107if [ "${LINK}" ]
108then    echo " STRPGMEXP PGMLVL(*CURRENT) SIGNATURE('LIBCURL_${SONAME}')" \
109            > "${BSF}"
110        for EXPORT in ${EXPORTS}
111        do      echo ' EXPORT    SYMBOL("'"${EXPORT}"'")' >> "${BSF}"
112        done
113
114        echo ' ENDPGMEXP' >> "${BSF}"
115fi
116
117
118#       Build the service program if needed.
119
120if action_needed "${LIBIFSNAME}/${SRVPGM}.SRVPGM"
121then    LINK=YES
122fi
123
124if [ "${LINK}" ]
125then    CMD="CRTSRVPGM SRVPGM(${TARGETLIB}/${SRVPGM})"
126        CMD="${CMD} SRCFILE(${TARGETLIB}/TOOLS) SRCMBR(BNDSRC)"
127        CMD="${CMD} MODULE(${TARGETLIB}/OS400)"
128        CMD="${CMD} BNDDIR(${TARGETLIB}/${STATBNDDIR}"
129        if [ "${WITH_ZLIB}" != 0 ]
130        then    CMD="${CMD} ${ZLIB_LIB}/${ZLIB_BNDDIR}"
131        fi
132        CMD="${CMD})"
133        CMD="${CMD} BNDSRVPGM(QADRTTS QGLDCLNT QGLDBRDR)"
134        CMD="${CMD} TEXT('curl API library')"
135        CMD="${CMD} TGTRLS(${TGTRLS})"
136        system "${CMD}"
137        LINK=YES
138fi
139
140
141#       If needed, (re)create the dynamic binding directory.
142
143if action_needed "${LIBIFSNAME}/${DYNBNDDIR}.BNDDIR"
144then    LINK=YES
145fi
146
147if [ "${LINK}" ]
148then    rm -rf "${LIBIFSNAME}/${DYNBNDDIR}.BNDDIR"
149        CMD="CRTBNDDIR BNDDIR(${TARGETLIB}/${DYNBNDDIR})"
150        CMD="${CMD} TEXT('LibCurl API dynamic binding directory')"
151        system "${CMD}"
152        CMD="ADDBNDDIRE BNDDIR(${TARGETLIB}/${DYNBNDDIR})"
153        CMD="${CMD} OBJ((*LIBL/${SRVPGM} *SRVPGM))"
154        system "${CMD}"
155fi
156
157
158#       Rebuild the formdata test if needed.
159
160if [ "${TEST_FORMDATA}" ]
161then    MODULES=
162        make_module TFORMDATA   formdata.c      "'_FORM_DEBUG' 'CURLDEBUG'"
163        make_module TSTREQUAL   strequal.c      "'_FORM_DEBUG' 'CURLDEBUG'"
164        make_module TMEMDEBUG   memdebug.c      "'_FORM_DEBUG' 'CURLDEBUG'"
165        make_module TMPRINTF    mprintf.c       "'_FORM_DEBUG' 'CURLDEBUG'"
166        make_module TSTRERROR   strerror.c      "'_FORM_DEBUG' 'CURLDEBUG'"
167        #       The following modules should not be needed (see comment in
168        #               formdata.c. However, there are some unsatisfied
169        #               external references leading in the following
170        #               modules to be (recursively) needed.
171        MODULES="${MODULES} EASY STRDUP SSLGEN GSKIT HOSTIP HOSTIP4 HOSTIP6"
172        MODULES="${MODULES} URL HASH TRANSFER GETINFO COOKIE SENDF SELECT"
173        MODULES="${MODULES} INET_NTOP SHARE HOSTTHRE MULTI LLIST FTP HTTP"
174        MODULES="${MODULES} HTTP_DIGES HTTP_CHUNK HTTP_NEGOT TIMEVAL HOSTSYN"
175        MODULES="${MODULES} CONNECT SOCKS PROGRESS ESCAPE INET_PTON GETENV"
176        MODULES="${MODULES} DICT LDAP TELNET FILE TFTP NETRC PARSEDATE"
177        MODULES="${MODULES} SPEEDCHECK SPLAY BASE64 SECURITY IF2IP MD5"
178        MODULES="${MODULES} KRB5 OS400SYS"
179
180        PGMIFSNAME="${LIBIFSNAME}/TFORMDATA.PGM"
181
182        if action_needed "${PGMIFSNAME}"
183        then    LINK=YES
184        fi
185
186        if [ "${LINK}" ]
187        then    CMD="CRTPGM PGM(${TARGETLIB}/TFORMDATA)"
188                CMD="${CMD} ENTMOD(QADRT/QADRTMAIN2)"
189                CMD="${CMD} MODULE("
190
191                for MODULE in ${MODULES}
192                do      CMD="${CMD} ${TARGETLIB}/${MODULE}"
193                done
194
195                CMD="${CMD} ) BNDSRVPGM(QADRTTS)"
196                CMD="${CMD} TGTRLS(${TGTRLS})"
197                system "${CMD}"
198        fi
199fi
200