OS400: fix shellcheck warnings in scripts

- use `$()` instead of backticks, and re-arrange double-quotes inside.
- add missing `|| exit 1` to `cd` calls. (could be dropped by using `set -eu`.)
- add `-n` to a few `if`s.
- shorten redirections by using `{} >` (as shellcheck recommended).
- silence warnings where variables were detected as unused (SC2034).
- a couple misc updates to silence warnings.
- switch to bash shebang for `-ot` feature.
- split two lines to unbreak syntax highlighting in my editor. (`$(expr \`, `$(dirname \`)

Also enable CI checks for OS/400 shell scripts.

Ref: #13307
Closes #13309
This commit is contained in:
Viktor Szakats 2024-04-07 12:39:59 +00:00
parent 8dd81bd5db
commit 8a622baf9e
No known key found for this signature in database
GPG Key ID: B5ABD165E2AEF201
8 changed files with 106 additions and 92 deletions

View File

@ -3,10 +3,8 @@
# #
# SPDX-License-Identifier: curl # SPDX-License-Identifier: curl
# FIXME: packages/OS400/* scripts
shellcheck --version shellcheck --version
# shellcheck disable=SC2046 # shellcheck disable=SC2046
shellcheck --exclude=1091 \ shellcheck --exclude=1091 \
--enable=avoid-nullary-conditions,deprecate-which \ --enable=avoid-nullary-conditions,deprecate-which \
$(grep -l -E '^#!(/usr/bin/env bash|/bin/sh|/bin/bash)' $(git ls-files | grep -v -F 'packages/OS400/')) $(grep -l -E '^#!(/usr/bin/env bash|/bin/sh|/bin/bash)' $(git ls-files))

View File

@ -1,4 +1,4 @@
#!/bin/sh #!/usr/bin/env bash
#*************************************************************************** #***************************************************************************
# _ _ ____ _ # _ _ ____ _
# Project ___| | | | _ \| | # Project ___| | | | _ \| |

View File

@ -1,4 +1,4 @@
#!/bin/sh #!/usr/bin/env bash
#*************************************************************************** #***************************************************************************
# _ _ ____ _ # _ _ ____ _
# Project ___| | | | _ \| | # Project ___| | | | _ \| |
@ -33,14 +33,14 @@ setenv()
{ {
# Define and export. # Define and export.
eval ${1}="${2}" eval "${1}=${2}"
export ${1} export "${1?}"
} }
case "${SCRIPTDIR}" in case "${SCRIPTDIR}" in
/*) ;; /*) ;;
*) SCRIPTDIR="`pwd`/${SCRIPTDIR}" *) SCRIPTDIR="$(pwd)/${SCRIPTDIR}"
esac esac
while true while true
@ -52,14 +52,14 @@ done
# The script directory is supposed to be in $TOPDIR/packages/os400. # The script directory is supposed to be in $TOPDIR/packages/os400.
TOPDIR=`dirname "${SCRIPTDIR}"` TOPDIR=$(dirname "${SCRIPTDIR}")
TOPDIR=`dirname "${TOPDIR}"` TOPDIR=$(dirname "${TOPDIR}")
export SCRIPTDIR TOPDIR export SCRIPTDIR TOPDIR
# Extract the SONAME from the library makefile. # Extract the SONAME from the library makefile.
SONAME=`sed -e '/^VERSIONCHANGE=/!d;s/^.*=\([0-9]*\).*/\1/' \ SONAME="$(sed -e '/^VERSIONCHANGE=/!d;s/^.*=\([0-9]*\).*/\1/' \
< "${TOPDIR}/lib/Makefile.soname"` < "${TOPDIR}/lib/Makefile.soname")"
export SONAME export SONAME
# Get OS/400 configuration parameters. # Get OS/400 configuration parameters.
@ -71,24 +71,24 @@ fi
# Need to get the version definitions. # Need to get the version definitions.
LIBCURL_VERSION=`grep '^#define *LIBCURL_VERSION ' \ LIBCURL_VERSION=$(grep '^#define *LIBCURL_VERSION ' \
"${TOPDIR}/include/curl/curlver.h" | "${TOPDIR}/include/curl/curlver.h" |
sed 's/.*"\(.*\)".*/\1/'` sed 's/.*"\(.*\)".*/\1/')
LIBCURL_VERSION_MAJOR=`grep '^#define *LIBCURL_VERSION_MAJOR ' \ LIBCURL_VERSION_MAJOR=$(grep '^#define *LIBCURL_VERSION_MAJOR ' \
"${TOPDIR}/include/curl/curlver.h" | "${TOPDIR}/include/curl/curlver.h" |
sed 's/^#define *LIBCURL_VERSION_MAJOR *\([^ ]*\).*/\1/'` sed 's/^#define *LIBCURL_VERSION_MAJOR *\([^ ]*\).*/\1/')
LIBCURL_VERSION_MINOR=`grep '^#define *LIBCURL_VERSION_MINOR ' \ LIBCURL_VERSION_MINOR=$(grep '^#define *LIBCURL_VERSION_MINOR ' \
"${TOPDIR}/include/curl/curlver.h" | "${TOPDIR}/include/curl/curlver.h" |
sed 's/^#define *LIBCURL_VERSION_MINOR *\([^ ]*\).*/\1/'` sed 's/^#define *LIBCURL_VERSION_MINOR *\([^ ]*\).*/\1/')
LIBCURL_VERSION_PATCH=`grep '^#define *LIBCURL_VERSION_PATCH ' \ LIBCURL_VERSION_PATCH=$(grep '^#define *LIBCURL_VERSION_PATCH ' \
"${TOPDIR}/include/curl/curlver.h" | "${TOPDIR}/include/curl/curlver.h" |
sed 's/^#define *LIBCURL_VERSION_PATCH *\([^ ]*\).*/\1/'` sed 's/^#define *LIBCURL_VERSION_PATCH *\([^ ]*\).*/\1/')
LIBCURL_VERSION_NUM=`grep '^#define *LIBCURL_VERSION_NUM ' \ LIBCURL_VERSION_NUM=$(grep '^#define *LIBCURL_VERSION_NUM ' \
"${TOPDIR}/include/curl/curlver.h" | "${TOPDIR}/include/curl/curlver.h" |
sed 's/^#define *LIBCURL_VERSION_NUM *0x\([^ ]*\).*/\1/'` sed 's/^#define *LIBCURL_VERSION_NUM *0x\([^ ]*\).*/\1/')
LIBCURL_TIMESTAMP=`grep '^#define *LIBCURL_TIMESTAMP ' \ LIBCURL_TIMESTAMP=$(grep '^#define *LIBCURL_TIMESTAMP ' \
"${TOPDIR}/include/curl/curlver.h" | "${TOPDIR}/include/curl/curlver.h" |
sed 's/.*"\(.*\)".*/\1/'` sed 's/.*"\(.*\)".*/\1/')
export LIBCURL_VERSION export LIBCURL_VERSION
export LIBCURL_VERSION_MAJOR LIBCURL_VERSION_MINOR LIBCURL_VERSION_PATCH export LIBCURL_VERSION_MAJOR LIBCURL_VERSION_MINOR LIBCURL_VERSION_PATCH
export LIBCURL_VERSION_NUM LIBCURL_TIMESTAMP export LIBCURL_VERSION_NUM LIBCURL_TIMESTAMP
@ -119,7 +119,7 @@ action_needed()
{ {
[ ! -e "${1}" ] && return 0 [ ! -e "${1}" ] && return 0
[ "${2}" ] || return 1 [ -n "${2}" ] || return 1
[ "${1}" -ot "${2}" ] && return 0 [ "${1}" -ot "${2}" ] && return 0
return 1 return 1
} }
@ -136,7 +136,7 @@ canonicalize_path()
{ {
if expr "${1}" : '^/' > /dev/null if expr "${1}" : '^/' > /dev/null
then P="${1}" then P="${1}"
else P="`pwd`/${1}" else P="$(pwd)/${1}"
fi fi
R= R=
@ -147,7 +147,8 @@ canonicalize_path()
do IFS="${IFSSAVE}" do IFS="${IFSSAVE}"
case "${C}" in case "${C}" in
.) ;; .) ;;
..) R=`expr "${R}" : '^\(.*/\)..*'` ..) R=$(expr \
"${R}" : '^\(.*/\)..*')
;; ;;
?*) R="${R}${C}/" ?*) R="${R}${C}/"
;; ;;
@ -156,7 +157,7 @@ canonicalize_path()
done done
IFS="${IFSSAVE}" IFS="${IFSSAVE}"
echo "/`expr "${R}" : '^\(.*\)/'`" echo "/$(expr "${R}" : '^\(.*\)/')"
} }
@ -172,7 +173,8 @@ make_module()
MODULES="${MODULES} ${1}" MODULES="${MODULES} ${1}"
MODIFSNAME="${LIBIFSNAME}/${1}.MODULE" MODIFSNAME="${LIBIFSNAME}/${1}.MODULE"
action_needed "${MODIFSNAME}" "${2}" || return 0; action_needed "${MODIFSNAME}" "${2}" || return 0;
SRCDIR=`dirname \`canonicalize_path "${2}"\`` SRCDIR="$(dirname \
"$(canonicalize_path "${2}")")"
# #pragma convert has to be in the source file itself, i.e. # #pragma convert has to be in the source file itself, i.e.
# putting it in an include file makes it only active # putting it in an include file makes it only active
@ -180,10 +182,12 @@ make_module()
# Thus we build a temporary file with the pragma prepended to # Thus we build a temporary file with the pragma prepended to
# the source file and we compile that temporary file. # the source file and we compile that temporary file.
echo "#line 1 \"${2}\"" > __tmpsrcf.c {
echo "#pragma convert(819)" >> __tmpsrcf.c echo "#line 1 \"${2}\""
echo "#line 1" >> __tmpsrcf.c echo "#pragma convert(819)"
cat "${2}" >> __tmpsrcf.c echo "#line 1"
cat "${2}"
} > __tmpsrcf.c
CMD="CRTCMOD MODULE(${TARGETLIB}/${1}) SRCSTMF('__tmpsrcf.c')" CMD="CRTCMOD MODULE(${TARGETLIB}/${1}) SRCSTMF('__tmpsrcf.c')"
CMD="${CMD} SYSIFCOPT(*IFS64IO *ASYNCSIGNAL)" CMD="${CMD} SYSIFCOPT(*IFS64IO *ASYNCSIGNAL)"
# CMD="${CMD} OPTION(*INCDIRFIRST *SHOWINC *SHOWSYS)" # CMD="${CMD} OPTION(*INCDIRFIRST *SHOWINC *SHOWSYS)"
@ -217,12 +221,13 @@ make_module()
then DEFINES="${DEFINES} USE_LIBSSH2" then DEFINES="${DEFINES} USE_LIBSSH2"
fi fi
if [ "${DEFINES}" ] if [ -n "${DEFINES}" ]
then CMD="${CMD} DEFINE(${DEFINES})" then CMD="${CMD} DEFINE(${DEFINES})"
fi fi
CLcommand "${CMD}" CLcommand "${CMD}"
rm -f __tmpsrcf.c rm -f __tmpsrcf.c
# shellcheck disable=SC2034
LINK=YES LINK=YES
} }
@ -272,7 +277,7 @@ versioned_copy()
get_make_vars() get_make_vars()
{ {
eval "`sed -e ': begin' \ eval "$(sed -e ': begin' \
-e '/\\\\$/{' \ -e '/\\\\$/{' \
-e 'N' \ -e 'N' \
-e 's/\\\\\\n/ /' \ -e 's/\\\\\\n/ /' \
@ -283,5 +288,5 @@ get_make_vars()
-e 's/[[:space:]]*=[[:space:]]*/=/' \ -e 's/[[:space:]]*=[[:space:]]*/=/' \
-e 's/=\\(.*[^[:space:]]\\)[[:space:]]*$/=\\"\\1\\"/' \ -e 's/=\\(.*[^[:space:]]\\)[[:space:]]*$/=\\"\\1\\"/' \
-e 's/\\\$(\\([^)]*\\))/\${\\1}/g' \ -e 's/\\\$(\\([^)]*\\))/\${\\1}/g' \
< \"${1}\"`" < \""${1}"\")"
} }

View File

@ -1,4 +1,4 @@
#!/bin/sh #!/usr/bin/env bash
#*************************************************************************** #***************************************************************************
# _ _ ____ _ # _ _ ____ _
# Project ___| | | | _ \| | # Project ___| | | | _ \| |
@ -26,9 +26,9 @@
# Installation of the header files in the OS/400 library. # Installation of the header files in the OS/400 library.
# #
SCRIPTDIR=`dirname "${0}"` SCRIPTDIR=$(dirname "${0}")
. "${SCRIPTDIR}/initscript.sh" . "${SCRIPTDIR}/initscript.sh"
cd "${TOPDIR}/include" cd "${TOPDIR}/include" || exit 1
# Create the OS/400 source program file for the header files. # Create the OS/400 source program file for the header files.
@ -71,16 +71,16 @@ copy_hfile()
# Copy the header files. # Copy the header files.
for HFILE in curl/*.h ${SCRIPTDIR}/ccsidcurl.h for HFILE in curl/*.h ${SCRIPTDIR}/ccsidcurl.h
do case "`basename \"${HFILE}\" .h`" in do case "$(basename "${HFILE}" .h)" in
stdcheaders|typecheck-gcc) stdcheaders|typecheck-gcc)
continue;; continue;;
esac esac
DEST="${SRCPF}/`db2_name \"${HFILE}\" nomangle`.MBR" DEST="${SRCPF}/$(db2_name "${HFILE}" nomangle).MBR"
if action_needed "${DEST}" "${HFILE}" if action_needed "${DEST}" "${HFILE}"
then copy_hfile "${DEST}" "${HFILE}" then copy_hfile "${DEST}" "${HFILE}"
IFSDEST="${IFSINCLUDE}/`basename \"${HFILE}\"`" IFSDEST="${IFSINCLUDE}/$(basename "${HFILE}")"
rm -f "${IFSDEST}" rm -f "${IFSDEST}"
ln -s "${DEST}" "${IFSDEST}" ln -s "${DEST}" "${IFSDEST}"
fi fi

View File

@ -1,4 +1,4 @@
#!/bin/sh #!/usr/bin/env bash
#*************************************************************************** #***************************************************************************
# _ _ ____ _ # _ _ ____ _
# Project ___| | | | _ \| | # Project ___| | | | _ \| |
@ -26,9 +26,9 @@
# libcurl compilation script for the OS/400. # libcurl compilation script for the OS/400.
# #
SCRIPTDIR=`dirname "${0}"` SCRIPTDIR=$(dirname "${0}")
. "${SCRIPTDIR}/initscript.sh" . "${SCRIPTDIR}/initscript.sh"
cd "${TOPDIR}/lib" cd "${TOPDIR}/lib" || exit 1
# Need to have IFS access to the mih/cipher header file. # Need to have IFS access to the mih/cipher header file.
@ -40,10 +40,12 @@ fi
# Create and compile the identification source file. # Create and compile the identification source file.
echo '#pragma comment(user, "libcurl version '"${LIBCURL_VERSION}"'")' > os400.c {
echo '#pragma comment(user, __DATE__)' >> os400.c echo '#pragma comment(user, "libcurl version '"${LIBCURL_VERSION}"'")'
echo '#pragma comment(user, __TIME__)' >> os400.c echo '#pragma comment(user, __DATE__)'
echo '#pragma comment(copyright, "Copyright (C) Daniel Stenberg et al. OS/400 version by P. Monnerat")' >> os400.c echo '#pragma comment(user, __TIME__)'
echo '#pragma comment(copyright, "Copyright (C) Daniel Stenberg et al. OS/400 version by P. Monnerat")'
} > os400.c
make_module OS400 os400.c BUILDING_LIBCURL make_module OS400 os400.c BUILDING_LIBCURL
LINK= # No need to rebuild service program yet. LINK= # No need to rebuild service program yet.
MODULES= MODULES=
@ -56,13 +58,14 @@ get_make_vars Makefile.inc
# Compile the sources into modules. # Compile the sources into modules.
INCLUDES="'`pwd`'" # shellcheck disable=SC2034
INCLUDES="'$(pwd)'"
make_module OS400SYS "${SCRIPTDIR}/os400sys.c" BUILDING_LIBCURL make_module OS400SYS "${SCRIPTDIR}/os400sys.c" BUILDING_LIBCURL
make_module CCSIDCURL "${SCRIPTDIR}/ccsidcurl.c" BUILDING_LIBCURL make_module CCSIDCURL "${SCRIPTDIR}/ccsidcurl.c" BUILDING_LIBCURL
for SRC in ${CSOURCES} for SRC in ${CSOURCES}
do MODULE=`db2_name "${SRC}"` do MODULE=$(db2_name "${SRC}")
make_module "${MODULE}" "${SRC}" BUILDING_LIBCURL make_module "${MODULE}" "${SRC}" BUILDING_LIBCURL
done done
@ -73,7 +76,7 @@ if action_needed "${LIBIFSNAME}/${STATBNDDIR}.BNDDIR"
then LINK=YES then LINK=YES
fi fi
if [ "${LINK}" ] if [ -n "${LINK}" ]
then rm -rf "${LIBIFSNAME}/${STATBNDDIR}.BNDDIR" then rm -rf "${LIBIFSNAME}/${STATBNDDIR}.BNDDIR"
CMD="CRTBNDDIR BNDDIR(${TARGETLIB}/${STATBNDDIR})" CMD="CRTBNDDIR BNDDIR(${TARGETLIB}/${STATBNDDIR})"
CMD="${CMD} TEXT('LibCurl API static binding directory')" CMD="${CMD} TEXT('LibCurl API static binding directory')"
@ -104,14 +107,14 @@ fi
# - Drop the parenthesized function arguments and what follows. # - Drop the parenthesized function arguments and what follows.
# - Keep the trailing function name only. # - Keep the trailing function name only.
EXPORTS=`cat "${TOPDIR}"/include/curl/*.h "${SCRIPTDIR}/ccsidcurl.h" | EXPORTS=$(cat "${TOPDIR}"/include/curl/*.h "${SCRIPTDIR}/ccsidcurl.h" |
sed -e 'H;s/.*//;x;s/\n//;s/.*/& /' \ sed -e 'H;s/.*//;x;s/\n//;s/.*/& /' \
-e '/^CURL_EXTERN[[:space:]]/!d' \ -e '/^CURL_EXTERN[[:space:]]/!d' \
-e '/\;/!{x;d;}' \ -e '/\;/!{x;d;}' \
-e 's/ CURL_DEPRECATED([^)]*)//g' \ -e 's/ CURL_DEPRECATED([^)]*)//g' \
-e 's/ CURL_TEMP_PRINTF([^)]*)//g' \ -e 's/ CURL_TEMP_PRINTF([^)]*)//g' \
-e 's/[[:space:]]*(.*$//' \ -e 's/[[:space:]]*(.*$//' \
-e 's/^.*[^A-Za-z0-9_]\([A-Za-z0-9_]*\)$/\1/'` -e 's/^.*[^A-Za-z0-9_]\([A-Za-z0-9_]*\)$/\1/')
# Create the service program exportation file in DB2 member if needed. # Create the service program exportation file in DB2 member if needed.
@ -122,7 +125,7 @@ if action_needed "${BSF}" Makefile.am
then LINK=YES then LINK=YES
fi fi
if [ "${LINK}" ] if [ -n "${LINK}" ]
then echo " STRPGMEXP PGMLVL(*CURRENT) SIGNATURE('LIBCURL_${SONAME}')" \ then echo " STRPGMEXP PGMLVL(*CURRENT) SIGNATURE('LIBCURL_${SONAME}')" \
> "${BSF}" > "${BSF}"
for EXPORT in ${EXPORTS} for EXPORT in ${EXPORTS}
@ -139,7 +142,7 @@ if action_needed "${LIBIFSNAME}/${SRVPGM}.SRVPGM"
then LINK=YES then LINK=YES
fi fi
if [ "${LINK}" ] if [ -n "${LINK}" ]
then CMD="CRTSRVPGM SRVPGM(${TARGETLIB}/${SRVPGM})" then CMD="CRTSRVPGM SRVPGM(${TARGETLIB}/${SRVPGM})"
CMD="${CMD} SRCFILE(${TARGETLIB}/TOOLS) SRCMBR(BNDSRC)" CMD="${CMD} SRCFILE(${TARGETLIB}/TOOLS) SRCMBR(BNDSRC)"
CMD="${CMD} MODULE(${TARGETLIB}/OS400)" CMD="${CMD} MODULE(${TARGETLIB}/OS400)"
@ -167,7 +170,7 @@ if action_needed "${LIBIFSNAME}/${DYNBNDDIR}.BNDDIR"
then LINK=YES then LINK=YES
fi fi
if [ "${LINK}" ] if [ -n "${LINK}" ]
then rm -rf "${LIBIFSNAME}/${DYNBNDDIR}.BNDDIR" then rm -rf "${LIBIFSNAME}/${DYNBNDDIR}.BNDDIR"
CMD="CRTBNDDIR BNDDIR(${TARGETLIB}/${DYNBNDDIR})" CMD="CRTBNDDIR BNDDIR(${TARGETLIB}/${DYNBNDDIR})"
CMD="${CMD} TEXT('LibCurl API dynamic binding directory')" CMD="${CMD} TEXT('LibCurl API dynamic binding directory')"

View File

@ -1,4 +1,4 @@
#!/bin/sh #!/usr/bin/env bash
#*************************************************************************** #***************************************************************************
# _ _ ____ _ # _ _ ____ _
# Project ___| | | | _ \| | # Project ___| | | | _ \| |
@ -25,9 +25,9 @@
# #
# Command line interface tool compilation script for the OS/400. # Command line interface tool compilation script for the OS/400.
SCRIPTDIR=`dirname "${0}"` SCRIPTDIR=$(dirname "${0}")
. "${SCRIPTDIR}/initscript.sh" . "${SCRIPTDIR}/initscript.sh"
cd "${TOPDIR}/src" cd "${TOPDIR}/src" || exit 1
# Get source lists. # Get source lists.
@ -40,25 +40,27 @@ get_make_vars Makefile.inc
# Compile the sources into modules. # Compile the sources into modules.
# shellcheck disable=SC2034
LINK= LINK=
MODULES= MODULES=
# shellcheck disable=SC2034
INCLUDES="'${TOPDIR}/lib'" INCLUDES="'${TOPDIR}/lib'"
for SRC in ${CURLX_CFILES} for SRC in ${CURLX_CFILES}
do MODULE=`db2_name "${SRC}"` do MODULE=$(db2_name "${SRC}")
MODULE=`db2_name "X${MODULE}"` MODULE=$(db2_name "X${MODULE}")
make_module "${MODULE}" "${SRC}" make_module "${MODULE}" "${SRC}"
done done
for SRC in ${CURL_CFILES} for SRC in ${CURL_CFILES}
do MODULE=`db2_name "${SRC}"` do MODULE=$(db2_name "${SRC}")
make_module "${MODULE}" "${SRC}" make_module "${MODULE}" "${SRC}"
done done
# Link modules into program. # Link modules into program.
MODULES="`echo \"${MODULES}\" | sed \"s/[^ ][^ ]*/${TARGETLIB}\/&/g\"`" MODULES="$(echo "${MODULES}" | sed "s/[^ ][^ ]*/${TARGETLIB}\/&/g")"
CMD="CRTPGM PGM(${TARGETLIB}/${CURLPGM})" CMD="CRTPGM PGM(${TARGETLIB}/${CURLPGM})"
CMD="${CMD} ENTMOD(${TARGETLIB}/CURLMAIN)" CMD="${CMD} ENTMOD(${TARGETLIB}/CURLMAIN)"
CMD="${CMD} MODULE(${MODULES})" CMD="${CMD} MODULE(${MODULES})"

View File

@ -1,4 +1,4 @@
#!/bin/sh #!/usr/bin/env bash
#*************************************************************************** #***************************************************************************
# _ _ ____ _ # _ _ ____ _
# Project ___| | | | _ \| | # Project ___| | | | _ \| |
@ -27,9 +27,9 @@
# #
SCRIPTDIR=`dirname "${0}"` SCRIPTDIR=$(dirname "${0}")
. "${SCRIPTDIR}/initscript.sh" . "${SCRIPTDIR}/initscript.sh"
cd "${TOPDIR}/tests" cd "${TOPDIR}/tests" || exit 1
# Build programs in a directory. # Build programs in a directory.
@ -40,23 +40,26 @@ build_all_programs()
# Compile all programs. # Compile all programs.
# The list is found in variable "noinst_PROGRAMS" # The list is found in variable "noinst_PROGRAMS"
INCLUDES="'`pwd`' '${TOPDIR}/lib' '${TOPDIR}/src'" # shellcheck disable=SC2034
INCLUDES="'$(pwd)' '${TOPDIR}/lib' '${TOPDIR}/src'"
MODS="${1}" MODS="${1}"
SRVPGMS="${2}" SRVPGMS="${2}"
# shellcheck disable=SC2154
for PGM in ${noinst_PROGRAMS} for PGM in ${noinst_PROGRAMS}
do DB2PGM=`db2_name "${PGM}"` do DB2PGM=$(db2_name "${PGM}")
PGMIFSNAME="${LIBIFSNAME}/${DB2PGM}.PGM" PGMIFSNAME="${LIBIFSNAME}/${DB2PGM}.PGM"
# Extract preprocessor symbol definitions from # Extract preprocessor symbol definitions from
# compilation options for the program. # compilation options for the program.
PGMCFLAGS="`eval echo \"\\${${PGM}_CFLAGS}\"`" PGMCFLAGS="$(eval echo "\${${PGM}_CFLAGS}")"
PGMDFNS= PGMDFNS=
for FLAG in ${PGMCFLAGS} for FLAG in ${PGMCFLAGS}
do case "${FLAG}" in do case "${FLAG}" in
-D?*) DEFINE="`echo \"${FLAG}\" | sed 's/^..//'`" -D?*) # shellcheck disable=SC2001
DEFINE="$(echo "${FLAG}" | sed 's/^..//')"
PGMDFNS="${PGMDFNS} '${DEFINE}'" PGMDFNS="${PGMDFNS} '${DEFINE}'"
;; ;;
esac esac
@ -64,7 +67,7 @@ build_all_programs()
# Compile all C sources for the program into modules. # Compile all C sources for the program into modules.
PGMSOURCES="`eval echo \"\\${${PGM}_SOURCES}\"`" PGMSOURCES="$(eval echo "\${${PGM}_SOURCES}")"
LINK= LINK=
MODULES= MODULES=
@ -77,7 +80,7 @@ build_all_programs()
case "${SOURCE}" in case "${SOURCE}" in
lib*.c) MODULE="${DB2PGM}" lib*.c) MODULE="${DB2PGM}"
;; ;;
*) MODULE=`db2_name "${SOURCE}"` *) MODULE=$(db2_name "${SOURCE}")
;; ;;
esac esac
@ -85,7 +88,7 @@ build_all_programs()
# prefix module name with 'X'. # prefix module name with 'X'.
case "${SOURCE}" in case "${SOURCE}" in
../*) MODULE=`db2_name "X${MODULE}"` ../*) MODULE=$(db2_name "X${MODULE}")
;; ;;
esac esac
@ -99,17 +102,17 @@ build_all_programs()
# Link program if needed. # Link program if needed.
if [ "${LINK}" ] if [ -n "${LINK}" ]
then PGMLDADD="`eval echo \"\\${${PGM}_LDADD}\"`" then PGMLDADD="$(eval echo "\${${PGM}_LDADD}")"
for ARG in ${PGMLDADD} for ARG in ${PGMLDADD}
do case "${ARG}" in do case "${ARG}" in
-*) ;; # Ignore non-module. -*) ;; # Ignore non-module.
*) MODULES="${MODULES} "`db2_name "${ARG}"` *) MODULES="${MODULES} $(db2_name "${ARG}")"
;; ;;
esac esac
done done
MODULES="`echo \"${MODULES}\" | MODULES="$(echo "${MODULES}" |
sed \"s/[^ ][^ ]*/${TARGETLIB}\/&/g\"`" sed "s/[^ ][^ ]*/${TARGETLIB}\/&/g")"
CMD="CRTPGM PGM(${TARGETLIB}/${DB2PGM})" CMD="CRTPGM PGM(${TARGETLIB}/${DB2PGM})"
CMD="${CMD} ENTMOD(${TARGETLIB}/CURLMAIN)" CMD="${CMD} ENTMOD(${TARGETLIB}/CURLMAIN)"
CMD="${CMD} MODULE(${MODULES} ${MODS})" CMD="${CMD} MODULE(${MODULES} ${MODS})"
@ -124,7 +127,7 @@ build_all_programs()
# Build programs in the server directory. # Build programs in the server directory.
( (
cd server cd server || exit 1
get_make_vars Makefile.inc get_make_vars Makefile.inc
build_all_programs "${TARGETLIB}/OS400SYS" build_all_programs "${TARGETLIB}/OS400SYS"
) )
@ -133,13 +136,16 @@ build_all_programs()
# Build all programs in the libtest subdirectory. # Build all programs in the libtest subdirectory.
( (
cd libtest cd libtest || exit 1
get_make_vars Makefile.inc get_make_vars Makefile.inc
# Special case: redefine chkhostname compilation parameters. # Special case: redefine chkhostname compilation parameters.
# shellcheck disable=SC2034
chkhostname_SOURCES=chkhostname.c chkhostname_SOURCES=chkhostname.c
# shellcheck disable=SC2034
chkhostname_LDADD=curl_gethostname.o chkhostname_LDADD=curl_gethostname.o
# shellcheck disable=SC2153
build_all_programs "" "${TARGETLIB}/${SRVPGM}" build_all_programs "" "${TARGETLIB}/${SRVPGM}"
) )

