initscript.sh 9.8 KB

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