
# This is the makefile for the server and the clients of the
# C-Browsing and Analysis Toolkit for C, version 0.1f

DEBUG = -g 
CCFLAGS = -aux-brs -I/usr/local/include
# -DNO_STRERROR  if your libc does not have the strerror-function,
#                use this define to take the built in function
#                in intrface.c
# -DCALLTREE_DEBUG

LIBS=-lncurses
CC=cc


all:    brs_collect brs_server brs_client brs_calltree debug_msg \
	brs_sendcmd brs_cleanup	brs_extract brs_f_list

.c.o:
	$(CC) -c $(CCFLAGS) $(DEBUG) $<

brs_server.c:   brs_server.lex
	flex -d brs_server.lex
	mv lex.yy.c brs_server.c

brs_server.o:   brs_server.c hash.h c-bat.h intrface.c
	cp intrface.c intrface_tmp.c
	$(CC) -c -DBRS_SERVER=1 $(CCFLAGS) $(DEBUG) intrface_tmp.c
	$(CC) -c -DBRS_SERVER=1 $(CCFLAGS) $(DEBUG) brs_server.c

brs_server:             brs_server.o hash.o brs_collect
	$(CC) -o brs_server $(CCFLAGS) $(DEBUG) brs_server.o hash.o intrface_tmp.o
	./brs_collect -o brs_server  brs_server.o hash.o intrface_tmp.o

hash.o:         hash.c hash.h
	$(CC) -c $(CCFLAGS) $(DEBUG) hash.c

intrface.o:	intrface.c c-bat.h
	$(CC) -c $(CCFLAGS) $(DEBUG) intrface.c

clients.o:      clients.c clients.h hash.h c-bat.h
	$(CC) -c $(CCFLAGS) $(DEBUG) clients.c

brs_client.o:   brs_client.c clients.h c-bat.h
	$(CC) -c $(CCFLAGS) $(DEBUG) brs_client.c

brs_client:     brs_client.o clients.o intrface.o brs_collect
	$(CC) -o brs_client $(CCFLAGS) $(DEBUG) brs_client.o \
	         intrface.o clients.o $(LIBS)
	./brs_collect -o brs_client  brs_client.o hash.o \
	         intrface.o clients.o

brs_calltree.o:   brs_calltree.c clients.h hash.h c-bat.h
	$(CC) -c $(CCFLAGS) $(DEBUG) brs_calltree.c

brs_calltree:	brs_calltree.o clients.o hash.o intrface.o brs_collect
	$(CC) -o brs_calltree $(CCFLAGS) $(DEBUG) brs_calltree.o hash.o \
	         intrface.o clients.o
	./brs_collect -o brs_calltree  brs_calltree.o hash.o \
	         intrface.o clients.o

debug_msg.o:	debug_msg.c  c-bat.h
	$(CC) -c $(CCFLAGS) $(DEBUG) debug_msg.c

debug_msg:	debug_msg.o intrface.o
	$(CC) -o debug_msg $(CCFLAGS) $(DEBUG) debug_msg.o intrface.o

brs_sendcmd.o:	brs_sendcmd.c  c-bat.h
	$(CC) -c $(CCFLAGS) $(DEBUG) brs_sendcmd.c

brs_sendcmd:	brs_sendcmd.o intrface.o
	$(CC) -o brs_sendcmd $(CCFLAGS) $(DEBUG) brs_sendcmd.o intrface.o

brs_cleanup.o:	brs_cleanup.c  c-bat.h
	$(CC) -c $(CCFLAGS) $(DEBUG) brs_cleanup.c

brs_cleanup:	brs_cleanup.o intrface.o
	$(CC) -o brs_cleanup $(CCFLAGS) $(DEBUG) brs_cleanup.o intrface.o

brs_extract.c:   brs_extract.lex
	flex -d brs_extract.lex
	mv lex.yy.c brs_extract.c

brs_extract.o:   brs_extract.c
	$(CC) -c -DSTAND_ALONE $(CCFLAGS) $(DEBUG) brs_extract.c

brs_extract:	brs_extract.o brs_collect
	$(CC) -o brs_extract $(CCFLAGS) $(DEBUG) brs_extract.o
	./brs_collect -o brs_extract  brs_extract.o

brs_cut.c:   brs_extract.lex
	flex brs_extract.lex
	mv lex.yy.c brs_cut.c

brs_cut.o:   brs_cut.c
	$(CC) -c $(CCFLAGS) $(DEBUG) brs_cut.c

brs_collect.c:   brs_collect.lex
	flex brs_collect.lex
	mv lex.yy.c brs_collect.c

brs_collect.o:   brs_collect.c
	$(CC) -c $(CCFLAGS) $(DEBUG) brs_collect.c

brs_collect:	brs_collect.o hash.o
	$(CC) -o brs_collect $(CCFLAGS) $(DEBUG) brs_collect.o hash.o

brs_f_list.o:   brs_f_list.c
	$(CC) -c $(CCFLAGS) $(DEBUG) brs_f_list.c

brs_f_list:	brs_f_list.o hash.o brs_cut.o
	$(CC) -o brs_f_list $(CCFLAGS) $(DEBUG) brs_f_list.o hash.o brs_cut.o \
	clients.o intrface.o

clean:  
	rm -f *.o
	rm -f *.brs
	rm -f *.brp
	rm -f *.brc
	rm -f *.bri
	rm -f brs_server.c
	rm -f brs_extract.c
	rm -f brs_cut.c
	rm -f brs_collect.c
	rm -f strip_line.c
	rm -f intrface_tmp.c
	rm -f brs_calltree
	rm -f brs_server
	rm -f brs_client
	rm -f debug_msg
	rm -f brs_sendcmd
	rm -f brs_cleanup
	rm -f brs_extract
	rm -f brs_collect
