diff --git a/Makefile b/Makefile
index c5bade7138d4d17bd83718deae8e9c2b82d65c60..7ebf890813a79e54d564c65589296e3a8dc12002 100644
--- a/Makefile
+++ b/Makefile
@@ -331,7 +331,7 @@ distclean: clean
 	rm -f build_tools/menuselect-deps
 
 datafiles: all
-	if [ x`$(ID) -un` = xroot ]; then sh build_tools/mkpkgconfig $(DESTDIR)/usr/lib/pkgconfig; fi
+	if [ x`$(ID) -un` = xroot ]; then CFLAGS="$(ASTCFLAGS)" sh build_tools/mkpkgconfig $(DESTDIR)/usr/lib/pkgconfig; fi
 # Should static HTTP be installed during make samples or even with its own target ala
 # webvoicemail?  There are portions here that *could* be customized but might also be
 # improved a lot.  I'll put it here for now.
diff --git a/build_tools/mkpkgconfig b/build_tools/mkpkgconfig
index 0ae2a24bf9851511878754d35390697caef1bc17..bc04f756194be3437fad2d81e2b47790fa1d3bf4 100755
--- a/build_tools/mkpkgconfig
+++ b/build_tools/mkpkgconfig
@@ -15,11 +15,11 @@ fi
 
 ## Clean out CFLAGS for the spec file.
 
-LOCAL_CFLAGS=`echo $CFLAGS | sed -e 's/\s*-pipe\s*//g' | sed -e 's/-[Wmp]\S*\s*//g' | \
-  sed -r -e 's/-I(include|\.\.\/include) //g' | \
-  sed -e 's/-DINSTALL_PREFIX=\S* //g' | \
-  sed -r -e 's/-DASTERISK_VERSION=\S* //g' | \
-  sed -r -e 's/-DAST(ETCDIR|LIBDIR|VARLIBDIR|VARRUNDIR|SPOOLDIR|LOGDIR|CONFPATH|MODDIR|AGIDIR)=\S* //g'`
+LOCAL_CFLAGS=`echo $CFLAGS | sed -e 's/[[:space:]]*-pipe[[:space:]]*//g' | sed -e 's/-[Wmp][^[:space:]]*[[:space:]]*//g' | \
+  sed -e 's/-I\(include|\.\.\/include\) //g' | \
+  sed -e 's/-DINSTALL_PREFIX=[^[:space:]]* //g' | \
+  sed -e 's/-DASTERISK_VERSION=[^[:space:]]* //g' | \
+  sed -e 's/-DAST\(ETCDIR|LIBDIR|VARLIBDIR|VARRUNDIR|SPOOLDIR|LOGDIR|CONFPATH|MODDIR|AGIDIR\)=[^[:space:]]* //g'`
 
 
 cat <<EOF > $PPATH/asterisk.pc