Browse Source

build: fix developer mode compilation on FreeBSD

Recent FreeBSD versions use LLVM's lld as a linker, not the GNU ld.
Their behavior slightly differs, so adapt the build system to handle
either one.

* The LLVM's linker prints "undefined symbol:" instead of
  "undefined reference to". Tweak tools/mockup.sh to also look for that
  message.

* The LLVM's linker may only print the first dozen errors (omitting
  the rest to avoid flooding the screen). tools/update-mocks.sh relies
  on getting all errors as it extracts the missing symbols' names from
  the error output and creates mocks for them. Detect if errors were
  omitted and re-run, telling the linker to not omit any. The GNU linker
  does not support -error-limit=0, so unfortunately we can't just run
  with that option unconditionally from the first attempt.

* Nit: FreeBSD's sed(1) prints "t" for "\t" instead of a horizontal tab.
  Use a verbatim tab in the command, instead of "\t" which works on
  both.

Changelog-Fixed: Developer mode compilation on FreeBSD.
travis-debug
Vasil Dimov 5 years ago
committed by Christian Decker
parent
commit
b2c4d5e952
  1. 5
      tools/mockup.sh
  2. 15
      tools/update-mocks.sh

5
tools/mockup.sh

@ -6,9 +6,14 @@ if [ $# -eq 0 ]; then
set -- $(while read -r LINE; do set -- $(while read -r LINE; do
case "$LINE" in case "$LINE" in
*undefined\ reference\ to*) *undefined\ reference\ to*)
# file.cc:(.text+0x10): undefined reference to `foo()'
LINE=${LINE#*undefined reference to \`} LINE=${LINE#*undefined reference to \`}
echo "${LINE%\'*}" echo "${LINE%\'*}"
;; ;;
*undefined\ symbol:*)
# ld: error: undefined symbol: foo()
echo "${LINE#*undefined symbol: }"
;;
*) *)
continue continue
;; ;;

15
tools/update-mocks.sh

@ -12,20 +12,31 @@ trap 'mv $BASE.old $FILE; rm -f $BASE.*' EXIT
START=$(grep -F -n '/* AUTOGENERATED MOCKS START */' "$FILE" | cut -d: -f1) START=$(grep -F -n '/* AUTOGENERATED MOCKS START */' "$FILE" | cut -d: -f1)
END=$(grep -F -n '/* AUTOGENERATED MOCKS END */' "$FILE" | cut -d: -f1) END=$(grep -F -n '/* AUTOGENERATED MOCKS END */' "$FILE" | cut -d: -f1)
function make_binary() {
$MAKE "${FILE/%.c/}" 2> "${BASE}.err" >/dev/null
}
if [ -n "$START" ]; then if [ -n "$START" ]; then
mv "$FILE" "${BASE}.old" mv "$FILE" "${BASE}.old"
echo "${FILE}:" echo "${FILE}:"
head -n "$START" "${BASE}.old" > "$FILE" head -n "$START" "${BASE}.old" > "$FILE"
tail -n +"$END" "${BASE}.old" >> "$FILE" tail -n +"$END" "${BASE}.old" >> "$FILE"
# Try to make binary. # Try to make binary.
if ! $MAKE "${FILE/%.c/}" 2> "${BASE}.err" >/dev/null; then if ! make_binary; then
# Some linkers (e.g. LLVM's one) don't print all errors. If this is the
# case, then re-run, asking them to do so. Search for something like
# this in the output:
# ld: error: too many errors emitted, stopping now (use -error-limit=0 to see all errors)
if grep -q 'too many errors emitted.*-error-limit=0' "${BASE}.err"; then
LDFLAGS=-Wl,-error-limit=0 make_binary || :
fi
tools/mockup.sh < "${BASE}.err" >> "${BASE}.stubs" tools/mockup.sh < "${BASE}.err" >> "${BASE}.stubs"
# If there are no link errors, maybe compile fail for other reason? # If there are no link errors, maybe compile fail for other reason?
if ! grep -F -q 'Generated stub for' "${BASE}.stubs"; then if ! grep -F -q 'Generated stub for' "${BASE}.stubs"; then
cat "${BASE}.err" cat "${BASE}.err"
exit 1 exit 1
fi fi
sed -n 's,.*Generated stub for \(.*\) .*,\t\1,p' < "${BASE}.stubs" sed -n 's,.*Generated stub for \(.*\) .*, \1,p' < "${BASE}.stubs"
head -n "$START" "${BASE}.old" > "$FILE" head -n "$START" "${BASE}.old" > "$FILE"
cat "${BASE}.stubs" >> "$FILE" cat "${BASE}.stubs" >> "$FILE"
tail -n +"$END" "${BASE}.old" >> "$FILE" tail -n +"$END" "${BASE}.old" >> "$FILE"

Loading…
Cancel
Save