initscript.sh 9.8 KB

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