[21.5] Clean up dupes from pkg-config --cflags

"Stephen J. Turnbull" <[email protected]> Sun, 11 Jan 2015 00:25:54 +0900
Newsgroups gmane.emacs.xemacs.patches
Message-ID <[email protected]>
21.5

I'm not real sure I like this patch; I can always keep it in a local
branch.  MacPorts has other problems (including the fact that unlike
every other installation I know of it puts the Freetype includes in
.../include/freetype2 instead of in .../include/freetype2/freetype).

The problem the patch solves is that MacPorts "pkg-config xft --cflags"
reports the concatenation of CFLAGS used by several packages required
by Xft, resulting in

    -I/opt/local/include -I/opt/local/include/freetype2 \
    -I/opt/local/include -I/opt/local/include/libpng16 \
    -I/opt/local/include -I/opt/local/include/freetype2 \
    -I/opt/local/include

which isn't pretty.  This patch simply detects and removes
duplicates, so the search path is effectively the same:

    -I/opt/local/include -I/opt/local/include/freetype2 \
    -I/opt/local/include/libpng16

I tried to turn this into an M4 macro, but my M4-foo is weak (as I
mentioned elsewhere), so it's inline in this patch.

Comments (and help with the macro!) are welcome.

diff -r 6b57aad276aa -r 4f97461d589a configure.ac
--- a/configure.ac	Sat Jan 10 21:11:10 2015 +0900
+++ b/configure.ac	Sat Jan 10 23:12:25 2015 +0900
@@ -3217,6 +3229,17 @@
     xft_config_ok=`$xft_config_prog --cflags 2>/dev/null`
     if test "$?" = 0 ; then
 	xft_cflags=`$xft_config_prog --cflags`
+        dnl I tried to create XE_REMOVE_DUPS(xft_cflags,$xft_cflags),
+        dnl but it didn't work.
+        cleaned_xft_cflags=""
+        for xft_cflag in $xft_cflags; do
+          case $xft_cleaned_cflags in
+          *${xft_cflag}* ) ;;
+          * ) xft_cleaned_cflags="$xft_cleaned_cflags $xft_cflag" ;;
+          esac
+        done
+        xft_cflags=$xft_cleaned_cflags
+        unset xft_cflag xft_cleaned_cflags
 	xft_libs=`$xft_config_prog --libs`
 	c_switch_site="$c_switch_site $xft_cflags"
 	ld_switch_site="$ld_switch_site $xft_libs"