# Info for make, this will be preprocessed by autoconf.
prefix		= @prefix@
exec_prefix 	= @exec_prefix@
datarootdir	= @datarootdir@
bindir		= @bindir@
icondir		= @datadir@/icons/wmbattery
man1dir		= @mandir@/man1
srcdir		= @srcdir@

PACKAGE_NAME    = @PACKAGE_NAME@
PACKAGE_TARNAME = @PACKAGE_TARNAME@
PACKAGE_VERSION = @PACKAGE_VERSION@

CC		= @CC@
CFLAGS		= @CFLAGS@ -Wall @Xlib_CFLAGS@ @Xext_CFLAGS@ @libXpm_CFLAGS@
CPPFLAGS	= @CPPFLAGS@ -DACPI_APM -DICONDIR=\"$(icondir)\"
INSTALL		= @INSTALL@
INSTALL_DATA	= @INSTALL_DATA@
INSTALL_PROGRAM	= @INSTALL_PROGRAM@
LDFLAGS		= @LDFLAGS@
LIBS		= @LIBS@ @Xlib_LIBS@ @Xext_LIBS@ @libXpm_LIBS@
USE_HAL         = @USE_HAL@
USE_UPOWER      = @USE_UPOWER@
USE_ENVSYS      = @USE_ENVSYS@

all: wmbattery

clean:
	rm -f wmbattery *.o

distclean: clean
	rm -rf autom4te.cache config.status config.cache config.log config.h \
		Makefile

install: all
	$(INSTALL) -d $(DESTDIR)$(bindir) $(DESTDIR)$(man1dir) $(DESTDIR)$(icondir)
	$(INSTALL_PROGRAM) wmbattery $(DESTDIR)$(bindir)
	$(INSTALL_DATA) $(srcdir)/wmbattery.1 $(DESTDIR)$(man1dir)/wmbattery.1
	$(INSTALL_DATA) $(srcdir)/*.xpm $(DESTDIR)$(icondir)

uninstall:
	rm -rf $(bindir)/wmbattery $(man1dir)/wmbattery.1 $(icondir)

dist:
	@test -d $(PACKAGE_NAME)-$(PACKAGE_VERSION) \
	  && rm -fr $(PACKAGE_NAME)-$(PACKAGE_VERSION) || :
	@$(INSTALL) -d $(PACKAGE_NAME)-$(PACKAGE_VERSION)
	@$(INSTALL) -d $(PACKAGE_NAME)-$(PACKAGE_VERSION)/autoconf
	@find . -type f \
	  ! -name autogen ! -name configure ! -name .gitignore \
	  ! -name config.status ! -name config.cache ! -name config.log \
	  ! -name config.h ! -name Makefile \
	  ! -name $(PACKAGE_TARNAME)-$(PACKAGE_VERSION).tar.gz \
	  ! -path './autoconf/*' \
	  ! -path './autom4te.cache/*' \
	  ! -path './$(PACKAGE_NAME)-$(PACKAGE_VERSION)/*' \
	  -exec $(INSTALL_DATA) '{}' $(PACKAGE_NAME)-$(PACKAGE_VERSION) \;
	@$(INSTALL_PROGRAM) autogen configure $(PACKAGE_NAME)-$(PACKAGE_VERSION)
	@$(INSTALL_PROGRAM) autoconf/install-sh $(PACKAGE_NAME)-$(PACKAGE_VERSION)/autoconf
	@tar cf - $(PACKAGE_NAME)-$(PACKAGE_VERSION) \
	  | gzip >$(PACKAGE_TARNAME)-$(PACKAGE_VERSION).tar.gz
	@rm -fr $(PACKAGE_NAME)-$(PACKAGE_VERSION)

OBJS=wmbattery.o acpi.o sonypi.o

ifdef USE_HAL
CPPFLAGS += -DHAL
CFLAGS += @hal_CFLAGS@
LIBS += @hal_LIBS@
OBJS += simplehal.o
simplehal.o: simplehal.c
	$(CC) $(CPPFLAGS) $(CFLAGS) -c simplehal.c -o simplehal.o
endif

ifdef USE_UPOWER
CPPFLAGS += -DUPOWER
CFLAGS += @upower_CFLAGS@
LIBS += @upower_LIBS@
OBJS += upower.o
upower.o: upower.c
	$(CC) $(CPPFLAGS) $(CFLAGS) -c upower.c -o upower.o
endif

ifdef USE_ENVSYS
CPPFLAGS += -DENVSYS
LIBS += -lprop
OBJS += envsys.o
envsys.o: envsys.c
	$(CC) $(CPPFLAGS) $(CFLAGS) -c envsys.c -o envsys.o
endif

wmbattery: $(OBJS)
	$(CC) -o wmbattery $(LDFLAGS) $(OBJS) $(LIBS)

wmbattery.o: wmbattery.c wmbattery.h