View File

@ -1,4 +1,4 @@
#!/bin/sh #!/usr/bin/env bash
#*************************************************************************** #***************************************************************************
# _ _ ____ _ # _ _ ____ _
# Project ___| | | | _ \| | # Project ___| | | | _ \| |
@ -28,9 +28,9 @@
# #
# This is a shell script since make is not a standard component of OS/400. # This is a shell script since make is not a standard component of OS/400.
SCRIPTDIR=`dirname "${0}"` SCRIPTDIR=$(dirname "${0}")
. "${SCRIPTDIR}/initscript.sh" . "${SCRIPTDIR}/initscript.sh"
cd "${TOPDIR}" cd "${TOPDIR}" || exit 1
# Create the OS/400 library if it does not exist. # Create the OS/400 library if it does not exist.
@ -57,9 +57,9 @@ for TEXT in "${TOPDIR}/COPYING" "${SCRIPTDIR}/README.OS400" \
"${TOPDIR}/docs/FEATURES" "${TOPDIR}/docs/SSLCERTS.md" \ "${TOPDIR}/docs/FEATURES" "${TOPDIR}/docs/SSLCERTS.md" \
"${TOPDIR}/docs/RESOURCES" "${TOPDIR}/docs/VERSIONS.md" \ "${TOPDIR}/docs/RESOURCES" "${TOPDIR}/docs/VERSIONS.md" \
"${TOPDIR}/docs/HISTORY.md" "${TOPDIR}/docs/HISTORY.md"
do MEMBER="`basename \"${TEXT}\" .OS400`" do MEMBER="$(basename "${TEXT}" .OS400)"
MEMBER="`basename \"${MEMBER}\" .md`" MEMBER="$(basename "${MEMBER}" .md)"
MEMBER="${LIBIFSNAME}/DOCS.FILE/`db2_name \"${MEMBER}\"`.MBR" MEMBER="${LIBIFSNAME}/DOCS.FILE/$(db2_name "${MEMBER}").MBR"
[ -e "${TEXT}" ] || continue [ -e "${TEXT}" ] || continue
@ -83,8 +83,8 @@ fi
# Copy RPG examples if needed. # Copy RPG examples if needed.
for EXAMPLE in "${SCRIPTDIR}/rpg-examples"/* for EXAMPLE in "${SCRIPTDIR}/rpg-examples"/*
do MEMBER="`basename \"${EXAMPLE}\"`" do MEMBER="$(basename "${EXAMPLE}")"
IFSMEMBER="${LIBIFSNAME}/RPGXAMPLES.FILE/`db2_name \"${MEMBER}\"`.MBR" IFSMEMBER="${LIBIFSNAME}/RPGXAMPLES.FILE/$(db2_name "${MEMBER}").MBR"
[ -e "${EXAMPLE}" ] || continue [ -e "${EXAMPLE}" ] || continue
@ -92,8 +92,8 @@ do MEMBER="`basename \"${EXAMPLE}\"`"
then CMD="CPY OBJ('${EXAMPLE}') TOOBJ('${IFSMEMBER}')" then CMD="CPY OBJ('${EXAMPLE}') TOOBJ('${IFSMEMBER}')"
CMD="${CMD} TOCCSID(${TGTCCSID}) DTAFMT(*TEXT) REPLACE(*YES)" CMD="${CMD} TOCCSID(${TGTCCSID}) DTAFMT(*TEXT) REPLACE(*YES)"
CLcommand "${CMD}" CLcommand "${CMD}"
MBRTEXT=`sed -e '1!d;/^ \*/!d;s/^ *\* *//' \ MBRTEXT=$(sed -e '1!d;/^ \*/!d;s/^ *\* *//' \
-e 's/ *$//;s/'"'"'/&&/g' < "${EXAMPLE}"` -e 's/ *$//;s/'"'"'/&&/g' < "${EXAMPLE}")
CMD="CHGPFM FILE(${TARGETLIB}/RPGXAMPLES) MBR(${MEMBER})" CMD="CHGPFM FILE(${TARGETLIB}/RPGXAMPLES) MBR(${MEMBER})"
CMD="${CMD} SRCTYPE(RPGLE) TEXT('${MBRTEXT}')" CMD="${CMD} SRCTYPE(RPGLE) TEXT('${MBRTEXT}')"
CLcommand "${CMD}" CLcommand "${CMD}"