diff --git a/stepmake/aclocal.m4 b/stepmake/aclocal.m4
index cdb6dc3..75d172e 100644
--- a/stepmake/aclocal.m4
+++ b/stepmake/aclocal.m4
@@ -989,7 +989,8 @@ AC_DEFUN(STEPMAKE_PYTHON_DEVEL, [
     if test -z "$PYTHON_CFLAGS" -a "$PYTHON_CONFIG" != "no"; then
         # Clean out junk: http://bugs.python.org/issue3290
 	# Python headers may need some -f* flags, leave them in.
-	PYTHON_CFLAGS=`$PYTHON_CONFIG --cflags | sed -e 's/ -\(W\|D\|O\|m\)\(\w\|-\|=\|,\)\+//g'`
+	# We want the sed commands to look like 's/-[OWDOm][[:alnum:][:punct:]][[:alnum:][:punct:]]*//g' and 's/-arch [^[:space:]]*//g', but automake eats brackets.
+	PYTHON_CFLAGS=`$PYTHON_CONFIG --cflags | sed -e 's/-[[OWDOm]][[[:alnum:][:punct:]]][[[:alnum:][:punct:]]]*//g' | sed -e 's/-arch @<:@^@<:@:space:@:>@@:>@*//g'`
 	PYTHON_LDFLAGS=`$PYTHON_CONFIG --ldflags`
     fi
     
