CC          = gcc -pipe
CC_I        = -I.
CC_O        = -O2
CC_G        = -g
CC_W        = -Wall
CFLAGS      = $(CC_D) $(CC_I) $(CC_O) $(CC_G) $(CC_W)
FFLAGS 	    = # -d
RM          = rm -f
#############################################################################
prefix  =  /usr/local
BIN_EXE =  $(prefix)/bin
BIN_SCR =  $(prefix)/bin
LIB_A   =  $(prefix)/lib
LIB_SO  =  $(prefix)/lib
DOC_MAN =  $(prefix)/share/man
DOC_MISC=  $(prefix)/doc
CC_D    = -DINSTALL_PREFIX=\"$(LIB_A)\"
###########################################################################
.PHONY: all test check clean yclean

all:	dbctl dbctl-rex

.c.o:
	$(CC) $(CFLAGS) -g -c $<
 
lex.yy.c: token.l
	flex $(FFLAGS) -i token.l

config.tab.c config.tab.h: config.y
	bison -d -v config.y

dbctl: config.tab.o lex.yy.o dbctl.o hash.o
	$(CC) $(LDFLAGS) -o dbctl config.tab.o lex.yy.o dbctl.o hash.o $(LIBS)

dbctl-rex: dbctl-rex.c
	$(CC) $(CFLAGS) $(LDFLAGS) -o dbctl-rex dbctl-rex.c $(LIBS)

test-hier1: test-hier1.c
	$(CC) $(CFLAGS) $(LDFLAGS) -o test-hier1 test-hier1.c $(LIBS)

test-hier2: test-hier2.c
	$(CC) $(CFLAGS) $(LDFLAGS) -o test-hier2 test-hier2.c $(LIBS)

test-exec: test-exec.c
	$(CC) $(CFLAGS) $(LDFLAGS) -o test-exec test-exec.c $(LIBS)

test: test-hier1 test-hier2 test-exec

check:
	profile-gdb -expr test-hier1@work@n gdb-getnums test-hier1
	profile-gdb -L 3 test-hier1

clean:
	$(RM) dbctl dbctl-rex *.o *core* *.out out_log in_log test-hier[12]

yclean:	clean
	$(RM) $(TARGET) *.o core *.core *.out out_log in_log
	$(RM) config.tab.h config.tab.c lex.yy.c config.output

install:
	install -c -m 755 dbctl dbctl-rex $(BIN_EXE)
	install -c -m 644 gdbprof.dbctl gdbprof_prol.dbctl gdbprof_epil.dbctl \
                $(LIB_A)

uninstall:
	cd $(BIN_EXE) && $(RM) dbctl dbctl-rex
	cd $(LIB_A) && $(RM) gdbprof.dbctl gdbprof_prol.dbctl gdbprof_epil.dbctl
