--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -184,19 +184,19 @@
 	s/^ \| $$//g;				\
 	/:/ {	s/[ ]*:/:/;			\
 		s/:[ ]*\($$\|\\n\|\\\)/:\1/;	\
-		s/: /:\t/	};		\
+		s/: /:\t/;	};		\
 	/ *\\n/ s//\\\\n/;			\
 	/\\$$/,/[^\]$$/ {			\
 		H;				\
 		/\\$$/ d;			\
-		z;				\
+		s/.*//;				\
 		x;				\
-		s/^\n//		};		\
+		s/^\n//;	};		\
 	/\\\n/ {				\
 		s/ *\\\n/"\n\t\t"/g;		\
-		/\#\(augment\|override\|replace\)"/ s//\#\1 "/	};	\
+		/\#\(augment\|override\|replace\)"/ s//\#\1 "/;	};	\
 	s/^/\t"/;				\
-	s/$$/",/			'
+	s/$$/",/'
 fallback.c: $(top_srcdir)/app-defaults/Fig
 	echo "/* generated by make from $(top_srcdir)/app-defaults/Fig */" >$@
 	echo "#include <stddef.h>" >>$@
--- a/doc/Makefile.am
+++ b/doc/Makefile.am
@@ -41,7 +41,7 @@
 	cd $(srcdir)/html && htmldoc -f ../xfig_ref_en.pdf --no-title	\
 		--webpage --header ..c -t pdf14 --size a4 contents.html	\
 		$$($(FGREP) '<a href=' contents.html |			\
-			$(SED) 's/.*a href="//;s/["\#].*//;' | uniq |	\
+			$(SED) 's/.*a href="//; s/["\#].*//;' | uniq |	\
 			$(FGREP) -v japanese)
 
 # To create xfig-title.png, probably test:
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -138,7 +138,7 @@
 # and try again (the line with $(FGREP)), using ImageMagick's convert-program.
 version.xbm: version.fig.in $(top_srcdir)/version.m4
 	-fig2dev -L ppm version.fig | ppmtopgm | pgmtopbm -threshold | pnmcrop \
-	| pbmtoxbm | sed '1,3 s/noname_/letters_/; 3 s/char/unsigned &/' >$@
+	| pbmtoxbm | $(SED) '1,3 s/noname_/letters_/; 3 s/char/unsigned &/' >$@
 	$(FGREP) -q 0xff $@ || fig2dev -L ppm version.fig | \
 		convert ppm:- -trim xbm:- | \
 		$(SED) '1,3 s/-_/letters_/; 3 s/char/unsigned &/' >$@
@@ -154,7 +154,7 @@
 splash.xpm: $(top_srcdir)/splash-image/spl_bckgnd.fig.in \
 		$(top_srcdir)/version.m4
 	fig2dev -L xpm ../splash-image/spl_bckgnd.fig \
-	| sed '2 {s/static //; s/noname/spl_bckgnd_xpm/}' > $@
+	| $(SED) '2 {s/static //; s/noname/spl_bckgnd_xpm/;}' > $@
 
 splash.xbm: $(top_srcdir)/splash-image/spl_bckgnd.fig.in \
 		$(top_srcdir)/version.m4
@@ -163,9 +163,13 @@
 	| $(SED) '1,3 s/noname/spl_bckgnd/; 3 s/char/unsigned &/' > $@
 
 # The sed script below transforms a X resource file to an array of strings.
+# Note on quoting: to match one backslash, sed '/\\/' but sed "/\\\\/"
+# sed on macOS needs a literal newline, not \n in the replacement string.
+# To embed a newline, see info autoconf > Portable Make > Newlines in Make Rules
+# The script is therefore split into a single-quoted and a double-quoted part.
 # Comments to the script:
 #	# remove comment lines and blank lines
-#	# compress any whitespace to single blank
+#	# compress any whitespace (= space or tab) to single blank
 #	# remove blank at beginning or end of line;
 #	# colon: remove whitespace before colon, put one tab after colon
 #	#	 except if followed by newline or \n; blank before \
@@ -178,30 +182,40 @@
 #	# backslash - newline becomes newline - tab - tab
 #	# but add a blank after #augment, #override or #replace
 #	# and surround the text with quotes, writing C strings
-fallback_script = '				\
-	/^[ \t]*\(!\|$$\)/ d;			\
-	s/[ \t][ \t]*/ /g;			\
-	s/^ \| $$//g;				\
+fallbackscript1 = '				\
+	/^[[:blank:]]*!/ d;			\
+	/^[[:blank:]]*$$/ d;			\
+	s/[[:blank:]][[:blank:]]*/ /g;		\
+	s/^ //;					\
+	s/ $$//;				\
 	/:/ {	s/[ ]*:/:/;			\
-		s/:[ ]*\($$\|\\n\|\\\)/:\1/;	\
-		s/: /:\t/;	};		\
+		s/:[ ]*$$/:/;			\
+		s/:[ ]*\\n/:\\n/;		\
+		s/:[ ]*\\/: \\/;		\
+		s/: /:	/;	};		\
 	/ *\\n/ s//\\\\n/;			\
 	/\\$$/,/[^\]$$/ {			\
 		H;				\
 		/\\$$/ d;			\
 		s/.*//;				\
 		x;				\
-		s/^\n//;	};		\
-	/\\\n/ {				\
-		s/ *\\\n/"\n\t\t"/g;		\
-		/\#\(augment\|override\|replace\)"/ s//\#\1 "/;	};	\
-	s/^/\t"/;				\
-	s/$$/",/'
+		s/^\n//;	}'
+fallbackscript2 = "					\
+	/\\\\\n/ {					\
+		s/ *\\\\\n/\"\\$${nl}		\"/g;	\
+		/\#augment\"/ s//\#augment \"/;		\
+		/\#override\"/ s//\#override \"/;	\
+		/\#replace\"/ s//\#replace \"/; };	\
+	s/^/	\"/;					\
+	s/$$/\",/"
+
 fallback.c: $(top_srcdir)/app-defaults/Fig
 	echo "/* generated by make from $(top_srcdir)/app-defaults/Fig */" >$@
 	echo "#include <stddef.h>" >>$@
 	echo "#include <X11/Intrinsic.h>" >>$@
 	echo "String	fallback_resources[] = {" >>$@
-	$(SED) -e $(fallback_script) $(top_srcdir)/app-defaults/Fig >>$@
+	nlinit=`echo 'nl="'; echo '"'`; eval "$$nlinit";	\
+	$(SED) -e $(fallbackscript1) -e $(fallbackscript2)	\
+	$(top_srcdir)/app-defaults/Fig >>$@
 	echo "	NULL" >>$@
 	echo "};" >>$@
diff -Nurd xfig-3.2.9.orig/src/Makefile.am xfig-3.2.9/src/Makefile.am
--- xfig-3.2.9.orig/src/Makefile.am	2023-08-23 17:27:29.000000000 -0400
+++ xfig-3.2.9/src/Makefile.am	2023-10-28 16:11:03.000000000 -0400
@@ -26,7 +26,7 @@
 # Xft #includes <ft2build.h>, not <freetype2/ft2build.h>, hence freetype2
 # must be put into the search path.
 
-AM_CPPFLAGS = -I$(oldincludedir)/freetype2 $(XCPPFLAGS) -DNDEBUG -DXFIGLIBDIR="\"$(compkeydbdir)\"" \
+AM_CPPFLAGS = $(XCPPFLAGS) -DNDEBUG -DXFIGLIBDIR="\"$(compkeydbdir)\"" \
 	-DOBJLIBDIR="\"$(pkgdatadir)/Libraries\"" -DXFIGDOCDIR="\"$(docdir)\""
 
 AM_LDFLAGS = $(XLDFLAGS)
diff -Nurd xfig-3.2.9.orig/tests/Makefile.am xfig-3.2.9/tests/Makefile.am
--- xfig-3.2.9.orig/tests/Makefile.am	2023-03-10 06:33:14.000000000 -0500
+++ xfig-3.2.9/tests/Makefile.am	2023-10-28 16:10:53.000000000 -0400
@@ -39,7 +39,7 @@
 	  echo 'm4_define([AT_PACKAGE_URL], [@PACKAGE_URL@])'; \
 	} >'$(srcdir)/package.m4'
 
-AM_CPPFLAGS = -I$(top_srcdir)/src -I$(oldincludedir)/freetype2 $(XCPPFLAGS)
+AM_CPPFLAGS = -I$(top_srcdir)/src $(XCPPFLAGS)
 
 AM_LDFLAGS = $(XLDFLAGS)
 LDADD = $(top_builddir)/src/libxfig.a $(XLIBS)
