From: Jon Ludlam <jonathan.ludlam@eu.citrix.com>
Date: Fri, 9 Dec 2011 16:31:27 +0000
Subject: fhs

---
 .gitignore                                         |    2 +
 Makefile                                           |   44 +++-
 OMakefile                                          |   13 +-
 java/OMakefile                                     |    4 +-
 javascript/OMakefile                               |   12 +-
 ocaml/OMakefile                                    |    4 +-
 ocaml/auth/OMakefile                               |    4 +-
 ocaml/auth/extauth.ml                              |    8 +-
 ocaml/auth/extauth_plugin_ADlikewise.ml            |    2 +-
 ocaml/autogen/OMakefile                            |    4 +-
 ocaml/cdrommon/OMakefile                           |    6 +-
 ocaml/database/OMakefile                           |   10 +-
 ocaml/database/redo_log.ml                         |    2 +-
 ocaml/db_process/OMakefile                         |    6 +-
 ocaml/events/OMakefile                             |    4 +-
 ocaml/gpg/OMakefile                                |    2 +-
 ocaml/gpg/gpg.ml                                   |    2 +-
 ocaml/graph/OMakefile                              |    4 +-
 ocaml/idl/OMakefile                                |    2 +-
 ocaml/idl/js_backend/OMakefile                     |    4 +-
 ocaml/idl/ocaml_backend/OMakefile                  |    4 +-
 ocaml/license/OMakefile                            |   13 +-
 ocaml/license/v6client.ml                          |    2 +-
 ocaml/license/v6d_reopen_logs.ml                   |    2 +-
 ocaml/license/v6daemon.ml                          |    2 +-
 ocaml/lvhdrt/OMakefile                             |   12 +-
 ocaml/lvhdrt/lvhdrt-trash-vdi                      |    2 +-
 ocaml/mpathalert/OMakefile                         |    8 +-
 ocaml/mpathalert/mpathalert.ml                     |    2 +-
 ocaml/multipathrt/OMakefile                        |    8 +-
 ocaml/multipathrt/multipathrt-helper               |    4 +-
 ocaml/perftest/OMakefile                           |   12 +-
 ocaml/perftest/apiperf.ml                          |    2 +-
 ocaml/perftest/client_stunnel.conf                 |    2 +-
 ocaml/perftest/perfutil.ml                         |    2 +-
 ocaml/ptoken/OMakefile                             |    8 +-
 ocaml/ptoken/genptoken.ml                          |    2 +-
 ocaml/sm-cli/OMakefile                             |   12 +-
 ocaml/sm-cli/main.ml                               |    2 +-
 ocaml/sm-cli/test.ml                               |    2 +-
 ocaml/toplevel/OMakefile                           |    4 +-
 ocaml/toplevel/mkwrapper                           |    2 +-
 ocaml/util/OMakefile                               |    3 +
 ocaml/util/util_globs_inventory.ml                 |    2 +-
 ocaml/util/util_inventory.ml                       |    2 +-
 ocaml/vncproxy/OMakefile                           |    8 +-
 ocaml/vncproxy/vncproxy.ml                         |    2 +-
 ocaml/xapi/OMakefile                               |   36 +--
 ocaml/xapi/certificates.ml                         |    2 +-
 ocaml/xapi/config_constants.ml.in                  |    1 -
 ocaml/xapi/console.ml                              |    2 +-
 ocaml/xapi/create_misc.ml                          |    2 +-
 ocaml/xapi/events.ml                               |    2 +-
 ocaml/xapi/helpers.ml                              |    2 +-
 ocaml/xapi/monitor.ml                              |    2 +-
 ocaml/xapi/monitor_fake_common.ml                  |    2 +-
 ocaml/xapi/nm.ml                                   |    2 +-
 ocaml/xapi/pool_db_backup.ml                       |    2 +-
 ocaml/xapi/quicktest                               |    2 +-
 ocaml/xapi/quicktest_storage.ml                    |    2 +-
 ocaml/xapi/sm_exec.ml                              |    2 +-
 ocaml/xapi/sparse_dd_wrapper.ml                    |    2 +-
 ocaml/xapi/static_vdis.ml                          |    2 +-
 ocaml/xapi/static_vdis_list.ml                     |    2 +-
 ocaml/xapi/storage_impl.ml                         |    2 +-
 ocaml/xapi/vmops.ml                                |    2 +-
 ocaml/xapi/xapi.ml                                 |    8 +-
 ocaml/xapi/xapi_globs.ml                           |   69 ++---
 ocaml/xapi/xapi_ha.ml                              |   18 +-
 ocaml/xapi/xapi_host.ml                            |    6 +-
 ocaml/xapi/xapi_host_backup.ml                     |    4 +-
 ocaml/xapi/xapi_logs_download.ml                   |    2 +-
 ocaml/xapi/xapi_message.ml                         |    8 +-
 ocaml/xapi/xapi_mgmt_iface.ml                      |    2 +-
 ocaml/xapi/xapi_pci.ml                             |    2 +-
 ocaml/xapi/xapi_pool_patch.ml                      |    6 +-
 ocaml/xapi/xapi_services.ml                        |    2 +-
 ocaml/xapi/xapi_support.ml                         |    2 +-
 ocaml/xapi/xapi_sync.ml                            |    2 +-
 ocaml/xapi/xapi_templates_install.ml               |    2 +-
 ocaml/xapi/xapi_udhcpd.ml                          |    8 +-
 ocaml/xapi/xapi_vif.ml                             |    2 +-
 ocaml/xapi/xha_interface.ml                        |    2 +-
 ocaml/xe-cli/OMakefile                             |   11 +-
 ocaml/xe-cli/cli.ml                                |    2 +-
 ocaml/xe-cli/newcli.ml                             |    2 +-
 ocaml/xe-cli/rt/OMakefile                          |    4 +-
 ocaml/xe-cli/rt/geneva/OMakefile                   |    4 +-
 ocaml/xe-cli/rt/install-debian-pv.sh               |    2 +-
 ocaml/xenguest/OMakefile                           |    4 +-
 ocaml/xenops/OMakefile                             |   21 +-
 ocaml/xenops/device.ml                             |    6 +-
 ocaml/xenops/xenguestHelper.ml                     |    2 +-
 ocaml/xenops/xenops.ml                             |    2 +-
 ocaml/xenops/xenvm.readme                          |    2 +-
 ocaml/xiu/OMakefile                                |   20 +-
 ocaml/xiu/xiu.ml                                   |    6 +-
 ocaml/xsh/OMakefile                                |    4 +-
 scripts/10resetvdis                                |    2 +-
 scripts/InterfaceReconfigure.py                    |    4 +-
 scripts/OMakefile                                  |  160 +++++-----
 scripts/backup-metadata-cron                       |    6 +-
 scripts/bugtool-plugin/xapi/stuff.xml              |    4 +-
 scripts/db.conf.skel                               |    2 +-
 scripts/debug_ha_query_liveset                     |    4 +-
 scripts/examples/bash-cli/install-debian           |    4 +-
 scripts/examples/bash-cli/install-debian.html      |    4 +-
 scripts/examples/python/OMakefile                  |   12 +-
 scripts/examples/python/XenAPI.py                  |    3 +-
 scripts/examples/python/inventory.py               |    2 +-
 .../examples/python/monitor-unwanted-domains.py    |    4 +-
 scripts/fake-pv-drivers.sh                         |    2 +-
 scripts/fence                                      |    2 +-
 scripts/host-backup-restore/OMakefile              |    4 +-
 scripts/host-backup-restore/host-restore           |    2 +-
 scripts/host-bugreport-upload                      |    2 +-
 scripts/init.d-genptoken                           |    4 +-
 scripts/init.d-management-interface                |    4 +-
 scripts/init.d-perfmon                             |    4 +-
 scripts/init.d-sdkinit                             |    8 +-
 scripts/init.d-squeezed                            |    4 +-
 scripts/init.d-v6d                                 |    2 +-
 scripts/init.d-xapi                                |   12 +-
 scripts/init.d-xapi-domains                        |    8 +-
 scripts/init.d-xapissl                             |   12 +-
 scripts/init.d-xenservices                         |   14 +-
 scripts/install.sh                                 |   37 ++-
 scripts/interface-reconfigure                      |    2 +-
 scripts/interface-reconfigure-test                 |    2 +-
 scripts/interface-reconfigure-test-setup           |    2 +-
 scripts/interface-visualise                        |    2 +-
 scripts/license-check.py                           |    6 +-
 scripts/mpathalert-daemon                          |    2 +-
 scripts/plugins/iovirt                             |    4 +-
 scripts/poweron/OMakefile                          |   12 +-
 scripts/poweron/iLO.py                             |    2 +-
 scripts/rewrite-management-interface               |    4 +-
 scripts/rio.db.conf.skel                           |    2 +-
 scripts/runtests                                   |    2 +-
 scripts/set-dom0-memory-target-from-packs          |    4 +-
 scripts/sm_diagnostics                             |    2 +-
 scripts/static-vdis                                |    2 +-
 scripts/sysconfig-perfmon                          |    2 +-
 scripts/templates/OMakefile                        |    6 +-
 scripts/templates/debian                           |    2 +-
 scripts/thread_diagnostics                         |    2 +-
 scripts/vif                                        |    2 +-
 scripts/vncterm-wrapper                            |    4 +-
 scripts/with-vdi                                   |    2 +-
 scripts/xapi-autostart-vms                         |    2 +-
 scripts/xapi-logrotate                             |    2 +-
 scripts/xapi-rolling-upgrade-miami                 |    4 +-
 scripts/xapi.conf                                  |    4 +-
 scripts/xe-backup-metadata                         |   12 +-
 scripts/xe-edit-bootloader                         |    6 +-
 scripts/xe-mount-iso-sr                            |    4 +-
 scripts/xe-reset-networking                        |    6 +-
 scripts/xe-restore-metadata                        |   12 +-
 scripts/xe-set-iscsi-iqn                           |    6 +-
 scripts/xe-toolstack-restart                       |    6 +-
 scripts/xe-xentrace                                |    6 +-
 scripts/xen-backend.agent                          |    8 +-
 scripts/xen-backend.rules                          |    8 +-
 scripts/xen-frontend.rules                         |    2 +-
 xapi.spec.in                                       |  322 ++++++++++----------
 165 files changed, 723 insertions(+), 662 deletions(-)
 delete mode 100644 ocaml/xapi/config_constants.ml.in

diff --git a/.gitignore b/.gitignore
index 228e293..027ed28 100644
--- a/.gitignore
+++ b/.gitignore
@@ -197,3 +197,5 @@ ocaml/xenops/memory_breakdown
 ocaml/xenops/squeezed
 ocaml/xenops/squeezed_client
 xapi.spec
+
+ocaml/fhs.*
diff --git a/Makefile b/Makefile
index e7253fe..c15c352 100644
--- a/Makefile
+++ b/Makefile
@@ -23,8 +23,27 @@ COMPILE_NATIVE=yes
 COMPILE_BYTE=no # bytecode version does not build
 export COMPILE_NATIVE COMPILE_BYTE
 
+# FHS stuff
+VARDIR=/var/xapi
+VARPATCHDIR=/var/patch
+ETCDIR=/etc/xensource
+OPTDIR=/opt/xensource
+PLUGINDIR=/etc/xapi.d/plugins
+HOOKSDIR=/etc/xapi.d
+INVENTORY=/etc/xensource-inventory
+XAPICONF=/etc/xapi.conf
+LIBEXECDIR=/opt/xensource/libexec
+SCRIPTSDIR=/etc/xensource/scripts
+SHAREDIR=/opt/xensource
+WEBDIR=/opt/xensource/www
+XHADIR=/opt/xensource/xha
+BINDIR=/opt/xensource/bin
+SBINDIR=/opt/xensource/bin
+
+export VARDIR ETCDIR OPTDIR PLUGINDIR HOOKSDIR INVENTORY VARPATCHDIR LIBEXECDIR XAPICONF SCRIPTSDIR SHAREDIR WEBDIR XHADIR BINDIR SBINDIR
+
 .PHONY: all
-all: version
+all: version ocaml/fhs.ml
 	omake phase1
 	omake phase2
 	omake phase3
@@ -91,13 +110,32 @@ version:
 	let xapi_version_minor = $(shell cut -d. -f2 VERSION) \n" \
 	> ocaml/util/version.ml
 
- .PHONY: clean
+ocaml/fhs.ml :
+	@printf "(* This file is autogenerated by xen-api.git/Makefile *)\n \
+	let vardir=\"$(VARDIR)\"\n \
+	let etcdir=\"$(ETCDIR)\"\n \
+	let optdir=\"$(OPTDIR)\"\n \
+	let plugindir=\"$(PLUGINDIR)\"\n \
+	let inventory=\"$(INVENTORY)\"\n \
+	let hooksdir=\"$(HOOKSDIR)\"\n \
+	let libexecdir=\"$(LIBEXECDIR)\"\n \
+	let xapiconf=\"$(XAPICONF)\"\n \
+	let scriptsdir=\"$(SCRIPTSDIR)\"\n \
+	let varpatchdir=\"$(VARPATCHDIR)\"\n \
+	let webdir=\"$(WEBDIR)\"\n \
+	let xhadir=\"$(XHADIR)\"\n \
+	let bindir=\"$(BINDIR)\"\n \
+	let sbindir=\"$(SBINDIR)\"\n \
+	let sharedir=\"$(SHAREDIR)\"\n" \
+	> ocaml/fhs.ml
+ 
+.PHONY: clean
  clean:
 
 .PHONY: xapi.spec
 xapi.spec: xapi.spec.in
 	sed -e 's/@RPM_RELEASE@/$(shell git rev-list HEAD | wc -l)/g' < $< > $@
-	sed -i "s!@BASE_PATH@!${BASE_PATH}!g" $@
+	sed -i "s!@OPTDIR@!${OPTDIR}!g" $@
 
 .PHONY: srpm
 srpm: xapi.spec
diff --git a/OMakefile b/OMakefile
index b51e020..4392945 100644
--- a/OMakefile
+++ b/OMakefile
@@ -41,6 +41,9 @@ LDFLAGS+=-static
 if $(not $(defined-env XEN_ROOT))
   XEN_ROOT =
   export
+if $(not $(defined-env DESTDIR))
+  DESTDIR = 
+  export
 
 XEN_CFLAGS=-I$(XEN_ROOT)/usr/include
 XEN_OCAML_LINK_FLAGS=-cclib -L$(XEN_ROOT)/usr/$(LIBDIR)
@@ -49,14 +52,6 @@ XEN_OCAML_CLIBS=
 # For the Zurich chroot environment
 CFLAGS+=-I$(shell ocamlc -where)
 
-DESTDIR=$(getenv DESTDIR, $(ROOT)/dist/staging)
-RAW_BASE_PATH=$(shell scripts/base-path scripts/xapi.conf)
-BASE_PATH=$(DESTDIR)$(RAW_BASE_PATH)
-BIN_DIR=$(RAW_BASE_PATH)/bin
-BIN_PATH=$(DESTDIR)$(BIN_DIR)
-DEBUGDIST=$(BASE_PATH)/debug
-LIBEXEC=$(BASE_PATH)/libexec
-
 DIST=$(ROOT)/dist
 SDK=$(DESTDIR)/usr/share/doc/xapi
 SDKWWW=$(DESTDIR)/usr/share/doc/xapi/www
@@ -84,7 +79,7 @@ export
 .PHONY: none
 
 # Ocaml #############################################################################
-OCAML_PHASE1= generate_constants autogen_idl
+OCAML_PHASE1= autogen_idl
 OCAML_PHASE2= $(if $(BYTE_ENABLED), ocaml/idl/ocaml_backend/xapi_client.cma) $(if $(NATIVE_ENABLED), ocaml/idl/ocaml_backend/xapi_client.cmxa)
 
 # JS ################################################################################
diff --git a/java/OMakefile b/java/OMakefile
index 025bb70..39f30db 100644
--- a/java/OMakefile
+++ b/java/OMakefile
@@ -8,6 +8,6 @@ clean:
 
 .PHONY: install
 install:
-	mkdir -p $(DEBUGDIST)/www
+	mkdir -p $(DESTDIR)$(OPTDIR)/debug/www
 	# If we haven't built it then we can't install it (see COMPILE_JAVA)
-	$(IDATA) XenServerConsole.jar $(DEBUGDIST)/www || /bin/true
\ No newline at end of file
+	$(IDATA) XenServerConsole.jar $(DESTDIR)$(OPTDIR)/debug/www || /bin/true
diff --git a/javascript/OMakefile b/javascript/OMakefile
index c330295..f84390e 100644
--- a/javascript/OMakefile
+++ b/javascript/OMakefile
@@ -1,10 +1,10 @@
 
 .PHONY: install
 install:
