initscript.sh 9.5 KB

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