commit 93b69b36a88d8a36ac0cc13c16bd690118f315e7
Author: Richard Hughes <richard@hughsie.com>
Date:   Thu Sep 3 10:01:14 2009 +0100

    Allow compile without HAL. Inspired from a patch from Javier Jardón, many thanks.

diff --git a/Makefile.am b/Makefile.am
index 6c225e6..d0d7c63 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -2,7 +2,6 @@
 ACLOCAL_AMFLAGS = -I m4
 
 SUBDIRS = 						\
-	libhal-glib					\
 	src						\
 	po						\
 	docs						\
@@ -15,6 +14,10 @@ if HAVE_APPLETS
 SUBDIRS += applets
 endif
 
+if HAVE_HAL
+SUBDIRS += libhal-glib
+endif
+
 EXTRA_DIST =						\
 	HACKING						\
 	MAINTAINERS					\
diff --git a/configure.ac b/configure.ac
index a44b1ad..e038b52 100644
--- a/configure.ac
+++ b/configure.ac
@@ -95,7 +95,6 @@ GTK_REQUIRED=2.11.0
 GDK_REQUIRED=2.11.0
 GCONF_REQUIRED=2.10.0
 GNOME_KEYRING_REQUIRED=0.6.0
-HAL_REQUIRED=0.5.8
 DBUS_REQUIRED=0.70
 LIBNOTIFY_REQUIRED=0.4.3
 LIBWNCK_REQUIRED=2.10.0
@@ -112,7 +111,6 @@ dnl ---------------------------------------------------------------------------
 AC_SUBST(GLIB_REQUIRED)
 AC_SUBST(GTK_REQUIRED)
 AC_SUBST(GDK_REQUIRED)
-AC_SUBST(HAL_REQUIRED)
 AC_SUBST(DBUS_REQUIRED)
 AC_SUBST(LIBNOTIFY_REQUIRED)
 AC_SUBST(LIBWNCK_REQUIRED)
@@ -128,10 +126,6 @@ PKG_CHECK_MODULES(GLIB, glib-2.0 >= $GLIB_REQUIRED gobject-2.0)
 AC_SUBST(GLIB_CFLAGS)
 AC_SUBST(GLIB_LIBS)
 
-PKG_CHECK_MODULES(HAL, hal >= $HAL_REQUIRED)
-AC_SUBST(HAL_CFLAGS)
-AC_SUBST(HAL_LIBS)
-
 PKG_CHECK_MODULES(CANBERRA, libcanberra-gtk >= $CANBERRA_REQUIRED)
 AC_SUBST(CANBERRA_CFLAGS)
 AC_SUBST(CANBERRA_LIBS)
@@ -234,6 +228,19 @@ dnl ---------------------------------------------------------------------------
 AC_PATH_PROG(DEVKIT_POWER, devkit-power)
 
 dnl ---------------------------------------------------------------------------
