$OpenBSD: patch-ltnasm_sh,v 1.1 2021/09/02 20:44:44 sthen Exp $

Use a libtool-wrapper script for NASM.

Libtool thinks NASM acts just like the C-compiler, which isn't true
for e.g. -f options. Previously we used -prefer-non-pic to avoid libtool
passing any additional flags, which worked well on all tested platforms
but as it turns out at least on OpenBSD this does not work.
This now also means we'll automatically get the -DPIC flag as needed,
which might perhaps also help some platforms we didn't test yet; before
we fully relied on x86inc's automatic setting for PIC in assembly.

https://github.com/libass/libass/issues/539

Index: ltnasm.sh
--- ltnasm.sh.orig
+++ ltnasm.sh
@@ -0,0 +1,29 @@
+#!/bin/sh
+
+# Translate libtool supplied C-compiler options for NASM.
+# libtool treats NASM like the C compiler, and may supply -f… options
+# which are interpreted as the output file format by NASM, causing errors.
+# Notably libtool will set -DPIC -fPIC and -fno-common; we want to keep
+# -DPIC but remove everything else.
+#
+# Filtering the options as done here in this plain POSIX shell script would
+# mess up if there were any spaces in the arguments, but this will never happen
+# since our filenames or options do not contain spaces and source paths are
+# also not allowed to contain spaces.
+
+cmd=""
+while [ "$#" -gt 0 ] ; do
+    case "$1" in
+        # NASM accepts both -f format and -fformat,
+        # we always use the former, and libtool supplied
+        # C-compiler options will always use the latter.
+        -f) cmd="$cmd $1" ;;
+        -f*) : ;;
+        -DPIC) cmd="$cmd -DPIC=1" ;;
+        *) cmd="$cmd $1" ;;
+    esac
+    shift
+done
+
+#echo "$cmd"
+exec $cmd
