Skip to content

Commit

Permalink
metabuild.sh: don't use tr for 2->1 spaces
Browse files Browse the repository at this point in the history
Previously, we combined strings with:
    d="$a $b $c"
If $b was "", that would leave two spaces, which we trimmed with
    tr -s ' '

However, that was an inelegant solution, and more importantly, was not
compatible with code such as:
    -D_TWO_SPACES="\"2  spaces\""
when defined in Makefile.BSD.
  • Loading branch information
gperciva committed Nov 16, 2024
1 parent 96c9bd8 commit 2d2a2d5
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions release-tools/metabuild.sh
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,22 @@ get_apisupport_cflags() {
done | sed 's/^ //'
}

join_str() {
out=""
for text in "$@"; do
if [ -n "${out}" ]; then
# If we already have something in ${out}, add a space.
if [ -n "${text}" ]; then
out="${out} ${text}"
fi
else
# If ${out} is empty, set it to the first item.
out="${text}"
fi
done
printf "%s" "${out}"
}

add_object_files() {
# Set up useful variables
OBJ=$(${MAKEBSD} -v SRCS | \
Expand All @@ -131,8 +147,8 @@ add_object_files() {
CF_MANUAL=$(${MAKEBSD} -v CFLAGS."$(basename "${S}")")
CF_CPUSUPPORT=$(get_cpusupport_cflags "${S}")
CF_APISUPPORT=$(get_apisupport_cflags "${S}")
CF=$(echo "${CF_CPUSUPPORT} ${CF_APISUPPORT} ${CF_MANUAL}" | \
sed 's/^ //' | sed 's/ $//')
CF=$(join_str "${CF_CPUSUPPORT}" "${CF_APISUPPORT}" \
"${CF_MANUAL}")
IDIRS=$(${MAKEBSD} -v IDIRS)
# Get the build dependencies, then remove newlines, condense
# multiple spaces, remove line continuations, and replace the
Expand All @@ -145,8 +161,9 @@ add_object_files() {
sed -e 's| $||g'
printf "\n"
# Print the build instructions
echo " ${OUT_CC_BEGIN} ${OUT_CC_MID} ${CF} -c ${S} -o ${F}" |
tr -s ' '
line=$(join_str "${OUT_CC_BEGIN}" "${OUT_CC_MID}" \
"${CF}" "-c" "${S}" "-o" "${F}")
printf "\t%s\n" "${line}"
done >> "${OUT}"
}

Expand Down

0 comments on commit 2d2a2d5

Please sign in to comment.