#!/usr/bin/make -f
#
# This file is part of the battery-stats package.
# Copyright (C) 2002 Karl E. Jrgensen <karl@jorgensen.com> 
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

SHELL = /bin/sh

INSTALL = install
INSTALL_PROGRAM = $(INSTALL)
INSTALL_DATA = $(INSTALL) --mode 644

prefix = /usr/local
exec_prefix = $(prefix)
bindir = $(exec_prefix)/bin
sbindir = $(exec_prefix)/sbin
libdir = $(exec_prefix)/lib
logdir = /var/log
sysconfdir = $(prefix)/etc
mandir = $(prefix)/share/man
man1dir = $(mandir)/man1
man5dir = $(mandir)/man5
man8dir = $(mandir)/man8

# Defaults for CFLAGS and LDFLAGS. These are handy for development
# Callers are welcome to override it
CFLAGS = -g3
LDFLAGS = -g3

# Allow the caller to play with variables as they wish
ALL_CFLAGS = $(CFLAGS)
ALL_LDLIBS = -lapm $(LDLIBS)

.PHONY : all
all : battery-stats-collector

battery-stats-collector : battery-stats-collector.o

battery-stats-collector.o : battery-stats-collector.c

.PHONY : clean
clean : 
	rm -f battery-stats-collector.o
	rm -f battery-stats-collector

.PHONY : distclean
distclean : clean

.PHONY : mostlyclean
mostlyclean : clean

.PHONY : maintainer-clean
maintainer-clean : clean

.PHONY : install
install : all installdirs
	$(INSTALL_PROGRAM) battery-stats-collector $(DESTDIR)$(sbindir)/battery-stats-collector
	$(INSTALL_DATA) battery-stats-collector.8 $(DESTDIR)$(man8dir)/battery-stats-collector.8
	$(INSTALL_PROGRAM) battery-graph $(DESTDIR)$(bindir)/battery-graph
	$(INSTALL_DATA) battery-graph.1 $(DESTDIR)$(man1dir)/battery-graph.1
	$(INSTALL_PROGRAM) battery-log $(DESTDIR)$(bindir)/battery-log
	$(INSTALL_DATA) battery-log.1 $(DESTDIR)$(man1dir)/battery-log.1
	$(INSTALL_DATA) battery-stats.5 $(DESTDIR)$(man5dir)/battery-stats.5
	$(INSTALL_DATA) graph-setup $(DESTDIR)$(libdir)/battery-stats/graph-setup
	$(INSTALL_DATA) default.config $(DESTDIR)$(sysconfdir)/battery-stats.conf

.PHONY : install-strip
install-strip :
	$(MAKE) INSTALL_PROGRAM='$(INSTALL_PROGRAM) -s' install

# Should only be used internally
.PHONY : installdirs
installdirs : mkinstalldirs
	./mkinstalldirs $(DESTDIR)$(sbindir) $(DESTDIR)$(bindir)
	./mkinstalldirs $(DESTDIR)$(logdir)
	./mkinstalldirs $(DESTDIR)$(libdir)/battery-stats
	./mkinstalldirs $(DESTDIR)$(man1dir)
	./mkinstalldirs $(DESTDIR)$(man5dir)
	./mkinstalldirs $(DESTDIR)$(man8dir)
	./mkinstalldirs $(DESTDIR)$(sysconfdir)

.PHONY : uninstall
uninstall :
	rm -f $(DESTDIR)$(sbindir)/battery-stats-collector

%.o : %.c
	$(CC) -c $(CPPFLAGS) $(ALL_CFLAGS) $<
    
%: %.o
	$(LINK.o) $^ $(LOADLIBES) $(ALL_LDLIBS) -o $@
