diff --git a/configure.ac b/configure.ac
index cb3152486..090a0f5cc 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2118,7 +2118,6 @@ hw/xnest/Makefile
hw/xwin/Makefile
hw/xquartz/Makefile
hw/xquartz/bundle/Makefile
-hw/xquartz/bundle/org.x.X11.plist
hw/xquartz/xpr/Makefile
hw/kdrive/Makefile
hw/kdrive/ati/Makefile
diff --git a/hw/xquartz/Makefile.am b/hw/xquartz/Makefile.am
index 612a7d81f..97b8c94e0 100644
--- a/hw/xquartz/Makefile.am
+++ b/hw/xquartz/Makefile.am
@@ -1,7 +1,3 @@
-libexec_PROGRAMS = x11-exec
-
-x11_exec_LDFLAGS = -framework ApplicationServices
-
noinst_LTLIBRARIES = libXquartz.la
AM_CFLAGS = $(XSERVER_CFLAGS) $(DIX_CFLAGS)
AM_CPPFLAGS = \
@@ -13,6 +9,12 @@ AM_CPPFLAGS = \
if X11APP
X11APP_SUBDIRS = bundle
+
+if LAUNCHD
+libexec_PROGRAMS = x11-exec
+x11_exec_LDFLAGS = -framework ApplicationServices
+endif
+
endif
SUBDIRS = . xpr $(X11APP_SUBDIRS)
diff --git a/hw/xquartz/bundle/Makefile.am b/hw/xquartz/bundle/Makefile.am
index 8aa23575f..775e1aad0 100644
--- a/hw/xquartz/bundle/Makefile.am
+++ b/hw/xquartz/bundle/Makefile.am
@@ -9,7 +9,14 @@ install-data-hook:
xcodebuild install DSTROOT="/$(DESTDIR)" INSTALL_PATH="$(APPLE_APPLICATIONS_DIR)" DEPLOYMENT_LOCATION=YES SKIP_INSTALL=NO ARCHS="$(X11APP_ARCHS)"
if LAUNCHD
-launchagents_DATA = org.x.X11.plist
+launchagents_PRE = org.x.X11.plist.pre
+launchagents_DATA = $(launchagents_PRE:plist.pre=plist)
+
+CPP_FILES_FLAGS = -D__libexecdir__="${libexecdir}"
+
+CLEANFILES = $(launchagents_DATA)
+
+include $(top_srcdir)/cpprules.in
endif
clean-local:
diff --git a/hw/xquartz/bundle/org.x.X11.plist b/hw/xquartz/bundle/org.x.X11.plist.pre
similarity index 91%
rename from hw/xquartz/bundle/org.x.X11.plist
rename to hw/xquartz/bundle/org.x.X11.plist.pre
index 1e646ac63..83d8b2f31 100644
--- a/hw/xquartz/bundle/org.x.X11.plist
+++ b/hw/xquartz/bundle/org.x.X11.plist.pre
@@ -6,7 +6,7 @@
org.x.X11
ProgramArguments
- /usr/libexec/x11-exec
+ __libexecdir__/x11-exec
-launchd
Sockets