3 # ZLIB compilation script for the OS/400.
6 # This is a shell script since make is not a standard component of OS/400.
9 ################################################################################
11 # Tunable configuration parameters.
13 ################################################################################
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
26 export TARGETLIB STATBNDDIR DYNBNDDIR SRVPGM IFSDIR
27 export TGTCCSID DEBUG OPTIMIZE OUTPUT TGTRLS
30 ################################################################################
32 # OS/400 specific definitions.
34 ################################################################################
36 LIBIFSNAME
="/QSYS.LIB/${TARGETLIB}.LIB"
39 ################################################################################
43 ################################################################################
45 # action_needed dest [src]
47 # dest is an object to build
48 # if specified, src is an object on which dest depends.
50 # exit 0 (succeeds) if some action has to be taken, else 1.
55 [ ! -e "${1}" ] && return 0
56 [ "${2}" ] ||
return 1
57 [ "${1}" -ot "${2}" ] && return 0
62 # make_module module_name source_name [additional_definitions]
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.
71 MODULES
="${MODULES} ${1}"
72 MODIFSNAME
="${LIBIFSNAME}/${1}.MODULE"
73 CSRC
="`basename \"${2}\"`"
75 if action_needed
"${MODIFSNAME}" "${2}"
77 elif [ ! "`sed -e \"/<source name=\\\"${CSRC}\\\">/,/<\\\\/source>/!d\" \
79 -e 's/.* name=\"\\([^\"]*\\)\".*/\\1/' < \"${TOPDIR}/treebuild.xml\" |
81 do if action_needed \"${MODIFSNAME}\" \"${IFSDIR}/include/${HDR}\"
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})"
102 # Determine DB2 object name from IFS name.
110 -e 's/^\(.\).*\(.........\)$/\1\2/'
114 # Force enumeration types to be the same size as integers.
127 ################################################################################
129 # Script initialization.
131 ################################################################################
133 SCRIPTDIR
=`dirname "${0}"`
135 case "${SCRIPTDIR}" in
137 *) SCRIPTDIR
="`pwd`/${SCRIPTDIR}"
141 do case "${SCRIPTDIR}" in
142 */.
) SCRIPTDIR
="${SCRIPTDIR%/.}";;
147 # The script directory is supposed to be in ${TOPDIR}/os400.
149 TOPDIR
=`dirname "${SCRIPTDIR}"`
150 export SCRIPTDIR TOPDIR
154 # Extract the version from the master compilation XML file.
156 VERSION
=`sed -e '/^<package /!d' \
157 -e 's/^.* version="\([0-9.]*\)".*$/\1/' -e 'q' \
161 ################################################################################
164 # Create the OS/400 library if it does not exist.
166 if action_needed
"${LIBIFSNAME}"
167 then CMD
="CRTLIB LIB(${TARGETLIB}) TEXT('ZLIB: Data compression API')"
172 # Create the DOCS source file if it does not exist.
174 if action_needed
"${LIBIFSNAME}/DOCS.FILE"
175 then CMD
="CRTSRCPF FILE(${TARGETLIB}/DOCS) RCDLEN(112)"
176 CMD
="${CMD} CCSID(${TGTCCSID}) TEXT('Documentation texts')"
180 # Copy some documentation files if needed.
182 for TEXT
in "${TOPDIR}/ChangeLog" "${TOPDIR}/FAQ" \
183 "${TOPDIR}/README" "${SCRIPTDIR}/README400"
184 do MEMBER
="${LIBIFSNAME}/DOCS.FILE/`db2_name \"${TEXT}\"`.MBR"
186 if action_needed
"${MEMBER}" "${TEXT}"
187 then CMD
="CPY OBJ('${TEXT}') TOOBJ('${MEMBER}') TOCCSID(${TGTCCSID})"
188 CMD
="${CMD} DTAFMT(*TEXT) REPLACE(*YES)"
194 # Create the OS/400 source program file for the C header files.
196 SRCPF
="${LIBIFSNAME}/H.FILE"
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')"
205 # Create the IFS directory for the C header files.
207 if action_needed
"${IFSDIR}/include"
208 then mkdir
-p "${IFSDIR}/include"
211 # Copy the header files to DB2 library. Link from IFS include directory.
213 for HFILE
in "${TOPDIR}/"*.h
214 do DEST
="${SRCPF}/`db2_name \"${HFILE}\"`.MBR"
216 if action_needed
"${DEST}" "${HFILE}"
217 then copy_hfile
< "${HFILE}" > tmphdrfile
219 # Need to translate to target CCSID.
221 CMD
="CPY OBJ('`pwd`/tmphdrfile') TOOBJ('${DEST}')"
222 CMD
="${CMD} TOCCSID(${TGTCCSID}) DTAFMT(*TEXT) REPLACE(*YES)"
224 # touch -r "${HFILE}" "${DEST}"
228 IFSFILE
="${IFSDIR}/include/`basename \"${HFILE}\"`"
230 if action_needed
"${IFSFILE}" "${DEST}"
231 then rm -f "${IFSFILE}"
232 ln -s "${DEST}" "${IFSFILE}"
237 # Install the ILE/RPG header file.
240 HFILE
="${SCRIPTDIR}/zlib.inc"
241 DEST
="${SRCPF}/ZLIB.INC.MBR"
243 if action_needed
"${DEST}" "${HFILE}"
244 then CMD
="CPY OBJ('${HFILE}') TOOBJ('${DEST}')"
245 CMD
="${CMD} TOCCSID(${TGTCCSID}) DTAFMT(*TEXT) REPLACE(*YES)"
247 # touch -r "${HFILE}" "${DEST}"
250 IFSFILE
="${IFSDIR}/include/`basename \"${HFILE}\"`"
252 if action_needed
"${IFSFILE}" "${DEST}"
253 then rm -f "${IFSFILE}"
254 ln -s "${DEST}" "${IFSFILE}"
258 # Create and compile the identification source file.
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.
271 CSOURCES
=`sed -e '/<source name="/!d' \
272 -e 's/.* name="\([^"]*\)".*/\1/' < treebuild.xml`
274 # Compile the sources into modules.
276 for SRC
in ${CSOURCES}
277 do MODULE
=`db2_name "${SRC}"`
278 make_module
"${MODULE}" "${SRC}"
282 # If needed, (re)create the static binding directory.
284 if action_needed
"${LIBIFSNAME}/${STATBNDDIR}.BNDDIR"
289 then rm -rf "${LIBIFSNAME}/${STATBNDDIR}.BNDDIR"
290 CMD
="CRTBNDDIR BNDDIR(${TARGETLIB}/${STATBNDDIR})"
291 CMD
="${CMD} TEXT('ZLIB static binding directory')"
294 for MODULE
in ${MODULES}
295 do CMD
="ADDBNDDIRE BNDDIR(${TARGETLIB}/${STATBNDDIR})"
296 CMD
="${CMD} OBJ((${TARGETLIB}/${MODULE} *MODULE))"
302 # The exportation file for service program creation must be in a DB2
303 # source file, so make sure it exists.
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')"
312 DEST
="${LIBIFSNAME}/TOOLS.FILE/BNDSRC.MBR"
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)"
318 # touch -r "${SCRIPTDIR}/bndsrc" "${DEST}"
323 # Build the service program if needed.
325 if action_needed
"${LIBIFSNAME}/${SRVPGM}.SRVPGM"
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})"
339 # Duplicate the service program for a versioned backup.
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})"
352 # If needed, (re)create the dynamic binding directory.
354 if action_needed
"${LIBIFSNAME}/${DYNBNDDIR}.BNDDIR"
359 then rm -rf "${LIBIFSNAME}/${DYNBNDDIR}.BNDDIR"
360 CMD
="CRTBNDDIR BNDDIR(${TARGETLIB}/${DYNBNDDIR})"
361 CMD
="${CMD} TEXT('ZLIB dynamic binding directory')"
363 CMD
="ADDBNDDIRE BNDDIR(${TARGETLIB}/${DYNBNDDIR})"
364 CMD
="${CMD} OBJ((*LIBL/${SRVPGM} *SRVPGM))"