###############################################################################
#  Makefile for wbuild

###############################################################################
#  At run-time, wbuild reads a file that contains a
#  description of the intrinsic classes. The full path
#  name of that file is compiled in.

INITFILE = `pwd`/wbuild.cfg

###############################################################################
#  Debug flags: -g, -O, -s,...

COMPFLAGS = -O2

###############################################################################
#  If you use varargs.h instead of stdarg.h, add -DUSE_VARARGS
#  This is what I use for HP-UX:
#  CFLAGS = -DINITFILE=\"$(INITFILE)\" -Aa -D_HPUX_SOURCE $(COMPFLAGS)

CFLAGS = -DINITFILE=\"$(INITFILE)\" -DUSE_VARARGS $(COMPFLAGS)

###############################################################################
#  Where do you want wbuild to be installed by `make install install.man'?

DEST = $(HOME)/bin
MANDIR = $(HOME)/Man/man1

###############################################################################
#  The install command

INSTALL = /etc/install

###############################################################################
#  If you use flex instead of lex, define the following
#  (It doesn't seem to work with lex, I don't know why)

LEX = flex
LFLAGS = -s

###############################################################################
#  If you use bison instead of yacc, define the following

YACC = bison -y
YFLAGS = -d -t

###############################################################################
#  Should need no change below this


EXTHDRS	      =

HDRS	      = debug.e \
		generate.e \
		parse.tab.h \
		util.e \
		y.tab.h

LD	      = cc

LDFLAGS	      = $(COMPFLAGS)

LIBS	      = -lfl

LINTLIBS      =

LINTFLAGS     = -u $(CFLAGS)

MAKEFILE      = Makefile

OBJS	      = debug.o \
		generate.o \
		parse.o \
		scan.o \
		util.o \
		wbuild.o

PRINT	      = pr

PRINTFLAGS    =

LP	      = lp

LPFLAGS       = 

PROGRAM       = wbuild

SHELL	      = /bin/sh

SRCS	      = debug.web \
		generate.web \
		parse.y \
		scan.l \
		types.web \
		util.web \
		wbuild.web


# This is for cproto. If you want to use it, check the flags and
# uncomment the inference rule below.

CPROTOFLAGS   =	 -e -f4 -v -D__STDC__=1
SUFFIX	      =	.e:h .h:h
.SUFFIXES: .e
#.c.e:;		cproto $(CPROTOFLAGS) $*.c >$*.e



all:		$(PROGRAM)

$(PROGRAM):     $(OBJS) $(LIBS) $(MAKEFILE)
		@echo "Linking $(PROGRAM) ..."
		$(LD) $(LDFLAGS) $(OBJS) -o $(PROGRAM) $(LIBS)
		@echo "done"

clean:;		@rm -f $(OBJS) core

clobber:;	@rm -f $(OBJS) $(PROGRAM) core tags

depend:;	@mkmf -f $(MAKEFILE) ROOT=$(ROOT)

echo:;		@echo $(HDRS) $(SRCS)

-1:;		@ctags -wx $(HDRS) $(SRCS)

install:	$(PROGRAM)
		@echo Installing $(PROGRAM) in $(DEST)
		@-strip $(PROGRAM)
		@if [ $(DEST) != . ]; then \
		(rm -f $(DEST)/$(PROGRAM); $(INSTALL) -f $(DEST) $(PROGRAM)); fi

lint:		$(LINTLIBS) $(SRCS) $(HDRS) $(EXTHDRS) $(SRCS:.web=.c)
		lint $(LINTFLAGS) $(LINTLIBS) $(SRCS) $(SRCS:.web=.c)

print:;		@$(PRINT) $(PRINTFLAGS) $(HDRS) $(SRCS) | $(LP) $(LPFLAGS)

tags:           $(HDRS) $(SRCS); @ctags $(HDRS) $(SRCS)

update:		$(DEST)/$(PROGRAM)

touch:;		@touch $(SRCS) $(HDRS)

$(DEST)/$(PROGRAM): $(SRCS) $(LIBS) $(HDRS) $(EXTHDRS)
		@$(MAKE) -f $(MAKEFILE) ROOT=$(ROOT) DEST=$(DEST) install

install.man:	wbuild.1
		cp wbuild.1 $(MANDIR)

###
generate.o: types.c util.e debug.e
parse.o: types.c debug.e util.e
scan.o: types.c y.tab.h util.e
wbuild.o: types.c util.e generate.e
