#sccs	"@(#)lint:Makefile	1.5"

include $(MAKEINC)/Makepre.h

SUBDIRS=pcc
MIP = ./pcc
LINT = lint
LINT1 = $(USRLIB)/lint1
LINTLIBS = llib-lc.ln llib-port.ln llib-lm.ln 
LINTLIBSRC = llib-lc llib-port llib-lm
TMPDIR = /usr/tmp
LFLAGS = -s
#  -DBUG4 is necessary to turn off pcc debugging tools (these tools cannot
#   be used with the lint shell script since their output conflicts)
# LCFLAGS = -DLINT -I$(MIP) -I. -DBUG4
LCFLAGS = -DLINT -DBUG4
MFILES = macdefs $(MIP)/manifest $(MIP)/mfile1

#object files for the first and second passes
OFILES1 = trees.o pftn.o scan.o comm1.o messages.o optim.o xdefs.o cgram.o\
	lerror.o msgbuf.o lint.o
OFILES2 = lpass2.o lerror2.o messages.o msgbuf2.o

DEPENDLIST = \
	lerror.c \
	lerror2.c \
	lint.c \
	lmanifest \
	lpass2.c \
	msgbuf.c \
	msgbuf2.c

all: Makeincludes lint1 lint2 llib-lc.ln llib-port.ln llib-lm.ln

Makeincludes: $(DEPENDLIST)
	$(INCCMD) $(DEPENDLIST) | $(SORT) | $(FILTER) > Makeincludes
	$(MAKE)

includes: $(DEPENDLIST)
	$(INCCMD) $(DEPENDLIST) | $(SORT) | $(FILTER) > Makeincludes

#makes for the first pass of lint
lint1:	$(OFILES1) $(FRC) id.o
	$(CC) $(LFLAGS) -o lint1.mini $(OFILES1)
	$(LD) $(LFLAGS) $(SHAREDLIB) -o lint1 $(OFILES1) id.o

trees.o: $(MIP)/trees.c
	$(CC) $(CFLAGS) -c  $(MIP)/trees.c

pftn.o:	$(MIP)/pftn.c
	$(CC) $(CFLAGS) -c  $(MIP)/pftn.c

scan.o:	$(MIP)/scan.c
	$(CC) $(CFLAGS) -c  $(MIP)/scan.c

comm1.o: $(MIP)/comm1.c
	$(CC) $(CFLAGS) -c  $(MIP)/comm1.c

messages.o: $(MIP)/messages.c
	$(CC) $(CFLAGS) -c  $(MIP)/messages.c

optim.o: $(MIP)/optim.c
	$(CC) $(CFLAGS) -c  $(MIP)/optim.c

xdefs.o: $(MIP)/xdefs.c
	$(CC) $(CFLAGS) -c  $(MIP)/xdefs.c

cgram.c: $(MIP)/cgram.y
	yacc $(MIP)/cgram.y ; mv y.tab.c cgram.c

#makes for the lint libraries

llib-lc.ln:  llib-lc $(LINT1) $(FRC)
	$(CC) -E -C -Dlint llib-lc | $(LINT1) -vx -H$(TMPDIR)/hlint >llib-lc.ln 
	rm -f $(TMPDIR)/hlint

llib-port.ln:  llib-port $(LINT1) $(FRC)
	$(CC) -E -C -Dlint llib-port | $(LINT1) -vxp -H$(TMPDIR)/hlint >llib-port.ln
	rm -f $(TMPDIR)/hlint 

llib-lm.ln:  llib-lm $(LINT1) $(FRC)
	$(CC) -E -C -Dlint llib-lm | $(LINT1) -vx -H$(TMPDIR)/hlint >llib-lm.ln
	rm -f $(TMPDIR)/hlint 

#makes for the second pass of lint
lint2:	$(OFILES2) $(FRC) id.o
	$(CC) $(LFLAGS) -o lint2.mini $(OFILES2)
	$(LD) $(LFLAGS) $(SHAREDLIB) -o lint2 $(OFILES2) id.o

install:
	rm -f lint; ln lint.sh lint
	@for I in lint lint1 lint2 $(LINTLIBS) $(LINTLIBSRC) ; \
		do echo installing $$I...; \
		$(INSTALL) -i$(EXITFLAG) $$I $(INSDIR) $(PROTOFILE); done

clean:
	rm -f *.o cgram.c $(LINT) $(LINTLIBS)    

clobber: clean
	rm -f lint1 lint2 llib-lc.ln llib-port.ln llib-lm.ln lint id.c

id.c: lint.sl
	mkslid > id.c

populate: $(SUBDIRS)
	UNIT=`cat .unit`; export UNIT; \
	for D in $(SUBDIRS); \
	do (cd $$D; echo "$$UNIT/$$D" >.unit; echo "** $$D **:"; getunit); \
	done

$(SUBDIRS):
	mkdir $@

include Makeincludes
include $(MAKEINC)/Makepost.h
