# Remove -lXext if you don't have it; it's only used for button shapes which
# default to rectangle anyway.
CC	= cc
CFLAGS	= -O
LDFLAGS	= -lXaw -lXmu -lXt -lX11 -lXext


# o Define SIGNALRETURNSINT if your signal(3) returns int not void.
# o Define FORKRETURNSSHORT/FORKRETURNSLONG/FORKRETURNSPID_T if your fork(2)
#   returns short/long/pid_t not int.
# o Define USEFLOCK or USELOCKF to use flock(2) or lockf(3) to lock files,
#   rather than fcntl(2).
# o Define USELSEEK to use lseek(2) to move to the end of the file, rather than
#   fseek(3).
# o Define USERENAME to use rename(2) to rename file names (otherwise
#   un/link(2)).
# o Define USEGETHOSTNAME or USEUNAME (or neither if you don't have
#   gethostname(2) or uname(2)) to get the name of your system.
# o Define USEGETPWUID to use getpwuid(2) and getuid(2) to get the user name
#   and home directory on your system.  Note that if you want to use this
#   method to get the user's home directory, but another method to get the user
#   name, this symbol must still be defined.
# o Define USEGETLOGIN to use getlogin(3) to get the user name (note that this
#   may not work if xalarm is invoked from a pseudo terminal).
# o Define USECUSERID to use cuserid(3) to get the user name.

DEFINES = -DUSERENAME -DUSEGETHOSTNAME -DUSEGETPWUID


# My, is this complex!  These are the usual places for installation.
PREFIX	= 
MANSUFX	= n
X11BIN	= $(PREFIX)/usr/bin/X11
X11MAN	= $(PREFIX)/usr/man/man$(MANSUFX)
X11AD	= $(PREFIX)/usr/lib/X11/app-defaults


# Bits and bobs.
# How we find commands.  Use WHICH, LOCATE or FIND.
WHICH	= WHICH
MADE	= test -f
STRIP	= /bin/strip
CP	= /bin/cp
RM	= /bin/rm -f
TAGS	= etags -t
LINT	= lint -hbxca


OBJS	= alarm.o when.o warnings.o times.o dates.o file.o fns.o xalarm.o
SRCS	= alarm.c when.c warnings.c times.c dates.c file.c fns.c xalarm.c

# If your make complains about the && conditional sequences, you may have to do
# them by hand or go hacking below...  The executables and man pages go in the
# same directories as xalarm do.

# The & variable tells a Sequent to do a parallel make, forking compilation
# processes.  Set this variable to whatever value you need for your parallel
# machine.  Or you could just use GNU make with "-j".

# If your make will not except this (ie. it is brain dead), try "make
# MADE=test" or "make config" (or both), then "make xalarm" if necessary.  The
# other solution is to use GNU make.

all: .config xalarm

xalarm: $& $(OBJS)
	$(CC) $(CFLAGS) -o xalarm $(OBJS) $(LDFLAGS)

.c.o:
	$(CC) -c $(CFLAGS) $(DEFINES) $<

install: all
	$(STRIP) xalarm
	$(CP) xalarm xmemo $(X11BIN)
	$(MADE) xfortune && $(CP) xfortune $(X11BIN)
	$(MADE) xyow && $(CP) xyow $(X11BIN)
	$(CP) XAlarm.ad $(X11AD)/XAlarm
	$(CP) XAlarm-color.ad $(X11AD)/XAlarm-color

install.man:
	$(CP) xalarm.man $(X11MAN)/xalarm.$(MANSUFX)
	$(MAKE) xmemo.man && $(CP) xmemo.man $(X11MAN)/xmemo.$(MANSUFX)
	$(MADE) xfortune && $(MAKE) xfortune.man && \
		$(CP) xfortune.man $(X11MAN)/xfortune.$(MANSUFX)
	$(MADE) xyow && $(MAKE) xyow.man && $(CP) xyow.man $(X11MAN)/xyow.$(MANSUFX)

xmemo.man xyow.man xfortune.man:
	echo ".so man$(MANSUFX)/xalarm.$(MANSUFX)" > $@
	

fns.h:
	@./config.1st -quick $(WHICH) fortune yow

tags:
	$(TAGS) $(SRCS)

clean:
	$(RM) $(OBJS) xalarm xfortune xyow fns.h .config core *~ #*

lint:
	$(LINT) $(SRCS)

# Make sure the resources are loaded so xalarm can be used before installed etc.
config:
	@./config.1st -quick $(WHICH) fortune yow
	@xrdb -merge XAlarm.ad
	@xrdb -merge XAlarm.ad+

.config::
	@-$(MADE) .config || make config

alarm.o:	xalarm.h patchlevel.h
when.o:		xalarm.h patchlevel.h dates.h
warnings.o:	xalarm.h patchlevel.h
times.o:	xalarm.h patchlevel.h dates.h
dates.o:	xalarm.h patchlevel.h dates.h
file.o:		xalarm.h patchlevel.h dates.h
fns.o:		xalarm.h patchlevel.h fns.h
xalarm.o:	xalarm.h patchlevel.h