+dnl - HAL support
+dnl ---------------------------------------------------------------------------
+AC_ARG_ENABLE(hal, AS_HELP_STRING([--enable-hal],[Build using HAL support]),
+	      enable_hal=$enableval,enable_hal=yes)
+if test x$enable_hal = xyes; then
+	AC_DEFINE(HAVE_HAL, 1, [Define if we have HAL support])
+	PKG_CHECK_MODULES(HAL, hal >= 0.5.8)
+	AC_SUBST(HAL_CFLAGS)
+	AC_SUBST(HAL_LIBS)
+fi
+AM_CONDITIONAL([HAVE_HAL], [test $enable_hal = yes])
+
+dnl ---------------------------------------------------------------------------
 dnl - Use check-foreground-console (Ubuntu specific) support?
 dnl ---------------------------------------------------------------------------
 AC_ARG_ENABLE(checkfg,
@@ -631,6 +638,7 @@ echo "
         compiler:                  ${CC}
         cflags:                    ${CFLAGS}
         Building extra applets:    ${enable_applets}
+        HAL support:               ${enable_hal}
         DPMS support:              ${have_dpms}
         Self test support:         ${have_tests}
         GConf default support:     ${have_gconfdefaults}
diff --git a/src/Makefile.am b/src/Makefile.am
index 14f2fe1..e89d816 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -38,8 +38,10 @@ INCLUDES =						\
 	-I$(top_srcdir)/libhal-glib			\
 	$(NULL)
 
+if HAVE_HAL
 LOCAL_LIBHAL_LIBS =					\
 	$(top_builddir)/libhal-glib/libhal.la
+endif
 
 bin_PROGRAMS =						\
 	gnome-power-manager				\
@@ -115,10 +117,13 @@ gnome_power_preferences_LDADD =				\
 	$(DBUS_LIBS)					\
 	$(UNIQUE_LIBS)					\
 	$(GPM_EXTRA_LIBS)				\
-	$(LOCAL_LIBHAL_LIBS)				\
 	$(DEVKIT_LIBS)					\
 	$(NULL)
 
+if HAVE_HAL
+gnome_power_preferences_LDADD += $(LOCAL_LIBHAL_LIBS)
+endif
+
 gnome_power_preferences_CFLAGS =			\
 	$(WARNINGFLAGS)					\
 	$(NULL)
@@ -144,8 +149,6 @@ gnome_power_manager_SOURCES =				\
 	gpm-button.c					\
 	gpm-brightness.h				\
 	gpm-brightness.c				\
-	gpm-brightness-hal.h				\
-	gpm-brightness-hal.c				\
 	gpm-brightness-xrandr.h				\
 	gpm-brightness-xrandr.c				\
 	gpm-main.c					\
@@ -166,6 +169,13 @@ gnome_power_manager_SOURCES =				\
 	gpm-engine.c					\
 	$(NULL)
 
+if HAVE_HAL
+gnome_power_manager_SOURCES += 				\
+	gpm-brightness-hal.h				\
+	gpm-brightness-hal.c				\
+	$(NULL)
+endif
+
 gnome_power_manager_LDADD =				\
 	libgpmshared.a					\
 	$(GLIB_LIBS)					\
@@ -177,10 +187,13 @@ gnome_power_manager_LDADD =				\
 	$(CANBERRA_LIBS)				\
 	$(LIBNOTIFY_LIBS)				\
 	$(GPM_EXTRA_LIBS)				\
-	$(LOCAL_LIBHAL_LIBS)				\
 	$(DEVKIT_LIBS)					\
 	$(NULL)
 
+if HAVE_HAL
+gnome_power_preferences_LDADD += $(LOCAL_LIBHAL_LIBS)
+endif
+
 gnome_power_manager_CFLAGS =				\
 	$(WARNINGFLAGS)					\
 	$(NULL)
@@ -244,10 +257,13 @@ gnome_power_self_test_LDADD =				\
 	$(DEVKIT_LIBS)					\
 	$(DBUS_LIBS)					\
 	$(LIBNOTIFY_LIBS)				\
-	$(LOCAL_LIBHAL_LIBS)				\
 	$(GPM_EXTRA_LIBS)				\
 	$(NULL)
 
+if HAVE_HAL
+gnome_power_self_test_LDADD += $(LOCAL_LIBHAL_LIBS)
+endif
+
 gnome_power_self_test_CFLAGS = -DEGG_TEST $(AM_CFLAGS) $(WARNINGFLAGS)
 
 BUILT_SOURCES = 					\
diff --git a/src/gpm-brightness.c b/src/gpm-brightness.c
index f45508f..6d2d3a1 100644
--- a/src/gpm-brightness.c
+++ b/src/gpm-brightness.c
@@ -36,7 +36,9 @@
 #endif /* HAVE_UNISTD_H */
 
 #include "gpm-brightness.h"
+#ifdef HAVE_HAL
 #include "gpm-brightness-hal.h"
+#endif
 #include "gpm-brightness-xrandr.h"
 #include "gpm-common.h"
 #include "egg-debug.h"
@@ -48,11 +50,15 @@
 struct GpmBrightnessPrivate
 {
 	gboolean		 use_xrandr;
+#ifdef HAVE_HAL
 	gboolean		 use_hal;
+#endif
 	gboolean		 has_changed_events;
 	gboolean		 cache_trusted;
 	guint			 cache_percentage;
+#ifdef HAVE_HAL
 	GpmBrightnessHal	*hal;
+#endif
 	GpmBrightnessXRandR	*xrandr;
 };
 
@@ -135,12 +141,14 @@ gpm_brightness_set (GpmBrightness *brightness, guint percentage, gboolean *hw_ch
 		egg_warning ("failed to set using xrandr, falling back to HAL");
 		brightness->priv->use_xrandr = FALSE;
 	}
+#ifdef HAVE_HAL
 	if (brightness->priv->use_hal) {
 		ret = gpm_brightness_hal_set (brightness->priv->hal, percentage, &hw_changed_local);
 		if (ret)
 			goto out;
 		egg_warning ("failed to set using HAL");
 	}
+#endif
 	egg_debug ("no hardware support");
 	return FALSE;
 out:
@@ -188,12 +196,14 @@ gpm_brightness_get (GpmBrightness *brightness, guint *percentage)
 		egg_warning ("failed to set using xrandr, falling back to HAL");
 		brightness->priv->use_xrandr = FALSE;
 	}