-	mkdir -p $(DEBUGDIST)/www
-	cp *.js *.html *.css $(DEBUGDIST)/www
-	mkdir -p $(DEBUGDIST)/www/jquery
-	cp -v jquery/* $(DEBUGDIST)/www/jquery
-	mkdir -p $(DEBUGDIST)/www/images
-	cp -v images/xen_logo.gif $(DEBUGDIST)/www/images
+	mkdir -p $(DESTDIR)$(OPTDIR)/debug/www
+	cp *.js *.html *.css $(DESTDIR)$(OPTDIR)/debug/www
+	mkdir -p $(DESTDIR)$(OPTDIR)/debug/www/jquery
+	cp -v jquery/* $(DESTDIR)$(OPTDIR)/debug/www/jquery
+	mkdir -p $(DESTDIR)$(OPTDIR)/debug/www/images
+	cp -v images/xen_logo.gif $(DESTDIR)$(OPTDIR)/debug/www/images
 
diff --git a/ocaml/OMakefile b/ocaml/OMakefile
index ec45103..006df31 100644
--- a/ocaml/OMakefile
+++ b/ocaml/OMakefile
@@ -1,9 +1,11 @@
 # You must set your XEN_ROOT env var before building
 XEN_CFLAGS    = -I$(XEN_ROOT)/usr/include
 OCAMLINCLUDES = +ocamldoc
-OCAML_LIBS    = $(ROOT)/ocaml/util/version $(ROOT)/ocaml/util/stats
+OCAML_LIBS    = $(ROOT)/ocaml/fhs $(ROOT)/ocaml/util/version $(ROOT)/ocaml/util/stats
 OCAMLPACKS    = stdext log
 
+OCamlLibrary(fhs, fhs)
+
 .SUBDIRS: \
 	ptoken \
 	autogen \
diff --git a/ocaml/auth/OMakefile b/ocaml/auth/OMakefile
index 6ea9231..007caae 100644
--- a/ocaml/auth/OMakefile
+++ b/ocaml/auth/OMakefile
@@ -1,5 +1,5 @@
 OTHER_CLIBS = -cclib -lpam
-OCAMLINCLUDES += ../autogen ../idl/ocaml_backend ../idl ../xapi 
+OCAMLINCLUDES += ../autogen ../idl/ocaml_backend ../idl ../xapi ..
 
 StaticCLibrary(auth_stubs, xa_auth xa_auth_stubs)
 OCamlLibraryClib(pam, pam, auth_stubs)
@@ -17,4 +17,4 @@ clean:
 
 .PHONY: install
 install:
-	mkdir -p $(BIN_PATH)
+	mkdir -p $(DESTDIR)$(OPTDIR)/bin
diff --git a/ocaml/auth/extauth.ml b/ocaml/auth/extauth.ml
index a9d2aa7..c0e5c8f 100644
--- a/ocaml/auth/extauth.ml
+++ b/ocaml/auth/extauth.ml
@@ -74,7 +74,7 @@ struct
 end
 
 (* some constants *)
-let extauth_hook_script_name = "extauth-hook" (* script name in /etc/xapi.d/plugins/ *)
+let extauth_hook_script_name = "extauth-hook" (* script name in @PLUGINDIR@/ *)
 let event_name_after_subject_add = "after-subject-add"
 let event_name_after_subject_remove = "after-subject-remove"
 let event_name_after_xapi_initialize = "after-xapi-initialize"
@@ -102,10 +102,10 @@ let can_execute_extauth_hook_script ~__context host event_name =
 (* use the generic call below to avoid concurrency problems between the script and host.{enable,disable}_extauth *)
 let call_extauth_hook_script_in_host_wrapper ~__context host event_name ~call_plugin_fn =
 	(* CP-709: call extauth-hook-script *)
-	(* Forkhelpers.execute_command_get_output hook-script "/etc/xapi.d/plugins/extauth-hook" *)
+	(* Forkhelpers.execute_command_get_output hook-script "@PLUGINDIR@/extauth-hook" *)
 	(* fork a new thread and call new xapi.host.call-subject-add-hook-script method *)
 	(* see xapi_sync.ml *)
-	(* host.call-plugins scriptname (calls /etc/xapi.d/plugins/scriptname*)
+	(* host.call-plugins scriptname (calls @PLUGINDIR@/scriptname*)
 
 	if can_execute_extauth_hook_script ~__context host event_name
 	then begin
@@ -148,7 +148,7 @@ let call_extauth_hook_script_in_host ~__context host event_name =
 	let call_plugin_fn () = 
 		Helpers.call_api_functions ~__context (fun rpc session_id ->
 			Client.Client.Host.call_plugin rpc session_id host (* will call extauth plugin with mutex *) 
-			extauth_hook_script_name (* script name in /etc/xapi.d/plugins/ *) 
+			extauth_hook_script_name (* script name in @PLUGINDIR@/ *) 
 			event_name (* event name sent to script *)
 			event_params (* parameters sent to event name *)
 		)
diff --git a/ocaml/auth/extauth_plugin_ADlikewise.ml b/ocaml/auth/extauth_plugin_ADlikewise.ml
index 9ffcaa8..7b091bf 100644
--- a/ocaml/auth/extauth_plugin_ADlikewise.ml
+++ b/ocaml/auth/extauth_plugin_ADlikewise.ml
@@ -700,7 +700,7 @@ let on_disable config_params =
 	debug "Doing a manual Likewise domain-leave cleanup...";
 	(* When likewise raises an exception during domain-leave, we try again, using *)
 	(* some of the command-line workarounds that Kyle describes in CA-27627: *)
-	let lw_force_domain_leave_script = Xapi_globs.base_path ^ "/libexec/lw-force-domain-leave" in
+	let lw_force_domain_leave_script = Filename.concat Fhs.libexecdir "lw-force-domain-leave" in
 	(try
 		let output, stderr = Forkhelpers.execute_command_get_output lw_force_domain_leave_script [] in
 		debug "execute %s: stdout=[%s],stderr=[%s]" lw_force_domain_leave_script (Stringext.String.replace "\n" ";" output) (Stringext.String.replace "\n" ";" stderr)
diff --git a/ocaml/autogen/OMakefile b/ocaml/autogen/OMakefile
index 531811d..07b090b 100644
--- a/ocaml/autogen/OMakefile
+++ b/ocaml/autogen/OMakefile
@@ -20,5 +20,5 @@ api_docs: custom_actions_doc
 
 .PHONY: install
 install:
-	mkdir -p $(BASE_PATH)/debug
-	$(IPROG) rbac_static.csv $(BASE_PATH)/debug
+	mkdir -p $(DESTDIR)$(OPTDIR)/debug
+	$(IPROG) rbac_static.csv $(DESTDIR)$(OPTDIR)/debug
diff --git a/ocaml/cdrommon/OMakefile b/ocaml/cdrommon/OMakefile
index 128665d..1a9c126 100644
--- a/ocaml/cdrommon/OMakefile
+++ b/ocaml/cdrommon/OMakefile
@@ -1,4 +1,4 @@
-OCAML_LIBS    = ../util/version ../idl/ocaml_backend/common
+OCAML_LIBS    = ../fhs ../util/version ../idl/ocaml_backend/common
 OCAMLINCLUDES = ../xapi
 OCAMLPACKS += unix cdrom
 
@@ -6,8 +6,8 @@ OCamlProgram(cdrommon, cdrommon)
 
 .PHONY: install
 install:
-	mkdir -p $(LIBEXEC)
-	cp -f cdrommon $(LIBEXEC)
+	mkdir -p $(DESTDIR)$(LIBEXECDIR)
+	cp -f cdrommon $(DESTDIR)$(LIBEXECDIR)
 
 .PHONY: clean
 clean:
diff --git a/ocaml/database/OMakefile b/ocaml/database/OMakefile
index 9db1696..aeeba67 100644
--- a/ocaml/database/OMakefile
+++ b/ocaml/database/OMakefile
@@ -1,5 +1,5 @@
 
-OCAMLINCLUDES = ../idl/ocaml_backend ../xapi ../idl ../util ../autogen
+OCAMLINCLUDES = ../idl/ocaml_backend ../xapi ../idl ../util ../autogen ..
 OCAMLPACKS    = xml-light2 stdext stunnel http-svr log sexpr rpc-light
 #OCAMLPPFLAGS  = -pp "camlp4o" 
 #OCAMLDEPFLAGS = -pp "camlp4o"
@@ -13,7 +13,7 @@ OCamlProgram(unit_test_sql, unit_test_sql)
 BLOCK_DEVICE_IO_FILES = \
 	block_device_io_errors \
 	block_device_io \
-	../xapi/config_constants ../xapi/xapi_globs ../idl/ocaml_backend/ref \
+	../xapi/xapi_globs ../idl/ocaml_backend/ref \
 	../xapi/helper_process ../xapi/helper_hostname ../idl/api_errors
 
 OCamlProgram(block_device_io, $(BLOCK_DEVICE_IO_FILES))
@@ -28,13 +28,13 @@ section:
 	OCamlProgram(database_test, $(DATABASE_TEST_FILES))
 
 section:
-	OCAML_LIBS +=  ../idl/ocaml_backend/common ../idl/ocaml_backend/client ../idl/ocaml_backend/server
+	OCAML_LIBS += ../idl/ocaml_backend/common ../idl/ocaml_backend/client ../idl/ocaml_backend/server
 	OCamlProgram(unit_test_marshall, unit_test_marshall db_remote_cache_access_v1)
 
 .PHONY: install
 install:
-	mkdir -p $(LIBEXEC)
-	$(IPROG) block_device_io $(LIBEXEC)
+	mkdir -p $(DESTDIR)$(LIBEXECDIR)
+	$(IPROG) block_device_io $(DESTDIR)$(LIBEXECDIR)
 
 .PHONY: sdk-install
 sdk-install: install
diff --git a/ocaml/database/redo_log.ml b/ocaml/database/redo_log.ml
index ac7c4c2..82cd1b5 100644
--- a/ocaml/database/redo_log.ml
+++ b/ocaml/database/redo_log.ml
@@ -202,7 +202,7 @@ let string_to_redo_log_entry str =
 exception RedoLogFailure of string
 exception CommunicationsProblem of string
 
-let prog = Xapi_globs.base_path ^ "/libexec/block_device_io"
+let prog = Filename.concat Fhs.libexecdir "block_device_io"
 
 let generation_size = 16
 let length_size = 16
diff --git a/ocaml/db_process/OMakefile b/ocaml/db_process/OMakefile
index 3193bb2..37ef81c 100644
--- a/ocaml/db_process/OMakefile
+++ b/ocaml/db_process/OMakefile
@@ -1,4 +1,4 @@
-OCAML_LIBS    = ../util/version ../idl/ocaml_backend/common ../idl/ocaml_backend/client ../util/stats ../idl/ocaml_backend/server
+OCAML_LIBS    = ../fhs ../util/version ../idl/ocaml_backend/common ../idl/ocaml_backend/client ../util/stats ../idl/ocaml_backend/server
 OCAMLINCLUDES = ../idl/ocaml_backend ../xapi ../database
 OCAMLPACKS    =  xml-light2 uuid sexpr log stunnel http-svr
 
@@ -7,8 +7,8 @@ OCamlProgram(xapi-db-process, xapi_db_process)
 
 .PHONY: install
 install:
-	mkdir -p $(BIN_PATH)
-	cp -f xapi-db-process $(BIN_PATH)
+	mkdir -p $(DESTDIR)$(OPTDIR)/bin
+	cp -f xapi-db-process $(DESTDIR)$(OPTDIR)/bin
 
 .PHONY: sdk-install
 sdk-install: install
diff --git a/ocaml/events/OMakefile b/ocaml/events/OMakefile
index 5aa0295..15588de 100644
--- a/ocaml/events/OMakefile
+++ b/ocaml/events/OMakefile
@@ -10,7 +10,7 @@ clean:
 
 .PHONY: install
 install:
-	mkdir -p $(DEBUGDIST)
-	$(IPROG) event_listen $(DEBUGDIST)
+	mkdir -p $(DESTDIR)$(OPTDIR)/debug
+	$(IPROG) event_listen $(DESTDIR)$(OPTDIR)/debug
 
 
diff --git a/ocaml/gpg/OMakefile b/ocaml/gpg/OMakefile
index 727e7a4..263c4e3 100644
--- a/ocaml/gpg/OMakefile
+++ b/ocaml/gpg/OMakefile
@@ -1,4 +1,4 @@
-OCAMLINCLUDES += ../xapi
+OCAMLINCLUDES += ../xapi ..
 
 .PHONY: clean
 clean:
diff --git a/ocaml/gpg/gpg.ml b/ocaml/gpg/gpg.ml
index b656dc2..38f6f61 100644
--- a/ocaml/gpg/gpg.ml
+++ b/ocaml/gpg/gpg.ml
@@ -23,7 +23,7 @@ open D
 let filename = ref ""
 
 let gpg_binary_path = "/usr/bin/gpg"
-let gpg_homedir = Xapi_globs.base_path ^ "/gpg/"
+let gpg_homedir = Filename.concat Fhs.optdir "gpg/"
 let gpg_pub_keyring = gpg_homedir ^ "pubring.gpg"
 let allowed_gpg_checksum =
 	[ "be00ee82bffad791edfba477508d5d84"; (* centos52 version *)
diff --git a/ocaml/graph/OMakefile b/ocaml/graph/OMakefile
index 176be82..e8db205 100644
--- a/ocaml/graph/OMakefile
+++ b/ocaml/graph/OMakefile
@@ -10,7 +10,7 @@ clean:
 
 .PHONY: install
 install:
-	mkdir -p $(DEBUGDIST)
-	$(IPROG) graph $(DEBUGDIST)
+	mkdir -p $(DESTDIR)$(OPTDIR)/debug
+	$(IPROG) graph $(DESTDIR)$(OPTDIR)/debug
 
 
diff --git a/ocaml/idl/OMakefile b/ocaml/idl/OMakefile
index 39bbbec..be7d073 100644
--- a/ocaml/idl/OMakefile
+++ b/ocaml/idl/OMakefile
@@ -100,7 +100,7 @@ sdk-install: doc sdk-README.txt
 META: META.in
 	sed 's/@VERSION@/$(PRODUCT_VERSION)/g' < $< > $@
 
-if $(defined DESTDIR)
+if $(defined-env DESTDIR)
 	INSTALL_PATH = $(DESTDIR)/$(shell ocamlfind printconf destdir)
 	export
 else
diff --git a/ocaml/idl/js_backend/OMakefile b/ocaml/idl/js_backend/OMakefile
index d8a36e2..2c8f8a5 100644
--- a/ocaml/idl/js_backend/OMakefile
+++ b/ocaml/idl/js_backend/OMakefile
@@ -29,5 +29,5 @@ js_binding: main
 
 .PHONY: install
 install:
-	mkdir -p $(DEBUGDIST)/www
-	cp api.js $(DEBUGDIST)/www
+	mkdir -p $(DESTDIR)$(OPTDIR)/debug/www
+	cp api.js $(DESTDIR)$(OPTDIR)/debug/www
diff --git a/ocaml/idl/ocaml_backend/OMakefile b/ocaml/idl/ocaml_backend/OMakefile
index 567afeb..b28ce88 100644
--- a/ocaml/idl/ocaml_backend/OMakefile
+++ b/ocaml/idl/ocaml_backend/OMakefile
@@ -52,7 +52,7 @@ autogen_idl: $(AUTOGEN_DIR)/client.ml $(AUTOGEN_DIR)/aPI.ml $(AUTOGEN_DIR)/serve
 
 COMMON_OBJS = ref \
 	../datamodel_types event_types \
-	../api_errors ../api_messages ../../xapi/config_constants ../../xapi/xapi_globs \
+	../api_errors ../api_messages ../../xapi/xapi_globs \
 	../constants
 CLIENT_OBJS = $(AUTOGEN_DIR)/aPI $(AUTOGEN_DIR)/client event_helper
 SERVER_OBJS = ../../database/escaping locking_helpers \
@@ -152,7 +152,7 @@ clean:
 META: META.in
 	sed 's/@VERSION@/$(PRODUCT_VERSION)/g' < $< > $@
 
-if $(defined DESTDIR)
+if $(defined-env DESTDIR)
 	INSTALL_PATH = $(DESTDIR)/$(shell ocamlfind printconf destdir)
 	export
 else
diff --git a/ocaml/license/OMakefile b/ocaml/license/OMakefile
index d510033..2db459a 100644
--- a/ocaml/license/OMakefile
+++ b/ocaml/license/OMakefile
@@ -1,10 +1,11 @@
 OCAML_LIBS    = ../util/version ../idl/ocaml_backend/xapi_client
-OCAMLINCLUDES = ../idl/ocaml_backend ../idl ../autogen ../xapi ../gpg ../util
+OCAMLINCLUDES = ../idl/ocaml_backend ../idl ../autogen ../xapi ../gpg ../util ..
 OCAMLPACKS    = xml-light2 stdext stunnel http-svr log rpc-light
 
 UseCamlp4(rpc-light.syntax, v6rpc v6errors)
 
 V6FILES = \
+	../fhs \
 	fakev6 \
 	v6rpc \
 	v6errors \
@@ -18,14 +19,14 @@ V6D = v6d
 OCamlProgram($(V6D), $(V6FILES))
 OCamlDocProgram($(V6D), $(V6FILES))
 
-OCamlProgram(v6d-reopen-logs, v6d_reopen_logs)
+OCamlProgram(v6d-reopen-logs, v6d_reopen_logs ../fhs)
 
 .PHONY: install
 install: $(V6D)
-	mkdir -p $(LIBEXEC)
-	$(IPROG) $(V6D) $(LIBEXEC)
-	mkdir -p $(BIN_PATH)
-	$(IPROG) v6d-reopen-logs $(BIN_PATH)
+	mkdir -p $(DESTDIR)$(LIBEXECDIR)
+	$(IPROG) $(V6D) $(DESTDIR)$(LIBEXECDIR)
+	mkdir -p $(DESTDIR)$(OPTDIR)/bin
+	$(IPROG) v6d-reopen-logs $(DESTDIR)$(OPTDIR)/bin
 
 .PHONY: clean
 clean:
diff --git a/ocaml/license/v6client.ml b/ocaml/license/v6client.ml
index bfc3e8c..bd0d327 100644
--- a/ocaml/license/v6client.ml
+++ b/ocaml/license/v6client.ml
@@ -20,7 +20,7 @@ exception V6DaemonFailure
 let retry = ref true
 
 (* RPC function for communication with the v6 daemon *)
-let socket = "/var/xapi/v6"
+let socket = Filename.concat Fhs.vardir "v6"
 let v6rpc call =
 	let open Xmlrpc_client in
 	XMLRPC_protocol.rpc ~transport:(Unix socket) ~http:(xmlrpc ~version:"1.0" "/") call
diff --git a/ocaml/license/v6d_reopen_logs.ml b/ocaml/license/v6d_reopen_logs.ml
index 5a504d3..69c7596 100644
--- a/ocaml/license/v6d_reopen_logs.ml
+++ b/ocaml/license/v6d_reopen_logs.ml
@@ -13,7 +13,7 @@
  *)
 (** Small executable that sends a reopen-logs XML/RPC message to the licensing daemon *)
  
-let socket = "/var/xapi/v6"
+let socket = Filename.concat Fhs.vardir "v6"
 
 (* RPC function for communication with the v6 daemon *)
 let v6rpc xml = 
diff --git a/ocaml/license/v6daemon.ml b/ocaml/license/v6daemon.ml
index 46983b8..b2d40ef 100644
--- a/ocaml/license/v6daemon.ml
+++ b/ocaml/license/v6daemon.ml
@@ -42,7 +42,7 @@ let daemon_init post_daemonize_hook process =
 	post_daemonize_hook ();
 	
 	(* unix socket *)
-	let unix_socket_path = "/var/xapi/v6" in
+	let unix_socket_path = Filename.concat Fhs.vardir "v6" in
 	Unixext.mkdir_safe (Filename.dirname unix_socket_path) 0o700;
 	Unixext.unlink_safe unix_socket_path;
 	let domain_sock = Http_svr.bind (Unix.ADDR_UNIX(unix_socket_path)) "unix_rpc" in
diff --git a/ocaml/lvhdrt/OMakefile b/ocaml/lvhdrt/OMakefile
index eafd134..7d28b89 100644
--- a/ocaml/lvhdrt/OMakefile
+++ b/ocaml/lvhdrt/OMakefile
@@ -1,4 +1,4 @@
-OCAML_LIBS    = ../util/version ../idl/ocaml_backend/common ../idl/ocaml_backend/client
+OCAML_LIBS    = ../fhs ../util/version ../idl/ocaml_backend/common ../idl/ocaml_backend/client 
 OCAMLINCLUDES = ../xapi ../idl/ocaml_backend/ ../idl ../autogen
 OCAMLPACKS    = xml-light2 stdext stunnel http-svr log rpc-light
 
@@ -11,9 +11,9 @@ clean:
 
 .PHONY: install
 install:
-	mkdir -p $(DEBUGDIST)
-	$(IPROG) lvhdrt $(DEBUGDIST)
-	mkdir -p $(DESTDIR)/etc/xapi.d/plugins
-	$(IPROG) lvhdrt-helper $(DESTDIR)/etc/xapi.d/plugins/lvhdrt-helper
-	$(IPROG) lvhdrt-trash-vdi $(DESTDIR)/etc/xapi.d/plugins/lvhdrt-trash-vdi 
+	mkdir -p $(DESTDIR)$(OPTDIR)/debug
+	$(IPROG) lvhdrt $(DESTDIR)$(OPTDIR)/debug
+	mkdir -p $(DESTDIR)$(PLUGINDIR)
+	$(IPROG) lvhdrt-helper $(DESTDIR)$(PLUGINDIR)/lvhdrt-helper
+	$(IPROG) lvhdrt-trash-vdi $(DESTDIR)$(PLUGINDIR)/lvhdrt-trash-vdi 
 
diff --git a/ocaml/lvhdrt/lvhdrt-trash-vdi b/ocaml/lvhdrt/lvhdrt-trash-vdi
index f455c3b..948ba07 100755
--- a/ocaml/lvhdrt/lvhdrt-trash-vdi
+++ b/ocaml/lvhdrt/lvhdrt-trash-vdi
@@ -20,7 +20,7 @@ import os, sys, tempfile
 import XenAPI, inventory
 import XenAPIPlugin
 
-sm_dir = "@BASE_PATH@/sm"
+sm_dir = "@OPTDIR@/sm"
 
 def dd(input, output):
     os.system("dd if=%s of=%s bs=1M count=16" % (input, output))
diff --git a/ocaml/mpathalert/OMakefile b/ocaml/mpathalert/OMakefile
index 8b865d3..9f45bac 100644
--- a/ocaml/mpathalert/OMakefile
+++ b/ocaml/mpathalert/OMakefile
@@ -1,8 +1,8 @@
 OCAML_LIBS    = ../util/version ../idl/ocaml_backend/common ../idl/ocaml_backend/client
-OCAMLINCLUDES = ../idl/ocaml_backend/ ../idl ../autogen
+OCAMLINCLUDES = ../idl/ocaml_backend/ ../idl ../autogen ..
 OCAMLPACKS    = xml-light2 stdext stunnel http-svr log rpc-light
 
-OCamlProgram(mpathalert, mpathalert)
+OCamlProgram(mpathalert, mpathalert ../fhs)
 OCamlDocProgram(mpathalert, mpathalert)
 
 .PHONY: clean
@@ -12,6 +12,6 @@ clean:
 
 .PHONY: install
 install:
-	mkdir -p $(BIN_PATH)
-	$(IPROG) mpathalert $(BIN_PATH)
+	mkdir -p $(DESTDIR)$(OPTDIR)/bin
+	$(IPROG) mpathalert $(DESTDIR)$(OPTDIR)/bin
 
diff --git a/ocaml/mpathalert/mpathalert.ml b/ocaml/mpathalert/mpathalert.ml
index 6a2431e..2c96a32 100644
--- a/ocaml/mpathalert/mpathalert.ml
+++ b/ocaml/mpathalert/mpathalert.ml
@@ -296,7 +296,7 @@ let _ =
 	let rpc xml =
 		let open Xmlrpc_client in
 		let http = xmlrpc ~version:"1.0" "/" in
-		XML_protocol.rpc ~transport:(Unix "/var/xapi/xapi") ~http xml in
+		XML_protocol.rpc ~transport:(Unix (Filename.concat Fhs.vardir "xapi")) ~http xml in
 	let queue = Queue.create () in
 	let msg = Buffer.create 1024 in
 
diff --git a/ocaml/multipathrt/OMakefile b/ocaml/multipathrt/OMakefile
index e1f44ea..a294aa7 100644
--- a/ocaml/multipathrt/OMakefile
+++ b/ocaml/multipathrt/OMakefile
@@ -15,7 +15,7 @@ clean:
 
 .PHONY: install
 install:
-	mkdir -p $(DEBUGDIST)
-	$(IPROG) multipathrt $(DEBUGDIST)
-	mkdir -p $(DESTDIR)/etc/xapi.d/plugins
-	$(IPROG) multipathrt-helper $(DESTDIR)/etc/xapi.d/plugins/multipathrt-helper
+	mkdir -p $(DESTDIR)$(OPTDIR)/debug
+	$(IPROG) multipathrt $(DESTDIR)$(OPTDIR)/debug
+	mkdir -p $(DESTDIR)$(PLUGINDIR)
+	$(IPROG) multipathrt-helper $(DESTDIR)$(PLUGINDIR)/multipathrt-helper
diff --git a/ocaml/multipathrt/multipathrt-helper b/ocaml/multipathrt/multipathrt-helper
index bdf26ab..4284dd3 100644
--- a/ocaml/multipathrt/multipathrt-helper
+++ b/ocaml/multipathrt/multipathrt-helper
@@ -16,8 +16,8 @@ dmsetup = "/sbin/dmsetup"
 iptables = "/sbin/iptables"
 dd = "/bin/dd"
 scli = "/usr/local/bin/scli"
-list_domains = "@BASE_PATH@/bin/list_domains"
-xs = "@BASE_PATH@/debug/xs"
+list_domains = "@OPTDIR@/bin/list_domains"
+xs = "@OPTDIR@/debug/xs"
 
 def doexec(args, inputtext=None):
     """Execute a subprocess, then return its return code, stdout and stderr"""
diff --git a/ocaml/perftest/OMakefile b/ocaml/perftest/OMakefile
index cbd0eca..1b5abad 100644
--- a/ocaml/perftest/OMakefile
+++ b/ocaml/perftest/OMakefile
@@ -1,11 +1,11 @@
-OCAML_LIBS    = ../util/version ../idl/ocaml_backend/common ../idl/ocaml_backend/client
-OCAMLINCLUDES = ../idl/ocaml_backend ../xapi ../idl ../autogen ../client_records
+OCAML_LIBS    = ../fhs ../util/version ../idl/ocaml_backend/common ../idl/ocaml_backend/client
+OCAMLINCLUDES = ../idl/ocaml_backend ../xapi ../idl ../autogen ../client_records ..
 OCAMLPACKS    = xml-light2 stdext stunnel http-svr log rpc-light
 
-PERFTEST_FILES = scenario perfutil createVM createpool testtypes perftest tests ../xapi/xapi_inventory perfdebug
+PERFTEST_FILES = scenario perfutil createVM createpool testtypes perftest tests ../xapi/xapi_inventory perfdebug 
 OCamlProgram(perftest, $(PERFTEST_FILES))
 OCamlDocProgram(perftest, $(PERFTEST_FILES))
-OCamlProgram(apiperf, perfutil apiperf)
+OCamlProgram(apiperf, perfutil apiperf ../fhs)
 OCamlProgram(histogram, statistics histogram gnuplot testtypes perfdebug graphutil)
 OCamlProgram(cumulative_time, cumulative_time gnuplot testtypes perfdebug graphutil)
 
@@ -20,6 +20,6 @@ clean:
 
 .PHONY: install
 install:
-        mkdir -p $(DEBUGDIST)
-        $(IPROG) perftest $(DEBUGDIST)
+        mkdir -p $(DESTDIR)$(OPTDIR)/debug
+        $(IPROG) perftest $(DESTDIR)$(OPTDIR)/debug
 
diff --git a/ocaml/perftest/apiperf.ml b/ocaml/perftest/apiperf.ml
index ec017d9..7bf7f19 100644
--- a/ocaml/perftest/apiperf.ml
+++ b/ocaml/perftest/apiperf.ml
@@ -30,7 +30,7 @@ let use_stunnel_cache = ref false
 let master = ref false
 let slave_limit = ref 0
 let threads = ref 1
-let url = ref "file:///var/xapi/xapi"
+let url = ref ("file://" ^ Fhs.vardir ^ "xapi")
 
 
 type url = 
diff --git a/ocaml/perftest/client_stunnel.conf b/ocaml/perftest/client_stunnel.conf
index 1de5511..91bfdf4 100644
--- a/ocaml/perftest/client_stunnel.conf
+++ b/ocaml/perftest/client_stunnel.conf
@@ -9,6 +9,6 @@ client=yes
 [localhost-xapi]
 accept = 80
 connect = 10.80.226.181:443
-cert = /etc/xensource/xapi-ssl.pem
+cert = @ETCDIR@/xapi-ssl.pem
 
 
diff --git a/ocaml/perftest/perfutil.ml b/ocaml/perftest/perfutil.ml
index 4ed0c02..8305764 100644
--- a/ocaml/perftest/perfutil.ml
+++ b/ocaml/perftest/perfutil.ml
@@ -18,7 +18,7 @@ open Stringext
 
 let rpc xml =
 	let open Xmlrpc_client in
-	XML_protocol.rpc ~transport:(Unix "/var/xapi/xapi") ~http:(xmlrpc ~version:"1.0" "/") xml
+	XML_protocol.rpc ~transport:(Unix (Filename.concat Fhs.vardir "xapi")) ~http:(xmlrpc ~version:"1.0" "/") xml
 
 let remoterpc host xml =
 	let open Xmlrpc_client in
diff --git a/ocaml/ptoken/OMakefile b/ocaml/ptoken/OMakefile
index 788ef0e..be29c2d 100644
--- a/ocaml/ptoken/OMakefile
+++ b/ocaml/ptoken/OMakefile
@@ -1,9 +1,9 @@
 OCAMLPACKS = uuid
-
+OCAMLINCLUDES = ..
 GENSECRET_SRC_FILES = genptoken.ml
 
 section
-	OCamlProgram(genptoken, genptoken)
+	OCamlProgram(genptoken, genptoken ../fhs)
 
 .PHONY: clean
 clean:
@@ -11,8 +11,8 @@ clean:
 
 .PHONY: install
 install:
-	mkdir -p $(LIBEXEC)
-	$(IPROG) genptoken $(LIBEXEC)
+	mkdir -p $(DESTDIR)$(LIBEXECDIR)
+	$(IPROG) genptoken $(DESTDIR)$(LIBEXECDIR)
 	mkdir -p $(DIST)/genptoken-src
 	$(IDATA) $(GENSECRET_SRC_FILES) $(DIST)/genptoken-src
 
diff --git a/ocaml/ptoken/genptoken.ml b/ocaml/ptoken/genptoken.ml
index 1053042..9667906 100644
--- a/ocaml/ptoken/genptoken.ml
+++ b/ocaml/ptoken/genptoken.ml
@@ -2,7 +2,7 @@
 
 type options = { force : bool; tgtfile : string }
 
-let options = ref { force = false; tgtfile = "/etc/xensource/ptoken" }
+let options = ref { force = false; tgtfile = Filename.concat Fhs.etcdir "ptoken" }
 
 let set_force _ = options := { !options with force = true }
 let set_target s = options := { !options with tgtfile = s }
diff --git a/ocaml/sm-cli/OMakefile b/ocaml/sm-cli/OMakefile
index a25d7b5..9e444b0 100644
--- a/ocaml/sm-cli/OMakefile
+++ b/ocaml/sm-cli/OMakefile
@@ -1,12 +1,12 @@
 OCAML_LIBS    =
-OCAMLINCLUDES = ../xapi
+OCAMLINCLUDES = ../xapi ..
 OCAMLPACKS    = xml-light2 stdext stunnel log http-svr oUnit
 
 section
-	OCAMLINCLUDES += .
+	OCAMLINCLUDES += . 
 	OCAMLFLAGS = -dtypes -thread -warn-error F
-	CLI_FILES = main ../xapi/storage_interface ../xapi/vdi_automaton
-	TEST_FILES = test ../xapi/storage_interface ../xapi/vdi_automaton
+	CLI_FILES = main ../xapi/storage_interface ../xapi/vdi_automaton ../fhs
+	TEST_FILES = test ../xapi/storage_interface ../xapi/vdi_automaton ../fhs
 	OCamlProgram(sm, $(CLI_FILES))
 	OCamlDocProgram(sm, $(CLI_FILES))
 	OCamlProgram(smtest, $(TEST_FILES))
@@ -23,6 +23,6 @@ clean:
 
 .PHONY: install
 install:
-	mkdir -p $(DEBUGDIST)
-	$(IPROG) sm $(DEBUGDIST)
+	mkdir -p $(DESTDIR)$(OPTDIR)/debug
+	$(IPROG) sm $(DESTDIR)$(OPTDIR)/debug
 
diff --git a/ocaml/sm-cli/main.ml b/ocaml/sm-cli/main.ml
index 97b67ed..747b7f0 100644
--- a/ocaml/sm-cli/main.ml
+++ b/ocaml/sm-cli/main.ml
@@ -20,7 +20,7 @@ open Fun
 open Stringext
 open Xmlrpc_client
 
-let url = ref (Http.Url.File ({ Http.Url.path = "/var/xapi/storage" }, "/"))
+let url = ref (Http.Url.File ({ Http.Url.path = Filename.concat Fhs.vardir "storage" }, "/"))
 
 module RPC = struct
 let rpc call =
diff --git a/ocaml/sm-cli/test.ml b/ocaml/sm-cli/test.ml
index d57aa4e..46a5877 100644
--- a/ocaml/sm-cli/test.ml
+++ b/ocaml/sm-cli/test.ml
@@ -22,7 +22,7 @@ open Stringext
 
 open Xmlrpc_client
 
-let default_path = "/var/xapi/storage"
+let default_path = Filename.concat Fhs.vardir "storage"
 let transport = ref (Unix default_path)
 
 let rpc call =
diff --git a/ocaml/toplevel/OMakefile b/ocaml/toplevel/OMakefile
index af2c946..7ff6ea6 100644
--- a/ocaml/toplevel/OMakefile
+++ b/ocaml/toplevel/OMakefile
@@ -1,11 +1,11 @@
-OCAML_LIBS    = ../idl/ocaml_backend/common ../idl/ocaml_backend/client $(BASE_PATH)/lib/ocaml/toplevellib
+OCAML_LIBS    = ../idl/ocaml_backend/common ../idl/ocaml_backend/client $(DESTDIR)$(OPTDIR)/lib/ocaml/toplevellib
 OCAMLINCLUDES = ../idl/ocaml_backend/
 OCAMLPACKS    = xml-light2 stdext uuid
 
 COMPILE_NATIVE=no
 section
 	OCAMLFLAGS+=-linkall
-	OCamlProgram(xencaml-bin, toplevelhelper $(BASE_PATH)/lib/ocaml/topstart )
+	OCamlProgram(xencaml-bin, toplevelhelper $(DESTDIR)$(OPTDIR)/lib/ocaml/topstart )
 
 .PHONY: clean
 
diff --git a/ocaml/toplevel/mkwrapper b/ocaml/toplevel/mkwrapper
index 537a5e6..29bfe7f 100755
--- a/ocaml/toplevel/mkwrapper
+++ b/ocaml/toplevel/mkwrapper
@@ -2,5 +2,5 @@
 
 echo "#!/bin/bash" > xencaml
 ROOT=`cd .. && pwd`
-echo "`pwd`/xencaml-bin.run -I @BASE_PATH@/lib/site-lib/stdext -I @BASE_PATH@/lib/site-lib/str -I @BASE_PATH@/lib/site-lib/xml-light2 -I @BASE_PATH@/lib/xmlm -I $ROOT/idl/ocaml_backend -I $ROOT/idl -I $ROOT/autogen/ -I $ROOT/http -I $ROOT/util \$@" >> xencaml
+echo "`pwd`/xencaml-bin.run -I @OPTDIR@/lib/site-lib/stdext -I @OPTDIR@/lib/site-lib/str -I @OPTDIR@/lib/site-lib/xml-light2 -I @OPTDIR@/lib/xmlm -I $ROOT/idl/ocaml_backend -I $ROOT/idl -I $ROOT/autogen/ -I $ROOT/http -I $ROOT/util \$@" >> xencaml
 chmod 755 xencaml
diff --git a/ocaml/util/OMakefile b/ocaml/util/OMakefile
index fa72bd9..93da645 100644
--- a/ocaml/util/OMakefile
+++ b/ocaml/util/OMakefile
@@ -1,3 +1,6 @@
+OCAMLINCLUDES = ..
+OCAML_LIBS = ../fhs
+
 #OCamlLibrary(util_globs_inventory, util_globs_inventory)
 OCamlLibrary(util_inventory, util_globs_inventory util_inventory)
 OCamlLibrary(version,        util_globs_inventory util_inventory version)
diff --git a/ocaml/util/util_globs_inventory.ml b/ocaml/util/util_globs_inventory.ml
index 797a88f..fefb852 100644
--- a/ocaml/util/util_globs_inventory.ml
+++ b/ocaml/util/util_globs_inventory.ml
@@ -1,2 +1,2 @@
 (* path to the xensource inventory file *)
-let inventory_filename = "/etc/xensource-inventory"
+let inventory_filename = Fhs.inventory
diff --git a/ocaml/util/util_inventory.ml b/ocaml/util/util_inventory.ml
index 103e15f..9a42f92 100644
--- a/ocaml/util/util_inventory.ml
+++ b/ocaml/util/util_inventory.ml
@@ -81,7 +81,7 @@ let read_inventory_contents () =
 		match parse_inventory_entry line with
 			| Some (k, v) -> Hashtbl.add inventory k v
 			| None -> warn
-				"Failed to parse line from xensource-inventory file: %s" line)
+				"Failed to parse line from inventory file: %s" line)
 		inventory_filename;
 	loaded_inventory := true
 
diff --git a/ocaml/vncproxy/OMakefile b/ocaml/vncproxy/OMakefile
index 8bc73e4..bf50fb0 100644
--- a/ocaml/vncproxy/OMakefile
+++ b/ocaml/vncproxy/OMakefile
@@ -1,13 +1,13 @@
 OCAML_LIBS    = ../util/version ../idl/ocaml_backend/common ../idl/ocaml_backend/client
-OCAMLINCLUDES = ../idl/ocaml_backend ../idl ../autogen
+OCAMLINCLUDES = ../idl/ocaml_backend ../idl ../autogen ..
 OCAMLPACKS    = xml-light2 stdext stunnel http-svr rpc-light
 
-OCamlProgram(vncproxy, vncproxy)
+OCamlProgram(vncproxy, vncproxy ../fhs)
 
 .PHONY: install
 install: 
-	mkdir -p $(DEBUGDIST)
-	$(IPROG) vncproxy $(DEBUGDIST)
+	mkdir -p $(DESTDIR)$(OPTDIR)/debug
+	$(IPROG) vncproxy $(DESTDIR)$(OPTDIR)/debug
 
 .PHONY: sdk-install
 sdk-install: install
diff --git a/ocaml/vncproxy/vncproxy.ml b/ocaml/vncproxy/vncproxy.ml
index 5facdd3..6b15ba1 100644
--- a/ocaml/vncproxy/vncproxy.ml
+++ b/ocaml/vncproxy/vncproxy.ml
@@ -65,7 +65,7 @@ let _ =
 	  let open Xmlrpc_client in
 	  let http = xmlrpc ~version:"1.0" "/" in
 	  match !server with
-		  | "" -> XML_protocol.rpc ~transport:(Unix "/var/xapi/xapi") ~http xml
+		  | "" -> XML_protocol.rpc ~transport:(Unix (Filename.concat Fhs.vardir "xapi")) ~http xml
 		  | host -> XML_protocol.rpc ~transport:(SSL(SSL.make ~use_fork_exec_helper:false (), host, 443)) ~http xml in
 
   let find_vm rpc session_id vm = 
diff --git a/ocaml/xapi/OMakefile b/ocaml/xapi/OMakefile
index 5b3cb7a..2b0aa43 100644
--- a/ocaml/xapi/OMakefile
+++ b/ocaml/xapi/OMakefile
@@ -1,10 +1,10 @@
 OCAMLPACKS    = xml-light2 cdrom pciutil sexpr log stunnel http-svr rss xen-utils netdev tapctl vhd xenstore rpc-light
-OCAML_LIBS    = ../util/version ../util/vm_memory_constraints ../util/sanitycheck ../util/stats \
+OCAML_LIBS    = ../fhs ../util/version ../util/vm_memory_constraints ../util/sanitycheck ../util/stats \
 	../idl/ocaml_backend/common ../idl/ocaml_backend/client ../idl/ocaml_backend/server ../util/ocamltest
 OCAMLINCLUDES = ../idl ../idl/ocaml_backend \
 	../autogen ../database/ \
 	../xenops ../xva ../util \
-	../auth ../license ../client_records ../rfb ../gpg
+	../auth ../license ../client_records ../rfb ../gpg ..
 
 UseCamlp4(rpc-light.syntax, features rrd monitor_fake monitor_fake_common vdi_automaton storage_impl xapi_udhcpd)
 UseCamlp4(rpc-light.idl, storage_interface)
@@ -278,34 +278,26 @@ OCamlProgram(at_least_once_more, at_least_once_more at_least_once_more_test)
 
 .DEFAULT: xapi
 
-.PHONY: generate_constants
-
-generate_constants: config_constants.ml
-
-config_constants.ml: config_constants.ml.in
-	sed "s!@BASE_PATH@!\"$(RAW_BASE_PATH)\"!" $< > $@
-
 .PHONY: install
 install:
-	mkdir -p $(BIN_PATH)
-	cp -f xapi $(BIN_PATH)
-	mkdir -p $(DEBUGDIST)
-	$(IPROG) quicktest $(DEBUGDIST)
-	cp -f quicktestbin $(DEBUGDIST)
-	$(IPROG) rrddump $(DEBUGDIST)
-	mkdir -p $(LIBEXEC)
-	$(IPROG) sparse_dd $(LIBEXEC)
-	mkdir -p $(DESTDIR)/etc/xapi.d/plugins
-	$(IPROG) monitor_fake_plugin $(DESTDIR)/etc/xapi.d/plugins
+	mkdir -p $(DESTDIR)$(SBINDIR)
+	cp -f xapi $(DESTDIR)$(SBINDIR)
+	mkdir -p $(DESTDIR)$(OPTDIR)/debug
+	$(IPROG) quicktest $(DESTDIR)$(OPTDIR)/debug
+	cp -f quicktestbin $(DESTDIR)$(OPTDIR)/debug
+	$(IPROG) rrddump $(DESTDIR)$(OPTDIR)/debug
+	mkdir -p $(DESTDIR)$(LIBEXECDIR)
+	$(IPROG) sparse_dd $(DESTDIR)$(LIBEXECDIR)
+	mkdir -p $(DESTDIR)$(PLUGINDIR)
+	$(IPROG) monitor_fake_plugin $(DESTDIR)$(PLUGINDIR)
 
 .PHONY: sdk-install
 sdk-install: install
-	mkdir -p $(LIBEXEC)
-	cp fakeguestagent $(LIBEXEC)/
+	mkdir -p $(DESTDIR)$(LIBEXECDIR)
+	cp fakeguestagent $(DESTDIR)$(LIBEXECDIR)/
 
 .PHONY: clean
 clean:
 	rm -rf $(CLEAN_OBJS) *.aux *.log *.fig xapi
-	rm -f config_constants.ml
 	rm -f binpack xapi_unit_test sparse_dd fakeguestagent monitor_fake_plugin rrddump quicktestbin
 
diff --git a/ocaml/xapi/certificates.ml b/ocaml/xapi/certificates.ml
index d370342..76ae5c2 100644
--- a/ocaml/xapi/certificates.ml
+++ b/ocaml/xapi/certificates.ml
@@ -23,7 +23,7 @@ open Client
 module D=Debug.Debugger(struct let name="certificates" end)
 open D
 
-let server_cert = "/etc/xensource/xapi-ssl.pem"
+let server_cert = Filename.concat Fhs.etcdir "xapi-ssl.pem"
 let c_rehash = "/usr/bin/c_rehash"
 let pem_certificate_header = "-----BEGIN CERTIFICATE-----"
 let pem_certificate_footer = "-----END CERTIFICATE-----"
diff --git a/ocaml/xapi/config_constants.ml.in b/ocaml/xapi/config_constants.ml.in
deleted file mode 100644
index bce7ed8..0000000
--- a/ocaml/xapi/config_constants.ml.in
+++ /dev/null
@@ -1 +0,0 @@
-let base_path = @BASE_PATH@
diff --git a/ocaml/xapi/console.ml b/ocaml/xapi/console.ml
index 93394df..b9a127b 100644
--- a/ocaml/xapi/console.ml
+++ b/ocaml/xapi/console.ml
@@ -62,7 +62,7 @@ let ws_proxy __context req protocol port s =
     | `rdp -> "rdp"
   in
 
-  let real_path = "/var/xapi/wsproxy" in    
+  let real_path = Filename.concat Fhs.vardir "wsproxy" in    
   let sock = 
     try
       Some (Fecomms.open_unix_domain_sock_client real_path)
diff --git a/ocaml/xapi/create_misc.ml b/ocaml/xapi/create_misc.ml
index 673c095..d231c0a 100644
--- a/ocaml/xapi/create_misc.ml
+++ b/ocaml/xapi/create_misc.ml
@@ -407,7 +407,7 @@ let create_host_cpu ~__context =
 		if !i >= 0 then String.sub s 0 (!i + 1) else "" in
 
 
-	(* The boot-time CPU info is copied into a file in /etc/xensource/ in the xenservices init script;
+	(* The boot-time CPU info is copied into a file in @ETCDIR@/ in the xenservices init script;
 	   we use that to generate CPU records from. This ensures that if xapi is started after someone has
 	   modified dom0's VCPUs we don't change out host config... [Important to get this right, otherwise
 	   pool homogeneity checks fail] *)
diff --git a/ocaml/xapi/events.ml b/ocaml/xapi/events.ml
index 879fbc2..df84cdb 100644
--- a/ocaml/xapi/events.ml
+++ b/ocaml/xapi/events.ml
@@ -48,7 +48,7 @@ module Crashdump = struct
   let to_file domid filename =
 	if true then (
 		(* opensource version *)
-		let path = Xapi_globs.base_path ^ "/libexec/dumpcore" in
+		let path = Filename.concat Fhs.libexecdir "dumpcore" in
 		let args = [ "-domid"; string_of_int domid;
 		              "-file"; filename ] in
 		let pid = Forkhelpers.safe_close_and_exec None None None [] path args in
diff --git a/ocaml/xapi/helpers.ml b/ocaml/xapi/helpers.ml
index 1970f72..9693f7f 100644
--- a/ocaml/xapi/helpers.ml
+++ b/ocaml/xapi/helpers.ml
@@ -644,7 +644,7 @@ let on_oem ~__context =
 
 exception File_doesnt_exist of string
 
-let find_partition_path = Xapi_globs.base_path ^ "/libexec/find-partition"
+let find_partition_path = Filename.concat Fhs.libexecdir "find-partition"
 
 let find_secondary_partition () =
 	try
diff --git a/ocaml/xapi/monitor.ml b/ocaml/xapi/monitor.ml
index 4e016a7..4f5e7d1 100644
--- a/ocaml/xapi/monitor.ml
+++ b/ocaml/xapi/monitor.ml
@@ -467,7 +467,7 @@ let set_cache_sr sr_uuid =
 let unset_cache_sr () =
 	Mutex.execute cache_sr_lock (fun () -> cache_sr_uuid := None)
 
-let tapdisk_cache_stats = Xapi_globs.base_path ^ "/bin/tapdisk-cache-stats"
+let tapdisk_cache_stats = Filename.concat Fhs.bindir "tapdisk-cache-stats"
 
 let read_cache_stats timestamp =
 	let cache_sr_opt = Mutex.execute cache_sr_lock (fun () -> !cache_sr_uuid) in
diff --git a/ocaml/xapi/monitor_fake_common.ml b/ocaml/xapi/monitor_fake_common.ml
index 14e9060..b1f9fe4 100644
--- a/ocaml/xapi/monitor_fake_common.ml
+++ b/ocaml/xapi/monitor_fake_common.ml
@@ -10,5 +10,5 @@ type fake_ds = {
 
 type fake_ds_list = fake_ds list with rpc
 
-let fake_dir = "/var/xapi/fake_data"
+let fake_dir = Filename.concat Fhs.vardir "fake_data"
 
diff --git a/ocaml/xapi/nm.ml b/ocaml/xapi/nm.ml
index 694be93..952ed95 100644
--- a/ocaml/xapi/nm.ml
+++ b/ocaml/xapi/nm.ml
@@ -34,7 +34,7 @@ let update_inventory ~__context =
 	let bridges = List.map (fun (_, pif_r) -> Db.Network.get_bridge ~__context ~self:pif_r.API.pIF_network) pifs in
 	Xapi_inventory.update Xapi_inventory._current_interfaces (String.concat " " bridges)
 
-let interface_reconfigure_script = Xapi_globs.base_path ^ "/libexec/interface-reconfigure"
+let interface_reconfigure_script = Filename.concat Fhs.libexecdir "interface-reconfigure"
 
 (* Call the interface reconfigure script. For development ignore the exn if it doesn't exist *)
 let reconfigure_pif ~__context (pif: API.ref_PIF) args =
diff --git a/ocaml/xapi/pool_db_backup.ml b/ocaml/xapi/pool_db_backup.ml
index 9273717..8469648 100644
--- a/ocaml/xapi/pool_db_backup.ml
+++ b/ocaml/xapi/pool_db_backup.ml
@@ -91,7 +91,7 @@ let prepare_database_for_restore ~old_context ~new_context =
 		let physical = List.filter (fun self -> Db.PIF.get_physical ~__context:old_context ~self) all_pifs in
 		List.map (fun self -> Db.PIF.get_device ~__context:old_context ~self, self) physical in
   
-	(* Since it's difficult for us to change the /etc/xensource-inventory and the ifcfg-
+	(* Since it's difficult for us to change the @INVENTORY@ and the ifcfg-
        files, we /preserve/ the current management PIF across the restore. NB this interface
        might be a bond or a vlan. *)
 	let mgmt_dev = 
diff --git a/ocaml/xapi/quicktest b/ocaml/xapi/quicktest
index d41daa0..c9e0d2d 100644
--- a/ocaml/xapi/quicktest
+++ b/ocaml/xapi/quicktest
@@ -1,4 +1,4 @@
 #!/bin/bash
 
 # Run quicktest with support for exception backtraces.
-OCAMLRUNPARAM=b "@BASE_PATH@/debug/quicktestbin" "$@"
+OCAMLRUNPARAM=b "@OPTDIR@/debug/quicktestbin" "$@"
diff --git a/ocaml/xapi/quicktest_storage.ml b/ocaml/xapi/quicktest_storage.ml
index e084241..68038e7 100644
--- a/ocaml/xapi/quicktest_storage.ml
+++ b/ocaml/xapi/quicktest_storage.ml
@@ -467,7 +467,7 @@ let sr_scan_test caps session_id sr =
   Client.SR.scan !rpc session_id sr;
   success test
 
-let iso_path = Xapi_globs.base_path ^ "/packages/iso"
+let iso_path = Filename.concat Fhs.sharedir "packages/iso"
 
 let packages_iso_test session_id =
   let test = make_test ("ISO SR should be able to create VDIs for " ^ iso_path) 2 in
diff --git a/ocaml/xapi/sm_exec.ml b/ocaml/xapi/sm_exec.ml
index 510fc4d..4e5fe35 100644
--- a/ocaml/xapi/sm_exec.ml
+++ b/ocaml/xapi/sm_exec.ml
@@ -23,7 +23,7 @@ open Smint
 module D=Debug.Debugger(struct let name="sm_exec" end)
 open D
 
-let sm_daemon_dir = "/var/xapi/sm"
+let sm_daemon_dir = Filename.concat Fhs.vardir "sm"
 
 let cmd_name driver = sprintf "%s/%sSR" Xapi_globs.sm_dir driver
 let daemon_path driver = sprintf "%s/%s" sm_daemon_dir driver
diff --git a/ocaml/xapi/sparse_dd_wrapper.ml b/ocaml/xapi/sparse_dd_wrapper.ml
index 8acdafb..4cbffe3 100644
--- a/ocaml/xapi/sparse_dd_wrapper.ml
+++ b/ocaml/xapi/sparse_dd_wrapper.ml
@@ -21,7 +21,7 @@ open Printf
 module D=Debug.Debugger(struct let name="xapi" end)
 open D
 
-let sparse_dd_path = Xapi_globs.base_path ^ "/libexec/sparse_dd"
+let sparse_dd_path = Filename.concat Fhs.libexecdir "sparse_dd"
 
 (** Use the new external sparse_dd program *)
 let dd ~__context prezeroed infile outfile size = 
diff --git a/ocaml/xapi/static_vdis.ml b/ocaml/xapi/static_vdis.ml
index 51574c7..74b092a 100644
--- a/ocaml/xapi/static_vdis.ml
+++ b/ocaml/xapi/static_vdis.ml
@@ -22,7 +22,7 @@ open Stringext
 open Pervasiveext
 include Static_vdis_list (* include the vdi type and the list() function *)
 
-let static_vdis = Xapi_globs.base_path ^ "/bin/static-vdis"
+let static_vdis = Filename.concat Fhs.bindir "static-vdis"
 
 (** Generate the static configuration and attach the VDI now *)
 let permanent_vdi_attach ~__context ~vdi ~reason =
diff --git a/ocaml/xapi/static_vdis_list.ml b/ocaml/xapi/static_vdis_list.ml
index 363394e..c5eb65d 100644
--- a/ocaml/xapi/static_vdis_list.ml
+++ b/ocaml/xapi/static_vdis_list.ml
@@ -27,7 +27,7 @@ type vdi = {
 (** Returns a list of vdi records, one for each VDI statically configured on this host *)
 let list () = 
   (* Read the filesystem structure directly *)
-  let main_dir = "/etc/xensource/static-vdis" in
+  let main_dir = Filename.concat Fhs.etcdir "static-vdis" in
   let all = try Array.to_list (Sys.readdir main_dir) with Sys_error _ -> [] in
   List.map (fun x ->
 	      let path = Filename.concat main_dir x in
diff --git a/ocaml/xapi/storage_impl.ml b/ocaml/xapi/storage_impl.ml
index e244483..54f2ddf 100644
--- a/ocaml/xapi/storage_impl.ml
+++ b/ocaml/xapi/storage_impl.ml
@@ -646,7 +646,7 @@ module Local_domain_socket = struct
 
 	let socket = ref None
 
-	let path = "/var/xapi/storage"
+	let path = Filename.concat Fhs.vardir "storage"
 
 	let xmlrpc_handler process req bio _ =
 		let body = Http_svr.read_body req bio in
diff --git a/ocaml/xapi/vmops.ml b/ocaml/xapi/vmops.ml
index d1a21d9..66e178a 100644
--- a/ocaml/xapi/vmops.ml
+++ b/ocaml/xapi/vmops.ml
@@ -577,7 +577,7 @@ let create_device_emulator ~__context ~xc ~xs ~self ?(restore=false) ?vnc_statef
 					List.map (String.strip String.isspace) l
 				with _ -> []
 			in
-		let dmpath = Xapi_globs.base_path ^ "/libexec/qemu-dm-wrapper" in
+		let dmpath = Filename.concat Fhs.libexecdir "qemu-dm-wrapper" in
 		let dmstart = if restore then Device.Dm.restore else Device.Dm.start in
 
 		(* Display and input devices are usually conflated *)
diff --git a/ocaml/xapi/xapi.ml b/ocaml/xapi/xapi.ml
index 81f517f..e8df2c3 100644
--- a/ocaml/xapi/xapi.ml
+++ b/ocaml/xapi/xapi.ml
@@ -675,7 +675,7 @@ let common_http_handlers = [
   ("get_export_metadata", (Http_svr.FdIO Export.metadata_handler));
   ("connect_console", Http_svr.FdIO (Console.handler Console.real_proxy));
   ("connect_console_ws", Http_svr.FdIO (Console.handler Console.ws_proxy));
-  ("get_root", Http_svr.BufIO (Fileserver.send_file "/" (Xapi_globs.base_path ^ "/www")));
+  ("get_root", Http_svr.BufIO (Fileserver.send_file "/" Fhs.webdir));
   ("post_cli", (Http_svr.BufIO Xapi_cli.handler));
   ("get_host_backup", (Http_svr.FdIO Xapi_host_backup.host_backup_handler));
   ("put_host_restore", (Http_svr.FdIO Xapi_host_backup.host_restore_handler));
@@ -1201,10 +1201,10 @@ let _ =
     Unixext.daemonize ();
   Unixext.pidfile_write "/var/run/xapi.pid";
 
-  (* chdir to /var/xapi/debug so that's where xapi coredumps go 
+  (* chdir to @VARDIR@/debug so that's where xapi coredumps go 
      (in the unlikely event that there are any ;) *)
-  Unixext.mkdir_rec "/var/xapi/debug" 0o700;
-  Unix.chdir "/var/xapi/debug";
+  Unixext.mkdir_rec (Filename.concat Fhs.vardir "debug") 0o700;
+  Unix.chdir (Filename.concat Fhs.vardir "debug");
 
 	set_thread_queue_params ();
 
diff --git a/ocaml/xapi/xapi_globs.ml b/ocaml/xapi/xapi_globs.ml
index cf86a87..7b16d6b 100644
--- a/ocaml/xapi/xapi_globs.ml
+++ b/ocaml/xapi/xapi_globs.ml
@@ -22,7 +22,7 @@ module D = Debug.Debugger(struct let name="xapi_globs" end)
 (* xapi process returns this code on exit when it wants to be restarted *)
 let restart_return_code = 123
 
-let pool_secret_path = "/etc/xensource/ptoken"
+let pool_secret_path = Filename.concat Fhs.etcdir "ptoken"
 let pool_secret = ref ""
 
 let localhost_ref : [`host] Ref.t ref = ref Ref.null
@@ -49,7 +49,7 @@ let xencenter_max_verstring = "1.10"
 
 (* linux pack vsn key in host.software_version (used for a pool join restriction *)
 let linux_pack_vsn_key = "xs:linux"
-let packs_dir = "/etc/xensource/installed-repos"
+let packs_dir = Filename.concat Fhs.etcdir "installed-repos"
 
 let ssl_pid = ref 0
 
@@ -63,10 +63,10 @@ let https_port = ref default_ssl_port
 
 let xapi_gc_debug = ref true
 
-let unix_domain_socket = "/var/xapi/xapi"
-let local_storage_unix_domain_socket = "/var/xapi/storage-local"
-let storage_unix_domain_socket = "/var/xapi/storage"
-let local_database = "/var/xapi/local.db"
+let unix_domain_socket = Filename.concat Fhs.vardir "xapi"
+let local_storage_unix_domain_socket = Filename.concat Fhs.vardir "storage-local"
+let storage_unix_domain_socket = Filename.concat Fhs.vardir "storage"
+let local_database = Filename.concat Fhs.vardir "local.db"
 
 
 (* if a slave in emergency "cannot see master mode" then this flag is set *)
@@ -83,17 +83,16 @@ let xe_key = "/mh/XenSource-TM_XenEnterprise-TM"
 let xe_val = "XenSource(TM) and XenEnterprise(TM) are registered trademarks of XenSource Inc."
 
 (* Base path and some of its immediate dependencies. *)
-let base_path = Config_constants.base_path
-let xe_path = base_path ^ "/bin/xe"
-let sm_dir = base_path ^ "/sm"
-
-let config_file = ref "/etc/xapi.conf"
-let log_config_file = ref "/etc/xensource/log.conf"
-let db_conf_path = "/etc/xensource/db.conf"
-let remote_db_conf_fragment_path = "/etc/xensource/remote.db.conf"
+let xe_path = Filename.concat Fhs.bindir "xe"
+let sm_dir = Filename.concat Fhs.optdir "sm"
+
+let config_file = ref Fhs.xapiconf
+let log_config_file = ref (Filename.concat Fhs.etcdir "log.conf")
+let db_conf_path = Filename.concat Fhs.etcdir "db.conf"
+let remote_db_conf_fragment_path = Filename.concat Fhs.etcdir "remote.db.conf"
 let simulator_config_file = ref "/etc/XenServer-simulator.conf"
-let pool_config_file = "/etc/xensource/pool.conf"
-let cpu_info_file = "/etc/xensource/boot_time_cpus"
+let pool_config_file = Filename.concat Fhs.etcdir "pool.conf"
+let cpu_info_file = Filename.concat Fhs.etcdir "boot_time_cpus"
 let initial_host_free_memory_file = "/var/run/xapi/boot_time_memory"
 let using_rrds = ref false
 
@@ -174,7 +173,7 @@ let tools_sr_tag = "xenserver_tools_sr"
 let rio_tools_sr_name = "XenSource Tools"
 let miami_tools_sr_name = "XenServer Tools"
 
-let tools_sr_dir = base_path ^ "/packages/iso"
+let tools_sr_dir = Filename.concat Fhs.sharedir "packages/iso"
 
 let default_template_key = "default_template"
 let linux_template_key = "linux_template"
@@ -191,7 +190,7 @@ let logrot_max = ref (1024*16*1024)
 (* logrotate is called without a stdin, and when it fork-and-execs gzip, it opens the src *)
 (* getting fd 0, opens the dest getting fd 3, then forks, then dups 0 to 0, dups 3 to 1 and *)
 (* then closes 0 and 3! *)
-let logrot_cmd = base_path ^ "/libexec/logrotate.sh"
+let logrot_cmd = Filename.concat Fhs.libexecdir "logrotate.sh"
 let logrot_arg = [ ]
 
 (* Error codes for internal storage backends -- these have counterparts in sm.hg/drivers/XE_SR_ERRORCODES.xml *)
@@ -203,16 +202,16 @@ let sm_error_generic_VDI_create_failure = 78
 let sm_error_generic_VDI_delete_failure = 80
 
 (* temporary restore path for db *)
-let db_temporary_restore_path = "/var/xapi/restore_db.db"
+let db_temporary_restore_path = Filename.concat Fhs.vardir "restore_db.db"
 
 (* temporary path for the HA metadata database *)
-let ha_metadata_db = "/var/xapi/ha_metadata.db"
+let ha_metadata_db = Filename.concat Fhs.vardir "ha_metadata.db"
 
 (* temporary path for the general metadata database *)
-let gen_metadata_db = "/var/xapi/gen_metadata.db"
+let gen_metadata_db = Filename.concat Fhs.vardir "gen_metadata.db"
 
 (* temporary path for opening a foreign metadata database *)
-let foreign_metadata_db = "/var/xapi/foreign.db"
+let foreign_metadata_db = Filename.concat Fhs.vardir "foreign.db"
 
 let migration_failure_test_key = "migration_wings_fall_off" (* set in other-config to simulate migration failures *)
 
@@ -252,14 +251,14 @@ let pool_ha_num_host_failures = "ha_tolerated_host_failures"
 (* the other-config key that reflects whether the pool is overprovisioned *)
 let pool_ha_currently_over_provisioned = "ha_currently_over_provisioned"
 
-let backup_db = "/var/xapi/state-backup.db"
+let backup_db = Filename.concat Fhs.vardir "state-backup.db"
 
 (* Place where database XML backups are kept *)
-let backup_db_xml = "/var/xapi/state-backup.xml"
+let backup_db_xml = Filename.concat Fhs.vardir "state-backup.xml"
 
 (* Directory containing scripts which are executed when a node becomes master
    and when a node gives up the master role *)
-let master_scripts_dir = "/etc/xensource/master.d"
+let master_scripts_dir = Filename.concat Fhs.etcdir "master.d"
 
 (* Indicates whether we should allow clones of suspended VMs via VM.clone *)
 let pool_allow_clone_suspended_vm = "allow_clone_suspended_vm"
@@ -268,8 +267,8 @@ let pool_allow_clone_suspended_vm = "allow_clone_suspended_vm"
 let shared_db_vdi_size = 134217728L (* 128 * 1024 * 1024 = 128 megs *)
 
 (* Mount point for the shared DB *)
-let shared_db_mount_point = "/var/xapi/shared_db"
-let snapshot_db = "/var/xapi/snapshot.db"
+let shared_db_mount_point = Filename.concat Fhs.vardir "shared_db"
+let snapshot_db = Filename.concat Fhs.vardir "snapshot.db"
 
 (* Device for shared DB VBD *)
 let shared_db_device = "15"
@@ -337,10 +336,10 @@ let default_ha_timeout = "default_ha_timeout"
 
 (* Executed during startup when the API/database is online but before storage or networks
    are fully initialised. *)
-let startup_script_hook = base_path ^ "/libexec/xapi-startup-script"
+let startup_script_hook = Filename.concat Fhs.libexecdir "xapi-startup-script"
 
 (* Executed when a rolling upgrade is detected starting or stopping *)
-let rolling_upgrade_script_hook = base_path ^ "/libexec/xapi-rolling-upgrade"
+let rolling_upgrade_script_hook = Filename.concat Fhs.libexecdir "xapi-rolling-upgrade"
 
 (* When set to true indicates that the host has still booted so we're initialising everything
    from scratch e.g. shared storage, sampling boot free mem etc *)
@@ -353,12 +352,12 @@ let listen_backlog = 128
 let artificial_reboot_delay = "artificial-reboot-delay"
 
 (* Xapi script hooks root *)
-let xapi_hooks_root = "/etc/xapi.d/"
+let xapi_hooks_root = Fhs.hooksdir 
 
 (* RRD storage location *)
-let xapi_rrd_location = "/var/xapi/blobs/rrds"
+let xapi_rrd_location = Filename.concat Fhs.vardir "blobs/rrds"
 
-let xapi_blob_location = "/var/xapi/blobs"
+let xapi_blob_location = Filename.concat Fhs.vardir "blobs"
 
 let last_blob_sync_time = "last_blob_sync_time"
 
@@ -378,13 +377,13 @@ let http_limit_max_rrd_size = 2 * 1024 * 1024 (* 2M -- FIXME : need to go below
 
 let message_limit=10000
 
-let xapi_message_script = base_path ^ "/libexec/mail-alarm"
+let xapi_message_script = Filename.concat Fhs.libexecdir "mail-alarm"
 
 (* Emit a warning if more than this amount of clock skew detected *)
 let max_clock_skew = 5. *. 60. (* 5 minutes *)
 
 (* Optional directory containing XenAPI plugins *)
-let xapi_plugins_root = "/etc/xapi.d/plugins"
+let xapi_plugins_root = Fhs.plugindir 
 
 
 
@@ -514,7 +513,7 @@ let serialize_pool_enable_disable_extauth = Mutex.create()
 let event_hook_auth_on_xapi_initialize_succeeded = ref false
 
 (** Directory used by the v6 license policy engine for caching *)
-let upgrade_grace_file = "/var/xapi/ugp"
+let upgrade_grace_file = Filename.concat Fhs.vardir "ugp"
 
 (** Where the ballooning daemon writes the initial overhead value *)
 let squeezed_reserved_host_memory = "/squeezed/reserved-host-memory"
diff --git a/ocaml/xapi/xapi_ha.ml b/ocaml/xapi/xapi_ha.ml
index a87ed30..405ed2d 100644
--- a/ocaml/xapi/xapi_ha.ml
+++ b/ocaml/xapi/xapi_ha.ml
@@ -36,15 +36,15 @@ let ha_redo_log = Redo_log.create ~name:"HA redo log" ~state_change_callback:Non
 (*********************************************************************************************)
 (* Interface with the low-level HA subsystem                                                 *)
 
-let ha_set_pool_state = Xapi_globs.base_path ^ "/xha/ha_set_pool_state"
-let ha_start_daemon = Xapi_globs.base_path ^ "/xha/ha_start_daemon"
-let ha_stop_daemon = Xapi_globs.base_path ^ "/xha/ha_stop_daemon"
-let ha_query_liveset = Xapi_globs.base_path ^ "/xha/ha_query_liveset"
-let ha_propose_master = Xapi_globs.base_path ^ "/xha/ha_propose_master"
-let ha_disarm_fencing = Xapi_globs.base_path ^  "/xha/ha_disarm_fencing"
-let ha_set_excluded = Xapi_globs.base_path ^ "/xha/ha_set_excluded"
-let fence_path = Xapi_globs.base_path ^ "/libexec/fence"
-(* Unused: let ha_clear_excluded = Xapi_globs.base_path ^ "/xha/ha_clear_excluded" *)
+let ha_set_pool_state = Filename.concat Fhs.xhadir "ha_set_pool_state"
+let ha_start_daemon = Filename.concat Fhs.xhadir "ha_start_daemon"
+let ha_stop_daemon = Filename.concat Fhs.xhadir "ha_stop_daemon"
+let ha_query_liveset = Filename.concat Fhs.xhadir "ha_query_liveset"
+let ha_propose_master = Filename.concat Fhs.xhadir "ha_propose_master"
+let ha_disarm_fencing = Filename.concat Fhs.xhadir "ha_disarm_fencing"
+let ha_set_excluded = Filename.concat Fhs.xhadir "ha_set_excluded"
+let fence_path = Filename.concat Fhs.libexecdir "fence"
+(* Unused: let ha_clear_excluded = Filename.concat Fhs.xhadir "ha_clear_excluded" *)
 
 (** The xHA scripts throw these exceptions: *)
 exception Xha_error of Xha_errno.code
diff --git a/ocaml/xapi/xapi_host.ml b/ocaml/xapi/xapi_host.ml
index a2a8584..c793524 100644
--- a/ocaml/xapi/xapi_host.ml
+++ b/ocaml/xapi/xapi_host.ml
@@ -24,8 +24,8 @@ open Workload_balancing
 module D = Debug.Debugger(struct let name="xapi" end)
 open D
 
-let host_bugreport_upload = Xapi_globs.base_path ^ "/libexec/host-bugreport-upload"
-let set_hostname = Xapi_globs.base_path ^ "/libexec/set-hostname"
+let host_bugreport_upload = Filename.concat Fhs.libexecdir "host-bugreport-upload"
+let set_hostname = Filename.concat Fhs.libexecdir "set-hostname"
 
 let set_emergency_mode_error code params = Xapi_globs.emergency_mode_error := Api_errors.Server_error(code, params)
 
@@ -711,7 +711,7 @@ let syslog_config_write host host_only enable_remote =
 		   else "") ^
 			  (if enable_remote then "SYSLOGD_OPTIONS=\"-r $SYSLOGD_OPTIONS\"\n" else "")
 		  in
-	let fd = Unix.openfile "/etc/xensource/syslog.conf"
+	let fd = Unix.openfile (Filename.concat Fhs.etcdir "syslog.conf")
 						   [ Unix.O_WRONLY; Unix.O_CREAT; Unix.O_TRUNC; ]
 				   0o640 in
 	ignore (Unix.write fd buf 0 (String.length buf));
diff --git a/ocaml/xapi/xapi_host_backup.ml b/ocaml/xapi/xapi_host_backup.ml
index 552b599..ab1b592 100644
--- a/ocaml/xapi/xapi_host_backup.ml
+++ b/ocaml/xapi/xapi_host_backup.ml
@@ -23,8 +23,8 @@ open Helpers
 module D = Debug.Debugger(struct let name="xapi" end)
 open D
 
-let host_backup = Xapi_globs.base_path ^ "/libexec/host-backup"
-let host_restore = Xapi_globs.base_path ^ "/libexec/host-restore"
+let host_backup = Filename.concat Fhs.libexecdir "host-backup"
+let host_restore = Filename.concat Fhs.libexecdir "host-restore"
 
 let host_backup_handler_core ~__context s =
 	match
diff --git a/ocaml/xapi/xapi_logs_download.ml b/ocaml/xapi/xapi_logs_download.ml
index 8a171a1..d73e640 100644
--- a/ocaml/xapi/xapi_logs_download.ml
+++ b/ocaml/xapi/xapi_logs_download.ml
@@ -18,7 +18,7 @@ open Forkhelpers
 module D = Debug.Debugger(struct let name="xapi" end)
 open D
 
-let logs_download = Xapi_globs.base_path ^ "/libexec/logs-download"
+let logs_download = Filename.concat Fhs.libexecdir "logs-download"
 
 let logs_download_handler (req: Request.t) s _ =
   debug "running logs-download handler";
diff --git a/ocaml/xapi/xapi_message.ml b/ocaml/xapi/xapi_message.ml
index 85f5bad..a1d0e36 100644
--- a/ocaml/xapi/xapi_message.ml
+++ b/ocaml/xapi/xapi_message.ml
@@ -19,13 +19,13 @@
 (** Message store *)
 
 (* We use a filesystem based 'database': 
- *  Base directory: /var/xapi/blobs/messages
+ *  Base directory: @VARDIR@/blobs/messages
  *  All messages go in there, filename=timestamp
  *  
  *  Symlinks are created to the messages for fast indexing:
- *  /var/xapi/blobs/messages/VM/<uuid>/<timestamp> -> message
- *  /var/xapi/blobs/messages/uuid/<message uuid> -> message
- *  /var/xapi/blobs/messages/ref/<message ref> -> message
+ *  @VARDIR@/blobs/messages/VM/<uuid>/<timestamp> -> message
+ *  @VARDIR@/blobs/messages/uuid/<message uuid> -> message
+ *  @VARDIR@/blobs/messages/ref/<message ref> -> message
  *)
 
 open Listext   
diff --git a/ocaml/xapi/xapi_mgmt_iface.ml b/ocaml/xapi/xapi_mgmt_iface.ml
index 823049f..c1b0dd9 100644
--- a/ocaml/xapi/xapi_mgmt_iface.ml
+++ b/ocaml/xapi/xapi_mgmt_iface.ml
@@ -24,7 +24,7 @@ open D
 let management_interface_server = ref None
 let management_m = Mutex.create ()
 
-let rewrite_management_interface_script = Xapi_globs.base_path ^ "/libexec/rewrite-management-interface"
+let rewrite_management_interface_script = Filename.concat Fhs.libexecdir "rewrite-management-interface"
 
 let rewrite_management_interface interface =
 	(* XXX: probably should decompose this into Xapi_inventory.update <k> <v> and
diff --git a/ocaml/xapi/xapi_pci.ml b/ocaml/xapi/xapi_pci.ml
index 8975c3f..b1934d7 100644
--- a/ocaml/xapi/xapi_pci.ml
+++ b/ocaml/xapi/xapi_pci.ml
@@ -30,7 +30,7 @@ type pci = {
 
 type pci_class = Display_controller | Network_controller
 
-let prog = Xapi_globs.base_path ^ "/libexec/pci-info"
+let prog = Filename.concat Fhs.libexecdir "pci-info"
 
 let find_class_id = function
 	| Display_controller -> "03"
diff --git a/ocaml/xapi/xapi_pool_patch.ml b/ocaml/xapi/xapi_pool_patch.ml
index 82d483c..719b850 100644
--- a/ocaml/xapi/xapi_pool_patch.ml
+++ b/ocaml/xapi/xapi_pool_patch.ml
@@ -273,10 +273,10 @@ let sync () =
       | Success(output, _) -> ()
 
 let patch_header_length = 8
-let skip_signature_flag = "/etc/xensource/skipsignature"
+let skip_signature_flag = Filename.concat Fhs.etcdir "skipsignature"
 
-let update_upload_pre_script = Xapi_globs.base_path ^ "/libexec/update-upload-pre"
-let update_upload_post_script = Xapi_globs.base_path ^ "/libexec/update-upload-post"
+let update_upload_pre_script = Filename.concat Fhs.libexecdir "update-upload-pre"
+let update_upload_post_script = Filename.concat Fhs.libexecdir "update-upload-post"
 
 let skip_signature_test () = Sys.file_exists skip_signature_flag
 
diff --git a/ocaml/xapi/xapi_services.ml b/ocaml/xapi/xapi_services.ml
index 4d0a42c..567e3ba 100644
--- a/ocaml/xapi/xapi_services.ml
+++ b/ocaml/xapi/xapi_services.ml
@@ -89,7 +89,7 @@ let get_handler (req: Http.Request.t) s _ =
 			debug "uri = %s" req.Http.Request.uri;
 			match String.split '/' req.Http.Request.uri with
 				| [ ""; services; "xenops" ] when services = _services ->
-					hand_over_connection req s "/var/xapi/xenopsd.forwarded"
+					hand_over_connection req s (Filename.concat Fhs.vardir "xenopsd.forwarded")
 				| [ ""; services; "SM"; driver ] when services = _services ->
 					begin
 						try
diff --git a/ocaml/xapi/xapi_support.ml b/ocaml/xapi/xapi_support.ml
index 6ccf3df..50d1b05 100644
--- a/ocaml/xapi/xapi_support.ml
+++ b/ocaml/xapi/xapi_support.ml
@@ -31,7 +31,7 @@ let do_upload label file url options =
 
 	match with_logfile_fd label
 		(fun log_fd ->
-			let upload_wrapper = Xapi_globs.base_path ^ "/libexec/upload-wrapper" in
+			let upload_wrapper = Filename.concat Fhs.libexecdir "upload-wrapper" in
 			let pid = safe_close_and_exec None (Some log_fd) (Some log_fd) [] upload_wrapper [file; url; proxy] in
 			waitpid_fail_if_bad_exit pid) with
 			| Success _ -> debug "Upload succeeded"
diff --git a/ocaml/xapi/xapi_sync.ml b/ocaml/xapi/xapi_sync.ml
index 25c8cff..1d80d91 100644
--- a/ocaml/xapi/xapi_sync.ml
+++ b/ocaml/xapi/xapi_sync.ml
@@ -38,7 +38,7 @@ let sync_host ~__context host =
 				let output,log = Forkhelpers.execute_command_get_output
 					~env:(Unix.environment ())
 					"/usr/bin/rsync"
-					["--delete";"--stats";"-az";localpath;remotepath;"-e"; Xapi_globs.base_path ^ "/bin/xsh"] in
+					["--delete";"--stats";"-az";localpath;remotepath;"-e"; Filename.concat Fhs.bindir "xsh"] in
 				debug "sync output: \n%s" output;
 				debug "log output: '%s'" log;
 
diff --git a/ocaml/xapi/xapi_templates_install.ml b/ocaml/xapi/xapi_templates_install.ml
index 041fc45..4468d95 100644
--- a/ocaml/xapi/xapi_templates_install.ml
+++ b/ocaml/xapi/xapi_templates_install.ml
@@ -25,7 +25,7 @@ module D = Debug.Debugger(struct let name="xapi" end)
 open D
 
 let allowed_dom0_directory_for_provision_scripts =
-  Xapi_globs.base_path ^ "/packages/post-install-scripts/"
+  Filename.concat Fhs.sharedir "packages/post-install-scripts/"
 
 let is_whitelisted script =
   let safe_char = function 'a'..'z'-> true |'-'->true |'/'->true |_ -> false in
diff --git a/ocaml/xapi/xapi_udhcpd.ml b/ocaml/xapi/xapi_udhcpd.ml
index 72fa1d6..bd1c383 100644
--- a/ocaml/xapi/xapi_udhcpd.ml
+++ b/ocaml/xapi/xapi_udhcpd.ml
@@ -25,9 +25,9 @@ open Threadext
 let ip_begin_key = "ip_begin"
 let ip_end_key = "ip_end"
 
-let udhcpd_conf = "/var/xapi/udhcpd.conf"
-let udhcpd_skel = "/var/xapi/udhcpd.skel"
-let leases_db = "/var/xapi/dhcp-leases.db"
+let udhcpd_conf = Filename.concat Fhs.vardir "udhcpd.conf"
+let udhcpd_skel = Filename.concat Fhs.etcdir "udhcpd.skel"
+let leases_db = Filename.concat Fhs.vardir "dhcp-leases.db"
 let pidfile = "/var/run/udhcpd.pid"
 
 module Ip = struct
@@ -123,7 +123,7 @@ let write_config_nolock ~__context ip_router =
 	Unixext.unlink_safe udhcpd_conf;
 	Unixext.write_string_to_file udhcpd_conf (Udhcpd_conf.to_string config)
 
-let command = Xapi_globs.base_path ^ "/libexec/udhcpd"
+let command = Filename.concat Fhs.libexecdir "udhcpd"
   
 let restart_nolock () =
 	let pid = try Unixext.pidfile_read pidfile with _ -> None in
diff --git a/ocaml/xapi/xapi_vif.ml b/ocaml/xapi/xapi_vif.ml
index 61f24e0..6ec7bfd 100644
--- a/ocaml/xapi/xapi_vif.ml
+++ b/ocaml/xapi/xapi_vif.ml
@@ -102,5 +102,5 @@ let move ~__context ~network vif =
 			with_xs (fun xs -> xs.Xs.write xs_bridge_path vif_device.Vm_config.bridge);
 			let domid = string_of_int vif_device.Vm_config.domid in
 			let devid = string_of_int vif_device.Vm_config.devid in
-			ignore(Helpers.call_script "/etc/xensource/scripts/vif" ["move"; "vif"; domid; devid])
+			ignore(Helpers.call_script (Filename.concat Fhs.scriptsdir "vif") ["move"; "vif"; domid; devid])
 
diff --git a/ocaml/xapi/xha_interface.ml b/ocaml/xapi/xha_interface.ml
index dcfa883..533f377 100644
--- a/ocaml/xapi/xha_interface.ml
+++ b/ocaml/xapi/xha_interface.ml
@@ -78,7 +78,7 @@ let hash_table_of_leaf_xml_element_list list =
 module DaemonConfiguration = struct
 
 	(* Taken from Marathon's spec section 4.1.4.4 *)
-	let filename = "/etc/xensource/xhad.conf"
+	let filename = Filename.concat Fhs.etcdir "xhad.conf"
 
 	module Host = struct
 
diff --git a/ocaml/xe-cli/OMakefile b/ocaml/xe-cli/OMakefile
index 41417a6..75d8a2a 100644
--- a/ocaml/xe-cli/OMakefile
+++ b/ocaml/xe-cli/OMakefile
@@ -1,5 +1,5 @@
-OCAML_LIBS    = ../idl/ocaml_backend/common ../idl/ocaml_backend/client
-OCAMLINCLUDES = ../idl/ocaml_backend ../xapi
+OCAML_LIBS    = ../fhs ../idl/ocaml_backend/common ../idl/ocaml_backend/client 
+OCAMLINCLUDES = ../idl/ocaml_backend ../xapi ..
 OCAMLPACKS    = xml-light2 stdext stunnel log
 
 section
@@ -99,13 +99,12 @@ clean:
 
 .PHONY: install
 install:
-	mkdir -p $(BIN_PATH)
-	$(IPROG) xe $(BIN_PATH)
+	mkdir -p $(DESTDIR)$(OPTDIR)/bin
+	$(IPROG) xe $(DESTDIR)$(OPTDIR)/bin
 	mkdir -p $(DESTDIR)/usr/bin
-	ln -sf $(BIN_DIR)/xe $(DESTDIR)/usr/bin/xe
+	ln -sf $(OPTDIR)/bin/xe $(DESTDIR)/usr/bin/xe
 	mkdir -p $(DESTDIR)/etc/bash_completion.d
 	$(IPROG) bash-completion $(DESTDIR)/etc/bash_completion.d/xe
-	mkdir -p $(DEBUGDIST)
 
 .PHONY: sdk-install
 sdk-install: install
diff --git a/ocaml/xe-cli/cli.ml b/ocaml/xe-cli/cli.ml
index 9b0b8b6..2fb9692 100644
--- a/ocaml/xe-cli/cli.ml
+++ b/ocaml/xe-cli/cli.ml
@@ -74,7 +74,7 @@ let nonpersistent_rpc xml =
 let local_rpc xml =
 	let open Xmlrpcclient in
 	let http = xmlrpc ~version:"1.0" "/" in
-	XML_protocol.rpc ~transport:(Unix "/var/xapi/xapi") ~http xml
+	XML_protocol.rpc ~transport:(Unix (Filename.concat Fhs.vardir "xapi")) ~http xml
 
 (* Read command, determine username, password, host and port, and then
    invoke cmd *)
diff --git a/ocaml/xe-cli/newcli.ml b/ocaml/xe-cli/newcli.ml
index 8dc3176..da4215b 100644
--- a/ocaml/xe-cli/newcli.ml
+++ b/ocaml/xe-cli/newcli.ml
@@ -241,7 +241,7 @@ let open_tcp server =
 let open_channels () =
   if is_localhost !xapiserver then (
     try
-      Unix.open_connection (Unix.ADDR_UNIX "/var/xapi/xapi")
+      Unix.open_connection (Unix.ADDR_UNIX (Filename.concat Fhs.vardir "xapi"))
     with _ ->
       open_tcp !xapiserver
   ) else
diff --git a/ocaml/xe-cli/rt/OMakefile b/ocaml/xe-cli/rt/OMakefile
index ca43d40..fcc8ee0 100644
--- a/ocaml/xe-cli/rt/OMakefile
+++ b/ocaml/xe-cli/rt/OMakefile
@@ -30,5 +30,5 @@ install:
 	mkdir -p /tmp/cli-rt-domu/root
 	cp gtmessages.ml gtcomms.ml gtlinuxops.ml gtserver_linux.ml /tmp/cli-rt-domu/root
 	(cd $(ROOT)/scripts; /bin/sh ./make-patch /tmp/cli-rt-domu /tmp/cli-rt-domu-shar.sh)
-	mv /tmp/cli-rt-domu-shar.sh $(BASE_PATH)/debug
-	$(IPROG) install-debian-pv.sh install-debian-pv-inside.sh $(BASE_PATH)/debug
+	mv /tmp/cli-rt-domu-shar.sh $(DESTDIR)$(OPTDIR)/debug
+	$(IPROG) install-debian-pv.sh install-debian-pv-inside.sh $(DESTDIR)$(OPTDIR)/debug
diff --git a/ocaml/xe-cli/rt/geneva/OMakefile b/ocaml/xe-cli/rt/geneva/OMakefile
index 266e74d..eb6b30d 100644
--- a/ocaml/xe-cli/rt/geneva/OMakefile
+++ b/ocaml/xe-cli/rt/geneva/OMakefile
@@ -14,8 +14,8 @@ clean:
 
 .PHONY: install
 install:
-	mkdir -p $(DEBUGDIST)
-	$(IPROG) cli_test sm_stress myfirstpatch.asc $(DEBUGDIST)
+	mkdir -p $(DESTDIR)$(OPTDIR)/debug
+	$(IPROG) cli_test sm_stress myfirstpatch.asc $(DESTDIR)$(OPTDIR)/debug
 
 .PHONY: install
 install:
diff --git a/ocaml/xe-cli/rt/install-debian-pv.sh b/ocaml/xe-cli/rt/install-debian-pv.sh
index b7c6a63..9bef0ed 100644
--- a/ocaml/xe-cli/rt/install-debian-pv.sh
+++ b/ocaml/xe-cli/rt/install-debian-pv.sh
@@ -49,7 +49,7 @@ VIF=`xe vif-create vm-uuid=${VM} network-uuid=${NETWORK} device=0`
 VDI=`xe vbd-list vm-uuid=${VM} userdevice=0 params=vdi-uuid --minimal`
 
 # Run the inner-script bit:
-"@BASE_PATH@/debug/with-vdi" ${VDI} "@BASE_PATH@/debug/install-debian-pv-inside.sh"
+"@OPTDIR@/debug/with-vdi" ${VDI} "@OPTDIR@/debug/install-debian-pv-inside.sh"
 
 # Start it up
 xe vm-start vm=${VM}
diff --git a/ocaml/xenguest/OMakefile b/ocaml/xenguest/OMakefile
index fe4a4d0..add2d91 100644
--- a/ocaml/xenguest/OMakefile
+++ b/ocaml/xenguest/OMakefile
@@ -21,8 +21,8 @@ clean:
 
 .PHONY: install
 install:
-	mkdir -p $(LIBEXEC)
-	$(IPROG) xenguest dumpcore $(LIBEXEC)
+	mkdir -p $(DESTDIR)$(LIBEXECDIR)
+	$(IPROG) xenguest dumpcore $(DESTDIR)$(LIBEXECDIR)
 	mkdir -p $(DIST)/xenguest-src
 	$(IDATA) $(XENGUEST_SRC_FILES) $(DIST)/xenguest-src
 
diff --git a/ocaml/xenops/OMakefile b/ocaml/xenops/OMakefile
index b196520..fed74a3 100644
--- a/ocaml/xenops/OMakefile
+++ b/ocaml/xenops/OMakefile
@@ -1,5 +1,5 @@
-OCAMLINCLUDES    = ../xapi ../util
-OCAML_LIBS       = ../util/stats
+OCAMLINCLUDES    = ../xapi ../util ..
+OCAML_LIBS       = ../util/stats ../fhs
 OCAML_CLIBS     += $(XEN_OCAML_CLIBS)
 # XXX: these should all be specified in the ocamlfind META file:
 XENLIGHT_LINK_FLAGS= -cclib -lxlutil -cclib -luuid -cclib -lblktapctl -cclib -lutil -cclib -lxenlight -cclib -lxenstore
@@ -66,14 +66,15 @@ allxenops: $(DEBUG_PROGS) $(BIN_PROGS) $(OTHER_PROGS)
 
 .PHONY: install
 install:
-	mkdir -p $(DEBUGDIST)
-	cp -f $(DEBUG_PROGS) $(DEBUGDIST)
-	sh -c 'for i in $(SYMLINK_PROGS); do ln -nfs xenops $(DEBUGDIST)/$$i; done'
-	mkdir -p $(BIN_PATH)
-	$(IPROG) $(BIN_PROGS) $(BIN_PATH)
-	mkdir -p $(LIBEXEC)
-	$(IPROG) fence $(LIBEXEC)/fence.bin
-	$(IPROG) squeezed $(LIBEXEC)/squeezed
+	mkdir -p $(DESTDIR)$(OPTDIR)/debug
+	cp -f $(DEBUG_PROGS) $(DESTDIR)$(OPTDIR)/debug
+	sh -c 'for i in $(SYMLINK_PROGS); do ln -nfs xenops $(DESTDIR)$(OPTDIR)/debug/$$i; done'
+	mkdir -p $(DESTDIR)$(BINDIR)
+	$(IPROG) $(BIN_PROGS) $(DESTDIR)$(BINDIR)
+	mkdir -p $(DESTDIR)$(LIBEXECDIR)
+	$(IPROG) fence $(DESTDIR)$(LIBEXECDIR)/fence.bin
+	mkdir -p $(DESTDIR)$(LIBEXECDIR)
+	$(IPROG) squeezed $(DESTDIR)$(LIBEXECDIR)
 
 .PHONY: sdk-install
 sdk-install: install
diff --git a/ocaml/xenops/device.ml b/ocaml/xenops/device.ml
index b7720d4..6200ff6 100644
--- a/ocaml/xenops/device.ml
+++ b/ocaml/xenops/device.ml
@@ -642,7 +642,7 @@ let add ~xs ~devid ~netty ~mac ~carrier ?mtu ?(rate=None) ?(protocol=Protocol_Na
 		"frontend-id", sprintf "%u" domid;
 		"online", "1";
 		"state", string_of_int (Xenbus_utils.int_of Xenbus_utils.Initialising);
-		"script", "/etc/xensource/scripts/vif";
+		"script", (Filename.concat Fhs.scriptsdir "vif");
 		"mac", mac;
 		"handle", string_of_int devid
 	] @ back_options in
@@ -720,7 +720,7 @@ end
 
 module PV_Vnc = struct
 
-let vncterm_wrapper = Xapi_globs.base_path ^ "/libexec/vncterm-wrapper"
+let vncterm_wrapper = Filename.concat Fhs.libexecdir "vncterm-wrapper"
 
 let vnc_pid_path domid = sprintf "/local/domain/%d/vncterm-pid" domid
 
@@ -1052,7 +1052,7 @@ let write_string_to_file file s =
 let do_flr device =
   debug "Doing FLR on pci device: %s" device;
 	let doflr = "/sys/bus/pci/drivers/pciback/do_flr" in
-	let script = Xapi_globs.base_path ^ "/libexec/pci-flr" in
+	let script = Filename.concat Fhs.libexecdir "pci-flr" in
 	let callscript =
                 let f s devstr =
 	                try ignore (Forkhelpers.execute_command_get_output script [ s; devstr; ])
diff --git a/ocaml/xenops/xenguestHelper.ml b/ocaml/xenops/xenguestHelper.ml
index 7fd579c..4cef74a 100644
--- a/ocaml/xenops/xenguestHelper.ml
+++ b/ocaml/xenops/xenguestHelper.ml
@@ -16,7 +16,7 @@ module D = Debug.Debugger(struct let name = "xenguesthelper" end)
 open D
 
 (** Installed path of the xenguest helper *)
-let path = Xapi_globs.base_path ^ "/libexec/xenguest"
+let path = Filename.concat Fhs.libexecdir "xenguest"
 
 (** Where to place the last xenguesthelper debug log (just in case) *)
 let last_log_file = "/tmp/xenguesthelper-log"
diff --git a/ocaml/xenops/xenops.ml b/ocaml/xenops/xenops.ml
index e088906..2a49eea 100644
--- a/ocaml/xenops/xenops.ml
+++ b/ocaml/xenops/xenops.ml
@@ -337,7 +337,7 @@ let list_pci ~xc ~xs ~domid =
 		  ) pcidevs
 
 let add_dm ~xs ~domid ~static_max_kib ~vcpus ~boot =
-    let dmpath = Xapi_globs.base_path ^ "/libexec/qemu-dm-wrapper" in
+    let dmpath = Filename.concat Fhs.libexecdir "qemu-dm-wrapper" in
 	let info = {
  	  Device.Dm.memory = static_max_kib;
  	  Device.Dm.boot = boot;
diff --git a/ocaml/xenops/xenvm.readme b/ocaml/xenops/xenvm.readme
index 35e329e..17d5ff0 100644
--- a/ocaml/xenops/xenvm.readme
+++ b/ocaml/xenops/xenvm.readme
@@ -89,7 +89,7 @@ architecture, and out-of-date-ness.
 And you need to replace your udev rules by the one available in
 scripts/xen-backend.rules and scripts/xen-frontend.rules and add the
 scripts/tap scripts/block scripts/block-front scripts/vif into
-/etc/xensource/scripts/
+@SCRIPTSDIR@/
 
 Also note that since xen-unstable doesn't have the dm-ready patch,
 hvm domain takes unfortunately a substantial time (around 20s.) to start.
diff --git a/ocaml/xiu/OMakefile b/ocaml/xiu/OMakefile
index dd2a183..e936775 100644
--- a/ocaml/xiu/OMakefile
+++ b/ocaml/xiu/OMakefile
@@ -1,6 +1,6 @@
 OCAMLPACKS    = stdext xenstore netdev log
-OCAML_LIBS    += ../util/version ../idl/ocaml_backend/common ../xenops/xenops
-OCAMLINCLUDES += ../xapi ../xenops
+OCAML_LIBS    += ../util/version ../fhs ../idl/ocaml_backend/common ../xenops/xenops
+OCAMLINCLUDES += ../xapi ../xenops ..
 
 CFLAGS += -fno-omit-frame-pointer -fno-optimize-sibling-calls -fno-strict-aliasing -std=gnu99
 CFLAGS += -mno-tls-direct-seg-refs
@@ -17,14 +17,14 @@ clean:
 
 .PHONY: install
 install:
-	mkdir -p $(LIBEXEC)
-	$(IPROG) xiu $(LIBEXEC)/
-	mkdir -p $(BASE_PATH)/lib
-	$(IDATA) libxenctrl_xiu.so $(BASE_PATH)/lib
+	mkdir -p $(DESTDIR)$(LIBEXECDIR)
+	$(IPROG) xiu $(DESTDIR)$(LIBEXECDIR)/
+	mkdir -p $(DESTDIR)$(OPTDIR)/lib
+	$(IDATA) libxenctrl_xiu.so $(DESTDIR)$(OPTDIR)/lib
 
 .PHONY: sdk-install
 sdk-install:
-	mkdir -p $(LIBEXEC)
-	$(IPROG) xiu $(LIBEXEC)/
-	mkdir -p $(BASE_PATH)/lib
-	$(IDATA) libxenctrl_xiu.so $(BASE_PATH)/lib
+	mkdir -p $(DESTDIR)$(LIBEXECDIR)
+	$(IPROG) xiu $(DESTDIR)$(LIBEXECDIR)/
+	mkdir -p $(DESTDIR)$(OPTDIR)/lib
+	$(IDATA) libxenctrl_xiu.so $(DESTDIR)$(OPTDIR)/lib
diff --git a/ocaml/xiu/xiu.ml b/ocaml/xiu/xiu.ml
index e15fa53..84d3afd 100644
--- a/ocaml/xiu/xiu.ml
+++ b/ocaml/xiu/xiu.ml
@@ -221,7 +221,7 @@ module Udev = struct
     | _, _ -> eprintf "(XIU) unknown error running udev script\n"
 
   let vif domid devid device action = 
-    let vif_script = "/etc/xensource/scripts/vif" in
+    let vif_script = Filename.concat Fhs.scriptsdir "vif" in
     let env = 
       [ "DEVPATH", sprintf "/devices/xen-backend/vif-%d-%d" domid devid;
 	"PHYSDEVBUS", "xen-backend";
@@ -229,7 +229,7 @@ module Udev = struct
 	"XENBUS_BASE_PATH", "backend";
 	"XENBUS_PATH", sprintf "backend/vif/%d/%d" domid devid;
 	"XENBUS_TYPE", "vif";
-	"PATH", Xapi_globs.base_path ^ "/bin:/usr/local/bin:/bin:/usr/bin"; (* added <base_path>/bin for xenstore wrapper *)
+	"PATH", Fhs.bindir ^ ":/usr/local/bin:/bin:/usr/bin"; (* added @BINDIR@ for xenstore wrapper *)
 	"XIU", !xiu_path; (* make sure we pick up the fake list_domains *)
 	"vif", device
       ] in
@@ -858,7 +858,7 @@ let main xiu_path =
 	()
 
 let _ =
-	let config_file = ref "/etc/xensource/xiu.conf" in
+	let config_file = ref (Filename.concat Fhs.etcdir "xiu.conf") in
 	let other_args = ref [] in
 	Arg.parse [ "-v", Arg.Unit (fun () -> incr debug_level), "increase debug level";
 	            "--conf", Arg.Set_string config_file, "set config file"; ]
diff --git a/ocaml/xsh/OMakefile b/ocaml/xsh/OMakefile
index 6c4349a..5bcd77a 100644
--- a/ocaml/xsh/OMakefile
+++ b/ocaml/xsh/OMakefile
@@ -10,8 +10,8 @@ section
 
 .PHONY: install
 install:
-	mkdir -p $(BIN_PATH)
-	cp -f xsh $(BIN_PATH)
+	mkdir -p $(DESTDIR)$(OPTDIR)/bin
+	cp -f xsh $(DESTDIR)$(OPTDIR)/bin
 
 clean:
 	rm -f *.cmi *.cmx *.cmo *.a *.cma *.cmxa *.run *.opt *.annot *.o xsh
diff --git a/scripts/10resetvdis b/scripts/10resetvdis
index 18da095..7e50a61 100644
--- a/scripts/10resetvdis
+++ b/scripts/10resetvdis
@@ -16,5 +16,5 @@ IFS=","
 for i in `xe pbd-list host-uuid=$HOSTUUID --minimal`
 do
    SR=`xe pbd-param-get uuid=$i param-name=sr-uuid`  
-   "@BASE_PATH@/sm/resetvdis.py" $HOSTUUID $SR
+   "@OPTDIR@/sm/resetvdis.py" $HOSTUUID $SR
 done
diff --git a/scripts/InterfaceReconfigure.py b/scripts/InterfaceReconfigure.py
index 6d90972..ed4c613 100644
--- a/scripts/InterfaceReconfigure.py
+++ b/scripts/InterfaceReconfigure.py
@@ -375,7 +375,7 @@ def db_init_from_xenapi(session):
     
 class DatabaseCache(object):
     def __read_xensource_inventory(self):
-        filename = root_prefix() + "/etc/xensource-inventory"
+        filename = root_prefix() + "@INVENTORY@"
         f = open(filename, "r")
         lines = [x.strip("\n") for x in f.readlines()]
         f.close()
@@ -948,7 +948,7 @@ def DatapathFactory():
     # XXX Need a datapath object for bridgeless PIFs
 
     try:
-        network_conf = open(root_prefix() + "/etc/xensource/network.conf", 'r')
+        network_conf = open(root_prefix() + "@ETCDIR@/network.conf", 'r')
         network_backend = network_conf.readline().strip()
         network_conf.close()                
     except Exception, e:
diff --git a/scripts/OMakefile b/scripts/OMakefile
index 64334f5..9ad8fba 100644
--- a/scripts/OMakefile
+++ b/scripts/OMakefile
@@ -2,35 +2,35 @@
 
 .PHONY: install
 install:
-	mkdir -p $(BIN_PATH)
-	mkdir -p $(DESTDIR)/var/patch
-	mkdir -p $(DESTDIR)/var/patch/applied
-	mkdir -p $(DESTDIR)/var/xapi
-	mkdir -p $(DESTDIR)/etc/xapi.d
-	mkdir -p $(DESTDIR)/etc/xensource
+	mkdir -p $(DESTDIR)$(BINDIR)
+	mkdir -p $(DESTDIR)$(VARPATCHDIR)
+	mkdir -p $(DESTDIR)$(VARPATCHDIR)/applied
+	mkdir -p $(DESTDIR)$(VARDIR)
+	mkdir -p $(DESTDIR)$(HOOKSDIR)
+	mkdir -p $(DESTDIR)$(ETCDIR)
 	mkdir -p $(DESTDIR)/etc/logrotate.d
-	mkdir -p $(DESTDIR)/etc/xensource/master.d
-	mkdir -p $(LIBEXEC)
+	mkdir -p $(DESTDIR)$(ETCDIR)/master.d
+	mkdir -p $(DESTDIR)$(LIBEXECDIR)
 	$(IPROG) base-path $(DESTDIR)/etc/xapi.d
-	$(IPROG) sm_diagnostics $(LIBEXEC)
-	$(IPROG) thread_diagnostics $(LIBEXEC)
-	mkdir -p $(DESTDIR)/etc/xensource/bugtool/xapi
-	$(IDATA) bugtool-plugin/xapi.xml $(DESTDIR)/etc/xensource/bugtool
-	$(IDATA) bugtool-plugin/xapi/stuff.xml $(DESTDIR)/etc/xensource/bugtool/xapi
-	$(IPROG) fence $(LIBEXEC)
-	$(IPROG) xha-lc $(LIBEXEC)
-	$(IPROG) xapi-health-check $(LIBEXEC)
-	$(IPROG) license-check.py $(LIBEXEC)
-	$(IPROG) mail-alarm $(LIBEXEC)
+	$(IPROG) sm_diagnostics $(DESTDIR)$(LIBEXECDIR)
+	$(IPROG) thread_diagnostics $(DESTDIR)$(LIBEXECDIR)
+	mkdir -p $(DESTDIR)$(ETCDIR)/bugtool/xapi
+	$(IDATA) bugtool-plugin/xapi.xml $(DESTDIR)$(ETCDIR)/bugtool
+	$(IDATA) bugtool-plugin/xapi/stuff.xml $(DESTDIR)$(ETCDIR)/bugtool/xapi
+	$(IPROG) fence $(DESTDIR)$(LIBEXECDIR)
+	$(IPROG) xha-lc $(DESTDIR)$(LIBEXECDIR)
+	$(IPROG) xapi-health-check $(DESTDIR)$(LIBEXECDIR)
+	$(IPROG) license-check.py $(DESTDIR)$(LIBEXECDIR)
+	$(IPROG) mail-alarm $(DESTDIR)$(LIBEXECDIR)
 	$(IPROG) audit-logrotate $(DESTDIR)/etc/logrotate.d/audit
 	$(IPROG) xapi-logrotate $(DESTDIR)/etc/logrotate.d/xapi
-	$(IPROG) xapi-wait-init-complete $(BIN_PATH)
-	$(IPROG) xapi-autostart-vms $(BIN_PATH)
-	$(IPROG) udhcpd.skel $(DESTDIR)/var/xapi/udhcpd.skel
-	$(IPROG) xapi.conf $(DESTDIR)/etc/xapi.conf
-	$(IPROG) log.conf $(DESTDIR)/etc/xensource/log.conf
-	$(IPROG) db.conf.skel $(DESTDIR)/etc/xensource/db.conf
-	$(IPROG) rio.db.conf.skel $(DESTDIR)/etc/xensource/db.conf.rio
+	$(IPROG) xapi-wait-init-complete $(DESTDIR)$(BINDIR)
+	$(IPROG) xapi-autostart-vms $(DESTDIR)$(BINDIR)
+	$(IPROG) udhcpd.skel $(DESTDIR)/var/xapi/udhcpd.skel  #### FHS_FIXME
+	$(IPROG) xapi.conf $(DESTDIR)$(XAPICONF)
+	$(IPROG) log.conf $(DESTDIR)$(ETCDIR)/log.conf
+	$(IPROG) db.conf.skel $(DESTDIR)$(ETCDIR)/db.conf
+	$(IPROG) rio.db.conf.skel $(DESTDIR)$(ETCDIR)/db.conf.rio
 	mkdir -p $(DESTDIR)/etc/init.d
 	mkdir -p $(DESTDIR)/etc/rc.d/init.d
 	$(IPROG) init.d-xenservices $(DESTDIR)/etc/rc.d/init.d/xenservices
@@ -43,72 +43,72 @@ install:
 	$(IDATA) squeezed-logrotate $(DESTDIR)/etc/logrotate.d/squeezed
 	$(IPROG) init.d-v6d $(DESTDIR)/etc/rc.d/init.d/v6d
 	$(IDATA) v6d-logrotate $(DESTDIR)/etc/logrotate.d/v6d
-	mkdir -p $(DESTDIR)/etc/xensource/master.d
-	$(IPROG) on-master-start $(DESTDIR)/etc/xensource/master.d/01-example
-	$(IPROG) mpathalert-daemon $(DESTDIR)/etc/xensource/master.d/03-mpathalert-daemon
+	mkdir -p $(DESTDIR)$(ETCDIR)/master.d
+	$(IPROG) on-master-start $(DESTDIR)$(ETCDIR)/master.d/01-example
+	$(IPROG) mpathalert-daemon $(DESTDIR)$(ETCDIR)/master.d/03-mpathalert-daemon
 	mkdir -p $(DESTDIR)/etc/sysconfig
 	$(IPROG) sysconfig-xapi $(DESTDIR)/etc/sysconfig/xapi
-	mkdir -p $(DESTDIR)/etc/udev
-	$(IPROG) xen-backend.rules $(DESTDIR)/etc/udev
-	$(IPROG) xen-frontend.rules $(DESTDIR)/etc/udev
-	$(IPROG) generate_ssl_cert $(LIBEXEC)
-	$(IPROG) fix_firewall.sh $(BIN_PATH)
-	mkdir -p $(BASE_PATH)/debug
-	$(IPROG) debug_ha_query_liveset $(BASE_PATH)/debug
-	$(IPROG) xe-scsi-dev-map $(BIN_PATH)
-	$(IPROG) xe-mount-iso-sr $(BIN_PATH)
-	$(IPROG) xe-reset-networking $(BIN_PATH)
-	$(IPROG) xe-set-iscsi-iqn $(BIN_PATH)
-	$(IPROG) xe-toolstack-restart $(BIN_PATH)
-	$(IPROG) xe-xentrace $(BIN_PATH)
-	$(IPROG) xe-edit-bootloader $(BIN_PATH)
-	$(IPROG) static-vdis $(BIN_PATH)
-	$(IPROG) with-vdi $(BASE_PATH)/debug
-	mkdir -p $(DESTDIR)/etc/udev/rules.d
+	mkdir -p $(DESTDIR)/etc/udev                    ### FHS_FIXME
+	$(IPROG) xen-backend.rules $(DESTDIR)/etc/udev  ### FHS_FIXME
+	$(IPROG) xen-frontend.rules $(DESTDIR)/etc/udev ### FHS_FIXME
+	$(IPROG) generate_ssl_cert $(DESTDIR)$(LIBEXECDIR)
+	$(IPROG) fix_firewall.sh $(DESTDIR)$(BINDIR)
+	mkdir -p $(DESTDIR)$(OPTDIR)/debug
+	$(IPROG) debug_ha_query_liveset $(DESTDIR)$(OPTDIR)/debug
+	$(IPROG) xe-scsi-dev-map $(DESTDIR)$(BINDIR)
+	$(IPROG) xe-mount-iso-sr $(DESTDIR)$(BINDIR)
+	$(IPROG) xe-reset-networking $(DESTDIR)$(BINDIR)
+	$(IPROG) xe-set-iscsi-iqn $(DESTDIR)$(BINDIR)
+	$(IPROG) xe-toolstack-restart $(DESTDIR)$(BINDIR)
+	$(IPROG) xe-xentrace $(DESTDIR)$(BINDIR)
+	$(IPROG) xe-edit-bootloader $(DESTDIR)$(BINDIR)
+	$(IPROG) static-vdis $(DESTDIR)$(BINDIR)
+	$(IPROG) with-vdi $(DESTDIR)$(OPTDIR)/debug
+	mkdir -p $(DESTDIR)/etc/udev/rules.d ### FHS_FIXME
 	sh -c \
 	'cd $(DESTDIR)/etc/udev/rules.d; \
 	ln -sf ../xen-backend.rules; \
 	ln -sf ../xen-frontend.rules'
-	mkdir -p $(DESTDIR)/etc/xensource/scripts
-	$(IPROG) block-frontend vif tap block $(DESTDIR)/etc/xensource/scripts
-	$(IPROG) pool.conf $(DESTDIR)/etc/xensource
+	mkdir -p $(DESTDIR)$(SCRIPTSDIR)
+	$(IPROG) block-frontend vif tap block $(DESTDIR)$(SCRIPTSDIR)
+	$(IPROG) pool.conf $(DESTDIR)$(ETCDIR)
 	mkdir -p $(DESTDIR)/etc/pam.d
 	$(IPROG) pam.d-xapi $(DESTDIR)/etc/pam.d/xapi
-	$(IPROG) qemu-dm-wrapper vncterm-wrapper upload-wrapper logs-download $(LIBEXEC)
-	mkdir -p $(BASE_PATH)/packages/iso #omg XXX
-	$(IPROG) interface-reconfigure $(LIBEXEC)
-	$(IPROG) InterfaceReconfigure.py $(LIBEXEC)
-	$(IPROG) InterfaceReconfigureBridge.py $(LIBEXEC)
-	$(IPROG) InterfaceReconfigureVswitch.py $(LIBEXEC)
-	$(IPROG) rewrite-management-interface $(LIBEXEC)
-	$(IPROG) interface-visualise $(LIBEXEC)
-	$(IPROG) logrotate.sh $(LIBEXEC)
-	$(IPROG) xapi-rolling-upgrade-miami $(LIBEXEC)/xapi-rolling-upgrade
-	$(IPROG) set-hostname $(LIBEXEC)
-	$(IPROG) update-mh-info $(LIBEXEC)
-	$(IPROG) host-bugreport-upload $(LIBEXEC)/host-bugreport-upload
-	$(IPROG) xe-backup-metadata $(BIN_PATH)
-	$(IPROG) xe-restore-metadata $(BIN_PATH)
-	$(IPROG) link-vms-by-sr.py $(LIBEXEC)
-	$(IPROG) print-custom-templates $(LIBEXEC)
-	$(IPROG) backup-sr-metadata.py $(LIBEXEC)
-	$(IPROG) restore-sr-metadata.py $(LIBEXEC)
-	$(IPROG) probe-device-for-file $(LIBEXEC)
-	$(IPROG) backup-metadata-cron $(LIBEXEC)
-	$(IPROG) lw-force-domain-leave $(LIBEXEC)
+	$(IPROG) qemu-dm-wrapper vncterm-wrapper upload-wrapper logs-download $(DESTDIR)$(LIBEXECDIR)
+	mkdir -p $(DESTDIR)$(OPTDIR)/packages/iso #omg XXX
+	$(IPROG) interface-reconfigure $(DESTDIR)$(LIBEXECDIR)
+	$(IPROG) InterfaceReconfigure.py $(DESTDIR)$(LIBEXECDIR)
+	$(IPROG) InterfaceReconfigureBridge.py $(DESTDIR)$(LIBEXECDIR)
+	$(IPROG) InterfaceReconfigureVswitch.py $(DESTDIR)$(LIBEXECDIR)
+	$(IPROG) rewrite-management-interface $(DESTDIR)$(LIBEXECDIR)
+	$(IPROG) interface-visualise $(DESTDIR)$(LIBEXECDIR)
+	$(IPROG) logrotate.sh $(DESTDIR)$(LIBEXECDIR)
+	$(IPROG) xapi-rolling-upgrade-miami $(DESTDIR)$(LIBEXECDIR)/xapi-rolling-upgrade
+	$(IPROG) set-hostname $(DESTDIR)$(LIBEXECDIR)
+	$(IPROG) update-mh-info $(DESTDIR)$(LIBEXECDIR)
+	$(IPROG) host-bugreport-upload $(DESTDIR)$(LIBEXECDIR)/host-bugreport-upload
+	$(IPROG) xe-backup-metadata $(DESTDIR)$(BINDIR)
+	$(IPROG) xe-restore-metadata $(DESTDIR)$(BINDIR)
+	$(IPROG) link-vms-by-sr.py $(DESTDIR)$(LIBEXECDIR)
+	$(IPROG) print-custom-templates $(DESTDIR)$(LIBEXECDIR)
+	$(IPROG) backup-sr-metadata.py $(DESTDIR)$(LIBEXECDIR)
+	$(IPROG) restore-sr-metadata.py $(DESTDIR)$(LIBEXECDIR)
+	$(IPROG) probe-device-for-file $(DESTDIR)$(LIBEXECDIR)
+	$(IPROG) backup-metadata-cron $(DESTDIR)$(LIBEXECDIR)
+	$(IPROG) lw-force-domain-leave $(DESTDIR)$(LIBEXECDIR)
 	$(IPROG) init.d-perfmon $(DESTDIR)/etc/rc.d/init.d/perfmon
 	mkdir -p $(DESTDIR)/etc/sysconfig
 	$(IPROG) sysconfig-perfmon $(DESTDIR)/etc/sysconfig/perfmon
-	$(IPROG) perfmon $(BIN_PATH)
-	mkdir -p $(DESTDIR)/etc/xapi.d/plugins
-	$(IPROG) plugins/perfmon $(DESTDIR)/etc/xapi.d/plugins
-	$(IPROG) plugins/extauth-hook $(DESTDIR)/etc/xapi.d/plugins
-	$(IPROG) plugins/extauth-hook-AD.py $(DESTDIR)/etc/xapi.d/plugins
-	$(IPROG) plugins/iovirt $(DESTDIR)/etc/xapi.d/plugins
-	$(IPROG) set-dom0-memory-target-from-packs $(LIBEXEC)
-	mkdir -p $(DESTDIR)/etc/xapi.d/host-post-declare-dead
-	$(IPROG) 10resetvdis $(DESTDIR)/etc/xapi.d/host-post-declare-dead
-	$(IPROG) pci-info $(LIBEXEC)
+	$(IPROG) perfmon $(DESTDIR)$(BINDIR)
+	mkdir -p $(DESTDIR)$(PLUGINDIR)
+	$(IPROG) plugins/perfmon $(DESTDIR)$(PLUGINDIR)
+	$(IPROG) plugins/extauth-hook $(DESTDIR)$(PLUGINDIR)
+	$(IPROG) plugins/extauth-hook-AD.py $(DESTDIR)$(PLUGINDIR)
+	$(IPROG) plugins/iovirt $(DESTDIR)$(PLUGINDIR)
+	$(IPROG) set-dom0-memory-target-from-packs $(DESTDIR)$(LIBEXECDIR)
+	mkdir -p $(DESTDIR)$(HOOKSDIR)/host-post-declare-dead
+	$(IPROG) 10resetvdis $(DESTDIR)$(HOOKSDIR)/host-post-declare-dead
+	$(IPROG) pci-info $(DESTDIR)$(LIBEXECDIR)
 
 .PHONY: sdk-install
 sdk-install: install
diff --git a/scripts/backup-metadata-cron b/scripts/backup-metadata-cron
index 0720d06..4b4c8f8 100755
--- a/scripts/backup-metadata-cron
+++ b/scripts/backup-metadata-cron
@@ -1,8 +1,8 @@
 #!/bin/bash
 
-if [ -e /etc/xensource/pool.conf ]; then
-    if [ "$(cat /etc/xensource/pool.conf)" = "master" ]; then
-        "@BASE_PATH@/bin/xe-backup-metadata" -c >/dev/null 2>&1
+if [ -e @ETCDIR@/pool.conf ]; then
+    if [ "$(cat @ETCDIR@/pool.conf)" = "master" ]; then
+        "@BINDIR@/xe-backup-metadata" -c >/dev/null 2>&1
         EXITVALUE=$?
         if [ $EXITVALUE != 0 ]; then
              /usr/bin/logger -t backup-metadata "ALERT exited abnormally with [$EXITVALUE]"
diff --git a/scripts/bugtool-plugin/xapi/stuff.xml b/scripts/bugtool-plugin/xapi/stuff.xml
index 8c0bc1a..fd543e1 100644
--- a/scripts/bugtool-plugin/xapi/stuff.xml
+++ b/scripts/bugtool-plugin/xapi/stuff.xml
@@ -1,4 +1,4 @@
 <collect>
-<command label="sm_diagnostics">/opt/xensource/libexec/sm_diagnostics</command>
-<command label="thread_diagnostics">/opt/xensource/libexec/thread_diagnostics</command>
+<command label="sm_diagnostics">@LIBEXECDIR@/sm_diagnostics</command>
+<command label="thread_diagnostics">@LIBEXECDIR@/thread_diagnostics</command>
 </collect>
diff --git a/scripts/db.conf.skel b/scripts/db.conf.skel
index 7d269eb..4b3b94c 100644
--- a/scripts/db.conf.skel
+++ b/scripts/db.conf.skel
@@ -1,4 +1,4 @@
-[/var/xapi/state.db]
+[@VARDIR@/state.db]
 mode:no_limit
 format:xml
 available_this_boot:true
diff --git a/scripts/debug_ha_query_liveset b/scripts/debug_ha_query_liveset
index 6c10d24..7f16ce5 100755
--- a/scripts/debug_ha_query_liveset
+++ b/scripts/debug_ha_query_liveset
@@ -2,8 +2,8 @@
 
 # Run by xen-bugtool
 
-export PATH=$PATH:@BASE_PATH@/xha
+export PATH=$PATH:@OPTDIR@/xha
 echo Running ha_query_liveset $*:
-"@BASE_PATH@/xha/ha_query_liveset" $*
+"@OPTDIR@/xha/ha_query_liveset" $*
 echo Output of command: $?
 
diff --git a/scripts/examples/bash-cli/install-debian b/scripts/examples/bash-cli/install-debian
index 88cea94..62c1719 100755
--- a/scripts/examples/bash-cli/install-debian
+++ b/scripts/examples/bash-cli/install-debian
@@ -30,8 +30,8 @@ fi
 
 # Source the inventory file, which tells us amongst other thing the name of
 # the management interface
-if [ -e /etc/xensource-inventory ]; then
-  . /etc/xensource-inventory
+if [ -e @INVENTORY@ ]; then
+  . @INVENTORY@
 fi
 if [ -z "${MANAGEMENT_INTERFACE}" ]; then
   echo No MANAGEMENT_INTERFACE environment varible set: assuming xenbr0
diff --git a/scripts/examples/bash-cli/install-debian.html b/scripts/examples/bash-cli/install-debian.html
index 6d6f40b..54d1e8d 100644
--- a/scripts/examples/bash-cli/install-debian.html
+++ b/scripts/examples/bash-cli/install-debian.html
@@ -41,8 +41,8 @@
 
 <I><FONT COLOR="#B22222"># Source the inventory file, which tells us amongst other thing the name of
 </FONT></I><I><FONT COLOR="#B22222"># the management interface
-</FONT></I><B><FONT COLOR="#A020F0">if</FONT></B> [ -e /etc/xensource-inventory ]; <B><FONT COLOR="#A020F0">then</FONT></B>
-  . /etc/xensource-inventory
+</FONT></I><B><FONT COLOR="#A020F0">if</FONT></B> [ -e @INVENTORY@ ]; <B><FONT COLOR="#A020F0">then</FONT></B>
+  . @INVENTORY@
 <B><FONT COLOR="#A020F0">fi</FONT></B>
 <B><FONT COLOR="#A020F0">if</FONT></B> [ -z <B><FONT COLOR="#BC8F8F">&quot;${MANAGEMENT_INTERFACE}&quot;</FONT></B> ]; <B><FONT COLOR="#A020F0">then</FONT></B>
   <B><FONT COLOR="#DA70D6">echo</FONT></B> No MANAGEMENT_INTERFACE environment varible <B><FONT COLOR="#DA70D6">set</FONT></B>: assuming xenbr0
diff --git a/scripts/examples/python/OMakefile b/scripts/examples/python/OMakefile
index 981a8eb..01888f9 100644
--- a/scripts/examples/python/OMakefile
+++ b/scripts/examples/python/OMakefile
@@ -37,14 +37,14 @@ README : index.html
 	lynx -dump index.html > README
 .PHONY: install
 install:
-	mkdir -p $(LIBEXEC)
+	mkdir -p $(DESTDIR)$(LIBEXECDIR)
 	mkdir -p $(DESTDIR)/usr/lib/$(PYTHON_DIR)/site-packages
-	mkdir -p $(DESTDIR)/etc/xapi.d/plugins
+	mkdir -p $(DESTDIR)$(PLUGINDIR)
 	$(IDATA) XenAPIPlugin.py XenAPI.py inventory.py $(DESTDIR)/usr/lib/$(PYTHON_DIR)/site-packages/
-	$(IEXE) echo.py $(DESTDIR)/etc/xapi.d/plugins/echo
-	$(IEXE) wake-on-lan.py $(DESTDIR)/etc/xapi.d/plugins/wake-on-lan
-	$(IEXE) shutdown.py $(LIBEXEC)/shutdown
-	$(IEXE) shell.py $(LIBEXEC)/shell.py
+	$(IEXE) echo.py $(DESTDIR)$(PLUGINDIR)/echo
+	$(IEXE) wake-on-lan.py $(DESTDIR)$(PLUGINDIR)/wake-on-lan
+	$(IEXE) shutdown.py $(DESTDIR)$(LIBEXECDIR)/shutdown
+	$(IEXE) shell.py $(DESTDIR)$(LIBEXECDIR)/shell.py
 
 .PHONY: sdk-install
 sdk-install:
diff --git a/scripts/examples/python/XenAPI.py b/scripts/examples/python/XenAPI.py
index c459d31..6ee8523 100644
--- a/scripts/examples/python/XenAPI.py
+++ b/scripts/examples/python/XenAPI.py
@@ -189,7 +189,8 @@ class Session(xmlrpclib.ServerProxy):
             return xmlrpclib.ServerProxy.__getattr__(self, name)
 
 def xapi_local():
-    return Session("http://_var_xapi_xapi/", transport=UDSTransport())
+    localpath = "@VARDIR@/xapi".replace("/","_")
+    return Session("http://%s/" % localpath, transport=UDSTransport())
 
 def _parse_result(result):
     if type(result) != dict or 'Status' not in result:
diff --git a/scripts/examples/python/inventory.py b/scripts/examples/python/inventory.py
index ba1e7af..0f06556 100644
--- a/scripts/examples/python/inventory.py
+++ b/scripts/examples/python/inventory.py
@@ -1,6 +1,6 @@
 # Simple functions to read the constants from the xensource-inventory file
 
-INVENTORY="/etc/xensource-inventory"
+INVENTORY="@INVENTORY@"
 INSTALLATION_UUID="INSTALLATION_UUID"
 
 def read_kvpairs(filename):
diff --git a/scripts/examples/python/monitor-unwanted-domains.py b/scripts/examples/python/monitor-unwanted-domains.py
index 34e3e4d..843d7ac 100644
--- a/scripts/examples/python/monitor-unwanted-domains.py
+++ b/scripts/examples/python/monitor-unwanted-domains.py
@@ -9,7 +9,7 @@ import os, subprocess, XenAPI, inventory, time, sys
 # Return a list of (domid, uuid) tuples, one per paused domain on this host
 def list_paused_domains():
     results = []
-    all = subprocess.Popen(["@BASE_PATH@/bin/list_domains"], stdout=subprocess.PIPE).communicate()[0]
+    all = subprocess.Popen(["@BINDIR@/list_domains"], stdout=subprocess.PIPE).communicate()[0]
     lines = all.split("\n")
     for domain in lines[1:]:
         bits = domain.split()
@@ -54,7 +54,7 @@ def log(str):
 # Destroy the given domain
 def destroy_domain((domid, uuid)):
     log("destroying domid %s uuid %s" % (domid, uuid))
-    all = subprocess.Popen(["@BASE_PATH@/debug/destroy_domain", "-domid", domid], stdout=subprocess.PIPE).communicate()[0]
+    all = subprocess.Popen(["@OPTDIR@/debug/destroy_domain", "-domid", domid], stdout=subprocess.PIPE).communicate()[0]
 
 # Keep track of when a domain first looked like it should be here
 domain_first_noticed = {}
diff --git a/scripts/fake-pv-drivers.sh b/scripts/fake-pv-drivers.sh
index 8926b26..e88ffe2 100644
--- a/scripts/fake-pv-drivers.sh
+++ b/scripts/fake-pv-drivers.sh
@@ -25,7 +25,7 @@ if [ $? -ne 0 ]; then
 fi
 
 # use the PRODUCT_VERSION from here:
-. /etc/xensource-inventory
+. @INVENTORY@
 
 major=$(echo ${PRODUCT_VERSION} | cut -f 1 -d .)
 minor=$(echo ${PRODUCT_VERSION} | cut -f 2 -d .)
diff --git a/scripts/fence b/scripts/fence
index 72b46b4..02027c4 100755
--- a/scripts/fence
+++ b/scripts/fence
@@ -3,4 +3,4 @@
 # Do not use the ocaml XIU stuff for this -- we want the real
 # hypervisor to fence this domain.
 unset XIU
-@BASE_PATH@/libexec/fence.bin $*
+@LIBEXECDIR@/fence.bin $*
diff --git a/scripts/host-backup-restore/OMakefile b/scripts/host-backup-restore/OMakefile
index f559fef..24dfd0c 100644
--- a/scripts/host-backup-restore/OMakefile
+++ b/scripts/host-backup-restore/OMakefile
@@ -1,7 +1,7 @@
 .PHONY: install
 install:
-	mkdir -p $(LIBEXEC)
-	$(IPROG) host-backup host-restore $(LIBEXEC)
+	mkdir -p $(DESTDIR)$(LIBEXECDIR)
+	$(IPROG) host-backup host-restore $(DESTDIR)$(LIBEXECDIR)
 
 .PHONY: sdk-install
 sdk-install: install
diff --git a/scripts/host-backup-restore/host-restore b/scripts/host-backup-restore/host-restore
index a908871..da0ff35 100755
--- a/scripts/host-backup-restore/host-restore
+++ b/scripts/host-backup-restore/host-restore
@@ -7,7 +7,7 @@ set -e
 set -x
 
 # Restore a backup to the other partition
-. /etc/xensource-inventory
+. @INVENTORY@
 DEVICE=$BACKUP_PARTITION
 
 if [ -z "$DEVICE" ]
diff --git a/scripts/host-bugreport-upload b/scripts/host-bugreport-upload
index f001f54..57a8d1f 100755
--- a/scripts/host-bugreport-upload
+++ b/scripts/host-bugreport-upload
@@ -19,7 +19,7 @@ BASE_URL=$(echo ${INPUT_URL} | sed -ne 's,\(^[^:]*://[^/]*\)\(/\([^/]*/\)*\)*[^/
 if [ -z "$FILENAME" ]; then
 # Build the remote filename
   now=$(date --utc +"%Y:%m:%dT%H:%M:%SZ")
-  . /etc/xensource-inventory
+  . @INVENTORY@
   FILENAME=${INSTALLATION_UUID}-${now}
 fi
 [ ! -z "${BASE_URL}" ] || BASE_URL="${DEFAULT_BASE_URL}"
diff --git a/scripts/init.d-genptoken b/scripts/init.d-genptoken
index 13939da..f918227 100644
--- a/scripts/init.d-genptoken
+++ b/scripts/init.d-genptoken
@@ -8,9 +8,9 @@
 . /etc/init.d/functions
 
 start() {
-    if [ ! -f /etc/xensource/ptoken ]; then
+    if [ ! -f @ETCDIR@/ptoken ]; then
         echo -n $"Creating pool secret (this may take some time)"
-        "@BASE_PATH@/libexec/genptoken" -f -o /etc/xensource/ptoken
+        "@LIBEXECDIR@/genptoken" -f -o @ETCDIR@/ptoken
         [ $? -eq 0 ] && success $"Done" || failure
         echo
     fi
diff --git a/scripts/init.d-management-interface b/scripts/init.d-management-interface
index c0bd5ae..1a8abc7 100644
--- a/scripts/init.d-management-interface
+++ b/scripts/init.d-management-interface
@@ -7,8 +7,8 @@
 
 . /etc/init.d/functions
 
-export XENSOURCE_INVENTORY=/etc/xensource-inventory
-export INTERFACE_RECONFIGURE="@BASE_PATH@/libexec/interface-reconfigure"
+export XENSOURCE_INVENTORY=@INVENTORY@
+export INTERFACE_RECONFIGURE="@LIBEXECDIR@/interface-reconfigure"
 
 [ -r ${XENSOURCE_INVENTORY} ] || exit 0
 . ${XENSOURCE_INVENTORY}
diff --git a/scripts/init.d-perfmon b/scripts/init.d-perfmon
index de9ca1f..fd64003 100644
--- a/scripts/init.d-perfmon
+++ b/scripts/init.d-perfmon
@@ -5,13 +5,13 @@
 # chkconfig: 2345 95 05
 # description: Performance monitoring/alarm generation daemon
 # processname: perfmon
-# config: /etc/xensource/perfmon.conf
+# config: @ETCDIR@/perfmon.conf
 # pidfile: /var/run/perfmon.pid
 
 # Source function library.
 . /etc/init.d/functions
 
-PERFMON="@BASE_PATH@/bin/perfmon"
+PERFMON="@BINDIR@/perfmon"
 PERFMON_FLAGS=
 
 if [ -f /etc/sysconfig/perfmon ]; then
diff --git a/scripts/init.d-sdkinit b/scripts/init.d-sdkinit
index 74a9cf6..7547ff5 100755
--- a/scripts/init.d-sdkinit
+++ b/scripts/init.d-sdkinit
@@ -11,12 +11,12 @@
 case "$1" in
     start)
 	# This is a run-once script!
-	if [ -e /etc/xensource-inventory ]; then
+	if [ -e @INVENTORY@ ]; then
             exit 0
 	fi
 	echo -n "Starting sdkinit: "
-	cat /proc/cpuinfo > /etc/xensource/boot_time_cpu
-	touch /etc/xensource/boot_time_info_updated
+	cat /proc/cpuinfo > @ETCDIR@/boot_time_cpu
+	touch @ETCDIR@/boot_time_info_updated
 
 	if [ -d /proc/xen ]; then
 		# Set the domain0 uuid to the real uuid of this SDK VM
@@ -31,7 +31,7 @@ case "$1" in
 	HOSTUUID=`uuidgen`
 	INSTALLDATE=`date "+%Y-%m-%d %H:%M:%S.000000"`
 
-	(cat /etc/xensource-inventory.skel; cat << EOF) > /etc/xensource-inventory
+	(cat @INVENTORY@.skel; cat << EOF) > @INVENTORY@
 KERNEL_VERSION='2.6.18-92.1.6.el5.xs4.1.920.367.638xen'
 XEN_VERSION='3.2.1'
 INSTALLATION_DATE='${INSTALLDATE}'
diff --git a/scripts/init.d-squeezed b/scripts/init.d-squeezed
index 1fbf00f..8abbe3b 100644
--- a/scripts/init.d-squeezed
+++ b/scripts/init.d-squeezed
@@ -13,7 +13,7 @@
 # Memory ballooning daemon
 
 # location of the executable:
-SQUEEZED="@BASE_PATH@/libexec/squeezed"
+SQUEEZED="@LIBEXECDIR@/squeezed"
 
 # pidfile:
 PID_FILE="/var/run/squeezed.pid"
@@ -25,7 +25,7 @@ SUBSYS_FILE="/var/lock/subsys/squeezed"
 . /etc/init.d/functions
 
 if [ -e /var/xapi/xiu-xc ]; then
-	export XENCTRL_OSDEP="@BASE_PATH@/lib/libxenctrl_xiu.so"
+	export XENCTRL_OSDEP="@OPTDIR@/lib/libxenctrl_xiu.so"
 	export XIU=/var/xapi/xiu
 fi
 
diff --git a/scripts/init.d-v6d b/scripts/init.d-v6d
index 66fec9a..854cec9 100644
--- a/scripts/init.d-v6d
+++ b/scripts/init.d-v6d
@@ -13,7 +13,7 @@
 # v6 licensing daemon
 
 # location of the executable:
-V6D="@BASE_PATH@/libexec/v6d"
+V6D="@LIBEXECDIR@/v6d"
 
 # pidfile:
 PID_FILE="/var/run/v6d.pid"
diff --git a/scripts/init.d-xapi b/scripts/init.d-xapi
index ee04289..05a75a3 100755
--- a/scripts/init.d-xapi
+++ b/scripts/init.d-xapi
@@ -16,14 +16,14 @@ if [ -f /etc/sysconfig/xapi ]; then
 fi
 
 if [ -e /var/xapi/xiu-xc ]; then
-	export XENCTRL_OSDEP="@BASE_PATH@/lib/libxenctrl_xiu.so"
+	export XENCTRL_OSDEP="@OPTDIR@/lib/libxenctrl_xiu.so"
 	export XIU=/var/xapi/xiu
 fi
 
 XAPI_STARTUP_COOKIE=/var/run/xapi_startup.cookie
 XAPI_INIT_COMPLETE_COOKIE=/var/run/xapi_init_complete.cookie
-XAPI_BLOCK_STARTUP_COOKIE=/etc/xensource/xapi_block_startup
-XAPI_BOOT_TIME_INFO_UPDATED=/etc/xensource/boot_time_info_updated
+XAPI_BLOCK_STARTUP_COOKIE=@ETCDIR@/xapi_block_startup
+XAPI_BOOT_TIME_INFO_UPDATED=@ETCDIR@/boot_time_info_updated
 
 # Enable core dumping for xapi
 ulimit -c unlimited
@@ -52,7 +52,7 @@ start() {
 	# Enable backtraces
 	export OCAMLRUNPARAM="b"
 	# Add HA scripts to the path
-	PATH=$PATH:@BASE_PATH@/xha
+	PATH=$PATH:@OPTDIR@/xha
 
 	# For debugging, prevent xapi startup
 	if [ -e ${XAPI_BLOCK_STARTUP_COOKIE} ]; then
@@ -68,12 +68,12 @@ start() {
 	if [ -e ${XAPI_BOOT_TIME_INFO_UPDATED} ]; then
 	    # clear out qemu coredumps/chroot dirs on system boot:
 	    rm -rf /var/xen/qemu/*
-	    "@BASE_PATH@/bin/xapi" -daemon ${xapiflags} \
+	    "@BINDIR@/xapi" -daemon ${xapiflags} \
 		-writereadyfile ${XAPI_STARTUP_COOKIE} -writeinitcomplete ${XAPI_INIT_COMPLETE_COOKIE} -onsystemboot
 		RETVAL=$?
 	    rm -f ${XAPI_BOOT_TIME_INFO_UPDATED}
 	else
-	    "@BASE_PATH@/bin/xapi" -daemon ${xapiflags} \
+	    "@BINDIR@/xapi" -daemon ${xapiflags} \
 		-writereadyfile ${XAPI_STARTUP_COOKIE} -writeinitcomplete ${XAPI_INIT_COMPLETE_COOKIE}
 		RETVAL=$?
 	fi
diff --git a/scripts/init.d-xapi-domains b/scripts/init.d-xapi-domains
index f2f2076..ef9cc71 100644
--- a/scripts/init.d-xapi-domains
+++ b/scripts/init.d-xapi-domains
@@ -6,16 +6,16 @@
 # chkconfig: 345 99 00
 # description: Start/stop XE VMs
 
-SHUTDOWN="@BASE_PATH@/libexec/shutdown"
+SHUTDOWN="@LIBEXECDIR@/shutdown"
 
 if [ ! -e /proc/xen/privcmd ] || \
-   [ ! -e /etc/xensource-inventory ] || \
+   [ ! -e @INVENTORY@ ] || \
    [ ! -e ${SHUTDOWN} ] ; then
         exit 0
 fi
 
 . /etc/init.d/functions
-. /etc/xensource-inventory
+. @INVENTORY@
 
 if [ "x${INSTALLATION_UUID}" = "x" ] ; then
     exit 1
@@ -27,7 +27,7 @@ case "$1" in
         touch /var/lock/subsys/xapi-domains
         # Fork background thread to wait for xapi to complete initialisation
         # and then try and start vms with auto_poweron=true in other-config
-	/opt/xensource/bin/xapi-autostart-vms &
+	@BINDIR@/xapi-autostart-vms &
         ;;
     stop)
         action $"Shutting down Virtual Machines: " \
diff --git a/scripts/init.d-xapissl b/scripts/init.d-xapissl
index 0f2b105..bd672c5 100755
--- a/scripts/init.d-xapissl
+++ b/scripts/init.d-xapissl
@@ -13,15 +13,15 @@
 # chkconfig: 2345 91 01
 # description: XenAPI server SSL proxy
 # processname: stunnel
-# config: /etc/xensource/stunnel.conf
+# config: @ETCDIR@/stunnel.conf
 # pidfile: /var/run/xapissl.pid
 
 # Source function library.
 . /lib/lsb/init-functions
 
-PEMFILE="/etc/xensource/xapi-ssl.pem"
+PEMFILE="@ETCDIR@/xapi-ssl.pem"
 SSLPIDFILE="/var/run/xapissl.pid"
-SSLCONFFILE="/etc/xensource/xapi-ssl.conf"
+SSLCONFFILE="@ETCDIR@/xapi-ssl.conf"
 XAPISSL_LOCK="/var/lock/xapissl"
 
 # If stunnel4 exists, use it. Otherwise use stunnel.
@@ -29,7 +29,7 @@ XAPISSL_LOCK="/var/lock/xapissl"
 [ -z ${STUNNEL} ] && STUNNEL=$(which stunnel)
 
 mgmt_ip() {
-    . /etc/xensource-inventory
+    . @INVENTORY@
     if [ -n "${MANAGEMENT_INTERFACE}" ] &&
         [ "${MANAGEMENT_INTERFACE}" != "lo" ];
     then
@@ -58,7 +58,7 @@ cert = ${PEMFILE}
 ciphers = !SSLv2:RSA+AES256-SHA:RSA+AES128-SHA:RSA+RC4-SHA:RSA+RC4-MD5:RSA+DES-CBC3-SHA
 EOF
 
-    . /etc/xensource-inventory
+    . @INVENTORY@
     # Only if the management interface is set ask stunnel to bind to it
     if [ -n "${MANAGEMENT_INTERFACE}" ] &&
         [ "${MANAGEMENT_INTERFACE}" != "lo" ];
@@ -100,7 +100,7 @@ start() {
             *)
                 CN=`mgmt_ip`;;
         esac
-        "@BASE_PATH@/libexec/generate_ssl_cert" ${PEMFILE} ${CN}
+        "@LIBEXECDIR@/generate_ssl_cert" ${PEMFILE} ${CN}
     fi
     writeconffile
     start_daemon ${STUNNEL} ${SSLCONFFILE}
diff --git a/scripts/init.d-xenservices b/scripts/init.d-xenservices
index 6fd8142..3350a58 100755
--- a/scripts/init.d-xenservices
+++ b/scripts/init.d-xenservices
@@ -5,7 +5,7 @@
 # chkconfig: 2345 21 78
 # description: Xen services required by xapi
 # processname: xenstored, xenconsoled
-# config: /etc/xensource/rio.conf
+# config: @ETCDIR@/rio.conf
 # pidfile: /var/run/xenstored.pid, /var/run/xenconsoled.pid
 
 [ -e /proc/xen ] || exit 0
@@ -16,11 +16,11 @@
 start() {
     # If this domain hasn't got sufficient privileges then assume it is a domU
     # and start the hypercall simulator
-    "@BASE_PATH@/bin/list_domains" 2>/dev/null 1>/dev/null
+    "@BINDIR@/list_domains" 2>/dev/null 1>/dev/null
     if [ $? -ne 0 ]; then
 	echo -n $"Starting simulator: "
 	rm -f /var/xapi/xiu-xc /var/xapi/xiu-xs
-	"@BASE_PATH@/libexec/xiu" /var/xapi/xiu 2>/dev/null 1>/dev/null &
+	"@LIBEXECDIR@/xiu" /var/xapi/xiu 2>/dev/null 1>/dev/null &
 
         # wait for unix domain socket to appear 
         RETRIES=180
@@ -36,7 +36,7 @@ start() {
 	    failure $"xiu"
 	    exit 1
 	fi
-	export XENCTRL_OSDEP="@BASE_PATH@/lib/libxenctrl_xiu.so"
+	export XENCTRL_OSDEP="@OPTDIR@/lib/libxenctrl_xiu.so"
 	export XIU=/var/xapi/xiu
     fi
 	echo -n $"Starting xenstored: "	
@@ -57,9 +57,9 @@ start() {
 
     # Existence of stampfile suppresses the access log (oem)
     XENSTORED_ARG=""
-    [ ! -e /etc/xensource/xenstored-no-access-log ] || XENSTORED_ARG="--no-access-log"
+    [ ! -e @ETCDIR@/xenstored-no-access-log ] || XENSTORED_ARG="--no-access-log"
     [ -e /var/lib/xenstored/tdb ] && mv -f /var/lib/xenstored/tdb /var/lib/xenstored/tdb.bak
-    "@BASE_PATH@/bin/xenstored" ${XENSTORED_ARG}
+    "@BINDIR@/xenstored" ${XENSTORED_ARG}
 
 	/usr/sbin/xenconsoled
 	[ -d /var/log/blktap ] || mkdir /var/log/blktap
@@ -72,7 +72,7 @@ start() {
 	xenstore-rm /vm
 
 	# start cdrommon on all physicals cdrom at startup
-	for i in `find /dev/xapi/cd/ ! -type d`; do "@BASE_PATH@/libexec/cdrommon" $i; done
+	for i in `find /dev/xapi/cd/ ! -type d`; do "@LIBEXECDIR@/cdrommon" $i; done
 
 	echo 
 	touch /var/lock/subsys/xen;
diff --git a/scripts/install.sh b/scripts/install.sh
index 8040960..3ff5fce 100755
--- a/scripts/install.sh
+++ b/scripts/install.sh
@@ -4,8 +4,22 @@
 #
 # Usage: ./install.sh <mode> <file1> .. <filen> <dest>
 #
-# Assumptions:
-# - The 'base-path' script is located in the same directory.
+# Replaces the following strings:
+#
+# @OPTDIR@ -> ${OPTDIR}
+# @ETCDIR@ -> ${ETCDIR}
+# @VARDIR@ -> ...etc...
+# @VARPATCHDIR@
+# @ETCDIR@
+# @OPTDIR@
+# @PLUGINDIR@
+# @HOOKSDIR@
+# @INVENTORY@
+# @XAPICONF@
+# @LIBEXECDIR@
+# @SCRIPTSDIR@
+
+set -x
 
 MODE=${1}
 NUM_FILES=$(($#-2))
@@ -27,6 +41,21 @@ for FILE in ${FILES}; do
     NEWFILE=${DEST}
   fi
   if file ${NEWFILE} | grep -q "text"; then
-    sed -i "s!@BASE_PATH@!${BASE_PATH}!g" ${NEWFILE}
+    sed -i -e "s!@OPTDIR@!${OPTDIR}!g" \
+	-e "s!@ETCDIR@!${ETCDIR}!g" \
+        -e "s!@VARDIR@!${VARDIR}!g" \
+        -e "s!@VARPATCHDIR@!${VARPATCHDIR}!g" \
+        -e "s!@PLUGINDIR@!${PLUGINDIR}!g" \
+        -e "s!@HOOKSDIR@!${HOOKSDIR}!g" \
+        -e "s!@INVENTORY@!${INVENTORY}!g" \
+        -e "s!@XAPICONF@!${XAPICONF}!g" \
+        -e "s!@LIBEXECDIR@!${LIBEXECDIR}!g" \
+        -e "s!@SCRIPTSDIR@!${SCRIPTSDIR}!g" \
+        -e "s!@SHAREDIR@!${SHAREDIR}!g" \
+        -e "s!@WEBDIR@!${WEBDIR}!g" \
+        -e "s!@XHADIR@!${XHADIR}!g" \
+        -e "s!@BINDIR@!${BINDIR}!g" \
+	-e "s!@SBINDIR@!${SBINDIR}!g" \
+         ${NEWFILE}
   fi
-done
\ No newline at end of file
+done
diff --git a/scripts/interface-reconfigure b/scripts/interface-reconfigure
index 6c6de9f..846cb53 100755
--- a/scripts/interface-reconfigure
+++ b/scripts/interface-reconfigure
@@ -54,7 +54,7 @@ import syslog
 
 management_pif = None
 
-dbcache_file = "/var/xapi/network.dbcache"
+dbcache_file = "@VARDIR@/network.dbcache"
 
 #
 # Logging.
diff --git a/scripts/interface-reconfigure-test b/scripts/interface-reconfigure-test
index f7e441e..44b5718 100644
--- a/scripts/interface-reconfigure-test
+++ b/scripts/interface-reconfigure-test
@@ -42,7 +42,7 @@ class Failure(Exception):
         #    self.msg = self.msg + "FAIL: " + m + "\n"
 
 def get_current_host():
-    f = open("/etc/xensource-inventory")
+    f = open("@INVENTORY@")
     hosts = [h.strip() for h in f.readlines() if h.startswith("INSTALLATION_UUID=")]
     f.close()
 
diff --git a/scripts/interface-reconfigure-test-setup b/scripts/interface-reconfigure-test-setup
index 37ed1ca..e41f717 100644
--- a/scripts/interface-reconfigure-test-setup
+++ b/scripts/interface-reconfigure-test-setup
@@ -2,7 +2,7 @@
 
 set -e
 
-. /etc/xensource-inventory
+. @INVENTORY@
 
 names=$(xe pif-list host-uuid="$INSTALLATION_UUID" management=false params=device VLAN=-1 --minimal | sed -e 's/,/+/g')
 pifs=$(xe pif-list host-uuid="$INSTALLATION_UUID" management=false VLAN=-1 --minimal)
diff --git a/scripts/interface-visualise b/scripts/interface-visualise
index bd15c60..9b62758 100755
--- a/scripts/interface-visualise
+++ b/scripts/interface-visualise
@@ -3,7 +3,7 @@
 # Copyright (c) Citrix Systems 2008. All rights reserved.
 #
 
-# Usage: ssh root@<host> @BASE_PATH@/libexec/interface-visualise > <host>-network.dot
+# Usage: ssh root@<host> @LIBEXECDIR@/interface-visualise > <host>-network.dot
 #        dotty <host>-network.dot
 
 echo "digraph G {"
diff --git a/scripts/license-check.py b/scripts/license-check.py
index f2de823..9eb8dcf 100755
--- a/scripts/license-check.py
+++ b/scripts/license-check.py
@@ -7,9 +7,9 @@ import os, re, subprocess, sys, syslog, time, traceback
 from xml.dom import minidom
 
 gpg_binary_path="/usr/bin/gpg"
-gpg_homedir="@BASE_PATH@/gpg"
+gpg_homedir="@OPTDIR@/gpg"
 gpg_pub_keyring=gpg_homedir + "/pubring.gpg"
-license_file="/etc/xensource/license"
+license_file="@ETCDIR@/license"
 expiry_message_name="LICENSE_EXPIRES_SOON"
 
 def match_installation(s):
@@ -17,7 +17,7 @@ def match_installation(s):
     return regex.search(s, 0)
 
 def get_localhost():
-    filename = '/etc/xensource-inventory'
+    filename = '@INVENTORY@'
     try:
         f = open(filename, 'r')
     except:
diff --git a/scripts/mpathalert-daemon b/scripts/mpathalert-daemon
index ddff433..fd30a7c 100644
--- a/scripts/mpathalert-daemon
+++ b/scripts/mpathalert-daemon
@@ -3,7 +3,7 @@
 # Multipath Alerting Daemon
 
 # location of the executable:
-MPATHALERT="@BASE_PATH@/bin/mpathalert"
+MPATHALERT="@BINDIR@/mpathalert"
 
 #delay in seconds between 2 consecutive alerts:
 DELAY="120"
diff --git a/scripts/plugins/iovirt b/scripts/plugins/iovirt
index 545891c..c663a1c 100755
--- a/scripts/plugins/iovirt
+++ b/scripts/plugins/iovirt
@@ -67,7 +67,7 @@ if [ -z "$VMUUID" ]; then
     logger -t $(basename $0) "VM UUID not found in args"
 fi
 
-. /etc/xensource-inventory
+. @INVENTORY@
 
 if [ -z "$INSTALLATION_UUID" ]; then
     logger -t $(basename $0) "Could not determine host UUID"
@@ -165,7 +165,7 @@ def _get_assignments(session):
     return devices
 
 def enable_iommu(session, args):
-    rc = os.system("@BASE_PATH@/libexec/xen-cmdline --set-xen iommu=1")
+    rc = os.system("@OPTDIR@/libexec/xen-cmdline --set-xen iommu=1")
     return str(rc == 0)
 
 #def list_assigned_vfs(session, args):
diff --git a/scripts/poweron/OMakefile b/scripts/poweron/OMakefile
index 654b124..e627538 100644
--- a/scripts/poweron/OMakefile
+++ b/scripts/poweron/OMakefile
@@ -1,8 +1,8 @@
 .PHONY: install
 install:
-             mkdir -p $(DESTDIR)/etc/xapi.d/plugins
-             $(IPROG) wlan.py $(DESTDIR)/etc/xapi.d/plugins/wlan.py
-             $(IPROG) iLOPowerON.xml $(DESTDIR)/etc/xapi.d/plugins/iLOPowerON.xml
-             $(IPROG) iLO.py $(DESTDIR)/etc/xapi.d/plugins/iLO.py
-             $(IPROG) DRAC.py $(DESTDIR)/etc/xapi.d/plugins/DRAC.py
-             $(IPROG) power-on.py $(DESTDIR)/etc/xapi.d/plugins/power-on-host
+             mkdir -p $(DESTDIR)$(PLUGINDIR)
+             $(IPROG) wlan.py $(DESTDIR)$(PLUGINDIR)/wlan.py
+             $(IPROG) iLOPowerON.xml $(DESTDIR)$(PLUGINDIR)/iLOPowerON.xml
+             $(IPROG) iLO.py $(DESTDIR)$(PLUGINDIR)/iLO.py
+             $(IPROG) DRAC.py $(DESTDIR)$(PLUGINDIR)/DRAC.py
+             $(IPROG) power-on.py $(DESTDIR)$(PLUGINDIR)/power-on-host
diff --git a/scripts/poweron/iLO.py b/scripts/poweron/iLO.py
index 76a7a07..252c7bf 100644
--- a/scripts/poweron/iLO.py
+++ b/scripts/poweron/iLO.py
@@ -14,7 +14,7 @@ class ILO_POWERON_FAILED(Exception):
 
 def getXmlWithLogin(user, password):
     
-    inputFile=open("/etc/xapi.d/plugins/iLOPowerON.xml",'r')
+    inputFile=open("@PLUGINDIR@/iLOPowerON.xml",'r')
     try:
         result= inputFile.read().replace('user',user).replace('password',password)
     finally:
diff --git a/scripts/rewrite-management-interface b/scripts/rewrite-management-interface
index b88cbb7..3656461 100755
--- a/scripts/rewrite-management-interface
+++ b/scripts/rewrite-management-interface
@@ -3,7 +3,7 @@
 # Copyright (c) Citrix Systems 2008. All rights reserved.
 #
 set -e
-INV=/etc/xensource-inventory
+INV=@INVENTORY@
 INTF=$1
 TMP=/tmp/rewrite-inventory.tmp.$$
 
@@ -17,4 +17,4 @@ cat ${INV} | grep -v ^MANAGEMENT_INTERFACE > ${TMP}
 echo "MANAGEMENT_INTERFACE='$INTF'" >> ${TMP}
 mv ${TMP} ${INV}
 
-"@BASE_PATH@/libexec/update-mh-info" $INTF
+"@LIBEXECDIR@/update-mh-info" $INTF
diff --git a/scripts/rio.db.conf.skel b/scripts/rio.db.conf.skel
index fd2e196..e9169d4 100644
--- a/scripts/rio.db.conf.skel
+++ b/scripts/rio.db.conf.skel
@@ -1,4 +1,4 @@
-[/var/xapi/state.db]
+[@VARDIR@/state.db]
 mode:no_limit
 format:sqlite
 available_this_boot:true
diff --git a/scripts/runtests b/scripts/runtests
index f26dfcd..dc1863d 100755
--- a/scripts/runtests
+++ b/scripts/runtests
@@ -12,7 +12,7 @@ fi
 
 IF=$1
 
-export PATH=$PATH:@BASE_PATH@/bin
+export PATH=$PATH:@BINDIR@
 
 # generic stuff, necessary for xenrt too
 
diff --git a/scripts/set-dom0-memory-target-from-packs b/scripts/set-dom0-memory-target-from-packs
index b39472a..43e0f63 100644
--- a/scripts/set-dom0-memory-target-from-packs
+++ b/scripts/set-dom0-memory-target-from-packs
@@ -16,13 +16,13 @@ import traceback
 import xml.dom.minidom
 from xml.parsers.expat import ExpatError
 
-INSTALLED_REPOS_DIR = '/etc/xensource/installed-repos'
+INSTALLED_REPOS_DIR = '@ETCDIR@/installed-repos'
 
 def main():
     session = XenAPI.xapi_local()
     logged_in = False
     # read dom0 uuid out of inventory file
-    uuid = filter(lambda x: x.startswith('CONTROL_DOMAIN_UUID'), open('/etc/xensource-inventory').readlines())[0].strip().split('=')[1].strip("'")
+    uuid = filter(lambda x: x.startswith('CONTROL_DOMAIN_UUID'), open('@INVENTORY@').readlines())[0].strip().split('=')[1].strip("'")
     oref = rec = None
     for tries in range(180):
         try:
diff --git a/scripts/sm_diagnostics b/scripts/sm_diagnostics
index f65905d..af03889 100644
--- a/scripts/sm_diagnostics
+++ b/scripts/sm_diagnostics
@@ -1,6 +1,6 @@
 #!/bin/sh
 
-. /etc/xensource-inventory
+. @INVENTORY@
 echo Host: ${INSTALLATION_UUID}
 echo
 xe host-get-sm-diagnostics uuid=${INSTALLATION_UUID}
diff --git a/scripts/static-vdis b/scripts/static-vdis
index c69452c..f216022 100755
--- a/scripts/static-vdis
+++ b/scripts/static-vdis
@@ -5,7 +5,7 @@
 import sys, os, subprocess
 import XenAPI, inventory, xmlrpclib
 
-main_dir = "/etc/xensource/static-vdis"
+main_dir = "@ETCDIR@/static-vdis"
 
 def read_whole_file(filename):
     f = open(filename)
diff --git a/scripts/sysconfig-perfmon b/scripts/sysconfig-perfmon
index 5af7863..75d7147 100644
--- a/scripts/sysconfig-perfmon
+++ b/scripts/sysconfig-perfmon
@@ -1,7 +1,7 @@
 #####################################################################
 # Example configuration file for perfmon. This file is read by
 # /etc/init.d/perfmon and used to construct the command line
-# arguments to pass to @BASE_PATH@/bin/perfmon.
+# arguments to pass to @BINDIR@/perfmon.
 
 # uncomment lines to enable options.
 
diff --git a/scripts/templates/OMakefile b/scripts/templates/OMakefile
index bd97f64..31a0f45 100644
--- a/scripts/templates/OMakefile
+++ b/scripts/templates/OMakefile
@@ -1,7 +1,7 @@
 .PHONY: install
 install:
-	mkdir -p $(BASE_PATH)/packages/post-install-scripts
-	$(IPROG) debug $(BASE_PATH)/packages/post-install-scripts
-	$(IPROG) debian $(BASE_PATH)/packages/post-install-scripts/debian-etch
+	mkdir -p $(DESTDIR)$(OPTDIR)/packages/post-install-scripts
+	$(IPROG) debug $(DESTDIR)$(OPTDIR)/packages/post-install-scripts
+	$(IPROG) debian $(DESTDIR)$(OPTDIR)/packages/post-install-scripts/debian-etch
 #	ln -f $(BASE_PATH)/packages/post-install-scripts/debian-etch
 #	      $(BASE_PATH)/packages/post-install-scripts/debian-sarge
diff --git a/scripts/templates/debian b/scripts/templates/debian
index 6cda786..0b30032 100644
--- a/scripts/templates/debian
+++ b/scripts/templates/debian
@@ -119,7 +119,7 @@ if __name__ == "__main__":
 
         run("/sbin/mkfs.ext3 %s", xvda_parts[0])
 
-        xgt = "/opt/xensource/packages/xgt/%s.xgt" % os.path.basename(sys.argv[0])
+        xgt = "@SHAREDIR@/packages/xgt/%s.xgt" % os.path.basename(sys.argv[0])
 
         run("/bin/mkdir -p %s", mountpoint)
         try:
diff --git a/scripts/thread_diagnostics b/scripts/thread_diagnostics
index 08fcda6..ba3fd0e 100644
--- a/scripts/thread_diagnostics
+++ b/scripts/thread_diagnostics
@@ -1,6 +1,6 @@
 #!/bin/sh
 
-. /etc/xensource-inventory
+. @INVENTORY@
 echo Host: ${INSTALLATION_UUID}
 echo
 xe host-get-thread-diagnostics uuid=${INSTALLATION_UUID}
diff --git a/scripts/vif b/scripts/vif
index d0662e1..12f935b 100755
--- a/scripts/vif
+++ b/scripts/vif
@@ -178,7 +178,7 @@ call_hook_script() {
     fi
 }
 
-NETWORK_MODE=$(cat /etc/xensource/network.conf)
+NETWORK_MODE=$(cat @ETCDIR@/network.conf)
 ACTION=$1
 
 # Older versions of XenServer do not pass in the type as an argument
diff --git a/scripts/vncterm-wrapper b/scripts/vncterm-wrapper
index 95e78bc..5b3ce0c 100755
--- a/scripts/vncterm-wrapper
+++ b/scripts/vncterm-wrapper
@@ -10,7 +10,7 @@ DOMID=$1
 shift 1
 
 #Getting the VM UUID
-export VMUUID=`"@BASE_PATH@/bin/list_domains" -domid $DOMID -minimal`
+export VMUUID=`"@BINDIR@/list_domains" -domid $DOMID -minimal`
 
 #For security reasons, we only listen on locahost by default
 export VNCTERM_LISTEN="-v 127.0.0.1:1"
@@ -18,7 +18,7 @@ export VNCTERM_LISTEN="-v 127.0.0.1:1"
 VNCVIEWER=""
 if test `/bin/ps aux | /bin/fgrep 'X :0' | /bin/fgrep -v fgrep | /usr/bin/wc -l` -eq 1 && test $DOMID -gt 0
 then
-    GRAPHICAL_CONF="/etc/xensource/graphical.conf"
+    GRAPHICAL_CONF="@ETCDIR@/graphical.conf"
     if egrep -s -q "^VNCTERM_DISPLAYS_ENABLED=[Ff][Aa][Ll][Ss][Ee]$" ${GRAPHICAL_CONF} ; then
         VNCVIEWER=""
     else
diff --git a/scripts/with-vdi b/scripts/with-vdi
index caf73c3..ae4e878 100755
--- a/scripts/with-vdi
+++ b/scripts/with-vdi
@@ -31,7 +31,7 @@ if [ -n "$COMMAND" ]; then
   fi
 fi
 
-. /etc/xensource-inventory
+. @INVENTORY@
 
 if [ `xe vdi-param-get uuid=${VDI} param-name=read-only` = "true" ] ; then 
     MODE=RO
diff --git a/scripts/xapi-autostart-vms b/scripts/xapi-autostart-vms
index 7dabdf8..d7c03ba 100755
--- a/scripts/xapi-autostart-vms
+++ b/scripts/xapi-autostart-vms
@@ -12,7 +12,7 @@
 XAPI_START_TIMEOUT_SECONDS=240
 
 # wait for xapi to complete initialisation for a max of XAPI_START_TIMEOUT_SECONDS
-/opt/xensource/bin/xapi-wait-init-complete ${XAPI_START_TIMEOUT_SECONDS}
+@BINDIR@/xapi-wait-init-complete ${XAPI_START_TIMEOUT_SECONDS}
 
 if [ $? -eq 0 ]; then
 
diff --git a/scripts/xapi-logrotate b/scripts/xapi-logrotate
index f0e8298..b197b97 100755
--- a/scripts/xapi-logrotate
+++ b/scripts/xapi-logrotate
@@ -3,6 +3,6 @@
 	size 16M
     sharedscripts
     postrotate
-	/opt/xensource/bin/xe log-reopen 2> /dev/null || true
+	@BINDIR@/xe log-reopen 2> /dev/null || true
     endscript
 }
diff --git a/scripts/xapi-rolling-upgrade-miami b/scripts/xapi-rolling-upgrade-miami
index a338914..c9797a5 100644
--- a/scripts/xapi-rolling-upgrade-miami
+++ b/scripts/xapi-rolling-upgrade-miami
@@ -7,8 +7,8 @@
 
 set -e
 
-. /etc/xensource-inventory
-XE="@BASE_PATH@/bin/xe"
+. @INVENTORY@
+XE="@BINDIR@/xe"
 
 # Clean all unreferenced patches out of the db now that the upgrade is complete.
 # When upgrading to 5.0, this should clean out all 4.1 patches at the end.
diff --git a/scripts/xapi.conf b/scripts/xapi.conf
index 31e7dbb..57578f3 100644
--- a/scripts/xapi.conf
+++ b/scripts/xapi.conf
@@ -1,7 +1,7 @@
 base_path = /opt/xensource
 
-schema_filename = /etc/xensource/db_schema.sql
-license_filename = /etc/xensource/license
+schema_filename = @ETCDIR@/db_schema.sql
+license_filename = @ETCDIR@/license
 
 http-port = 80
 
diff --git a/scripts/xe-backup-metadata b/scripts/xe-backup-metadata
index f1c30b9..ccb3706 100755
--- a/scripts/xe-backup-metadata
+++ b/scripts/xe-backup-metadata
@@ -4,14 +4,14 @@
 
 trap "cleanup" TERM INT
 
-if [ ! -e /etc/xensource-inventory ]; then
+if [ ! -e @INVENTORY@ ]; then
   echo Must run on a XenServer host.
   exit 1
 fi
 
-. /etc/xensource-inventory
+. @INVENTORY@
 
-XE="@BASE_PATH@/bin/xe"
+XE="@BINDIR@/xe"
 
 master_uuid=$(${XE} pool-list params=master --minimal)
 if [ $? -gt 0 ]; then
@@ -242,7 +242,7 @@ if [ ${leave_mounted} -eq 0 ]; then
   IFS=","
   echo -n "Backing up SR metadata: "
   mkdir -p ${metadir}
-  "@BASE_PATH@/libexec/backup-sr-metadata.py" -f ${metadir}/SRMETA.xml
+  "@LIBEXECDIR@/backup-sr-metadata.py" -f ${metadir}/SRMETA.xml
   echo "done"
 
   echo -n "Backing up VM metadata: "
@@ -255,14 +255,14 @@ if [ ${leave_mounted} -eq 0 ]; then
   echo "done"
   echo -n "Backing up Template metadata: "
   ${debug} echo ""
-  template_uuids=$("@BASE_PATH@/libexec/print-custom-templates")
+  template_uuids=$("@LIBEXECDIR@/print-custom-templates")
   if [ $? -eq 0 ]; then
       for tmpl_uuid in ${template_uuids}; do
           ${XE} template-export --metadata template-uuid=${tmpl_uuid} filename=${metadir}/all/${tmpl_uuid}.vmmeta >/dev/null 2>&1
       done
   fi
   echo "done"
-  "@BASE_PATH@/libexec/link-vms-by-sr.py" -d ${metadir}
+  "@LIBEXECDIR@/link-vms-by-sr.py" -d ${metadir}
 else
   cd ${mnt}
   env PS1="Mounted backup VDI on: ${mnt}\nPress ^D to exit shell and safely detach it.\n\n[\u@\h \W]\$ " bash
diff --git a/scripts/xe-edit-bootloader b/scripts/xe-edit-bootloader
index 2bab887..739bc45 100755
--- a/scripts/xe-edit-bootloader
+++ b/scripts/xe-edit-bootloader
@@ -4,14 +4,14 @@
 #
 # Script which lets you edit the grub.conf in a Linux guest virtual disk.
 
-if [ ! -e /etc/xensource-inventory ]; then
+if [ ! -e @INVENTORY@ ]; then
   echo Must run on a XenServer host.
   exit 1
 fi
 
-. /etc/xensource-inventory
+. @INVENTORY@
 
-XE="@BASE_PATH@/bin/xe"
+XE="@BINDIR@/xe"
 
 device_number=
 grub_conf=
diff --git a/scripts/xe-mount-iso-sr b/scripts/xe-mount-iso-sr
index d77426c..683053a 100755
--- a/scripts/xe-mount-iso-sr
+++ b/scripts/xe-mount-iso-sr
@@ -19,13 +19,13 @@ fi
 shift 1
 OPTIONS=$*
 
-XE="@BASE_PATH@/bin/xe"
+XE="@BINDIR@/xe"
 UUID=$(uuidgen)
 
 SR=$(${XE} sr-introduce name-label="Remote ISO Library on: ${LOCATION}" content-type=iso shared=true type=iso uuid=${UUID} physical-size=0)
 ${XE} sr-param-set other-config:auto-scan=true uuid=${UUID}
 
-. /etc/xensource-inventory 
+. @INVENTORY@ 
 
 PBD=$(${XE} pbd-create host-uuid=${INSTALLATION_UUID} sr-uuid=$SR device-config:location="${LOCATION}" device-config:options="${OPTIONS}")
 
diff --git a/scripts/xe-reset-networking b/scripts/xe-reset-networking
index 187649a..40ef9be 100644
--- a/scripts/xe-reset-networking
+++ b/scripts/xe-reset-networking
@@ -20,9 +20,9 @@ import time
 from optparse import OptionParser
 #import XenAPI
 
-pool_conf = '/etc/xensource/pool.conf'
-interface_reconfigure = "@BASE_PATH@/libexec/interface-reconfigure"
-inventory_file = '/etc/xensource-inventory'
+pool_conf = '@ETCDIR@/pool.conf'
+interface_reconfigure = "@LIBEXECDIR@/interface-reconfigure"
+inventory_file = '@INVENTORY@'
 management_conf = '/etc/firstboot.d/data/management.conf'
 network_reset = '/tmp/network-reset'
 
diff --git a/scripts/xe-restore-metadata b/scripts/xe-restore-metadata
index 05ee756..f7bb5fe 100755
--- a/scripts/xe-restore-metadata
+++ b/scripts/xe-restore-metadata
@@ -2,14 +2,14 @@
 # Script which restores metadata into a VDI
 # Citrix Systems Inc, 2008
 
-if [ ! -e /etc/xensource-inventory ]; then
+if [ ! -e @INVENTORY@ ]; then
   echo Must run on a XenServer host.
   exit 1
 fi
 
-. /etc/xensource-inventory
+. @INVENTORY@
 
-XE="@BASE_PATH@/bin/xe"
+XE="@BINDIR@/xe"
 
 master_uuid=$(${XE} pool-list params=master --minimal)
 if [ $? -gt 0 ]; then
@@ -170,7 +170,7 @@ for vdi_uuid in ${vdis}; do
    ${debug} echo ${device} >&2
 
    ${debug} echo -n "Probing device: " >&2
-   probecmd="@BASE_PATH@/libexec/probe-device-for-file"
+   probecmd="@LIBEXECDIR@/probe-device-for-file"
    metadata_stamp="/.ctxs-metadata-backup"
    mnt=
    ${probecmd} ${device} ${metadata_stamp}
@@ -287,7 +287,7 @@ for meta in *.vmmeta; do
    if [ ${dry_run} -gt 0 ]; then
        echo xe vm-import filename=${meta} sr-uuid=${sr_uuid} --metadata --preserve
    else
-       "@BASE_PATH@/bin/xe" vm-import filename="${full_dir}/${meta}" sr-uuid=${sr_uuid} --metadata --preserve
+       "@BINDIR@/xe" vm-import filename="${full_dir}/${meta}" sr-uuid=${sr_uuid} --metadata --preserve
        if [ $? -gt 0 ]; then
           error_count=$(( $error_count + 1 ))
        else
@@ -297,7 +297,7 @@ for meta in *.vmmeta; do
 done
 
 smmeta_file=${mnt}/metadata/${chosen_metadata_dir}/SRMETA.xml
-cmd="@BASE_PATH@/libexec/restore-sr-metadata.py -u ${sr_uuid} -f ${smmeta_file}"
+cmd="@LIBEXECDIR@/restore-sr-metadata.py -u ${sr_uuid} -f ${smmeta_file}"
 if [ -e ${smmeta_file} ]; then
     if [ ${dry_run} -gt 0 ]; then
         echo ${cmd}
diff --git a/scripts/xe-set-iscsi-iqn b/scripts/xe-set-iscsi-iqn
index b758847..9bbac25 100755
--- a/scripts/xe-set-iscsi-iqn
+++ b/scripts/xe-set-iscsi-iqn
@@ -6,12 +6,12 @@
 
 set -e
 
-XE="@BASE_PATH@/bin/xe"
+XE="@BINDIR@/xe"
 
 configmap="other-config"
 configkey="iscsi_iqn"
 
-if [ ! -f /etc/xensource-inventory ]; then
+if [ ! -f @INVENTORY@ ]; then
   echo Error: Not a XenServer host
   exit 1
 fi
@@ -28,7 +28,7 @@ else
   iqn="$1"
 fi
 
-. /etc/xensource-inventory
+. @INVENTORY@
 
 ${XE} host-param-remove uuid=${INSTALLATION_UUID} param-name=${configmap} param-key=${configkey} || true
 ${XE} host-param-set uuid=${INSTALLATION_UUID} ${configmap}-${configkey}=${iqn}
diff --git a/scripts/xe-toolstack-restart b/scripts/xe-toolstack-restart
index 9126616..2e99c99 100755
--- a/scripts/xe-toolstack-restart
+++ b/scripts/xe-toolstack-restart
@@ -12,7 +12,7 @@
 # GNU Lesser General Public License for more details.
 #
 
-POOLCONF=`cat /etc/xensource/pool.conf`
+POOLCONF=`cat @ETCDIR@/pool.conf`
 
 service xapi stop
 service v6d stop
@@ -20,13 +20,13 @@ service squeezed stop
 service perfmon stop
 service fe stop
 if [ $POOLCONF == "master" ]; then
-	/etc/xensource/master.d/03-mpathalert-daemon stop;
+	@ETCDIR@/master.d/03-mpathalert-daemon stop;
 fi
 
 set -e
 
 if [ $POOLCONF == "master" ]; then
-	/etc/xensource/master.d/03-mpathalert-daemon start;
+	@ETCDIR@/master.d/03-mpathalert-daemon start;
 fi
 service fe start
 service perfmon start
diff --git a/scripts/xe-xentrace b/scripts/xe-xentrace
index 6fb2416..2a8051d 100755
--- a/scripts/xe-xentrace
+++ b/scripts/xe-xentrace
@@ -30,14 +30,14 @@ done
 
 SIZE=$((${SIZE_GB} * 1024 * 1024 * 1024))
 
-if [ ! -e /etc/xensource-inventory ]; then
+if [ ! -e @INVENTORY@ ]; then
   echo Must run on a XenServer host.
   exit 1
 fi
 
-. /etc/xensource-inventory
+. @INVENTORY@
 
-XE="@BASE_PATH@/bin/xe"
+XE="@BINDIR@/xe"
 
 crashdump_sr=$(${XE} host-list params=crash-dump-sr-uuid --minimal uuid=${INSTALLATION_UUID})
 
diff --git a/scripts/xen-backend.agent b/scripts/xen-backend.agent
index d0909fe..a945101 100755
--- a/scripts/xen-backend.agent
+++ b/scripts/xen-backend.agent
@@ -2,15 +2,15 @@
 
 case "$XENBUS_TYPE" in
   tap)
-    /etc/xensource/scripts/tap "$ACTION"
+    @SCRIPTSDIR@/tap "$ACTION"
     ;;
   vbd)
-    /etc/xensource/scripts/block "$ACTION"
+    @SCRIPTSDIR@/block "$ACTION"
     ;;
   vtpm)
-    /etc/xensource/scripts/vtpm "$ACTION"
+    @SCRIPTSDIR@/vtpm "$ACTION"
     ;;
   vif)
-    /etc/xensource/scripts/vif "$ACTION"
+    @SCRIPTSDIR@/vif "$ACTION"
     ;;
 esac
diff --git a/scripts/xen-backend.rules b/scripts/xen-backend.rules
index 534b919..ef63888 100644
--- a/scripts/xen-backend.rules
+++ b/scripts/xen-backend.rules
@@ -1,7 +1,7 @@
-SUBSYSTEM=="xen-backend", KERNEL=="tap*", RUN+="/etc/xensource/scripts/tap $env{ACTION}"
-SUBSYSTEM=="xen-backend", KERNEL=="vbd*", RUN+="/etc/xensource/scripts/block $env{ACTION}"
+SUBSYSTEM=="xen-backend", KERNEL=="tap*", RUN+="@SCRIPTSDIR@/tap $env{ACTION}"
+SUBSYSTEM=="xen-backend", KERNEL=="vbd*", RUN+="@SCRIPTSDIR@/block $env{ACTION}"
 
-SUBSYSTEM=="xen-backend", KERNEL=="vif*", RUN+="/etc/xensource/scripts/vif $env{ACTION} vif"
-SUBSYSTEM=="net",         KERNEL=="tap*", RUN+="/etc/xensource/scripts/vif $env{ACTION} tap"
+SUBSYSTEM=="xen-backend", KERNEL=="vif*", RUN+="@SCRIPTSDIR@/vif $env{ACTION} vif"
+SUBSYSTEM=="net",         KERNEL=="tap*", RUN+="@SCRIPTSDIR@/vif $env{ACTION} tap"
 
 KERNEL=="evtchn", NAME="xen/%k"
diff --git a/scripts/xen-frontend.rules b/scripts/xen-frontend.rules
index 266ceab..001c58c 100755
--- a/scripts/xen-frontend.rules
+++ b/scripts/xen-frontend.rules
@@ -1 +1 @@
-SUBSYSTEM=="block", KERNEL=="xvd*", RUN+="/etc/xensource/scripts/block-frontend $env{ACTION} $number"
+SUBSYSTEM=="block", KERNEL=="xvd*", RUN+="@SCRIPTSDIR@/block-frontend $env{ACTION} $number"
diff --git a/xapi.spec.in b/xapi.spec.in
index ace6a26..4531ca5 100644
--- a/xapi.spec.in
+++ b/xapi.spec.in
@@ -123,7 +123,7 @@ rm -rf $RPM_BUILD_ROOT
 
 %files core
 %defattr(-,root,root,-)
-@BASE_PATH@/bin/xapi
+@OPTDIR@/bin/xapi
 /etc/xapi.conf
 /etc/logrotate.d/audit
 /etc/logrotate.d/v6d
@@ -173,91 +173,91 @@ rm -rf $RPM_BUILD_ROOT
 /etc/xensource/scripts/tap
 /etc/xensource/scripts/vif
 /etc/xensource/scripts/block
-@BASE_PATH@/bin/fix_firewall.sh
-@BASE_PATH@/bin/list_domains
-@BASE_PATH@/bin/mpathalert
-@BASE_PATH@/bin/perfmon
-@BASE_PATH@/bin/static-vdis
-@BASE_PATH@/bin/v6d-reopen-logs
-@BASE_PATH@/bin/xapi-autostart-vms
-@BASE_PATH@/bin/xapi-db-process
-@BASE_PATH@/bin/xapi-wait-init-complete
-@BASE_PATH@/bin/xe-backup-metadata
-@BASE_PATH@/bin/xe-edit-bootloader
-@BASE_PATH@/bin/xe-mount-iso-sr
-@BASE_PATH@/bin/xe-restore-metadata
-@BASE_PATH@/bin/xe-reset-networking
-@BASE_PATH@/bin/xe-scsi-dev-map
-@BASE_PATH@/bin/xe-set-iscsi-iqn
-@BASE_PATH@/bin/xe-toolstack-restart
-@BASE_PATH@/bin/xe-xentrace
-@BASE_PATH@/bin/xsh
+@OPTDIR@/bin/fix_firewall.sh
+@OPTDIR@/bin/list_domains
+@OPTDIR@/bin/mpathalert
+@OPTDIR@/bin/perfmon
+@OPTDIR@/bin/static-vdis
+@OPTDIR@/bin/v6d-reopen-logs
+@OPTDIR@/bin/xapi-autostart-vms
+@OPTDIR@/bin/xapi-db-process
+@OPTDIR@/bin/xapi-wait-init-complete
+@OPTDIR@/bin/xe-backup-metadata
+@OPTDIR@/bin/xe-edit-bootloader
+@OPTDIR@/bin/xe-mount-iso-sr
+@OPTDIR@/bin/xe-restore-metadata
+@OPTDIR@/bin/xe-reset-networking
+@OPTDIR@/bin/xe-scsi-dev-map
+@OPTDIR@/bin/xe-set-iscsi-iqn
+@OPTDIR@/bin/xe-toolstack-restart
+@OPTDIR@/bin/xe-xentrace
+@OPTDIR@/bin/xsh
 /etc/xensource/bugtool/xapi.xml
 /etc/xensource/bugtool/xapi/stuff.xml
-@BASE_PATH@/libexec/sm_diagnostics
-@BASE_PATH@/libexec/thread_diagnostics
-@BASE_PATH@/libexec/fakeguestagent
-@BASE_PATH@/libexec/InterfaceReconfigure.py
-@BASE_PATH@/libexec/InterfaceReconfigure.pyo
-@BASE_PATH@/libexec/InterfaceReconfigure.pyc
-@BASE_PATH@/libexec/InterfaceReconfigureBridge.py
-@BASE_PATH@/libexec/InterfaceReconfigureBridge.pyo
-@BASE_PATH@/libexec/InterfaceReconfigureBridge.pyc
-@BASE_PATH@/libexec/InterfaceReconfigureVswitch.py
-@BASE_PATH@/libexec/InterfaceReconfigureVswitch.pyo
-@BASE_PATH@/libexec/InterfaceReconfigureVswitch.pyc
-@BASE_PATH@/libexec/backup-metadata-cron
-@BASE_PATH@/libexec/backup-sr-metadata.py
-@BASE_PATH@/libexec/backup-sr-metadata.pyo
-@BASE_PATH@/libexec/backup-sr-metadata.pyc
-@BASE_PATH@/libexec/block_device_io
-@BASE_PATH@/libexec/cdrommon
-@BASE_PATH@/libexec/dumpcore
-@BASE_PATH@/libexec/fence
-@BASE_PATH@/libexec/fence.bin
-@BASE_PATH@/libexec/generate_ssl_cert
-@BASE_PATH@/libexec/host-backup
-@BASE_PATH@/libexec/host-bugreport-upload
-@BASE_PATH@/libexec/host-restore
-@BASE_PATH@/libexec/interface-reconfigure
-@BASE_PATH@/libexec/interface-visualise
-@BASE_PATH@/libexec/license-check.py
-@BASE_PATH@/libexec/license-check.pyo
-@BASE_PATH@/libexec/license-check.pyc
-@BASE_PATH@/libexec/link-vms-by-sr.py
-@BASE_PATH@/libexec/link-vms-by-sr.pyo
-@BASE_PATH@/libexec/link-vms-by-sr.pyc
-@BASE_PATH@/libexec/logrotate.sh
-@BASE_PATH@/libexec/logs-download
-@BASE_PATH@/libexec/lw-force-domain-leave
-@BASE_PATH@/libexec/mail-alarm
-@BASE_PATH@/libexec/print-custom-templates
-@BASE_PATH@/libexec/probe-device-for-file
-@BASE_PATH@/libexec/genptoken
-@BASE_PATH@/libexec/qemu-dm-wrapper
-@BASE_PATH@/libexec/restore-sr-metadata.py
-@BASE_PATH@/libexec/restore-sr-metadata.pyo
-@BASE_PATH@/libexec/restore-sr-metadata.pyc
-@BASE_PATH@/libexec/rewrite-management-interface
-@BASE_PATH@/libexec/set-dom0-memory-target-from-packs
-@BASE_PATH@/libexec/set-hostname
-@BASE_PATH@/libexec/shell.py
-@BASE_PATH@/libexec/shell.pyo
-@BASE_PATH@/libexec/shell.pyc
-@BASE_PATH@/libexec/shutdown
-@BASE_PATH@/libexec/sparse_dd
-@BASE_PATH@/libexec/update-mh-info
-@BASE_PATH@/libexec/upload-wrapper
-@BASE_PATH@/libexec/vncterm-wrapper
-@BASE_PATH@/libexec/xapi-health-check
-@BASE_PATH@/libexec/xapi-rolling-upgrade
-@BASE_PATH@/libexec/xenguest
-@BASE_PATH@/libexec/xha-lc
-@BASE_PATH@/libexec/xiu
-@BASE_PATH@/lib/libxenctrl_xiu.so
-@BASE_PATH@/libexec/pci-info
-@BASE_PATH@/packages/post-install-scripts/debian-etch
-@BASE_PATH@/packages/post-install-scripts/debug
+@OPTDIR@/libexec/sm_diagnostics
+@OPTDIR@/libexec/thread_diagnostics
+@OPTDIR@/libexec/fakeguestagent
+@OPTDIR@/libexec/InterfaceReconfigure.py
+@OPTDIR@/libexec/InterfaceReconfigure.pyo
+@OPTDIR@/libexec/InterfaceReconfigure.pyc
+@OPTDIR@/libexec/InterfaceReconfigureBridge.py
+@OPTDIR@/libexec/InterfaceReconfigureBridge.pyo
+@OPTDIR@/libexec/InterfaceReconfigureBridge.pyc
+@OPTDIR@/libexec/InterfaceReconfigureVswitch.py
+@OPTDIR@/libexec/InterfaceReconfigureVswitch.pyo
+@OPTDIR@/libexec/InterfaceReconfigureVswitch.pyc
+@OPTDIR@/libexec/backup-metadata-cron
+@OPTDIR@/libexec/backup-sr-metadata.py
+@OPTDIR@/libexec/backup-sr-metadata.pyo
+@OPTDIR@/libexec/backup-sr-metadata.pyc
+@OPTDIR@/libexec/block_device_io
+@OPTDIR@/libexec/cdrommon
+@OPTDIR@/libexec/dumpcore
+@OPTDIR@/libexec/fence
+@OPTDIR@/libexec/fence.bin
+@OPTDIR@/libexec/generate_ssl_cert
+@OPTDIR@/libexec/host-backup
+@OPTDIR@/libexec/host-bugreport-upload
+@OPTDIR@/libexec/host-restore
+@OPTDIR@/libexec/interface-reconfigure
+@OPTDIR@/libexec/interface-visualise
+@OPTDIR@/libexec/license-check.py
+@OPTDIR@/libexec/license-check.pyo
+@OPTDIR@/libexec/license-check.pyc
+@OPTDIR@/libexec/link-vms-by-sr.py
+@OPTDIR@/libexec/link-vms-by-sr.pyo
+@OPTDIR@/libexec/link-vms-by-sr.pyc
+@OPTDIR@/libexec/logrotate.sh
+@OPTDIR@/libexec/logs-download
+@OPTDIR@/libexec/lw-force-domain-leave
+@OPTDIR@/libexec/mail-alarm
+@OPTDIR@/libexec/print-custom-templates
+@OPTDIR@/libexec/probe-device-for-file
+@OPTDIR@/libexec/genptoken
+@OPTDIR@/libexec/qemu-dm-wrapper
+@OPTDIR@/libexec/restore-sr-metadata.py
+@OPTDIR@/libexec/restore-sr-metadata.pyo
+@OPTDIR@/libexec/restore-sr-metadata.pyc
+@OPTDIR@/libexec/rewrite-management-interface
+@OPTDIR@/libexec/set-dom0-memory-target-from-packs
+@OPTDIR@/libexec/set-hostname
+@OPTDIR@/libexec/shell.py
+@OPTDIR@/libexec/shell.pyo
+@OPTDIR@/libexec/shell.pyc
+@OPTDIR@/libexec/shutdown
+@OPTDIR@/libexec/sparse_dd
+@OPTDIR@/libexec/update-mh-info
+@OPTDIR@/libexec/upload-wrapper
+@OPTDIR@/libexec/vncterm-wrapper
+@OPTDIR@/libexec/xapi-health-check
+@OPTDIR@/libexec/xapi-rolling-upgrade
+@OPTDIR@/libexec/xenguest
+@OPTDIR@/libexec/xha-lc
+@OPTDIR@/libexec/xiu
+@OPTDIR@/lib/libxenctrl_xiu.so
+@OPTDIR@/libexec/pci-info
+@OPTDIR@/packages/post-install-scripts/debian-etch
+@OPTDIR@/packages/post-install-scripts/debug
 /usr/lib/python2.4/site-packages/XenAPI.py
 /usr/lib/python2.4/site-packages/XenAPI.pyo
 /usr/lib/python2.4/site-packages/XenAPI.pyc
@@ -270,110 +270,110 @@ rm -rf $RPM_BUILD_ROOT
 %exclude   /usr/lib/python2.4/site-packages/xen/*
 %exclude   /usr/lib/python2.4/site-packages/xen/lowlevel/*
 /var/xapi/udhcpd.skel
-@BASE_PATH@/debug/rbac_static.csv
+@OPTDIR@/debug/rbac_static.csv
 /etc/xapi.d/host-post-declare-dead/10resetvdis
 
 %files xe
 %defattr(-,root,root,-)
-@BASE_PATH@/bin/xe
-@BASE_PATH@/debug/sm
+@OPTDIR@/bin/xe
+@OPTDIR@/debug/sm
 /usr/bin/xe
 /etc/bash_completion.d/xe
 
 %files squeezed
 %defattr(-,root,root,-)
-@BASE_PATH@/libexec/squeezed
+@OPTDIR@/libexec/squeezed
 /etc/logrotate.d/squeezed
 /etc/rc.d/init.d/squeezed
-@BASE_PATH@/bin/squeezed_client
+@OPTDIR@/bin/squeezed_client
 
 %files v6d
 %defattr(-,root,root,-)
-@BASE_PATH@/libexec/v6d
+@OPTDIR@/libexec/v6d
 /etc/rc.d/init.d/v6d
 
 %files xenops
 %defattr(-,root,root,-)
-@BASE_PATH@/debug/xenops
-@BASE_PATH@/debug/add_vbd
-@BASE_PATH@/debug/add_vif
-@BASE_PATH@/debug/build_domain
-@BASE_PATH@/debug/build_hvm
-@BASE_PATH@/debug/create_domain
-@BASE_PATH@/debug/debug_ha_query_liveset
-@BASE_PATH@/debug/destroy_domain
-@BASE_PATH@/debug/event_listen
-@BASE_PATH@/debug/graph
-@BASE_PATH@/debug/memory_breakdown
-@BASE_PATH@/debug/memory_summary
-@BASE_PATH@/debug/pause_domain
-@BASE_PATH@/debug/restore_domain
-@BASE_PATH@/debug/rrddump
-@BASE_PATH@/debug/shutdown_domain
-@BASE_PATH@/debug/sm_stress
-@BASE_PATH@/debug/suspend_domain
-@BASE_PATH@/debug/unpause_domain
-@BASE_PATH@/debug/vncproxy
-@BASE_PATH@/debug/with-vdi
-@BASE_PATH@/debug/xal
-@BASE_PATH@/debug/xs
+@OPTDIR@/debug/xenops
+@OPTDIR@/debug/add_vbd
+@OPTDIR@/debug/add_vif
+@OPTDIR@/debug/build_domain
+@OPTDIR@/debug/build_hvm
+@OPTDIR@/debug/create_domain
+@OPTDIR@/debug/debug_ha_query_liveset
+@OPTDIR@/debug/destroy_domain
+@OPTDIR@/debug/event_listen
+@OPTDIR@/debug/graph
+@OPTDIR@/debug/memory_breakdown
+@OPTDIR@/debug/memory_summary
+@OPTDIR@/debug/pause_domain
+@OPTDIR@/debug/restore_domain
+@OPTDIR@/debug/rrddump
+@OPTDIR@/debug/shutdown_domain
+@OPTDIR@/debug/sm_stress
+@OPTDIR@/debug/suspend_domain
+@OPTDIR@/debug/unpause_domain
+@OPTDIR@/debug/vncproxy
+@OPTDIR@/debug/with-vdi
+@OPTDIR@/debug/xal
+@OPTDIR@/debug/xs
 
 %files www
 %defattr(-,root,root,-)
-#@BASE_PATH@/debug/www/XenServerConsole.jar
-@BASE_PATH@/debug/www/api.js
-@BASE_PATH@/debug/www/apicall.css
-@BASE_PATH@/debug/www/apicall.js
-@BASE_PATH@/debug/www/construct_tree.js
-@BASE_PATH@/debug/www/devweb.css
-@BASE_PATH@/debug/www/devweb.js
-@BASE_PATH@/debug/www/editables.js
-@BASE_PATH@/debug/www/graphs.js
-@BASE_PATH@/debug/www/haplan.css
-@BASE_PATH@/debug/www/haplan.js
-@BASE_PATH@/debug/www/images/xen_logo.gif
-@BASE_PATH@/debug/www/index.html
-@BASE_PATH@/debug/www/jquery/jqDnR.css
-@BASE_PATH@/debug/www/jquery/jqDnR.js
-@BASE_PATH@/debug/www/jquery/jqModal.css
-@BASE_PATH@/debug/www/jquery/jqModal.js
-@BASE_PATH@/debug/www/jquery/jquery-1.3.2.js
-@BASE_PATH@/debug/www/jquery/jquery-dom.js
-@BASE_PATH@/debug/www/jquery/jquery.autocomplete.css
-@BASE_PATH@/debug/www/jquery/jquery.autocomplete.js
-@BASE_PATH@/debug/www/jquery/jquery.bgiframe.js
-@BASE_PATH@/debug/www/jquery/jquery.color.js
-@BASE_PATH@/debug/www/jquery/jquery.cookie.js
-@BASE_PATH@/debug/www/jquery/jquery.jeditable.js
-@BASE_PATH@/debug/www/jquery/jquery.rpc.js
-@BASE_PATH@/debug/www/jquery/jquery.treeview.js
-@BASE_PATH@/debug/www/main.js
-@BASE_PATH@/debug/www/messages.js
-@BASE_PATH@/debug/www/networks.css
-@BASE_PATH@/debug/www/networks.js
-@BASE_PATH@/debug/www/objectviewoverrides.js
-@BASE_PATH@/debug/www/offline.js
-@BASE_PATH@/debug/www/process_rrd.js
-@BASE_PATH@/debug/www/tree.css
-@BASE_PATH@/debug/www/vmsearch.js
-@BASE_PATH@/debug/www/xenapi.js
+#@OPTDIR@/debug/www/XenServerConsole.jar
+@OPTDIR@/debug/www/api.js
+@OPTDIR@/debug/www/apicall.css
+@OPTDIR@/debug/www/apicall.js
+@OPTDIR@/debug/www/construct_tree.js
+@OPTDIR@/debug/www/devweb.css
+@OPTDIR@/debug/www/devweb.js
+@OPTDIR@/debug/www/editables.js
+@OPTDIR@/debug/www/graphs.js
+@OPTDIR@/debug/www/haplan.css
+@OPTDIR@/debug/www/haplan.js
+@OPTDIR@/debug/www/images/xen_logo.gif
+@OPTDIR@/debug/www/index.html
+@OPTDIR@/debug/www/jquery/jqDnR.css
+@OPTDIR@/debug/www/jquery/jqDnR.js
+@OPTDIR@/debug/www/jquery/jqModal.css
+@OPTDIR@/debug/www/jquery/jqModal.js
+@OPTDIR@/debug/www/jquery/jquery-1.3.2.js
+@OPTDIR@/debug/www/jquery/jquery-dom.js
+@OPTDIR@/debug/www/jquery/jquery.autocomplete.css
+@OPTDIR@/debug/www/jquery/jquery.autocomplete.js
+@OPTDIR@/debug/www/jquery/jquery.bgiframe.js
+@OPTDIR@/debug/www/jquery/jquery.color.js
+@OPTDIR@/debug/www/jquery/jquery.cookie.js
+@OPTDIR@/debug/www/jquery/jquery.jeditable.js
+@OPTDIR@/debug/www/jquery/jquery.rpc.js
+@OPTDIR@/debug/www/jquery/jquery.treeview.js
+@OPTDIR@/debug/www/main.js
+@OPTDIR@/debug/www/messages.js
+@OPTDIR@/debug/www/networks.css
+@OPTDIR@/debug/www/networks.js
+@OPTDIR@/debug/www/objectviewoverrides.js
+@OPTDIR@/debug/www/offline.js
+@OPTDIR@/debug/www/process_rrd.js
+@OPTDIR@/debug/www/tree.css
+@OPTDIR@/debug/www/vmsearch.js
+@OPTDIR@/debug/www/xenapi.js
 
 %files tests
 %defattr(-,root,root,-)
 /etc/xapi.d/plugins/lvhdrt-helper
 /etc/xapi.d/plugins/lvhdrt-trash-vdi
 /etc/xapi.d/plugins/multipathrt-helper
-@BASE_PATH@/debug/cli-rt-domu-shar.sh
-@BASE_PATH@/debug/cli_test
-@BASE_PATH@/debug/install-debian-pv-inside.sh
-@BASE_PATH@/debug/install-debian-pv.sh
-@BASE_PATH@/debug/lvhdrt
-@BASE_PATH@/debug/multipathrt
-@BASE_PATH@/debug/myfirstpatch.asc
-@BASE_PATH@/debug/perftest
-@BASE_PATH@/debug/quicktest
-@BASE_PATH@/debug/quicktestbin
-@BASE_PATH@/debug/watch_test
+@OPTDIR@/debug/cli-rt-domu-shar.sh
+@OPTDIR@/debug/cli_test
+@OPTDIR@/debug/install-debian-pv-inside.sh
+@OPTDIR@/debug/install-debian-pv.sh
+@OPTDIR@/debug/lvhdrt
+@OPTDIR@/debug/multipathrt
+@OPTDIR@/debug/myfirstpatch.asc
+@OPTDIR@/debug/perftest
+@OPTDIR@/debug/quicktest
+@OPTDIR@/debug/quicktestbin
+@OPTDIR@/debug/watch_test
 /cli-rt/*
 /etc/xapi.d/plugins/monitor_fake_plugin
 
-- 
