#
# Makefile (powerd)
#
# Copyright 1995   Alessandro Rubini
#
####
#
# If the following line is commented, compilation will optimize,
# otherwise, it will use "-g -Wall", and will print more msgs while
# running. However "disabled=y debug=y" should be enough to test things out.
#DEBUG = t

INSTALL = install -c
INSTALLBIN = $(INSTALL) -m 755 --strip
INSTALLCFG = $(INSTALL) -m 644

ifndef PREFIX
  PREFIX =
endif

BINDIR = $(PREFIX)/sbin
CFGDIR = $(PREFIX)/etc

ifdef DEBUG
  CFLAGS = -g -DDEBUG -Wall -DPREFIX=\"$(PREFIX)\"
else
  CFLAGS = -O3 -fomit-frame-pointer -DPREFIX=\"$(PREFIX)\"
endif



TARGET = powerd
CONFIG = powerd.conf


# force make depend
ifneq (.depend,$(wildcard .depend))
all: depend
endif

all: check $(TARGET) setserialbits

static: $(TARGET).static

$(TARGET).static: $(TARGET).o
	rm -f $@
	$(CC) -static $(CFLAGS) $^ -o $@

check:
	@if [ `uname` != Linux ]; then \
	  echo "" ;\
	  echo "**** This package can compile only under Linux."; \
	  echo "**** Please read the docs (after \"make -C doc\") "; \
	  echo "" ;\
	  exit 1; fi

#$(TARGET).8: README
#    ./manpager $^


############## misc targets

install: all
	$(INSTALLBIN) $(TARGET)     $(BINDIR)
	@if [ -f $(CFGDIR)/$(CONFIG) ]; then \
		echo "Warning: $(CFGDIR)/$(CONFIG) exists: not replaced"; \
	else \
		$(INSTALLCFG) $(CONFIG)     $(CFGDIR); \
	fi


terse:
	rm -f *~ */*~ 

clean: terse
	rm -f .depend TAGS
	rm -f $(TARGET) $(TARGET).static setserialbits core *.o

tar:
	n=`basename \`pwd\``; cd ..; tar cvf - $$n | gzip > $$n.tar.gz

depend dep:
	gcc -MM *.c > .depend

DEPEND DEP:
	gcc -M *.c > .depend


distrib: clean tar

ifeq (.depend,$(wildcard .depend))
include .depend
endif







