# $Id: Makefile,v 1.11 1991/07/09 18:27:12 steve Exp $

ifndef MAKEINCDIR
  MAKEINCDIR	:= $(wildcard ~ldm/src)
endif

NAME		:= udape
VERSION_FILE	:= patchlevel.h

include $(MAKEINCDIR)/defs.gmk

#
# The sources in this directory:
#
CSRCS		:= lib.c parser.c scanner.c udunits.c

HSRCS		:= patchlevel.h scanner.h udunits.h

manuals		:= udunits.1src udunits.3src

MANIFEST	:= $(CSRCS) $(HSRCS) $(manuals) \
		    Makefile depend $(pic) parser.y udunits.dat

db_path		:= $(ETCDIR)/udunits.dat
DEFINES		:= -DDEFAULT_PATH='"$(db_path)"'
INCLUDES	:= -I../udposix/$(OS) -I../misc -I../udres
LIBOBJS		:= $(subst .c,.o,$(filter-out udunits.c,$(CSRCS)))
SA_OBJS		:= parser.o
LOADLIBES	:= -L.. -l$(NAME) -L$(LIBDIR) -l$(NAME) \
		    -L$(X11_LIBDIR) -lX11 -lm

all::		$(LIBOBJS)

ifeq (sunos_sharable, $(OS_NAME)_$(LIBTYPE))
  all::		$(addprefix $(pic)/, $(LIBOBJS))
endif

#
# The following yacc(1)-line generates 3 shift/reduce warning messages that 
# may safely be ignored.
#
parser.c:	parser.y
	$(YACC) $(YFLAGS) -d parser.y
	sed '/extern *char *\*malloc(), *\*realloc();/d' < y.tab.c > $@
	rm y.tab.c
	mv y.tab.h parser.h

udunits:	udunits.o
	$(CC) $(LDFLAGS) -o $@ $^ $(LOADLIBES)

saber:		$(CSRCS)
	#setopt ansi
	#setopt ccargs $(CFLAGS) -DYYDEBUG
	#setopt load_flags $(CFLAGS) -DYYDEBUG
	#unload all
	#load $(CFLAGS) -DYYDEBUG $(CSRCS) $(LOADLIBES) /usr/5lib/libc.a

debug:		$(debug)/$(LIBOBJS)

install:	$(BINDIR)/udunits \
		$(INCDIR)/udunits.h \
		$(db_path) \
		$(MANDIR)/man3/udunits.3 \
		$(MANDIR)/man1/udunits.1
      ifeq ($(MAKELEVEL),0)
	@echo 1>&2 "You must make \"$@\" from ../"
	@exit 1
      endif

udunits.1\
udunits.3:	udunits.%:	udunits.%src
	sed 's;###DEFAULT_PATH###;$(db_path);g' $< > $@

clean::
	rm -f udunits udunits.1 udunits.3

realclean::
	rm -f parser.c parser.h

include $(MAKEINCDIR)/rules.gmk
include depend
