######################################################################
# birthday. Reminder of birthdays and other events in the near future.
# $Id: Makefile,v 1.4 2005/09/02 19:33:18 andymort Exp $

OS=UNIX
#OS=DOS

# can override this on the commandline if req'd
DEBUG=
ifeq ($(OS),DOS)
OSCFLAGS=-w
else
OSCFLAGS=-Wall -Wstrict-prototypes
endif
CFLAGS=-O2 $(DEBUG) -D$(OS) $(OSCFLAGS)

# engine
ENGSRC=bdengine.c xmalloc.c

# OS-specific sources 
ifeq ($(OS),DOS)
OSSRC=alloca.c getopt.c
else
OSSRC=
endif

CMDSRC=birthday.c bdcal.c $(ENGSRC) $(OSSRC)
WINSRC=winbd.c $(ENGSRC) $(OSSRC)

ifeq ($(OS),DOS)
CMDOBJ=$(CMDSRC:.c=.obj)
WINOBJ=$(WINSRC:.c=.obj) bdwin.res
else
CMDOBJ=$(CMDSRC:.c=.o)
#WINOBJ=$(WINSRC:.c=.o)
endif

ifeq ($(OS),DOS)
birthday.exe: $(CMDOBJ)
	$(CC) $(LDFLAGS) $(CMDOBJ) -e $@

bdwin.res: bdwin.rc
	rc -r bdwin

bdwin.exe: $(WINOBJ)
	$(CC) $(LDFLAGS) $(WINOBJ) -e $@
	rc bdwin

else
birthday: $(CMDOBJ)
	$(CC) $(LDFLAGS) $(CMDOBJ) -o $@

# you can override this to use the new FHS locations.
SHARE=
#SHARE=/share

install: birthday birthday.man
	install -d $(DESTDIR)/usr/bin $(DESTDIR)/usr$(SHARE)/man/man1
	install -s birthday $(DESTDIR)/usr/bin/birthday
	install -m 0644 birthday.man $(DESTDIR)/usr$(SHARE)/man/man1/birthday.1

test: birthday
	sh runtest.sh -exec `pwd`/birthday test/*.t

clean:
	rm -f birthday *.o

VERSION := $(shell sed -ne '/^birthday/s/.*(\(.*\))/\1/gp' ChangeLog | head -1)
dist:
	ln -s . birthday-$(VERSION)
	tar cf - `grep / CVS/Entries | cut -f2 -d/ | sed "s;^;birthday-$(VERSION)/;"` | bzip2 -c > birthday-$(VERSION).tar.bz2
	rm birthday-$(VERSION)
endif

.PHONY: test
