[pulseaudio-discuss] [RFC] allow conditionals in config input files like default.pa.in

Maarten Bosmans mkbosmans at gmail.com
Thu Mar 3 15:26:49 PST 2011


It would be nice to have the ability to use @if HAVE_FEATURE@ in the
configuration file templates. You could see it either as an extension
of the current @VARIABLE@ replacement or as a compile-time variant of
.ifexists.

Incidentally, does anybody know why these files are currently
generated in the Makefile using sed, instead of being included in
AC_CONFIG_FILES?

Adding that ability has several advantages:
 - The default.pa.in and default.pa.win32 files can be merged.
 - The BSDs still use module-hal-detect, so it can be included in
default.pa without littering it with [.ifexists module-hal-detect\n
load-module module-hal-detect\n .endif] for Linux users, so they
cannot be confused by it.
 - And thirdly, if sys/resource.h is not found the daemon does not
understand the --rlimit-* options, so in that case those lines should
be omitted from daemon.conf.

Would this be a good change, or are we then preprocessing at too many levels?

I propose to implement it by using awk, instead of where now sed is
used in the Makefiles. Below is a very rude patch, to give an idea.
Obviously the variable initialisation in the BEGIN section of the awk
script should depend on the results of the configure checks, either by
using awk -v VAR=$(VAR) in the Makefile or letting configure do the
substitution in the script itself.

Maarten



diff --git a/src/Makefile.am b/src/Makefile.am
index 24e2f82..4c2be0c 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1875,21 +1875,10 @@ start-pulseaudio-kde:
daemon/start-pulseaudio-kde.in Makefile
 client.conf: pulse/client.conf.in Makefile
        sed -e 's, at PA_BINARY\@,$(PA_BINARY),g' < $< > $@

-if OS_IS_WIN32
-default.pa: daemon/default.pa.win32
-       cp $< $@
-system.pa: daemon/default.pa.win32
-       cp $< $@
-else
 default.pa: daemon/default.pa.in Makefile
-       sed -e 's, at PA_BINARY\@,$(PA_BINARY),g' \
-            -e 's, at PA_DLSEARCHPATH\@,$(modlibexecdir),g' \
-           -e 's, at PA_SOEXT\@,.so,g' < $< > $@
+       awk -f script.awk $< > $@
 system.pa: daemon/system.pa.in Makefile
-       sed -e 's, at PA_BINARY\@,$(PA_BINARY),g' \
-            -e 's, at PA_DLSEARCHPATH\@,$(modlibexecdir),g' \
-           -e 's, at PA_SOEXT\@,.so,g' < $< > $@
-endif
+       awk -f script.awk $< > $@

 daemon.conf: daemon/daemon.conf.in Makefile
        sed -e 's, at PA_DLSEARCHPATH\@,$(modlibexecdir),g' \
diff --git a/src/daemon/default.pa.in b/src/daemon/default.pa.in
index ace0f09..8f660d7 100755
--- a/src/daemon/default.pa.in
+++ b/src/daemon/default.pa.in
@@ -22,10 +22,10 @@
 .nofail

 ### Load something into the sample cache
-#load-sample-lazy x11-bell /usr/share/sounds/gtk-events/activate.wav
-#load-sample-lazy pulse-hotplug /usr/share/sounds/startup3.wav
-#load-sample-lazy pulse-coldplug /usr/share/sounds/startup3.wav
-#load-sample-lazy pulse-access /usr/share/sounds/generic.wav
+#load-sample-lazy x11-bell @PA_DATA_DIR@/sounds/gtk-events/activate.wav
+#load-sample-lazy pulse-hotplug @PA_DATA_DIR@/sounds/startup3.wav
+#load-sample-lazy pulse-coldplug @PA_DATA_DIR@/sounds/startup3.wav
+#load-sample-lazy pulse-access @PA_DATA_DIR@/sounds/generic.wav

 .fail

@@ -41,6 +41,10 @@ load-module module-augment-properties
 ### Load audio drivers statically (it's probably better to not load
 ### these drivers manually, but instead use module-hal-detect --
 ### see below -- for doing this automatically)
+ at if OS_IS_WIN32@
+load-module module-waveout sink_name=output
+load-module module-waveout source_name=input
+ at endif@
 #load-module module-alsa-sink
 #load-module module-alsa-source device=hw:1,0
 #load-module module-oss device="/dev/dsp" sink_name=output source_name=input
@@ -49,6 +53,11 @@ load-module module-augment-properties
 #load-module module-pipe-sink

 ### Automatically load driver modules depending on the hardware available
+ at if HAVE_HAL@
+.ifexists module-hal-detect at PA_SOEXT@
+load-module module-hal-detect
+.endif
+ at endif@
 .ifexists module-udev-detect at PA_SOEXT@
 load-module module-udev-detect
 .else
diff --git a/src/script.awk b/src/script.awk
new file mode 100644
index 0000000..ed141f1
--- /dev/null
+++ b/src/script.awk
@@ -0,0 +1,24 @@
+BEGIN {
+  HAVE_HAL=0
+  OS_IS_WIN32=1
+  PA_DLSEARCHPATH="/usr/lib/pulse/modules"
+  PA_DATA_DIR="/usr/share"
+  PA_BINARY="pulseaudio"
+  PA_SOEXT=".so"
+
+  printline = 1
+}
+{
+  gsub(/@PA_DLSEARCHPATH@/, PA_DLSEARCHPATH)
+  gsub(/@PA_DATA_DIR@/, PA_DATA_DIR)
+  gsub(/@PA_BINARY@/, PA_BINARY)
+  gsub(/@PA_SOEXT@/, PA_SOEXT)
+  if (/@if [A-Z0-9_]+@/) {
+    if (/@if HAVE_HAL@/ && !HAVE_HAL) printline = 0
+    if (/@if OS_IS_WIN32@/ && !OS_IS_WIN32) printline = 0
+  }
+  else if (/@endif@/)
+    printline = 1
+  else if (printline)
+    print $0
+}



More information about the pulseaudio-discuss mailing list