[pulseaudio-discuss] [PATCH 1/6] build: Replace sed by awk for processing .in files

Maarten Bosmans mkbosmans at gmail.com
Mon Mar 14 08:26:58 PDT 2011


---
 Makefile.am     |    1 +
 configure.ac    |    3 +--
 man/Makefile.am |    4 +---
 process-in.awk  |   36 ++++++++++++++++++++++++++++++++++++
 src/Makefile.am |   30 ++++++++++++++----------------
 5 files changed, 53 insertions(+), 21 deletions(-)
 create mode 100644 process-in.awk

diff --git a/Makefile.am b/Makefile.am
index a8a9eaa..d69087a 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -26,6 +26,7 @@ EXTRA_DIST = \
 	doxygen/Makefile.am \
 	doxygen/Makefile.in \
 	doxygen/doxygen.conf.in \
+	process-in.awk \
 	README \
 	todo \
 	vala/libpulse.vapi
diff --git a/configure.ac b/configure.ac
index 9b73bc1..4d42b17 100644
--- a/configure.ac
+++ b/configure.ac
@@ -22,7 +22,7 @@
 
 AC_PREREQ(2.63)
 
-AC_INIT([pulseaudio],[m4_esyscmd(./git-version-gen .tarball-version)],[mzchyfrnhqvb (at) 0pointer (dot) net])
+AC_INIT([pulseaudio],[m4_esyscmd(./git-version-gen .tarball-version)],[mzchyfrnhqvb (at) 0pointer (dot) net],[pulseaudio],[http://pulseaudio.org/])
 AC_CONFIG_SRCDIR([src/daemon/main.c])
 AC_CONFIG_MACRO_DIR([m4])
 AC_CONFIG_HEADERS([config.h])
@@ -34,7 +34,6 @@ m4_define(pa_minor, `echo $VERSION | cut -d. -f2 | cut -d- -f1`)
 AC_SUBST(PA_MAJOR, pa_major)
 AC_SUBST(PA_MINOR, pa_minor)
 AC_SUBST(PA_MAJORMINOR, pa_major.pa_minor)
-AC_SUBST(PACKAGE_URL, [http://pulseaudio.org/])
 
 AC_SUBST(PA_API_VERSION, 12)
 AC_SUBST(PA_PROTOCOL_VERSION, 20)
diff --git a/man/Makefile.am b/man/Makefile.am
index eca1fb9..62278c6 100644
--- a/man/Makefile.am
+++ b/man/Makefile.am
@@ -36,9 +36,7 @@ noinst_DATA = \
 	default.pa.5.xml
 
 %.xml: %.xml.in Makefile
-	$(AM_V_GEN) sed -e 's, at pulseconfdir\@,$(pulseconfdir),g' \
-	    -e 's, at PACKAGE_BUGREPORT\@,$(PACKAGE_BUGREPORT),g' \
-            -e 's, at PACKAGE_URL\@,$(PACKAGE_URL),g' $< > $@
+	$(AM_V_GEN) $(AWK) -v configfile=$(top_builddir)/config.h -f $(top_srcdir)/process-in.awk pulseconfdir=$(pulseconfdir) $< > $@
 
 xmllint: $(noinst_DATA)
 	for f in $(noinst_DATA) ; do \
diff --git a/process-in.awk b/process-in.awk
new file mode 100644
index 0000000..f73859f
--- /dev/null
+++ b/process-in.awk
@@ -0,0 +1,36 @@
+# This AWK script processes input files by replacing @VAR@ by its value, similar to configure does to files added to
+# AC_CONFIG_FILES.  On top of that it allows the use of conditionals with @if, @else and @endif.
+BEGIN {
+  # Put variables from config.h into the config dictionary
+  while ((getline < configfile) > 0)
+    if (/^#define/) {
+      value = substr($0, index($0, $2)+length($2)+1)
+      if (value ~ /\".*\"/)
+        value = substr(value, 2, length(value)-2)
+      config[$2] = value
+    }
+  # Put variables from the command line into the config dictionary
+  for (i = 1; i < ARGC; i++)
+    if ((ind = index(ARGV[i], "=")) > 0)
+      config[substr(ARGV[i], 0, ind-1)] = substr(ARGV[i], ind+1)
+}
+{
+  # Replace all variables present in the config dictionary
+  for (define in config)
+    gsub("@" define "@", config[define])
+  # Process the conditional statements
+  if (match($0, /@if /))
+    stack[++stacklen] = int(substr($0, RSTART+RLENGTH))
+  else if (/@else$/)
+    stack[stacklen] = !stack[stacklen]
+  else if (/@endif$/)
+    delete stack[stacklen--]
+  else {
+    printline = 1
+    for (bla in stack)
+      if (!stack[bla])
+        printline = 0
+    if (printline)
+      print $0
+  }
+}
diff --git a/src/Makefile.am b/src/Makefile.am
index 2ab6355..139234f 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1865,24 +1865,27 @@ module_rygel_media_server_la_CFLAGS = $(AM_CFLAGS) $(DBUS_CFLAGS)
 
 CLEANFILES += esdcompat client.conf default.pa system.pa daemon.conf start-pulseaudio-x11 start-pulseaudio-kde daemon/pulseaudio.desktop daemon/pulseaudio-kde.desktop
 
+AWK_in=$(AWK) -v configfile=$(top_builddir)/config.h -f $(top_srcdir)/process-in.awk \
+	PACTL_BINARY=$(bindir)/pactl \
+	PA_BINARY=$(PA_BINARY) \
+	PA_DEFAULT_CONFIG_FILE=$(PA_DEFAULT_CONFIG_DIR)/default.pa \
+	PA_DLSEARCHPATH=$(modlibexecdir) \
+	PA_SOEXT=.so
+
 esdcompat: daemon/esdcompat.in Makefile
-	$(AM_V_GEN) sed -e 's, at PACKAGE_VERSION\@,$(PACKAGE_VERSION),g' \
-		-e 's, at PACKAGE_NAME\@,$(PACKAGE_NAME),g' \
-		-e 's, at PA_BINARY\@,$(PA_BINARY),g' < $< > $@
+	$(AM_V_GEN) $(AWK_in) $< > $@
 	$(AM_V_at) chmod +x esdcompat
 
 start-pulseaudio-x11: daemon/start-pulseaudio-x11.in Makefile
-	$(AM_V_GEN) sed -e 's, at PA_BINARY\@,$(PA_BINARY),g' \
-		-e 's, at PACTL_BINARY\@,$(bindir)/pactl,g' < $< > $@
+	$(AM_V_GEN) $(AWK_in) $< > $@
 	$(AM_V_at) chmod +x start-pulseaudio-x11
 
 start-pulseaudio-kde: daemon/start-pulseaudio-kde.in Makefile
-	$(AM_V_GEN) sed -e 's, at PA_BINARY\@,$(PA_BINARY),g' \
-		-e 's, at PACTL_BINARY\@,$(bindir)/pactl,g' < $< > $@
+	$(AM_V_GEN) $(AWK_in) $< > $@
 	$(AM_V_at) chmod +x start-pulseaudio-kde
 
 client.conf: pulse/client.conf.in Makefile
-	$(AM_V_GEN) sed -e 's, at PA_BINARY\@,$(PA_BINARY),g' < $< > $@
+	$(AM_V_GEN) $(AWK_in) $< > $@
 
 if OS_IS_WIN32
 default.pa: daemon/default.pa.win32
@@ -1891,18 +1894,13 @@ system.pa: daemon/default.pa.win32
 	cp $< $@
 else
 default.pa: daemon/default.pa.in Makefile
-	$(AM_V_GEN) sed -e 's, at PA_BINARY\@,$(PA_BINARY),g' \
-            -e 's, at PA_DLSEARCHPATH\@,$(modlibexecdir),g' \
-	    -e 's, at PA_SOEXT\@,.so,g' < $< > $@
+	$(AM_V_GEN) $(AWK_in) $< > $@
 system.pa: daemon/system.pa.in Makefile
-	$(AM_V_GEN) sed -e 's, at PA_BINARY\@,$(PA_BINARY),g' \
-            -e 's, at PA_DLSEARCHPATH\@,$(modlibexecdir),g' \
-	    -e 's, at PA_SOEXT\@,.so,g' < $< > $@
+	$(AM_V_GEN) $(AWK_in) $< > $@
 endif
 
 daemon.conf: daemon/daemon.conf.in Makefile
-	$(AM_V_GEN) sed -e 's, at PA_DLSEARCHPATH\@,$(modlibexecdir),g' \
-		-e 's, at PA_DEFAULT_CONFIG_FILE\@,$(DEFAULT_CONFIG_DIR),g' < $< > $@
+	$(AM_V_GEN) $(AWK_in) $< > $@
 
 install-exec-hook:
 	-chown root $(DESTDIR)$(pulselibexecdir)/proximity-helper
-- 
1.7.1




More information about the pulseaudio-discuss mailing list