# Makefile -- 
# Copyright 1996, 1997 Rickard E. Faith <faith@acm.org>
# Copyright 1999 Avery Pennarun <apenwarr@worldvisions.ca>
#
# 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, 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.,
# 675 Mass Ave, Cambridge, MA 02139, USA.
#
# $Id: Makefile,v 1.30 2001/11/25 22:46:16 apenwarr Exp $
#

VERSION=3.0.2

ifneq (,)
This makefile requires GNU Make.
endif

.SUFFIXES:

OBJS=apmlib.o
EXES=apm apmd xapm apmsleep
HEADERS=apm.h

PREFIX=/usr
MANDIR=${PREFIX}/man
APMD_PROXY_DIR=/etc

CC=gcc
CFLAGS=-O -g
XTRACFLAGS=-Wall -pipe -I. -I/usr/src/linux/include \
		-I/usr/src/linux-2.2/include -I /usr/src/linux-2.0/include \
		-DVERSION=\"$(VERSION)\" \
		-DAPMD_PROXY_NAME=\"$(APMD_PROXY_DIR)/apmd_proxy\"
LDFLAGS=
XTRALDFLAGS=-L. -lapm
XLDFLAGS=-L/usr/X11R6/lib
XLIBS=-lXaw -lXmu -lXt -lXext -lSM -lICE -lX11
LIB=libapm.a
RANLIB=ranlib

# Uncomment these lines for a production compile
#CFLAGS=-O3 -m486 -fomit-frame-pointer
#LDFLAGS=-s

all: $(EXES)

$(OBJS): $(HEADERS)

%.o: %.c
	$(CC) -c $(CPPFLAGS) $(CFLAGS) $(XTRACFLAGS) $<

%: %.o $(LIB)
	$(CC) -o $@ $< $(LDFLAGS) $(XTRALDFLAGS)

xapm.o: xapm.c
	$(CC) -c $(CPPFLAGS) $(CFLAGS) $(XTRACFLAGS) -DNARROWPROTO $<

apmsleep: apmsleep.o

xapm: xapm.o $(LIB)
	$(CC) -o $@ $< $(LDFLAGS) $(XTRALDFLAGS) $(XLDFLAGS) $(XLIBS)

libapm.a: $(OBJS)
	$(AR) $(ARFLAGS) $@ $(OBJS)
	$(RANLIB) $@

.PHONY:	ChangeLog
ChangeLog:
	-rm -f ChangeLog
	rcs2log > ChangeLog

install: $(EXES)
	[ -d ${PREFIX}/bin      ] || install -d ${PREFIX}/bin
	[ -d ${PREFIX}/sbin     ] || install -d ${PREFIX}/sbin
	[ -d ${MANDIR}/man1     ] || install -d ${MANDIR}/man1
	[ -d ${MANDIR}/fr/man1  ] || install -d ${MANDIR}/fr/man1
	[ -d ${MANDIR}/man8     ] || install -d ${MANDIR}/man8
	[ -d ${PREFIX}/lib      ] || install -d ${PREFIX}/lib
	[ -d ${PREFIX}/include  ] || install -d ${PREFIX}/include
	[ -d ${APMD_PROXY_DIR}  ] || install -d ${APMD_PROXY_DIR}
	install        apm             ${PREFIX}/bin
	install        on_ac_power     ${PREFIX}/bin
	install -m 644 apm.1           ${MANDIR}/man1
	install        apmd            ${PREFIX}/sbin
	install -b -Vt apmd_proxy      ${APMD_PROXY_DIR}
	install -m 644 apmd.8          ${MANDIR}/man8
	install        xapm            ${PREFIX}/bin
	install -m 644 xapm.1          ${MANDIR}/man1/xapm.1
	install        apmsleep	       ${PREFIX}/bin
	install -m 644 apmsleep.1      ${MANDIR}/man1
	install -m 644 apmsleep.1.fr   ${MANDIR}/fr/man1
	install -m 644 libapm.a        ${PREFIX}/lib
	install -m 644 apm.h           ${PREFIX}/include

.PHONY:	clean distclean
distclean clean:
	-rm -f *.o *.s *~ core a.out build-stamp $(LIB) $(EXES)
