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