+#ifdef HAVE_HAL
 	if (brightness->priv->use_hal) {
 		ret = gpm_brightness_hal_get (brightness->priv->hal, &percentage_local);
 		if (ret)
 			goto out;
 		egg_warning ("failed to set using HAL");
 	}
+#endif
 	egg_debug ("no hardware support");
 	return FALSE;
 out:
@@ -236,12 +246,14 @@ gpm_brightness_up (GpmBrightness *brightness, gboolean *hw_changed)
 		egg_warning ("failed to set using xrandr, falling back to HAL");
 		brightness->priv->use_xrandr = FALSE;
 	}
+#ifdef HAVE_HAL
 	if (brightness->priv->use_hal) {
 		ret = gpm_brightness_hal_up (brightness->priv->hal, &hw_changed_local);
 		if (ret)
 			goto out;
 		egg_warning ("failed to set using HAL");
 	}
+#endif
 	egg_debug ("no hardware support");
 	return FALSE;
 out:
@@ -278,12 +290,14 @@ gpm_brightness_down (GpmBrightness *brightness, gboolean *hw_changed)
 		egg_warning ("failed to set using xrandr, falling back to HAL");
 		brightness->priv->use_xrandr = FALSE;
 	}
+#ifdef HAVE_HAL
 	if (brightness->priv->use_hal) {
 		ret = gpm_brightness_hal_down (brightness->priv->hal, &hw_changed_local);
 		if (ret)
 			goto out;
 		egg_warning ("failed to set using HAL");
 	}
+#endif
 	egg_debug ("no hardware support");
 	return FALSE;
 out:
@@ -304,7 +318,11 @@ gboolean
 gpm_brightness_has_hw (GpmBrightness *brightness)
 {
 	g_return_val_if_fail (GPM_IS_BRIGHTNESS (brightness), FALSE);
+#ifdef HAVE_HAL
 	return (brightness->priv->use_xrandr || brightness->priv->use_hal);
+#else
+	return brightness->priv->use_xrandr;
+#endif
 }
 
 /**
@@ -317,7 +335,9 @@ gpm_brightness_finalize (GObject *object)
 	g_return_if_fail (object != NULL);
 	g_return_if_fail (GPM_IS_BRIGHTNESS (object));
 	brightness = GPM_BRIGHTNESS (object);
+#ifdef HAVE_HAL
 	g_object_unref (brightness->priv->hal);
+#endif
 	g_object_unref (brightness->priv->xrandr);
 	G_OBJECT_CLASS (gpm_brightness_parent_class)->finalize (object);
 }
@@ -380,6 +400,7 @@ gpm_brightness_xrandr_changed_cb (GpmBrightnessXRandR *xrandr, guint percentage,
 		gpm_brightness_changed (brightness, percentage);
 }
 
+#ifdef HAVE_HAL
 /**
  * gpm_brightness_hal_changed_cb:
  * This callback is called when the brightness value changes.
@@ -391,6 +412,7 @@ gpm_brightness_hal_changed_cb (GpmBrightnessHal *hal, guint percentage, GpmBrigh
 	if (brightness->priv->use_hal)
 		gpm_brightness_changed (brightness, percentage);
 }
+#endif
 
 /**
  * gpm_brightness_init:
@@ -402,7 +424,9 @@ gpm_brightness_init (GpmBrightness *brightness)
 	brightness->priv = GPM_BRIGHTNESS_GET_PRIVATE (brightness);
 
 	brightness->priv->use_xrandr = FALSE;
+#ifdef HAVE_HAL
 	brightness->priv->use_hal = FALSE;
+#endif
 	brightness->priv->cache_trusted = FALSE;
 	brightness->priv->has_changed_events = FALSE;
 	brightness->priv->cache_percentage = 0;
@@ -412,6 +436,9 @@ gpm_brightness_init (GpmBrightness *brightness)
 		egg_debug ("detected XRANDR hardware");
 		brightness->priv->use_xrandr = TRUE;
 	}
+	g_signal_connect (brightness->priv->xrandr, "brightness-changed",
+			  G_CALLBACK (gpm_brightness_xrandr_changed_cb), brightness);
+#ifdef HAVE_HAL
 	brightness->priv->hal = gpm_brightness_hal_new ();
 	if (gpm_brightness_hal_has_hw (brightness->priv->hal)) {
 		egg_debug ("detected HAL hardware");
@@ -419,8 +446,7 @@ gpm_brightness_init (GpmBrightness *brightness)
 	}
 	g_signal_connect (brightness->priv->hal, "brightness-changed",
 			  G_CALLBACK (gpm_brightness_hal_changed_cb), brightness);
-	g_signal_connect (brightness->priv->xrandr, "brightness-changed",
-			  G_CALLBACK (gpm_brightness_xrandr_changed_cb), brightness);
+#endif
 }
 
 /**
