--- a/Makefile.am
+++ b/Makefile.am
@@ -99,7 +99,7 @@ endif
 # Remake the version.h header file if, and only if, the git ID has changed
 .PHONY: .FORCE
 .FORCE:
-generate_ver = ver="`{ $(srcdir)/scripts/version || echo '$(VERSION)' ; } | sed 's/.*/\x23define JQ_VERSION \"&\"/'`"
+generate_ver = ver="`{ $(srcdir)/scripts/version || echo '$(VERSION)' ; } | xargs printf '\043define JQ_VERSION \"%s\"\n'`"
 .remake-version-h: .FORCE
 	@ $(generate_ver); test "x`cat src/version.h 2>/dev/null`" = "x$$ver" || touch .remake-version-h
 src/version.h: .remake-version-h

--- a/Makefile.in
+++ b/Makefile.in
@@ -754,7 +754,7 @@ endif
 @ENABLE_ERROR_INJECTION_TRUE@libinject_errors_la_SOURCES = src/inject_errors.c
 @ENABLE_ERROR_INJECTION_TRUE@libinject_errors_la_LIBADD = -ldl
 @ENABLE_ERROR_INJECTION_TRUE@libinject_errors_la_LDFLAGS = -module
-generate_ver = ver="`{ $(srcdir)/scripts/version || echo '$(VERSION)' ; } | sed 's/.*/\x23define JQ_VERSION \"&\"/'`"
+generate_ver = ver="`{ $(srcdir)/scripts/version || echo '$(VERSION)' ; } | xargs printf '\043define JQ_VERSION \"%s\"\n'`"
 CLEANFILES = src/version.h .remake-version-h src/builtin.inc \
 	src/config_opts.inc jq.1
 jq_SOURCES = src/main.c
 
