2
0

initscript.sh 9.9 KB

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