# Makefile for rpncalc - a rudimentary emulation of a HP28S
#
# $Id: Makefile,v 1.14 1997/12/27 19:33:33 david Exp david $

prefix = /usr/local
bindir = ${prefix}/bin
mandir = ${prefix}/man/man1

RM      = rm -f
CC      = gcc

VERSION	= $(shell expr "`head -1 debian/changelog`" : '[a-z]\+ (\([0-9.]\+\)-[0-9]\+).*')

DEFS	= -DVERSION=\"$(VERSION)\"

# Define -DHAVE_LIBREADLINE and -DHAVE_LIBHISTORY if you want readline and
# history support (strongly suggested) and have the readline/history libraries
# installed (most commercial Unices probably don't, though; Linux and FreeBSD
# almost certainly have them).
# -DHAVE_GETOPT_LONG if you want GNU-getopt (e.g. --version support),
# -DHAVE_POW2 and -DHAVE_POW10 if you're compiling under Linux libc5 and
# have the pow2 and pow10 functions in -lm
# -DHAVE_LDIV if you have ldiv() [almost certainly]

DEFS	+= -DHAVE_LIBREADLINE -DHAVE_LIBHISTORY -DHAVE_GETOPT_LONG -DHAVE_LDIV

CFLAGS  = -g -O2 -Wall -Wstrict-prototypes -Wmissing-prototypes -Wshadow\
  -Wpointer-arith -Wbad-function-cast -Wcast-qual -Wcast-align\
  -Wwrite-strings -Wmissing-declarations -Wnested-externs
LIBS    = -lm

#if defined(HAVE_LIBHISTORY)
LIBS   +=  -lhistory
#endif
#if defined(HAVE_LIBREADLINE)
LIBS   += -lreadline -lncurses
#endif
LDFLAGS =

BIN     = rpncalc
MAN     = $(BIN).1
MANTEMPL= $(MAN).sed
SRCS    = $(BIN).c cmds.c stack.c utils.c
OBJS	= $(SRCS:.c=.o)
HEADER  = $(SRCS:.c=.h)

all:	$(BIN) $(MAN)

$(MAN): $(MANTEMPL) proto.ed
	sed -e "s/\\\$$Date.*\\\$$/`date +'%B %-d, %Y'`"/g $(MANTEMPL) > $(MAN)
	ed -s - $(MAN) < proto.ed
	chmod 644 $(MAN)

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

$(BIN):	$(HEADER) $(SRCS) $(OBJS)
	$(CC) $(LDFLAGS) $(OBJS) -o $@ $(LIBS)

clean:
	-$(RM) *.o *~ *.bak \#*\# errors core* a.out TAGS tags gmon.out 

distclean: clean
	-$(RM) $(BIN) $(MAN)

realclean: distclean
	-rcsclean -u

install: 	$(MAN) $(BIN)
	install -d -g root -o root -m 755 $(bindir) $(mandir)
	install -s -g root -o root -m 755 $(BIN) $(bindir)
	install    -g root -o root -m 644 $(MAN) $(mandir)
