#-------------------------------------------------------------------
#
#  Makefile for "upsd"
#
#  make all     = Make upsd
#  make install = Make all, then copy to install dirs
#
#  $Id: Makefile,v 2.1 1998/05/26 23:04:25 bobh Exp bobh $
#-------------------------------------------------------------------

BINDIR=/sbin
MANDIR=/usr/man/man8

CC=gcc
LD=gcc
#CFLAGS=-g -Wall -DDEBUG
CFLAGS=-Wall -O2
LDFLAGS=

#  Change this to reflect where your init requires the power status 
#  file to be.  Some Linux systems want it in /var/run/powerstatus.

PWRSTAT=-DPWRSTAT="\"/etc/powerstatus\""
UPSSTAT=-DUPSSTAT="\"/etc/upstatus\""

#  No user-serviceable parts below here
#-------------------------------------------------------------------
DISTLVL=2.0
REVLEVL=b1
DISTVER=upsd-$(DISTLVL)$(REVLEVL)
VER=-DVERSION="\"v$(DISTLVL)$(REVLEVL)\""

OBJS=common.o net.o upsd.o ups.o
DIST=$(DISTVER)/README $(DISTVER)/COPYING $(DISTVER)/Makefile \
     $(DISTVER)/upsd $(DISTVER)/upsd.halt $(DISTVER)/upsd.init \
     $(DISTVER)/*.8 $(DISTVER)/*.c $(DISTVER)/*.h \
     $(DISTVER)/rc.upsd $(DISTVER)/upsdummy $(DISTVER)/Changes.txt \
     $(DISTVER)/*.lsm

all: makeall

ifeq (.depend,$(wildcard .depend))
include .depend
makeall: upsd
else
makeall: depend upsd
endif
	strip upsd

depend dep: 
	$(CC) -M *.c > .depend;

clean:
	rm $(OBJS)
	rm .depend

realclean: clean
	rm upsd

dist: 
	cd ..; tar cfz $(DISTVER).tgz $(DIST)

install: makeall
	cp upsd $(BINDIR)
	chmod 755 $(BINDIR)/upsd
	cp upsd.8 $(MANDIR)
	chmod 644 $(MANDIR)/upsd.8
	cp rc.upsd.8 $(MANDIR)
	chmod 644 $(MANDIR)/rc.upsd.8

upsd : $(OBJS)
	$(LD) $(LDFLAGS) $(OBJS) -o $@

.c.o:
	$(CC) $(DEBUG) $(CFLAGS) $(PWRSTAT) $(UPSSTAT) $(VER) -c $< -o $@
