initscript.sh 8.7 KB

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