# Makefile for mailleds-0.9-beta
CC = gcc
CFLAGS = -c -O2 
#CFLAGS = -c -O2 -g -Wall 
LDFLAGS = 
LN = ln -sf

#LIBS = 
LIBS = -L/usr/X11R6/lib/ -lX11

USE_X=yes
#USE_X=no

# -DPARALELL_SUPPORT will compile support for leds driven off
#	a bank connected to a port, like the one found in led-stat.txt
#
# -DDEBUG removes the call to fork(), making mailleds easier to debug.
#
#DEFINES = -DDEBUG -DPARALLEL_SUPPORT 

DEFINES = -DPARALLEL_SUPPORT 
BASEDIR = /usr/local
MANDIR = $(BASEDIR)/man/man1
BINDIR = $(BASEDIR)/bin
#XBINDIR is just for the xmailleds symlink
XBINDIR = /usr/X11R6/bin

INSTALLMAN = install -m 0644 
INSTALLBIN = install -o root -g bin

# probably no editing needed below here.

DIST		= mailleds
VERMAJ		= 0
VERMIN		= 93
VERSION		= $(VERMAJ).$(VERMIN)

ifeq ($(USE_X), yes)
	XDEFS=-DX_SUPPORT
endif

OBJS	= xmalloc.o mailleds.o mailfile.o leds.o tty.o pid.o X.o

.c.o: 
	$(CC) $(CFLAGS) $(DEFINES) $(XDEFS) $< -DVERSION=\"$(VERSION)\"

mailleds: $(OBJS)
	$(CC) $(LDFLAGS) $(OBJS) -o mailleds $(LIBS)

all: mailleds
	
clean:
	rm -f *.o mailleds

install_man:
	$(INSTALLMAN) mailleds.1 $(MANDIR)
	
install_bin:
	$(INSTALLBIN) -m 4755 mailleds $(BINDIR)
ifeq ($(USE_X), yes)
	$(LN) mailleds $(XBINDIR)/xmailleds
endif

install: mailleds install_man install_bin

# To let the author make a distribution.
LSMFILE		= $(DIST)-$(VERSION).lsm
DISTDIR		= $(DIST)-$(VERSION)
DISTFILE	= $(DIST)-$(VERSION).tar.gz
DISTFILES	= mailleds.c tty.c leds.c mailfile.c xmalloc.c pid.c \
		  mailleds.h port.h config.h led-stat.txt portato.c.diff X.c \
		  README $(LSMFILE) COPYING HISTORY $(DIST).1 INSTALL TODO Makefile

$(LSMFILE): FORCE
	VER=$(VERSION); \
	DATE=`date "+%d%b%y"|tr '[a-z]' '[A-Z]'`; \
	sed -e "s/VER/$$VER/g;s/DATE/$$DATE/g" $(DIST).lsm.in > $(LSMFILE)

FORCE:

veryclean: clean
	rm -f $(DIST)-$(VERSION).tar.gz

chmod:
	chmod a+r *

# Warning: distclean removes the lsm-file, which can not be
# regenerated without the lsm.in-file, which is not part of the package.
distclean: veryclean
	rm -f $(LSMFILE)

dist: $(LSMFILE) chmod
	mkdir $(DISTDIR)
	chmod a+rx $(DISTDIR)
	ln $(DISTFILES) $(DISTDIR)
	tar -cvzf $(DISTFILE) $(DISTDIR)
	chmod a+r $(DISTFILE)
	rm -rf $(DISTDIR)

X.o: X.c
leds.o: leds.c config.h mailleds.h port.h
mailfile.o: mailfile.c config.h mailleds.h
mailleds.o: mailleds.c config.h mailleds.h
pid.o: pid.c config.h mailleds.h
setled.o: setled.c port.h
tty.o: tty.c config.h mailleds.h
xmalloc.o: xmalloc.c
