#-------------------------------------------------------------------
#
#  Makefile for "upsd"
#
#  make all     = Make upsd
#  make install = Make all, then copy to install dirs
#
#  $Id: Makefile,v 2.3 2000/06/08 15:33:00 mikr Exp mikr $
#-------------------------------------------------------------------

#BINDIR=/usr/local/bin
BINDIR=/sbin
CFGDIR=/etc
MANDIR=/usr/man/man8

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

# WARNING, socks only!
#  use an IP address rather than a 
# host name in libsocks5.conf to avoid
# permanent lockup on initialization due
# to the way the socks library handles
# failed proxy hostname resolution.
#
# define SOCKS5 to support socks5 firewall
# comment out to remove socks5 support
#SOCKS5=yes

ifdef SOCKS5
  CFLAGS=-Wall -O2 -include /usr/local/include/socks.h -DSOCKS
  LDFLAGS=-L/usr/local/lib -lsocks5
else
# for socks5 -- does not work
  CFLAGS=-Wall -O2
  LDFLAGS=
endif

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

CFGFILE=-DCFGFILE="\"/etc/upsd.conf\""
PWRSTAT=-DPWRSTAT="\"/etc/powerstatus\""
UPSSTAT=-DUPSSTAT="\"/etc/upstatus\""

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

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

all: makeall

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

depend dep: 
	$(CC) -M *.c $(CFLAGS) > .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
	cp upsd.conf $(CFGDIR)
	chmod 644 upsd.conf

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

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