1 1.1 christos #!/bin/sh 2 1.1 christos # 3 1.1 christos # ZLIB compilation script for the OS/400. 4 1.1 christos # 5 1.1 christos # 6 1.1 christos # This is a shell script since make is not a standard component of OS/400. 7 1.1 christos 8 1.1 christos 9 1.1 christos ################################################################################ 10 1.1 christos # 11 1.1 christos # Tunable configuration parameters. 12 1.1 christos # 13 1.1 christos ################################################################################ 14 1.1 christos 15 1.1 christos TARGETLIB='ZLIB' # Target OS/400 program library 16 1.1 christos STATBNDDIR='ZLIB_A' # Static binding directory. 17 1.1 christos DYNBNDDIR='ZLIB' # Dynamic binding directory. 18 1.1 christos SRVPGM="ZLIB" # Service program. 19 1.1 christos IFSDIR='/zlib' # IFS support base directory. 20 1.1 christos TGTCCSID='500' # Target CCSID of objects 21 1.1 christos DEBUG='*NONE' # Debug level 22 1.1 christos OPTIMIZE='40' # Optimisation level 23 1.1 christos OUTPUT='*NONE' # Compilation output option. 24 1.1 christos TGTRLS='V6R1M0' # Target OS release 25 1.1 christos 26 1.1 christos export TARGETLIB STATBNDDIR DYNBNDDIR SRVPGM IFSDIR 27 1.1 christos export TGTCCSID DEBUG OPTIMIZE OUTPUT TGTRLS 28 1.1 christos 29 1.1 christos 30 1.1 christos ################################################################################ 31 1.1 christos # 32 1.1 christos # OS/400 specific definitions. 33 1.1 christos # 34 1.1 christos ################################################################################ 35 1.1 christos 36 1.1 christos LIBIFSNAME="/QSYS.LIB/${TARGETLIB}.LIB" 37 1.1 christos 38 1.1 christos 39 1.1 christos ################################################################################ 40 1.1 christos # 41 1.1 christos # Procedures. 42 1.1 christos # 43 1.1 christos ################################################################################ 44 1.1 christos 45 1.1 christos # action_needed dest [src] 46 1.1 christos # 47 1.1 christos # dest is an object to build 48 1.1 christos # if specified, src is an object on which dest depends. 49 1.1 christos # 50 1.1 christos # exit 0 (succeeds) if some action has to be taken, else 1. 51 1.1 christos 52 1.1 christos action_needed() 53 1.1 christos 54 1.1 christos { 55 1.1 christos [ ! -e "${1}" ] && return 0 56 1.1 christos [ "${2}" ] || return 1 57 1.1 christos [ "${1}" -ot "${2}" ] && return 0 58 1.1 christos return 1 59 1.1 christos } 60 1.1 christos 61 1.1 christos 62 1.1 christos # make_module module_name source_name [additional_definitions] 63 1.1 christos # 64 1.1 christos # Compile source name into module if needed. 65 1.1 christos # As side effect, append the module name to variable MODULES. 66 1.1 christos # Set LINK to "YES" if the module has been compiled. 67 1.1 christos 68 1.1 christos make_module() 69 1.1 christos 70 1.1 christos { 71 1.1 christos MODULES="${MODULES} ${1}" 72 1.1 christos MODIFSNAME="${LIBIFSNAME}/${1}.MODULE" 73 1.1 christos CSRC="`basename \"${2}\"`" 74 1.1 christos 75 1.1 christos if action_needed "${MODIFSNAME}" "${2}" 76 1.1 christos then : 77 1.1 christos elif [ ! "`sed -e \"/<source name=\\\"${CSRC}\\\">/,/<\\\\/source>/!d\" \ 78 1.1 christos -e '/<depend /!d' \ 79 1.1 christos -e 's/.* name=\"\\([^\"]*\\)\".*/\\1/' < \"${TOPDIR}/treebuild.xml\" | 80 1.1 christos while read HDR 81 1.1 christos do if action_needed \"${MODIFSNAME}\" \"${IFSDIR}/include/${HDR}\" 82 1.1 christos then echo recompile 83 1.1 christos break 84 1.1 christos fi 85 1.1 christos done`" ] 86 1.1 christos then return 0 87 1.1 christos fi 88 1.1 christos 89 1.1 christos CMD="CRTCMOD MODULE(${TARGETLIB}/${1}) SRCSTMF('${2}')" 90 1.1 christos CMD="${CMD} SYSIFCOPT(*IFS64IO) OPTION(*INCDIRFIRST)" 91 1.1 christos CMD="${CMD} LOCALETYPE(*LOCALE) FLAG(10)" 92 1.1 christos CMD="${CMD} INCDIR('${IFSDIR}/include' ${INCLUDES})" 93 1.1 christos CMD="${CMD} TGTCCSID(${TGTCCSID}) TGTRLS(${TGTRLS})" 94 1.1 christos CMD="${CMD} OUTPUT(${OUTPUT})" 95 1.1 christos CMD="${CMD} OPTIMIZE(${OPTIMIZE})" 96 1.1 christos CMD="${CMD} DBGVIEW(${DEBUG})" 97 1.1 christos system "${CMD}" 98 1.1 christos LINK=YES 99 1.1 christos } 100 1.1 christos 101 1.1 christos 102 1.1 christos # Determine DB2 object name from IFS name. 103 1.1 christos 104 1.1 christos db2_name() 105 1.1 christos 106 1.1 christos { 107 1.1 christos basename "${1}" | 108 1.1 christos tr 'a-z-' 'A-Z_' | 109 1.1 christos sed -e 's/\..*//' \ 110 1.1 christos -e 's/^\(.\).*\(.........\)$/\1\2/' 111 1.1 christos } 112 1.1 christos 113 1.1 christos 114 1.1 christos # Force enumeration types to be the same size as integers. 115 1.1 christos 116 1.1 christos copy_hfile() 117 1.1 christos 118 1.1 christos { 119 1.1 christos sed -e '1i\ 120 1.1 christos #pragma enum(int)\ 121 1.1 christos ' "${@}" -e '$a\ 122 1.1 christos #pragma enum(pop)\ 123 1.1 christos ' 124 1.1 christos } 125 1.1 christos 126 1.1 christos 127 1.1 christos ################################################################################ 128 1.1 christos # 129 1.1 christos # Script initialization. 130 1.1 christos # 131 1.1 christos ################################################################################ 132 1.1 christos 133 1.1 christos SCRIPTDIR=`dirname "${0}"` 134 1.1 christos 135 1.1 christos case "${SCRIPTDIR}" in 136 1.1 christos /*) ;; 137 1.1 christos *) SCRIPTDIR="`pwd`/${SCRIPTDIR}" 138 1.1 christos esac 139 1.1 christos 140 1.1 christos while true 141 1.1 christos do case "${SCRIPTDIR}" in 142 1.1 christos */.) SCRIPTDIR="${SCRIPTDIR%/.}";; 143 1.1 christos *) break;; 144 1.1 christos esac 145 1.1 christos done 146 1.1 christos 147 1.1 christos # The script directory is supposed to be in ${TOPDIR}/os400. 148 1.1 christos 149 1.1 christos TOPDIR=`dirname "${SCRIPTDIR}"` 150 1.1 christos export SCRIPTDIR TOPDIR 151 1.1 christos cd "${TOPDIR}" 152 1.1 christos 153 1.1 christos 154 1.1 christos # Extract the version from the master compilation XML file. 155 1.1 christos 156 1.1 christos VERSION=`sed -e '/^<package /!d' \ 157 1.1 christos -e 's/^.* version="\([0-9.]*\)".*$/\1/' -e 'q' \ 158 1.1 christos < treebuild.xml` 159 1.1 christos export VERSION 160 1.1 christos 161 1.1 christos ################################################################################ 162 1.1 christos 163 1.1 christos 164 1.1 christos # Create the OS/400 library if it does not exist. 165 1.1 christos 166 1.1 christos if action_needed "${LIBIFSNAME}" 167 1.1 christos then CMD="CRTLIB LIB(${TARGETLIB}) TEXT('ZLIB: Data compression API')" 168 1.1 christos system "${CMD}" 169 1.1 christos fi 170 1.1 christos 171 1.1 christos 172 1.1 christos # Create the DOCS source file if it does not exist. 173 1.1 christos 174 1.1 christos if action_needed "${LIBIFSNAME}/DOCS.FILE" 175 1.1 christos then CMD="CRTSRCPF FILE(${TARGETLIB}/DOCS) RCDLEN(112)" 176 1.1 christos CMD="${CMD} CCSID(${TGTCCSID}) TEXT('Documentation texts')" 177 1.1 christos system "${CMD}" 178 1.1 christos fi 179 1.1 christos 180 1.1 christos # Copy some documentation files if needed. 181 1.1 christos 182 1.1 christos for TEXT in "${TOPDIR}/ChangeLog" "${TOPDIR}/FAQ" \ 183 1.1 christos "${TOPDIR}/README" "${SCRIPTDIR}/README400" 184 1.1 christos do MEMBER="${LIBIFSNAME}/DOCS.FILE/`db2_name \"${TEXT}\"`.MBR" 185 1.1 christos 186 1.1 christos if action_needed "${MEMBER}" "${TEXT}" 187 1.1 christos then CMD="CPY OBJ('${TEXT}') TOOBJ('${MEMBER}') TOCCSID(${TGTCCSID})" 188 1.1 christos CMD="${CMD} DTAFMT(*TEXT) REPLACE(*YES)" 189 1.1 christos system "${CMD}" 190 1.1 christos fi 191 1.1 christos done 192 1.1 christos 193 1.1 christos 194 1.1 christos # Create the OS/400 source program file for the C header files. 195 1.1 christos 196 1.1 christos SRCPF="${LIBIFSNAME}/H.FILE" 197 1.1 christos 198 1.1 christos if action_needed "${SRCPF}" 199 1.1 christos then CMD="CRTSRCPF FILE(${TARGETLIB}/H) RCDLEN(112)" 200 1.1 christos CMD="${CMD} CCSID(${TGTCCSID}) TEXT('ZLIB: C/C++ header files')" 201 1.1 christos system "${CMD}" 202 1.1 christos fi 203 1.1 christos 204 1.1 christos 205 1.1 christos # Create the IFS directory for the C header files. 206 1.1 christos 207 1.1 christos if action_needed "${IFSDIR}/include" 208 1.1 christos then mkdir -p "${IFSDIR}/include" 209 1.1 christos fi 210 1.1 christos 211 1.1 christos # Copy the header files to DB2 library. Link from IFS include directory. 212 1.1 christos 213 1.1 christos for HFILE in "${TOPDIR}/"*.h 214 1.1 christos do DEST="${SRCPF}/`db2_name \"${HFILE}\"`.MBR" 215 1.1 christos 216 1.1 christos if action_needed "${DEST}" "${HFILE}" 217 1.1 christos then copy_hfile < "${HFILE}" > tmphdrfile 218 1.1 christos 219 1.1 christos # Need to translate to target CCSID. 220 1.1 christos 221 1.1 christos CMD="CPY OBJ('`pwd`/tmphdrfile') TOOBJ('${DEST}')" 222 1.1 christos CMD="${CMD} TOCCSID(${TGTCCSID}) DTAFMT(*TEXT) REPLACE(*YES)" 223 1.1 christos system "${CMD}" 224 1.1 christos # touch -r "${HFILE}" "${DEST}" 225 1.1 christos rm -f tmphdrfile 226 1.1 christos fi 227 1.1 christos 228 1.1 christos IFSFILE="${IFSDIR}/include/`basename \"${HFILE}\"`" 229 1.1 christos 230 1.1 christos if action_needed "${IFSFILE}" "${DEST}" 231 1.1 christos then rm -f "${IFSFILE}" 232 1.1 christos ln -s "${DEST}" "${IFSFILE}" 233 1.1 christos fi 234 1.1 christos done 235 1.1 christos 236 1.1 christos 237 1.1 christos # Install the ILE/RPG header file. 238 1.1 christos 239 1.1 christos 240 1.1 christos HFILE="${SCRIPTDIR}/zlib.inc" 241 1.1 christos DEST="${SRCPF}/ZLIB.INC.MBR" 242 1.1 christos 243 1.1 christos if action_needed "${DEST}" "${HFILE}" 244 1.1 christos then CMD="CPY OBJ('${HFILE}') TOOBJ('${DEST}')" 245 1.1 christos CMD="${CMD} TOCCSID(${TGTCCSID}) DTAFMT(*TEXT) REPLACE(*YES)" 246 1.1 christos system "${CMD}" 247 1.1 christos # touch -r "${HFILE}" "${DEST}" 248 1.1 christos fi 249 1.1 christos 250 1.1 christos IFSFILE="${IFSDIR}/include/`basename \"${HFILE}\"`" 251 1.1 christos 252 1.1 christos if action_needed "${IFSFILE}" "${DEST}" 253 1.1 christos then rm -f "${IFSFILE}" 254 1.1 christos ln -s "${DEST}" "${IFSFILE}" 255 1.1 christos fi 256 1.1 christos 257 1.1 christos 258 1.1 christos # Create and compile the identification source file. 259 1.1 christos 260 1.1 christos echo '#pragma comment(user, "ZLIB version '"${VERSION}"'")' > os400.c 261 1.1 christos echo '#pragma comment(user, __DATE__)' >> os400.c 262 1.1 christos echo '#pragma comment(user, __TIME__)' >> os400.c 263 1.1.1.2 christos echo '#pragma comment(copyright, "Copyright (C) 1995-2017 Jean-Loup Gailly, Mark Adler. OS/400 version by P. Monnerat.")' >> os400.c 264 1.1 christos make_module OS400 os400.c 265 1.1 christos LINK= # No need to rebuild service program yet. 266 1.1 christos MODULES= 267 1.1 christos 268 1.1 christos 269 1.1 christos # Get source list. 270 1.1 christos 271 1.1 christos CSOURCES=`sed -e '/<source name="/!d' \ 272 1.1 christos -e 's/.* name="\([^"]*\)".*/\1/' < treebuild.xml` 273 1.1 christos 274 1.1 christos # Compile the sources into modules. 275 1.1 christos 276 1.1 christos for SRC in ${CSOURCES} 277 1.1 christos do MODULE=`db2_name "${SRC}"` 278 1.1 christos make_module "${MODULE}" "${SRC}" 279 1.1 christos done 280 1.1 christos 281 1.1 christos 282 1.1 christos # If needed, (re)create the static binding directory. 283 1.1 christos 284 1.1 christos if action_needed "${LIBIFSNAME}/${STATBNDDIR}.BNDDIR" 285 1.1 christos then LINK=YES 286 1.1 christos fi 287 1.1 christos 288 1.1 christos if [ "${LINK}" ] 289 1.1 christos then rm -rf "${LIBIFSNAME}/${STATBNDDIR}.BNDDIR" 290 1.1 christos CMD="CRTBNDDIR BNDDIR(${TARGETLIB}/${STATBNDDIR})" 291 1.1 christos CMD="${CMD} TEXT('ZLIB static binding directory')" 292 1.1 christos system "${CMD}" 293 1.1 christos 294 1.1 christos for MODULE in ${MODULES} 295 1.1 christos do CMD="ADDBNDDIRE BNDDIR(${TARGETLIB}/${STATBNDDIR})" 296 1.1 christos CMD="${CMD} OBJ((${TARGETLIB}/${MODULE} *MODULE))" 297 1.1 christos system "${CMD}" 298 1.1 christos done 299 1.1 christos fi 300 1.1 christos 301 1.1 christos 302 1.1 christos # The exportation file for service program creation must be in a DB2 303 1.1 christos # source file, so make sure it exists. 304 1.1 christos 305 1.1 christos if action_needed "${LIBIFSNAME}/TOOLS.FILE" 306 1.1 christos then CMD="CRTSRCPF FILE(${TARGETLIB}/TOOLS) RCDLEN(112)" 307 1.1 christos CMD="${CMD} CCSID(${TGTCCSID}) TEXT('ZLIB: build tools')" 308 1.1 christos system "${CMD}" 309 1.1 christos fi 310 1.1 christos 311 1.1 christos 312 1.1 christos DEST="${LIBIFSNAME}/TOOLS.FILE/BNDSRC.MBR" 313 1.1 christos 314 1.1 christos if action_needed "${SCRIPTDIR}/bndsrc" "${DEST}" 315 1.1 christos then CMD="CPY OBJ('${SCRIPTDIR}/bndsrc') TOOBJ('${DEST}')" 316 1.1 christos CMD="${CMD} TOCCSID(${TGTCCSID}) DTAFMT(*TEXT) REPLACE(*YES)" 317 1.1 christos system "${CMD}" 318 1.1 christos # touch -r "${SCRIPTDIR}/bndsrc" "${DEST}" 319 1.1 christos LINK=YES 320 1.1 christos fi 321 1.1 christos 322 1.1 christos 323 1.1 christos # Build the service program if needed. 324 1.1 christos 325 1.1 christos if action_needed "${LIBIFSNAME}/${SRVPGM}.SRVPGM" 326 1.1 christos then LINK=YES 327 1.1 christos fi 328 1.1 christos 329 1.1 christos if [ "${LINK}" ] 330 1.1 christos then CMD="CRTSRVPGM SRVPGM(${TARGETLIB}/${SRVPGM})" 331 1.1 christos CMD="${CMD} SRCFILE(${TARGETLIB}/TOOLS) SRCMBR(BNDSRC)" 332 1.1 christos CMD="${CMD} MODULE(${TARGETLIB}/OS400)" 333 1.1 christos CMD="${CMD} BNDDIR(${TARGETLIB}/${STATBNDDIR})" 334 1.1 christos CMD="${CMD} TEXT('ZLIB ${VERSION} dynamic library')" 335 1.1 christos CMD="${CMD} TGTRLS(${TGTRLS})" 336 1.1 christos system "${CMD}" 337 1.1 christos LINK=YES 338 1.1 christos 339 1.1 christos # Duplicate the service program for a versioned backup. 340 1.1 christos 341 1.1 christos BACKUP=`echo "${SRVPGM}${VERSION}" | 342 1.1 christos sed -e 's/.*\(..........\)$/\1/' -e 's/\./_/g'` 343 1.1 christos BACKUP="`db2_name \"${BACKUP}\"`" 344 1.1 christos BKUPIFSNAME="${LIBIFSNAME}/${BACKUP}.SRVPGM" 345 1.1 christos rm -f "${BKUPIFSNAME}" 346 1.1 christos CMD="CRTDUPOBJ OBJ(${SRVPGM}) FROMLIB(${TARGETLIB})" 347 1.1 christos CMD="${CMD} OBJTYPE(*SRVPGM) NEWOBJ(${BACKUP})" 348 1.1 christos system "${CMD}" 349 1.1 christos fi 350 1.1 christos 351 1.1 christos 352 1.1 christos # If needed, (re)create the dynamic binding directory. 353 1.1 christos 354 1.1 christos if action_needed "${LIBIFSNAME}/${DYNBNDDIR}.BNDDIR" 355 1.1 christos then LINK=YES 356 1.1 christos fi 357 1.1 christos 358 1.1 christos if [ "${LINK}" ] 359 1.1 christos then rm -rf "${LIBIFSNAME}/${DYNBNDDIR}.BNDDIR" 360 1.1 christos CMD="CRTBNDDIR BNDDIR(${TARGETLIB}/${DYNBNDDIR})" 361 1.1 christos CMD="${CMD} TEXT('ZLIB dynamic binding directory')" 362 1.1 christos system "${CMD}" 363 1.1 christos CMD="ADDBNDDIRE BNDDIR(${TARGETLIB}/${DYNBNDDIR})" 364 1.1 christos CMD="${CMD} OBJ((*LIBL/${SRVPGM} *SRVPGM))" 365 1.1 christos system "${CMD}" 366 1.1 christos fi 367