initscript.sh 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. #!/bin/sh
  2. #***************************************************************************
  3. # _ _ ____ _
  4. # Project ___| | | | _ \| |
  5. # / __| | | | |_) | |
  6. # | (__| |_| | _ <| |___
  7. # \___|\___/|_| \_\_____|
  8. #
  9. # Copyright (C) 1998 - 2022, 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. system ()
  26. {
  27. /usr/bin/system "$@" || exit 1
  28. }
  29. setenv()
  30. {
  31. # Define and export.
  32. eval ${1}="${2}"
  33. export ${1}
  34. }
  35. case "${SCRIPTDIR}" in
  36. /*) ;;
  37. *) SCRIPTDIR="`pwd`/${SCRIPTDIR}"
  38. esac
  39. while true
  40. do case "${SCRIPTDIR}" in
  41. */.) SCRIPTDIR="${SCRIPTDIR%/.}";;
  42. *) break;;
  43. esac
  44. done
  45. # The script directory is supposed to be in $TOPDIR/packages/os400.
  46. TOPDIR=`dirname "${SCRIPTDIR}"`
  47. TOPDIR=`dirname "${TOPDIR}"`
  48. export SCRIPTDIR TOPDIR
  49. # Extract the SONAME from the library makefile.
  50. SONAME=`sed -e '/^VERSIONINFO=/!d' -e 's/^.* \([0-9]*\):.*$/\1/' -e 'q' \
  51. < "${TOPDIR}/lib/Makefile.am"`
  52. export SONAME
  53. ################################################################################
  54. #
  55. # Tunable configuration parameters.
  56. #
  57. ################################################################################
  58. setenv TARGETLIB 'CURL' # Target OS/400 program library.
  59. setenv STATBNDDIR 'CURL_A' # Static binding directory.
  60. setenv DYNBNDDIR 'CURL' # Dynamic binding directory.
  61. setenv SRVPGM "CURL.${SONAME}" # Service program.
  62. setenv TGTCCSID '500' # Target CCSID of objects.
  63. setenv DEBUG '*ALL' # Debug level.
  64. setenv OPTIMIZE '10' # Optimization level
  65. setenv OUTPUT '*NONE' # Compilation output option.
  66. setenv TGTRLS '*CURRENT' # Target OS release.
  67. setenv IFSDIR '/curl' # Installation IFS directory.
  68. # Define ZLIB availability and locations.
  69. setenv WITH_ZLIB 0 # Define to 1 to enable.
  70. setenv ZLIB_INCLUDE '/zlib/include' # ZLIB include IFS directory.
  71. setenv ZLIB_LIB 'ZLIB' # ZLIB library.
  72. setenv ZLIB_BNDDIR 'ZLIB_A' # ZLIB binding directory.
  73. # Define LIBSSH2 availability and locations.
  74. setenv WITH_LIBSSH2 0 # Define to 1 to enable.
  75. setenv LIBSSH2_INCLUDE '/libssh2/include' # LIBSSH2 include IFS directory.
  76. setenv LIBSSH2_LIB 'LIBSSH2' # LIBSSH2 library.
  77. setenv LIBSSH2_BNDDIR 'LIBSSH2_A' # LIBSSH2 binding directory.
  78. ################################################################################
  79. # Need to get the version definitions.
  80. LIBCURL_VERSION=`grep '^#define *LIBCURL_VERSION ' \
  81. "${TOPDIR}/include/curl/curlver.h" |
  82. sed 's/.*"\(.*\)".*/\1/'`
  83. LIBCURL_VERSION_MAJOR=`grep '^#define *LIBCURL_VERSION_MAJOR ' \
  84. "${TOPDIR}/include/curl/curlver.h" |
  85. sed 's/^#define *LIBCURL_VERSION_MAJOR *\([^ ]*\).*/\1/'`
  86. LIBCURL_VERSION_MINOR=`grep '^#define *LIBCURL_VERSION_MINOR ' \
  87. "${TOPDIR}/include/curl/curlver.h" |
  88. sed 's/^#define *LIBCURL_VERSION_MINOR *\([^ ]*\).*/\1/'`
  89. LIBCURL_VERSION_PATCH=`grep '^#define *LIBCURL_VERSION_PATCH ' \
  90. "${TOPDIR}/include/curl/curlver.h" |
  91. sed 's/^#define *LIBCURL_VERSION_PATCH *\([^ ]*\).*/\1/'`
  92. LIBCURL_VERSION_NUM=`grep '^#define *LIBCURL_VERSION_NUM ' \
  93. "${TOPDIR}/include/curl/curlver.h" |
  94. sed 's/^#define *LIBCURL_VERSION_NUM *0x\([^ ]*\).*/\1/'`
  95. LIBCURL_TIMESTAMP=`grep '^#define *LIBCURL_TIMESTAMP ' \
  96. "${TOPDIR}/include/curl/curlver.h" |
  97. sed 's/.*"\(.*\)".*/\1/'`
  98. export LIBCURL_VERSION
  99. export LIBCURL_VERSION_MAJOR LIBCURL_VERSION_MINOR LIBCURL_VERSION_PATCH
  100. export LIBCURL_VERSION_NUM LIBCURL_TIMESTAMP
  101. ################################################################################
  102. #
  103. # OS/400 specific definitions.
  104. #
  105. ################################################################################
  106. LIBIFSNAME="/QSYS.LIB/${TARGETLIB}.LIB"
  107. ################################################################################
  108. #
  109. # Procedures.
  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. action_needed()
  119. {
  120. [ ! -e "${1}" ] && return 0
  121. [ "${2}" ] || return 1
  122. [ "${1}" -ot "${2}" ] && return 0
  123. return 1
  124. }
  125. # canonicalize_path path
  126. #
  127. # Return canonicalized path as:
  128. # - Absolute
  129. # - No . or .. component.
  130. canonicalize_path()
  131. {
  132. if expr "${1}" : '^/' > /dev/null
  133. then P="${1}"
  134. else P="`pwd`/${1}"
  135. fi
  136. R=
  137. IFSSAVE="${IFS}"
  138. IFS="/"
  139. for C in ${P}
  140. do IFS="${IFSSAVE}"
  141. case "${C}" in
  142. .) ;;
  143. ..) R=`expr "${R}" : '^\(.*/\)..*'`
  144. ;;
  145. ?*) R="${R}${C}/"
  146. ;;
  147. *) ;;
  148. esac
  149. done
  150. IFS="${IFSSAVE}"
  151. echo "/`expr "${R}" : '^\(.*\)/'`"
  152. }
  153. # make_module module_name source_name [additional_definitions]
  154. #
  155. # Compile source name into ASCII module if needed.
  156. # As side effect, append the module name to variable MODULES.
  157. # Set LINK to "YES" if the module has been compiled.
  158. make_module()
  159. {
  160. MODULES="${MODULES} ${1}"
  161. MODIFSNAME="${LIBIFSNAME}/${1}.MODULE"
  162. action_needed "${MODIFSNAME}" "${2}" || return 0;
  163. SRCDIR=`dirname \`canonicalize_path "${2}"\``
  164. # #pragma convert has to be in the source file itself, i.e.
  165. # putting it in an include file makes it only active
  166. # for that include file.
  167. # Thus we build a temporary file with the pragma prepended to
  168. # the source file and we compile that themporary file.
  169. echo "#line 1 \"${2}\"" > __tmpsrcf.c
  170. echo "#pragma convert(819)" >> __tmpsrcf.c
  171. echo "#line 1" >> __tmpsrcf.c
  172. cat "${2}" >> __tmpsrcf.c
  173. CMD="CRTCMOD MODULE(${TARGETLIB}/${1}) SRCSTMF('__tmpsrcf.c')"
  174. # CMD="${CMD} SYSIFCOPT(*IFS64IO) OPTION(*INCDIRFIRST *SHOWINC *SHOWSYS)"
  175. CMD="${CMD} SYSIFCOPT(*IFS64IO) OPTION(*INCDIRFIRST)"
  176. CMD="${CMD} LOCALETYPE(*LOCALE) FLAG(10)"
  177. CMD="${CMD} INCDIR('/qibm/proddata/qadrt/include'"
  178. CMD="${CMD} '${TOPDIR}/include/curl' '${TOPDIR}/include' '${SRCDIR}'"
  179. CMD="${CMD} '${TOPDIR}/packages/OS400'"
  180. if [ "${WITH_ZLIB}" != "0" ]
  181. then CMD="${CMD} '${ZLIB_INCLUDE}'"
  182. fi
  183. if [ "${WITH_LIBSSH2}" != "0" ]
  184. then CMD="${CMD} '${LIBSSH2_INCLUDE}'"
  185. fi
  186. CMD="${CMD} ${INCLUDES})"
  187. CMD="${CMD} TGTCCSID(${TGTCCSID}) TGTRLS(${TGTRLS})"
  188. CMD="${CMD} OUTPUT(${OUTPUT})"
  189. CMD="${CMD} OPTIMIZE(${OPTIMIZE})"
  190. CMD="${CMD} DBGVIEW(${DEBUG})"
  191. DEFINES="${3} BUILDING_LIBCURL"
  192. if [ "${WITH_ZLIB}" != "0" ]
  193. then DEFINES="${DEFINES} HAVE_LIBZ"
  194. fi
  195. if [ "${WITH_LIBSSH2}" != "0" ]
  196. then DEFINES="${DEFINES} USE_LIBSSH2"
  197. fi
  198. if [ "${DEFINES}" ]
  199. then CMD="${CMD} DEFINE(${DEFINES})"
  200. fi
  201. system "${CMD}"
  202. rm -f __tmpsrcf.c
  203. LINK=YES
  204. }
  205. # Determine DB2 object name from IFS name.
  206. db2_name()
  207. {
  208. if [ "${2}" = 'nomangle' ]
  209. then basename "${1}" |
  210. tr 'a-z-' 'A-Z_' |
  211. sed -e 's/\..*//' \
  212. -e 's/^\(.\).*\(.........\)$/\1\2/'
  213. else basename "${1}" |
  214. tr 'a-z-' 'A-Z_' |
  215. sed -e 's/\..*//' \
  216. -e 's/^CURL_*/C/' \
  217. -e 's/^\(.\).*\(.........\)$/\1\2/'
  218. fi
  219. }
  220. # Copy IFS file replacing version info.
  221. versioned_copy()
  222. {
  223. sed -e "s/@LIBCURL_VERSION@/${LIBCURL_VERSION}/g" \
  224. -e "s/@LIBCURL_VERSION_MAJOR@/${LIBCURL_VERSION_MAJOR}/g" \
  225. -e "s/@LIBCURL_VERSION_MINOR@/${LIBCURL_VERSION_MINOR}/g" \
  226. -e "s/@LIBCURL_VERSION_PATCH@/${LIBCURL_VERSION_PATCH}/g" \
  227. -e "s/@LIBCURL_VERSION_NUM@/${LIBCURL_VERSION_NUM}/g" \
  228. -e "s/@LIBCURL_TIMESTAMP@/${LIBCURL_TIMESTAMP}/g" \
  229. < "${1}" > "${2}"
  230. }