initscript.sh 9.7 KB

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