$NetBSD: patch-Makefile,v 1.1 2017/01/02 02:19:47 schmonz Exp $

Libtoolize and avoid "echo -n" in subshells to fix build on OS X.

--- Makefile.orig	2015-02-12 14:10:37.000000000 +0000
+++ Makefile
@@ -56,7 +56,7 @@ dl.lib: compile load
 	@echo 'main() { ; }' >trylib-ldl.c
 	@{ ./compile trylib-ldl.c && ./load trylib-ldl -ldl; } >/dev/null 2>&1 \
 	  && { echo -ldl >dl.lib; echo yes; } \
-	  || { echo -n >dl.lib; echo no; }
+	  || { : >dl.lib; echo no; }
 	@rm -f trylib-ldl.c trylib-ldl.o trylib-ldl
 
 docs: 
@@ -103,11 +103,25 @@ makelib: 
 	) >makelib
 	chmod 755 makelib
 
-makeso: conf-ccso conf-ld
-	( echo '#!/bin/sh'; \
-	  echo 'source=$$1; shift'; \
-	  echo 'base=`echo "$$source" | sed -e s:\\\\.c$$::`'; \
-	  echo exec `head -n 1 conf-ccso` -DSHARED -I. -L. '-o $${base}.so $$source $${1+"$$@"}'; \
+makeso: conf-cc conf-ld conf-modules
+	( if libtool --tag=CC --help >/dev/null 2>&1; then tag='--tag=CC'; fi; \
+	  echo '#!/bin/sh'; \
+	  echo 'FIRSTOBJ=; ALLOBJS=; OTHERARGS='; \
+	  echo 'while [ $$# -gt 0 ]; do'; \
+	  echo '	source=$$1'; \
+	  echo '	base=`echo "$$source" | sed -e s:\\\\.c$$::`'; \
+	  echo '	if [ "$$base" = "$$source" ]; then'; \
+	  echo '		OTHERARGS="$${OTHERARGS} $$source"'; \
+	  echo '	else'; \
+	  echo '		if [ "x$$FIRSTOBJ" = "x" ]; then'; \
+	  echo '			FIRSTOBJ="$${base}.la"'; \
+	  echo '		fi'; \
+	  echo '		ALLOBJS="$${ALLOBJS} $${base}.lo"'; \
+	  echo '		libtool --mode=compile --silent $$tag '`head -n 1 conf-cc`' -I. -Iinclude/bglibs -Iinclude -o $${base}.lo -c $$source'; \
+	  echo '	fi'; \
+	  echo '	shift'; \
+	  echo 'done'; \
+	  echo libtool --mode=link --silent $$tag `head -n 1 conf-ld` -L. '-module -o $${FIRSTOBJ} $${ALLOBJS} $${OTHERARGS} -rpath' `head -n 1 conf-modules`;\
 	) >makeso
 	chmod 755 makeso
 
