#MAKEFILE -
#5 filters for extracting a list of declarations from a C source file;
#	delete: comments; 
#		(uncomment.l)
#	filter with cpp: replace #defines; execute #ifdef control statements;
#		(cdeclist1.l pre-processes, cdeclist2.l post-processes)
#	delete: function {bodies}; initializations (= ....;);
#		(cdeclist3.l)
#	reformat: to one-line declarations; and a bit more;
#		(cdeclist4.l)
#output should be suitable for:
#	making /*LINTLIBRARY*/, massaging with grep, awk..., etc;
#all filters read stdin, write stdout;
#probably need some adaptation for new ANSI standard;
#
#also 2 filters (identlist and identlist1) that prepare a C source
#file for making a word list or index of identifiers; please don't 
#flame me if the word list misses a few identifiers or includes a few 
#non-existent ones -- I make no great claim for it -- and it assumes,
#I am sure, an idiosyncratic style (mine).
#
#John Rupley
# uucp: ..{cmcl2 | hao!ncar!noao}!arizona!rupley!local
# internet: rupley!local@megaron.arizona.edu
# (H) 30 Calle Belleza, Tucson AZ 85716 - (602) 325-4533
# (O) Dept. Biochemistry, Univ. Arizona, Tucson AZ 85721 - (602) 621-3929

OPT=

dummy:
	@echo please supply a target

all:	uncomment cdeclist1 cdeclist2 cdeclist3 cdeclist4 identlist identlist1

#remove comments
uncomment:	uncomment.l
	lex -v uncomment.l
	$(CC) lex.yy.c $(CFLAGS) -ll $(LDFLAGS) -o uncomment


#remove comments and quoted strings etc
identlist:	identlist.l
	lex -v identlist.l
	$(CC) lex.yy.c $(CFLAGS) -ll $(LDFLAGS) -o identlist

#remove upper-case words and numbers
identlist1:	identlist1.l
	lex -v identlist1.l
	$(CC) lex.yy.c $(CFLAGS) -ll $(LDFLAGS) -o identlist1

#prepare C source file for cpp processing
cdeclist1:	cdeclist1.l
	lex -v cdeclist1.l
	$(CC) lex.yy.c $(CFLAGS) -ll $(LDFLAGS) -o cdeclist1

#remove additions associated with cpp processing
cdeclist2:	cdeclist2.l
	lex -v cdeclist2.l
	$(CC) lex.yy.c $(CFLAGS) -ll $(LDFLAGS) -o cdeclist2

#remove function {bodies}, put in appropriate { return (n); }
cdeclist3:	cdeclist3.l
	lex -v cdeclist3.l
	$(CC) lex.yy.c $(CFLAGS) -ll $(LDFLAGS) -o cdeclist3

#one-line declarations;remove initializatons;beautify a little
cdeclist4:	cdeclist4.l
	lex -v cdeclist4.l
	$(CC) lex.yy.c $(OPT) $(CFLAGS) -ll $(LDFLAGS) -o cdeclist4 

SHARLIST=	\
	README\
	Makefile\
	cdeclist.1\
	uncomment.l\
	cdeclist1.l\
	cdeclist2.l\
	cdeclist3.l\
	cdeclist4.l\
	mk_cdeclist\
	identlist.l\
	identlist1.l\
	mk_identlist

mkshar:
	shar -f cdeclist -c $(SHARLIST)

TESTC="please define TESTC=C_src_file on make line"
#HDIR=hard_wired_path_for_headers
#CDIR=hard_wired_path_for_sources
HDIR="."
CDIR="."

#test making a declaration list
testc:		all
	cat $(CDIR)/$(TESTC)|uncomment|cdeclist1 >temp1
	/lib/cpp -P -C -I$(HDIR) temp1 >temp2
	cat temp2|cdeclist2 >temp3
	echo /*$(TESTC)*/ >LL$(TESTC)
	echo >>LL$(TESTC)
	cat temp3|cdeclist3 >>LL$(TESTC)

test2c:		cdeclist2
	cat temp2|cdeclist2 >temp3

test3c:		cdeclist3
	echo /*$(TESTC)*/ >LL$(TESTC)
	echo >>LL$(TESTC)
	cat temp3|cdeclist3 >>LL$(TESTC)

TESTLL=LL$(TESTC)

testll:		cdeclist4
	cat $(TESTLL)|cdeclist4 >LL$(TESTLL)


#test making a word list
testw:		identlist identlist1
	cat $(TESTC)|identlist|identlist1	|\
		tr -s " 	" "\012\012"|sort|uniq	>ZZZZ$(TESTC)


#careful!
testlint:
	lint -uvx -Ml -otemp LL$(TESTLL)
	cp llib-ltemp.ln /usr/lib/large
	lint -uvx -Ml -ltemp $(TESTC)

testall: testc testll testw		#testlint 
