xref: /curl/packages/OS400/make-lib.sh (revision 5e46c290)
1#!/bin/sh
2#***************************************************************************
3#                                  _   _ ____  _
4#  Project                     ___| | | |  _ \| |
5#                             / __| | | | |_) | |
6#                            | (__| |_| |  _ <| |___
7#                             \___|\___/|_| \_\_____|
8#
9# Copyright (C) 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#
26#       libcurl compilation script for the OS/400.
27#
28
29SCRIPTDIR=$(dirname "${0}")
30. "${SCRIPTDIR}/initscript.sh"
31cd "${TOPDIR}/lib" || exit 1
32
33#       Need to have IFS access to the mih/cipher header file.
34
35if action_needed cipher.mih '/QSYS.LIB/QSYSINC.LIB/MIH.FILE/CIPHER.MBR'
36then    rm -f cipher.mih
37        ln -s '/QSYS.LIB/QSYSINC.LIB/MIH.FILE/CIPHER.MBR' cipher.mih
38fi
39
40
41#      Create and compile the identification source file.
42
43{
44        echo '#pragma comment(user, "libcurl version '"${LIBCURL_VERSION}"'")'
45        echo '#pragma comment(user, __DATE__)'
46        echo '#pragma comment(user, __TIME__)'
47        echo '#pragma comment(copyright, "Copyright (C) Daniel Stenberg et al. OS/400 version by P. Monnerat")'
48} > os400.c
49make_module     OS400           os400.c         BUILDING_LIBCURL
50LINK=                           # No need to rebuild service program yet.
51MODULES=
52
53
54#       Get source list (CSOURCES variable).
55
56get_make_vars Makefile.inc
57
58
59#       Compile the sources into modules.
60
61# shellcheck disable=SC2034
62INCLUDES="'$(pwd)'"
63
64make_module     OS400SYS        "${SCRIPTDIR}/os400sys.c"       BUILDING_LIBCURL
65make_module     CCSIDCURL       "${SCRIPTDIR}/ccsidcurl.c"      BUILDING_LIBCURL
66
67for SRC in ${CSOURCES}
68do      MODULE=$(db2_name "${SRC}")
69        make_module "${MODULE}" "${SRC}" BUILDING_LIBCURL
70done
71
72
73#       If needed, (re)create the static binding directory.
74
75if action_needed "${LIBIFSNAME}/${STATBNDDIR}.BNDDIR"
76then    LINK=YES
77fi
78
79if [ -n "${LINK}" ]
80then    rm -rf "${LIBIFSNAME}/${STATBNDDIR}.BNDDIR"
81        CMD="CRTBNDDIR BNDDIR(${TARGETLIB}/${STATBNDDIR})"
82        CMD="${CMD} TEXT('LibCurl API static binding directory')"
83        CLcommand "${CMD}"
84
85        for MODULE in ${MODULES}
86        do      CMD="ADDBNDDIRE BNDDIR(${TARGETLIB}/${STATBNDDIR})"
87                CMD="${CMD} OBJ((${TARGETLIB}/${MODULE} *MODULE))"
88                CLcommand "${CMD}"
89        done
90fi
91
92
93#       The exportation file for service program creation must be in a DB2
94#               source file, so make sure it exists.
95
96if action_needed "${LIBIFSNAME}/TOOLS.FILE"
97then    CMD="CRTSRCPF FILE(${TARGETLIB}/TOOLS) RCDLEN(112)"
98        CMD="${CMD} TEXT('curl: build tools')"
99        CLcommand "${CMD}"
100fi
101
102
103#       Gather the list of symbols to export.
104#       - Unfold lines from the header files so that they contain a semicolon.
105#       - Keep only CURL_EXTERN definitions.
106#       - Remove the CURL_DEPRECATED and CURL_TEMP_PRINTF macro calls.
107#       - Drop the parenthesized function arguments and what follows.
108#       - Keep the trailing function name only.
109
110EXPORTS=$(cat "${TOPDIR}"/include/curl/*.h "${SCRIPTDIR}/ccsidcurl.h"   |
111         sed -e 'H;s/.*//;x;s/\n//;s/.*/& /'                            \
112             -e '/^CURL_EXTERN[[:space:]]/!d'                           \
113             -e '/\;/!{x;d;}'                                           \
114             -e 's/ CURL_DEPRECATED([^)]*)//g'                          \
115             -e 's/ CURL_TEMP_PRINTF([^)]*)//g'                         \
116             -e 's/[[:space:]]*(.*$//'                                  \
117             -e 's/^.*[^A-Za-z0-9_]\([A-Za-z0-9_]*\)$/\1/')
118
119
120#       Create the service program exportation file in DB2 member if needed.
121
122BSF="${LIBIFSNAME}/TOOLS.FILE/BNDSRC.MBR"
123
124if action_needed "${BSF}" Makefile.am
125then    LINK=YES
126fi
127
128if [ -n "${LINK}" ]
129then    echo " STRPGMEXP PGMLVL(*CURRENT) SIGNATURE('LIBCURL_${SONAME}')" \
130            > "${BSF}"
131        for EXPORT in ${EXPORTS}
132        do      echo ' EXPORT    SYMBOL("'"${EXPORT}"'")' >> "${BSF}"
133        done
134
135        echo ' ENDPGMEXP' >> "${BSF}"
136fi
137
138
139#       Build the service program if needed.
140
141if action_needed "${LIBIFSNAME}/${SRVPGM}.SRVPGM"
142then    LINK=YES
143fi
144
145if [ -n "${LINK}" ]
146then    CMD="CRTSRVPGM SRVPGM(${TARGETLIB}/${SRVPGM})"
147        CMD="${CMD} SRCFILE(${TARGETLIB}/TOOLS) SRCMBR(BNDSRC)"
148        CMD="${CMD} MODULE(${TARGETLIB}/OS400)"
149        CMD="${CMD} BNDDIR(${TARGETLIB}/${STATBNDDIR}"
150        if [ "${WITH_ZLIB}" != 0 ]
151        then    CMD="${CMD} ${ZLIB_LIB}/${ZLIB_BNDDIR}"
152                liblist -a "${ZLIB_LIB}"
153        fi
154        if [ "${WITH_LIBSSH2}" != 0 ]
155        then    CMD="${CMD} ${LIBSSH2_LIB}/${LIBSSH2_BNDDIR}"
156                liblist -a "${LIBSSH2_LIB}"
157        fi
158        CMD="${CMD})"
159        CMD="${CMD} BNDSRVPGM(QADRTTS QGLDCLNT QGLDBRDR)"
160        CMD="${CMD} TEXT('curl API library')"
161        CMD="${CMD} TGTRLS(${TGTRLS})"
162        CLcommand "${CMD}"
163        LINK=YES
164fi
165
166
167#       If needed, (re)create the dynamic binding directory.
168
169if action_needed "${LIBIFSNAME}/${DYNBNDDIR}.BNDDIR"
170then    LINK=YES
171fi
172
173if [ -n "${LINK}" ]
174then    rm -rf "${LIBIFSNAME}/${DYNBNDDIR}.BNDDIR"
175        CMD="CRTBNDDIR BNDDIR(${TARGETLIB}/${DYNBNDDIR})"
176        CMD="${CMD} TEXT('LibCurl API dynamic binding directory')"
177        CLcommand "${CMD}"
178        CMD="ADDBNDDIRE BNDDIR(${TARGETLIB}/${DYNBNDDIR})"
179        CMD="${CMD} OBJ((*LIBL/${SRVPGM} *SRVPGM))"
180        CLcommand "${CMD}"
181fi
182